Пример #1
0
 def test_verify_policy(self):
     with direct.PlacementDirect(CONF, latest_microversion=True) as client:
         for route, methods in handler.ROUTE_DECLARATIONS.items():
             if route in self.EXCEPTIONS:
                 continue
             for method in methods:
                 self._test_request_403(client, method, route)
Пример #2
0
    def test_microversion_handling(self):
        with direct.PlacementDirect(CONF) as client:
            # create parent
            parent_data = {
                'name': uuidsentinel.p_rp,
                'uuid': uuidsentinel.p_rp
            }
            resp = client.post('/resource_providers', json=parent_data)
            self.assertTrue(resp, resp.text)

            # attempt to create child
            data = {'name': 'child', 'parent_provider_uuid': uuidsentinel.p_rp}
            # no microversion, 400
            resp = client.post('/resource_providers', json=data)
            self.assertFalse(resp)
            self.assertEqual(400, resp.status_code)
            # low microversion, 400
            resp = client.post('/resource_providers',
                               json=data,
                               microversion='1.13')
            self.assertFalse(resp)
            self.assertEqual(400, resp.status_code)
            resp = client.post('/resource_providers',
                               json=data,
                               microversion='1.14')
            self.assertTrue(resp, resp.text)
Пример #3
0
 def test_reshape(self):
     alloc_data = jsonutils.dump_as_bytes({
         'allocations': {
             uuids.consumer: {
                 'allocations': {
                     uuids.rp: {
                         'resources': {
                             orc.VCPU: 1,
                         },
                     }
                 },
                 'project_id': uuids.project,
                 'user_id': uuids.user,
                 'consumer_generation': None,
                 'consumer_type': 'INSTANCE',
             }
         },
         'inventories': {
             uuids.rp: {
                 'inventories': {
                     orc.VCPU: {
                         'total': 5,
                     }
                 },
                 'resource_provider_generation': 1,
             }
         }
     })
     conf = self.conf_fixture.conf
     with direct.PlacementDirect(conf) as client:
         # Create allocations
         url = '/reshaper'
         resp = client.post(url, data=alloc_data, headers=self.headers)
         self.assertEqual(204, resp.status_code)
Пример #4
0
 def test_create_resource_provider(self):
     data = {'name': 'fake'}
     with direct.PlacementDirect(CONF) as client:
         resp = client.post('/resource_providers', json=data)
         self.assertTrue(resp)
         resp = client.get('/resource_providers')
         self.assertTrue(resp)
         data = resp.json()
         self.assertEqual(1, len(data['resource_providers']))
Пример #5
0
    def setUp(self):
        super(TestAllocationProjectCreateRace, self).setUp()

        # Create resource provider and inventory for tests
        conf = self.conf_fixture.conf
        rp_data = jsonutils.dump_as_bytes({
            'name': 'a provider',
            'uuid': uuids.rp,
        })
        inv_data = jsonutils.dump_as_bytes({
            'inventories': {
                orc.VCPU: {
                    'total': 5,
                }
            },
            'resource_provider_generation': 0,
        })
        self.headers = {
            'x-auth-token': 'admin',
            'content-type': 'application/json',
            'OpenStack-API-Version': 'placement 1.38',
        }
        with direct.PlacementDirect(conf) as client:
            # Create a resource provider
            url = '/resource_providers'
            resp = client.post(url, data=rp_data, headers=self.headers)
            self.assertEqual(200, resp.status_code)

            # Add inventory to the resource provider
            url = '/resource_providers/%s/inventories' % uuids.rp
            resp = client.put(url, data=inv_data, headers=self.headers)
            self.assertEqual(200, resp.status_code)

        # simulate that when the below allocation update call tries to fetch
        # the project it gets ProjectNotFound but at the same time a
        # "parallel" transaction creates the project, so the project creation
        # will fail
        real_get_project = project_obj.Project.get_by_external_id

        def fake_get_project(cls, ctx, external_id):
            if not hasattr(fake_get_project, 'called'):
                proj = project_obj.Project(ctx, external_id=external_id)
                proj.create()
                fake_get_project.called = True
                raise exception.ProjectNotFound(external_id)
            else:
                return real_get_project(ctx, external_id)

        self.useFixture(
            fixtures.MonkeyPatch(
                'placement.objects.project.Project.get_by_external_id',
                fake_get_project))
Пример #6
0
    def test_set_allocations_for_consumer(self):
        alloc_data = jsonutils.dump_as_bytes({
            'allocations': {
                uuids.rp: {
                    'resources': {
                        orc.VCPU: 1,
                    },
                }
            },
            'project_id': uuids.project,
            'user_id': uuids.user,
            'consumer_generation': None,
            'consumer_type': 'INSTANCE',
        })
        conf = self.conf_fixture.conf
        with direct.PlacementDirect(conf) as client:
            # Create allocations
            url = '/allocations/%s' % uuids.consumer
            resp = client.put(url, data=alloc_data, headers=self.headers)

            # https://storyboard.openstack.org/#!/story/2009159 The expected
            # behavior would be that the allocation update succeeds as the
            # transaction can fetch the Project created by a racing transaction
            self.assertEqual(204, resp.status_code)
Пример #7
0
 def test_json_validation_happens(self):
     data = {'name': 'fake', 'cowsay': 'moo'}
     with direct.PlacementDirect(CONF) as client:
         resp = client.post('/resource_providers', json=data)
         self.assertFalse(resp)
         self.assertEqual(400, resp.status_code)
Пример #8
0
 def test_get_resource_providers(self):
     with direct.PlacementDirect(CONF) as client:
         resp = client.get('/resource_providers')
         self.assertTrue(resp)
         data = resp.json()
         self.assertEqual([], data['resource_providers'])
Пример #9
0
 def test_direct_is_there(self):
     with direct.PlacementDirect(CONF) as client:
         resp = client.get('/')
         self.assertTrue(resp)
         data = resp.json()
         self.assertEqual('v1.0', data['versions'][0]['id'])