This file is indexed.

/usr/lib/python2.7/dist-packages/magnumclient/tests/v1/test_bays.py is in python-magnumclient 2.0.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# Copyright 2015 IBM Corp.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import copy

import testtools
from testtools import matchers

from magnumclient import exceptions
from magnumclient.tests import utils
from magnumclient.v1 import bays


BAY1 = {'id': 123,
        'uuid': '66666666-7777-8888-9999-000000000001',
        'name': 'bay1',
        'baymodel_id': 'e74c40e0-d825-11e2-a28f-0800200c9a61',
        'stack_id': '5d12f6fd-a196-4bf0-ae4c-1f639a523a51',
        'api_address': '172.17.2.1',
        'node_addresses': ['172.17.2.3'],
        'node_count': 2,
        'master_count': 1,
        }
BAY2 = {'id': 124,
        'uuid': '66666666-7777-8888-9999-000000000002',
        'name': 'bay2',
        'baymodel_id': 'e74c40e0-d825-11e2-a28f-0800200c9a62',
        'stack_id': '5d12f6fd-a196-4bf0-ae4c-1f639a523a52',
        'api_address': '172.17.2.2',
        'node_addresses': ['172.17.2.4'],
        'node_count': 2,
        'master_count': 1,
        }

CREATE_BAY = copy.deepcopy(BAY1)
del CREATE_BAY['id']
del CREATE_BAY['uuid']
del CREATE_BAY['stack_id']
del CREATE_BAY['api_address']
del CREATE_BAY['node_addresses']

UPDATED_BAY = copy.deepcopy(BAY1)
NEW_NAME = 'newbay'
UPDATED_BAY['name'] = NEW_NAME

fake_responses = {
    '/v1/bays':
    {
        'GET': (
            {},
            {'bays': [BAY1, BAY2]},
        ),
        'POST': (
            {},
            CREATE_BAY,
        ),
    },
    '/v1/bays/%s' % BAY1['id']:
    {
        'GET': (
            {},
            BAY1
        ),
        'DELETE': (
            {},
            None,
        ),
        'PATCH': (
            {},
            UPDATED_BAY,
        ),
    },
    '/v1/bays/%s' % BAY1['name']:
    {
        'GET': (
            {},
            BAY1
        ),
        'DELETE': (
            {},
            None,
        ),
        'PATCH': (
            {},
            UPDATED_BAY,
        ),
    },
}


class BayManagerTest(testtools.TestCase):

    def setUp(self):
        super(BayManagerTest, self).setUp()
        self.api = utils.FakeAPI(fake_responses)
        self.mgr = bays.BayManager(self.api)

    def test_bay_list(self):
        bays = self.mgr.list()
        expect = [
            ('GET', '/v1/bays', {}, None),
        ]
        self.assertEqual(expect, self.api.calls)
        self.assertThat(bays, matchers.HasLength(2))

    def test_bay_show_by_id(self):
        bay = self.mgr.get(BAY1['id'])
        expect = [
            ('GET', '/v1/bays/%s' % BAY1['id'], {}, None)
        ]
        self.assertEqual(expect, self.api.calls)
        self.assertEqual(BAY1['name'], bay.name)
        self.assertEqual(BAY1['baymodel_id'], bay.baymodel_id)

    def test_bay_show_by_name(self):
        bay = self.mgr.get(BAY1['name'])
        expect = [
            ('GET', '/v1/bays/%s' % BAY1['name'], {}, None)
        ]
        self.assertEqual(expect, self.api.calls)
        self.assertEqual(BAY1['name'], bay.name)
        self.assertEqual(BAY1['baymodel_id'], bay.baymodel_id)

    def test_bay_create(self):
        bay = self.mgr.create(**CREATE_BAY)
        expect = [
            ('POST', '/v1/bays', {}, CREATE_BAY),
        ]
        self.assertEqual(expect, self.api.calls)
        self.assertTrue(bay)

    def test_bay_create_with_discovery_url(self):
        bay_with_discovery = dict()
        bay_with_discovery.update(CREATE_BAY)
        bay_with_discovery['discovery_url'] = 'discovery_url'
        bay = self.mgr.create(**bay_with_discovery)
        expect = [
            ('POST', '/v1/bays', {}, bay_with_discovery),
        ]
        self.assertEqual(expect, self.api.calls)
        self.assertTrue(bay)

    def test_bay_create_with_bay_create_timeout(self):
        bay_with_timeout = dict()
        bay_with_timeout.update(CREATE_BAY)
        bay_with_timeout['bay_create_timeout'] = '15'
        bay = self.mgr.create(**bay_with_timeout)
        expect = [
            ('POST', '/v1/bays', {}, bay_with_timeout),
        ]
        self.assertEqual(expect, self.api.calls)
        self.assertTrue(bay)

    def test_bay_create_fail(self):
        CREATE_BAY_FAIL = copy.deepcopy(CREATE_BAY)
        CREATE_BAY_FAIL["wrong_key"] = "wrong"
        self.assertRaisesRegexp(exceptions.InvalidAttribute,
                                ("Key must be in %s" %
                                 ','.join(bays.CREATION_ATTRIBUTES)),
                                self.mgr.create, **CREATE_BAY_FAIL)
        self.assertEqual([], self.api.calls)

    def test_bay_delete_by_id(self):
        bay = self.mgr.delete(BAY1['id'])
        expect = [
            ('DELETE', '/v1/bays/%s' % BAY1['id'], {}, None),
        ]
        self.assertEqual(expect, self.api.calls)
        self.assertIsNone(bay)

    def test_bay_delete_by_name(self):
        bay = self.mgr.delete(BAY1['name'])
        expect = [
            ('DELETE', '/v1/bays/%s' % BAY1['name'], {}, None),
        ]
        self.assertEqual(expect, self.api.calls)
        self.assertIsNone(bay)

    def test_bay_update(self):
        patch = {'op': 'replace',
                 'value': NEW_NAME,
                 'path': '/name'}
        bay = self.mgr.update(id=BAY1['id'], patch=patch)
        expect = [
            ('PATCH', '/v1/bays/%s' % BAY1['id'], {}, patch),
        ]
        self.assertEqual(expect, self.api.calls)
        self.assertEqual(NEW_NAME, bay.name)