Пример #1
0
    def test_update_registered_limit_duplicate(self):
        registered_limit_1 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume',
            default_limit=10,
            id=uuid.uuid4().hex)
        registered_limit_2 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_two['id'],
            resource_name='snapshot',
            default_limit=10,
            id=uuid.uuid4().hex)
        PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit_1, registered_limit_2])

        # Update registered_limit1 to registered_limit2
        update_ref = {
            'id': registered_limit_1['id'],
            'region_id': self.region_two['id'],
            'resource_name': 'snapshot'
        }
        self.assertRaises(exception.Conflict,
                          PROVIDERS.unified_limit_api.update_registered_limit,
                          registered_limit_1['id'], update_ref)
Пример #2
0
    def test_list_registered_limit_by_filter(self):
        registered_limit_1 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume',
            default_limit=10,
            id=uuid.uuid4().hex)
        registered_limit_2 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_two['id'],
            resource_name='snapshot',
            default_limit=10,
            id=uuid.uuid4().hex)
        PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit_1, registered_limit_2])

        hints = driver_hints.Hints()
        hints.add_filter('service_id', self.service_one['id'])
        res = PROVIDERS.unified_limit_api.list_registered_limits(hints)
        self.assertEqual(2, len(res))

        hints = driver_hints.Hints()
        hints.add_filter('region_id', self.region_one['id'])
        res = PROVIDERS.unified_limit_api.list_registered_limits(hints)
        self.assertEqual(1, len(res))

        hints = driver_hints.Hints()
        hints.add_filter('resource_name', 'backup')
        res = PROVIDERS.unified_limit_api.list_registered_limits(hints)
        self.assertEqual(0, len(res))
Пример #3
0
    def setUp(self):
        super(LimitsTestCase, self).setUp()

        # There is already a sample service and region created from
        # load_sample_data() but we're going to create another service and
        # region for specific testing purposes.
        response = self.post('/regions', body={'region': {}})
        self.region2 = response.json_body['region']
        self.region_id2 = self.region2['id']

        service_ref = {
            'service': {
                'name': uuid.uuid4().hex,
                'enabled': True,
                'type': 'type2'
            }
        }
        response = self.post('/services', body=service_ref)
        self.service2 = response.json_body['service']
        self.service_id2 = self.service2['id']

        ref1 = unit.new_registered_limit_ref(service_id=self.service_id,
                                             region_id=self.region_id,
                                             resource_name='volume')
        ref2 = unit.new_registered_limit_ref(service_id=self.service_id2,
                                             resource_name='snapshot')
        ref3 = unit.new_registered_limit_ref(service_id=self.service_id,
                                             region_id=self.region_id,
                                             resource_name='backup')
        self.post('/registered_limits',
                  body={'registered_limits': [ref1, ref2, ref3]},
                  expected_status=http_client.CREATED)
Пример #4
0
    def test_delete_registered_limit_when_reference_limit_exist(self):
        registered_limit_1 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume', default_limit=10, id=uuid.uuid4().hex)
        PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit_1])
        limit_1 = unit.new_limit_ref(
            project_id=self.tenant_bar['id'],
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume', resource_limit=10, id=uuid.uuid4().hex)
        PROVIDERS.unified_limit_api.create_limits([limit_1])

        self.assertRaises(exception.RegisteredLimitError,
                          PROVIDERS.unified_limit_api.delete_registered_limit,
                          registered_limit_1['id'])

        registered_limit_2 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            resource_name='volume', default_limit=10, id=uuid.uuid4().hex)
        PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit_2])
        limit_2 = unit.new_limit_ref(
            project_id=self.tenant_bar['id'],
            service_id=self.service_one['id'],
            resource_name='volume', resource_limit=10, id=uuid.uuid4().hex)
        PROVIDERS.unified_limit_api.create_limits([limit_2])

        self.assertRaises(exception.RegisteredLimitError,
                          PROVIDERS.unified_limit_api.delete_registered_limit,
                          registered_limit_2['id'])
Пример #5
0
    def setUp(self):
        super(SqlLimit, self).setUp()

        fixtures_to_cleanup = []
        for service in default_fixtures.SERVICES:
            service_id = service['id']
            rv = PROVIDERS.catalog_api.create_service(service_id, service)
            attrname = service['extra']['name']
            setattr(self, attrname, rv)
            fixtures_to_cleanup.append(attrname)
        for region in default_fixtures.REGIONS:
            rv = PROVIDERS.catalog_api.create_region(region)
            attrname = region['id']
            setattr(self, attrname, rv)
            fixtures_to_cleanup.append(attrname)
        self.addCleanup(self.cleanup_instance(*fixtures_to_cleanup))

        registered_limit_1 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume', default_limit=10, id=uuid.uuid4().hex)
        registered_limit_2 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_two['id'],
            resource_name='snapshot', default_limit=10, id=uuid.uuid4().hex)
        PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit_1, registered_limit_2])
Пример #6
0
    def setUp(self):
        super(SqlLimit, self).setUp()

        fixtures_to_cleanup = []
        for service in default_fixtures.SERVICES:
            service_id = service['id']
            rv = PROVIDERS.catalog_api.create_service(service_id, service)
            attrname = service['extra']['name']
            setattr(self, attrname, rv)
            fixtures_to_cleanup.append(attrname)
        for region in default_fixtures.REGIONS:
            rv = PROVIDERS.catalog_api.create_region(region)
            attrname = region['id']
            setattr(self, attrname, rv)
            fixtures_to_cleanup.append(attrname)
        self.addCleanup(self.cleanup_instance(*fixtures_to_cleanup))

        registered_limit_1 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume', default_limit=10, id=uuid.uuid4().hex)
        registered_limit_2 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_two['id'],
            resource_name='snapshot', default_limit=10, id=uuid.uuid4().hex)
        registered_limit_3 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_two['id'],
            resource_name='backup', default_limit=10, id=uuid.uuid4().hex)
        PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit_1, registered_limit_2, registered_limit_3])
Пример #7
0
    def test_update_registered_limit(self):
        # create two registered limits
        registered_limit_1 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume',
            default_limit=10,
            id=uuid.uuid4().hex)
        registered_limit_2 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='snapshot',
            default_limit=5,
            id=uuid.uuid4().hex)
        PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit_1, registered_limit_2])

        # update one, return all registered_limits
        registered_limit_update = {
            'id': registered_limit_1['id'],
            'region_id': 'region_two'
        }
        res = PROVIDERS.unified_limit_api.update_registered_limits(
            [registered_limit_update])
        for re in res:
            if re['id'] == registered_limit_1['id']:
                self.assertEqual('region_two', re['region_id'])
            if re['id'] == registered_limit_2['id']:
                self.assertDictEqual(registered_limit_2, re)
Пример #8
0
    def test_create_multi_registered_limits_duplicate(self):
        registered_limit_1 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume',
            default_limit=10,
            id=uuid.uuid4().hex)
        PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit_1])

        # Create with a duplicated one and a normal one. Both of them will not
        # be created.
        registered_limit_2 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume',
            default_limit=10,
            id=uuid.uuid4().hex)
        registered_limit_3 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='snapshot',
            default_limit=10,
            id=uuid.uuid4().hex)
        self.assertRaises(exception.Conflict,
                          PROVIDERS.unified_limit_api.create_registered_limits,
                          [registered_limit_2, registered_limit_3])

        reg_limits = PROVIDERS.unified_limit_api.list_registered_limits()
        self.assertEqual(1, len(reg_limits))
        self.assertEqual(registered_limit_1['id'], reg_limits[0]['id'])
Пример #9
0
    def test_delete_registered_limit(self):
        # create two registered limits
        registered_limit_1 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume',
            default_limit=10,
            id=uuid.uuid4().hex)
        registered_limit_2 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='snapshot',
            default_limit=5,
            id=uuid.uuid4().hex)
        PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit_1, registered_limit_2])

        # delete one
        PROVIDERS.unified_limit_api.delete_registered_limit(
            registered_limit_1['id'])
        self.assertRaises(exception.RegisteredLimitNotFound,
                          PROVIDERS.unified_limit_api.get_registered_limit,
                          registered_limit_1['id'])
        reg_limits = PROVIDERS.unified_limit_api.list_registered_limits()
        self.assertEqual(1, len(reg_limits))
        self.assertEqual(registered_limit_2['id'], reg_limits[0]['id'])
Пример #10
0
    def test_update_registered_limit(self):
        # create two registered limits
        registered_limit_1 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume', default_limit=10, id=uuid.uuid4().hex)
        registered_limit_2 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='snapshot', default_limit=5, id=uuid.uuid4().hex)
        PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit_1, registered_limit_2])

        expect_region = 'region_two'
        registered_limit_update = {'id': registered_limit_1['id'],
                                   'region_id': expect_region}
        res = PROVIDERS.unified_limit_api.update_registered_limit(
            registered_limit_1['id'], registered_limit_update)
        self.assertEqual(expect_region, res['region_id'])

        # 'id' can be omitted in the update body
        registered_limit_update = {'region_id': expect_region}
        res = PROVIDERS.unified_limit_api.update_registered_limit(
            registered_limit_2['id'], registered_limit_update)
        self.assertEqual(expect_region, res['region_id'])
Пример #11
0
    def test_create_registered_limit_crud(self):
        # create one, return it.
        registered_limit_1 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume',
            default_limit=10,
            id=uuid.uuid4().hex,
            description='test description')
        reg_limits = PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit_1])
        self.assertDictEqual(registered_limit_1, reg_limits[0])

        # create another two, return them.
        registered_limit_2 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='snapshot',
            default_limit=5,
            id=uuid.uuid4().hex)
        registered_limit_3 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='backup',
            default_limit=5,
            id=uuid.uuid4().hex)
        reg_limits = PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit_2, registered_limit_3])
        self.assertEqual(2, len(reg_limits))
        for reg_limit in reg_limits:
            if reg_limit['id'] == registered_limit_2['id']:
                self.assertDictEqual(registered_limit_2, reg_limit)
            if reg_limit['id'] == registered_limit_3['id']:
                self.assertDictEqual(registered_limit_3, reg_limit)
Пример #12
0
    def test_create_multi_registered_limits_duplicate(self):
        registered_limit_1 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume', default_limit=10, id=uuid.uuid4().hex)
        PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit_1])

        # Create with a duplicated one and a normal one. Both of them will not
        # be created.
        registered_limit_2 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume', default_limit=10, id=uuid.uuid4().hex)
        registered_limit_3 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='snapshot', default_limit=10, id=uuid.uuid4().hex)
        self.assertRaises(exception.Conflict,
                          PROVIDERS.unified_limit_api.create_registered_limits,
                          [registered_limit_2, registered_limit_3])

        reg_limits = PROVIDERS.unified_limit_api.list_registered_limits()
        self.assertEqual(1, len(reg_limits))
        self.assertEqual(registered_limit_1['id'], reg_limits[0]['id'])
Пример #13
0
    def test_update_registered_limit(self):
        # create two registered limits
        registered_limit_1 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume',
            default_limit=10,
            id=uuid.uuid4().hex)
        registered_limit_2 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='snapshot',
            default_limit=5,
            id=uuid.uuid4().hex)
        PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit_1, registered_limit_2])

        expect_region = 'region_two'
        registered_limit_update = {
            'id': registered_limit_1['id'],
            'region_id': expect_region
        }
        res = PROVIDERS.unified_limit_api.update_registered_limit(
            registered_limit_1['id'], registered_limit_update)
        self.assertEqual(expect_region, res['region_id'])

        # 'id' can be omitted in the update body
        registered_limit_update = {'region_id': expect_region}
        res = PROVIDERS.unified_limit_api.update_registered_limit(
            registered_limit_2['id'], registered_limit_update)
        self.assertEqual(expect_region, res['region_id'])
Пример #14
0
    def test_delete_registered_limit_when_reference_limit_exist(self):
        registered_limit_1 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume', default_limit=10, id=uuid.uuid4().hex)
        PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit_1])
        limit_1 = unit.new_limit_ref(
            project_id=self.project_bar['id'],
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume', resource_limit=10, id=uuid.uuid4().hex)
        PROVIDERS.unified_limit_api.create_limits([limit_1])

        self.assertRaises(exception.RegisteredLimitError,
                          PROVIDERS.unified_limit_api.delete_registered_limit,
                          registered_limit_1['id'])

        registered_limit_2 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            resource_name='volume', default_limit=10, id=uuid.uuid4().hex)
        PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit_2])
        limit_2 = unit.new_limit_ref(
            project_id=self.project_bar['id'],
            service_id=self.service_one['id'],
            resource_name='volume', resource_limit=10, id=uuid.uuid4().hex)
        PROVIDERS.unified_limit_api.create_limits([limit_2])

        self.assertRaises(exception.RegisteredLimitError,
                          PROVIDERS.unified_limit_api.delete_registered_limit,
                          registered_limit_2['id'])
Пример #15
0
    def test_list_registered_limit_by_limit(self):
        self.config_fixture.config(list_limit=1)
        # create two registered limits
        registered_limit_1 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume',
            default_limit=10,
            id=uuid.uuid4().hex)
        registered_limit_2 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='snapshot',
            default_limit=5,
            id=uuid.uuid4().hex)
        PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit_1, registered_limit_2])

        # list, limit is 1
        hints = driver_hints.Hints()
        reg_limits = PROVIDERS.unified_limit_api.list_registered_limits(
            hints=hints)
        self.assertEqual(1, len(reg_limits))

        if reg_limits[0]['id'] == registered_limit_1['id']:
            self.assertDictEqual(registered_limit_1, reg_limits[0])
        else:
            self.assertDictEqual(registered_limit_2, reg_limits[0])
Пример #16
0
    def setUp(self):
        super(LimitsTestCase, self).setUp()

        # There is already a sample service and region created from
        # load_sample_data() but we're going to create another service and
        # region for specific testing purposes.
        response = self.post('/regions', body={'region': {}})
        self.region2 = response.json_body['region']
        self.region_id2 = self.region2['id']

        service_ref = {'service': {
            'name': uuid.uuid4().hex,
            'enabled': True,
            'type': 'type2'}}
        response = self.post('/services', body=service_ref)
        self.service2 = response.json_body['service']
        self.service_id2 = self.service2['id']

        ref1 = unit.new_registered_limit_ref(service_id=self.service_id,
                                             region_id=self.region_id,
                                             resource_name='volume')
        ref2 = unit.new_registered_limit_ref(service_id=self.service_id2,
                                             resource_name='snapshot')
        r = self.post(
            '/registered_limits',
            body={'registered_limits': [ref1, ref2]},
            expected_status=http_client.CREATED)
        self.registered_limit1 = r.result['registered_limits'][0]
        self.registered_limit2 = r.result['registered_limits'][1]
Пример #17
0
    def test_list_registered_limit_by_filter(self):
        registered_limit_1 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume', default_limit=10, id=uuid.uuid4().hex)
        registered_limit_2 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_two['id'],
            resource_name='snapshot', default_limit=10, id=uuid.uuid4().hex)
        PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit_1, registered_limit_2])

        hints = driver_hints.Hints()
        hints.add_filter('service_id', self.service_one['id'])
        res = PROVIDERS.unified_limit_api.list_registered_limits(hints)
        self.assertEqual(2, len(res))

        hints = driver_hints.Hints()
        hints.add_filter('region_id', self.region_one['id'])
        res = PROVIDERS.unified_limit_api.list_registered_limits(hints)
        self.assertEqual(1, len(res))

        hints = driver_hints.Hints()
        hints.add_filter('resource_name', 'backup')
        res = PROVIDERS.unified_limit_api.list_registered_limits(hints)
        self.assertEqual(0, len(res))
Пример #18
0
    def test_create_registered_limit_crud(self):
        # create one, return it.
        registered_limit_1 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume', default_limit=10, id=uuid.uuid4().hex,
            description='test description')
        reg_limits = PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit_1])
        self.assertDictEqual(registered_limit_1, reg_limits[0])

        # create another two, return them.
        registered_limit_2 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='snapshot', default_limit=5, id=uuid.uuid4().hex)
        registered_limit_3 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='backup', default_limit=5, id=uuid.uuid4().hex)
        reg_limits = PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit_2, registered_limit_3])
        self.assertEqual(2, len(reg_limits))
        for reg_limit in reg_limits:
            if reg_limit['id'] == registered_limit_2['id']:
                self.assertDictEqual(registered_limit_2, reg_limit)
            if reg_limit['id'] == registered_limit_3['id']:
                self.assertDictEqual(registered_limit_3, reg_limit)
Пример #19
0
 def test_create_registered_limit_with_invalid_input(self):
     ref1 = unit.new_registered_limit_ref()
     ref2 = unit.new_registered_limit_ref(default_limit='not_int')
     ref3 = unit.new_registered_limit_ref(resource_name=123)
     ref4 = unit.new_registered_limit_ref(region_id='fake_region')
     for input_limit in [ref1, ref2, ref3, ref4]:
         self.post('/registered_limits',
                   body={'registered_limits': [input_limit]},
                   expected_status=http_client.BAD_REQUEST)
Пример #20
0
 def test_create_registered_limit_with_invalid_input(self):
     ref1 = unit.new_registered_limit_ref()
     ref2 = unit.new_registered_limit_ref(default_limit='not_int')
     ref3 = unit.new_registered_limit_ref(resource_name=123)
     ref4 = unit.new_registered_limit_ref(region_id='fake_region')
     for input_limit in [ref1, ref2, ref3, ref4]:
         self.post(
             '/registered_limits',
             body={'registered_limits': [input_limit]},
             expected_status=http_client.BAD_REQUEST)
Пример #21
0
    def test_list_registered_limit(self):
        r = self.get(
            '/registered_limits',
            expected_status=http_client.OK)
        self.assertEqual([], r.result.get('registered_limits'))

        ref1 = unit.new_registered_limit_ref(service_id=self.service_id,
                                             resource_name='test_resource',
                                             region_id=self.region_id)
        ref2 = unit.new_registered_limit_ref(service_id=self.service_id2,
                                             resource_name='test_resource',
                                             region_id=self.region_id2)
        r = self.post(
            '/registered_limits',
            body={'registered_limits': [ref1, ref2]},
            expected_status=http_client.CREATED)
        id1 = r.result['registered_limits'][0]['id']
        r = self.get(
            '/registered_limits',
            expected_status=http_client.OK)
        registered_limits = r.result['registered_limits']
        self.assertEqual(len(registered_limits), 2)
        for key in ['service_id', 'region_id', 'resource_name',
                    'default_limit']:
            if registered_limits[0]['id'] == id1:
                self.assertEqual(registered_limits[0][key], ref1[key])
                self.assertEqual(registered_limits[1][key], ref2[key])
                break
            self.assertEqual(registered_limits[1][key], ref1[key])
            self.assertEqual(registered_limits[0][key], ref2[key])

        r = self.get(
            '/registered_limits?service_id=%s' % self.service_id,
            expected_status=http_client.OK)
        registered_limits = r.result['registered_limits']
        self.assertEqual(len(registered_limits), 1)
        for key in ['service_id', 'region_id', 'resource_name',
                    'default_limit']:
            self.assertEqual(registered_limits[0][key], ref1[key])

        r = self.get(
            '/registered_limits?region_id=%s' % self.region_id2,
            expected_status=http_client.OK)
        registered_limits = r.result['registered_limits']
        self.assertEqual(len(registered_limits), 1)
        for key in ['service_id', 'region_id', 'resource_name',
                    'default_limit']:
            self.assertEqual(registered_limits[0][key], ref2[key])

        r = self.get(
            '/registered_limits?resource_name=test_resource',
            expected_status=http_client.OK)
        registered_limits = r.result['registered_limits']
        self.assertEqual(len(registered_limits), 2)
Пример #22
0
    def test_list_registered_limit(self):
        r = self.get(
            '/registered_limits',
            expected_status=http_client.OK)
        self.assertEqual([], r.result.get('registered_limits'))

        ref1 = unit.new_registered_limit_ref(service_id=self.service_id,
                                             resource_name='test_resource',
                                             region_id=self.region_id)
        ref2 = unit.new_registered_limit_ref(service_id=self.service_id2,
                                             resource_name='test_resource',
                                             region_id=self.region_id2)
        r = self.post(
            '/registered_limits',
            body={'registered_limits': [ref1, ref2]},
            expected_status=http_client.CREATED)
        id1 = r.result['registered_limits'][0]['id']
        r = self.get(
            '/registered_limits',
            expected_status=http_client.OK)
        registered_limits = r.result['registered_limits']
        self.assertEqual(len(registered_limits), 2)
        for key in ['service_id', 'region_id', 'resource_name',
                    'default_limit']:
            if registered_limits[0]['id'] == id1:
                self.assertEqual(registered_limits[0][key], ref1[key])
                self.assertEqual(registered_limits[1][key], ref2[key])
                break
            self.assertEqual(registered_limits[1][key], ref1[key])
            self.assertEqual(registered_limits[0][key], ref2[key])

        r = self.get(
            '/registered_limits?service_id=%s' % self.service_id,
            expected_status=http_client.OK)
        registered_limits = r.result['registered_limits']
        self.assertEqual(len(registered_limits), 1)
        for key in ['service_id', 'region_id', 'resource_name',
                    'default_limit']:
            self.assertEqual(registered_limits[0][key], ref1[key])

        r = self.get(
            '/registered_limits?region_id=%s' % self.region_id2,
            expected_status=http_client.OK)
        registered_limits = r.result['registered_limits']
        self.assertEqual(len(registered_limits), 1)
        for key in ['service_id', 'region_id', 'resource_name',
                    'default_limit']:
            self.assertEqual(registered_limits[0][key], ref2[key])

        r = self.get(
            '/registered_limits?resource_name=test_resource',
            expected_status=http_client.OK)
        registered_limits = r.result['registered_limits']
        self.assertEqual(len(registered_limits), 2)
Пример #23
0
 def test_create_multi_registered_limit(self):
     ref1 = unit.new_registered_limit_ref(service_id=self.service_id,
                                          region_id=self.region_id,
                                          resource_name='volume')
     ref2 = unit.new_registered_limit_ref(service_id=self.service_id,
                                          resource_name='snapshot')
     r = self.post('/registered_limits',
                   body={'registered_limits': [ref1, ref2]},
                   expected_status=http_client.CREATED)
     registered_limits = r.result['registered_limits']
     for key in ['service_id', 'resource_name', 'default_limit']:
         self.assertEqual(registered_limits[0][key], ref1[key])
         self.assertEqual(registered_limits[1][key], ref2[key])
     self.assertEqual(registered_limits[0]['region_id'], ref1['region_id'])
     self.assertIsNone(registered_limits[1].get('region_id'))
Пример #24
0
    def test_create_registered_limit_duplicate(self):
        registered_limit_1 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume', default_limit=10, id=uuid.uuid4().hex)
        PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit_1])

        registered_limit_2 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume', default_limit=10, id=uuid.uuid4().hex)
        self.assertRaises(exception.Conflict,
                          PROVIDERS.unified_limit_api.create_registered_limits,
                          [registered_limit_2])
Пример #25
0
    def test_create_registered_limit_duplicate(self):
        registered_limit_1 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume', default_limit=10, id=uuid.uuid4().hex)
        PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit_1])

        registered_limit_2 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume', default_limit=10, id=uuid.uuid4().hex)
        self.assertRaises(exception.Conflict,
                          PROVIDERS.unified_limit_api.create_registered_limits,
                          [registered_limit_2])
Пример #26
0
 def test_update_registered_limit_with_invalid_input(self):
     update_ref1 = unit.new_registered_limit_ref(id=uuid.uuid4().hex,
                                                 service_id='fake_id')
     update_ref2 = unit.new_registered_limit_ref(id=uuid.uuid4().hex,
                                                 default_limit='not_int')
     update_ref3 = unit.new_registered_limit_ref(id=uuid.uuid4().hex,
                                                 resource_name=123)
     update_ref4 = unit.new_registered_limit_ref(id=uuid.uuid4().hex,
                                                 region_id='fake_region')
     for input_limit in [
             update_ref1, update_ref2, update_ref3, update_ref4
     ]:
         self.put('/registered_limits',
                  body={'registered_limits': [input_limit]},
                  expected_status=http_client.BAD_REQUEST)
Пример #27
0
    def test_user_cannot_create_limits(self):
        service = PROVIDERS.catalog_api.create_service(uuid.uuid4().hex,
                                                       unit.new_service_ref())

        registered_limit = unit.new_registered_limit_ref(
            service_id=service['id'], id=uuid.uuid4().hex)
        registered_limits = (
            PROVIDERS.unified_limit_api.create_registered_limits(
                [registered_limit]))
        registered_limit = registered_limits[0]

        project = PROVIDERS.resource_api.create_project(
            uuid.uuid4().hex,
            unit.new_project_ref(domain_id=CONF.identity.default_domain_id))

        create = {
            'limits': [
                unit.new_limit_ref(
                    project_id=project['id'],
                    service_id=service['id'],
                    resource_name=registered_limit['resource_name'],
                    resource_limit=5)
            ]
        }

        with self.test_client() as c:
            c.post('/v3/limits',
                   json=create,
                   headers=self.headers,
                   expected_status_code=http.client.FORBIDDEN)
Пример #28
0
 def test_create_multi_registered_limit(self):
     ref1 = unit.new_registered_limit_ref(service_id=self.service_id,
                                          region_id=self.region_id,
                                          resource_name='volume')
     ref2 = unit.new_registered_limit_ref(service_id=self.service_id,
                                          resource_name='snapshot')
     r = self.post(
         '/registered_limits',
         body={'registered_limits': [ref1, ref2]},
         expected_status=http_client.CREATED)
     registered_limits = r.result['registered_limits']
     for key in ['service_id', 'resource_name', 'default_limit']:
         self.assertEqual(registered_limits[0][key], ref1[key])
         self.assertEqual(registered_limits[1][key], ref2[key])
     self.assertEqual(registered_limits[0]['region_id'], ref1['region_id'])
     self.assertIsNone(registered_limits[1].get('region_id'))
Пример #29
0
def _create_limit_and_dependencies():
    """Create a limit and its dependencies to test with."""
    service = PROVIDERS.catalog_api.create_service(
        uuid.uuid4().hex, unit.new_service_ref()
    )

    registered_limit = unit.new_registered_limit_ref(
        service_id=service['id'], id=uuid.uuid4().hex
    )
    registered_limits = (
        PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit]
        )
    )
    registered_limit = registered_limits[0]

    project = PROVIDERS.resource_api.create_project(
        uuid.uuid4().hex,
        unit.new_project_ref(domain_id=CONF.identity.default_domain_id)
    )

    limit = unit.new_limit_ref(
        project_id=project['id'], service_id=service['id'],
        resource_name=registered_limit['resource_name'],
        resource_limit=5, id=uuid.uuid4().hex
    )
    limits = PROVIDERS.unified_limit_api.create_limits([limit])
    return limits
Пример #30
0
    def test_update_registered_limit(self):
        ref = unit.new_registered_limit_ref(service_id=self.service_id,
                                            region_id=self.region_id,
                                            resource_name='volume',
                                            default_limit=10)
        r = self.post('/registered_limits',
                      body={'registered_limits': [ref]},
                      expected_status=http_client.CREATED)
        update_ref = {
            'service_id': self.service_id2,
            'region_id': self.region_id2,
            'resource_name': 'snapshot',
            'default_limit': 5,
            'description': 'test description'
        }
        r = self.patch('/registered_limits/%s' %
                       r.result['registered_limits'][0]['id'],
                       body={'registered_limit': update_ref},
                       expected_status=http_client.OK)
        new_registered_limits = r.result['registered_limit']

        self.assertEqual(new_registered_limits['service_id'], self.service_id2)
        self.assertEqual(new_registered_limits['region_id'], self.region_id2)
        self.assertEqual(new_registered_limits['resource_name'], 'snapshot')
        self.assertEqual(new_registered_limits['default_limit'], 5)
        self.assertEqual(new_registered_limits['description'],
                         'test description')
Пример #31
0
    def test_update_registered_limit_description(self):
        ref = unit.new_registered_limit_ref(service_id=self.service_id,
                                            region_id=self.region_id,
                                            resource_name='volume',
                                            default_limit=10)
        r = self.post('/registered_limits',
                      body={'registered_limits': [ref]},
                      expected_status=http_client.CREATED)
        update_ref = {
            'id': r.result['registered_limits'][0]['id'],
            'description': 'test description'
        }
        r = self.put('/registered_limits',
                     body={'registered_limits': [update_ref]},
                     expected_status=http_client.OK)
        new_registered_limits = r.result['registered_limits'][0]
        self.assertEqual(new_registered_limits['description'],
                         'test description')

        update_ref['description'] = ''
        r = self.put('/registered_limits',
                     body={'registered_limits': [update_ref]},
                     expected_status=http_client.OK)
        new_registered_limits = r.result['registered_limits'][0]
        self.assertEqual(new_registered_limits['description'], '')
Пример #32
0
    def test_update_registered_limit_with_referenced_limit(self):
        ref = unit.new_registered_limit_ref(service_id=self.service_id,
                                            region_id=self.region_id,
                                            resource_name='volume',
                                            default_limit=10)
        r = self.post('/registered_limits',
                      body={'registered_limits': [ref]},
                      expected_status=http_client.CREATED)

        ref = unit.new_limit_ref(project_id=self.project_id,
                                 service_id=self.service_id,
                                 region_id=self.region_id,
                                 resource_name='volume')
        self.post('/limits',
                  body={'limits': [ref]},
                  expected_status=http_client.CREATED)

        update_ref = {
            'service_id': self.service_id2,
            'region_id': self.region_id2,
            'resource_name': 'snapshot',
            'default_limit': 5
        }
        self.patch('/registered_limits/%s' %
                   r.result['registered_limits'][0]['id'],
                   body={'registered_limit': update_ref},
                   expected_status=http_client.FORBIDDEN)
Пример #33
0
    def test_user_cannot_create_limits(self):
        service = PROVIDERS.catalog_api.create_service(
            uuid.uuid4().hex, unit.new_service_ref()
        )

        registered_limit = unit.new_registered_limit_ref(
            service_id=service['id'], id=uuid.uuid4().hex
        )
        registered_limits = (
            PROVIDERS.unified_limit_api.create_registered_limits(
                [registered_limit]
            )
        )
        registered_limit = registered_limits[0]

        project = PROVIDERS.resource_api.create_project(
            uuid.uuid4().hex,
            unit.new_project_ref(domain_id=CONF.identity.default_domain_id)
        )

        create = {
            'limits': [
                unit.new_limit_ref(
                    project_id=project['id'], service_id=service['id'],
                    resource_name=registered_limit['resource_name'],
                    resource_limit=5
                )
            ]
        }

        with self.test_client() as c:
            c.post(
                '/v3/limits', json=create, headers=self.headers,
                expected_status_code=http_client.FORBIDDEN
            )
Пример #34
0
 def test_delete_registered_limit(self):
     ref1 = unit.new_registered_limit_ref(service_id=self.service_id,
                                          region_id=self.region_id)
     ref2 = unit.new_registered_limit_ref(service_id=self.service_id2,
                                          region_id=self.region_id2)
     r = self.post('/registered_limits',
                   body={'registered_limits': [ref1, ref2]},
                   expected_status=http_client.CREATED)
     id1 = r.result['registered_limits'][0]['id']
     self.delete('/registered_limits/%s' % id1,
                 expected_status=http_client.NO_CONTENT)
     self.delete('/registered_limits/fake_id',
                 expected_status=http_client.NOT_FOUND)
     r = self.get('/registered_limits', expected_status=http_client.OK)
     registered_limits = r.result['registered_limits']
     self.assertEqual(len(registered_limits), 1)
Пример #35
0
    def test_update_registered_limit_description(self):
        ref = unit.new_registered_limit_ref(service_id=self.service_id,
                                            region_id=self.region_id,
                                            resource_name='volume',
                                            default_limit=10)
        r = self.post(
            '/registered_limits',
            body={'registered_limits': [ref]},
            expected_status=http_client.CREATED)
        update_ref = {
            'id': r.result['registered_limits'][0]['id'],
            'description': 'test description'
        }
        r = self.put(
            '/registered_limits',
            body={'registered_limits': [update_ref]},
            expected_status=http_client.OK)
        new_registered_limits = r.result['registered_limits'][0]
        self.assertEqual(new_registered_limits['description'],
                         'test description')

        update_ref['description'] = ''
        r = self.put(
            '/registered_limits',
            body={'registered_limits': [update_ref]},
            expected_status=http_client.OK)
        new_registered_limits = r.result['registered_limits'][0]
        self.assertEqual(new_registered_limits['description'], '')
Пример #36
0
    def test_update_registered_limit_with_referenced_limit(self):
        ref = unit.new_registered_limit_ref(service_id=self.service_id,
                                            region_id=self.region_id,
                                            resource_name='volume',
                                            default_limit=10)
        r = self.post(
            '/registered_limits',
            body={'registered_limits': [ref]},
            expected_status=http_client.CREATED)

        ref = unit.new_limit_ref(project_id=self.project_id,
                                 service_id=self.service_id,
                                 region_id=self.region_id,
                                 resource_name='volume')
        self.post(
            '/limits',
            body={'limits': [ref]},
            expected_status=http_client.CREATED)

        update_ref = {
            'id': r.result['registered_limits'][0]['id'],
            'service_id': self.service_id2,
            'region_id': self.region_id2,
            'resource_name': 'snapshot',
            'default_limit': 5
        }
        self.put(
            '/registered_limits',
            body={'registered_limits': [update_ref]},
            expected_status=http_client.FORBIDDEN)
Пример #37
0
 def test_create_registered_limit_invalid_service(self):
     registered_limit_1 = unit.new_registered_limit_ref(
         service_id=uuid.uuid4().hex,
         region_id=self.region_one['id'],
         resource_name='volume', default_limit=10, id=uuid.uuid4().hex)
     self.assertRaises(exception.ValidationError,
                       PROVIDERS.unified_limit_api.create_registered_limits,
                       [registered_limit_1])
Пример #38
0
 def test_create_registered_limit_invalid_service(self):
     registered_limit_1 = unit.new_registered_limit_ref(
         service_id=uuid.uuid4().hex,
         region_id=self.region_one['id'],
         resource_name='volume', default_limit=10, id=uuid.uuid4().hex)
     self.assertRaises(exception.ValidationError,
                       PROVIDERS.unified_limit_api.create_registered_limits,
                       [registered_limit_1])
Пример #39
0
    def test_get_registered_limit(self):
        # create two registered limits
        registered_limit_1 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume', default_limit=10, id=uuid.uuid4().hex)
        registered_limit_2 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='snapshot', default_limit=5, id=uuid.uuid4().hex)
        PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit_1, registered_limit_2])

        # show one
        res = PROVIDERS.unified_limit_api.get_registered_limit(
            registered_limit_2['id'])
        self.assertDictEqual(registered_limit_2, res)
Пример #40
0
    def test_create_registered_limit_return_count(self):
        ref1 = unit.new_registered_limit_ref(service_id=self.service_id,
                                             region_id=self.region_id)
        r = self.post('/registered_limits',
                      body={'registered_limits': [ref1]},
                      expected_status=http_client.CREATED)
        registered_limits = r.result['registered_limits']
        self.assertEqual(1, len(registered_limits))

        ref2 = unit.new_registered_limit_ref(service_id=self.service_id2,
                                             region_id=self.region_id2)
        ref3 = unit.new_registered_limit_ref(service_id=self.service_id2)
        r = self.post('/registered_limits',
                      body={'registered_limits': [ref2, ref3]},
                      expected_status=http_client.CREATED)
        registered_limits = r.result['registered_limits']
        self.assertEqual(2, len(registered_limits))
Пример #41
0
    def test_get_registered_limit(self):
        # create two registered limits
        registered_limit_1 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume', default_limit=10, id=uuid.uuid4().hex)
        registered_limit_2 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='snapshot', default_limit=5, id=uuid.uuid4().hex)
        PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit_1, registered_limit_2])

        # show one
        res = PROVIDERS.unified_limit_api.get_registered_limit(
            registered_limit_2['id'])
        self.assertDictEqual(registered_limit_2, res)
Пример #42
0
 def test_update_registered_limit_with_invalid_input(self):
     update_ref1 = unit.new_registered_limit_ref(id=uuid.uuid4().hex,
                                                 service_id='fake_id')
     update_ref2 = unit.new_registered_limit_ref(id=uuid.uuid4().hex,
                                                 default_limit='not_int')
     update_ref3 = unit.new_registered_limit_ref(id=uuid.uuid4().hex,
                                                 resource_name=123)
     update_ref4 = unit.new_registered_limit_ref(id=uuid.uuid4().hex,
                                                 region_id='fake_region')
     update_ref5 = unit.new_registered_limit_ref(id=uuid.uuid4().hex,
                                                 description=123)
     for input_limit in [update_ref1, update_ref2, update_ref3,
                         update_ref4, update_ref5]:
         self.put(
             '/registered_limits',
             body={'registered_limits': [input_limit]},
             expected_status=http_client.BAD_REQUEST)
Пример #43
0
 def test_show_registered_limit(self):
     ref1 = unit.new_registered_limit_ref(service_id=self.service_id,
                                          region_id=self.region_id)
     ref2 = unit.new_registered_limit_ref(service_id=self.service_id2,
                                          region_id=self.region_id2)
     r = self.post('/registered_limits',
                   body={'registered_limits': [ref1, ref2]},
                   expected_status=http_client.CREATED)
     id1 = r.result['registered_limits'][0]['id']
     self.get('/registered_limits/fake_id',
              expected_status=http_client.NOT_FOUND)
     r = self.get('/registered_limits/%s' % id1,
                  expected_status=http_client.OK)
     registered_limit = r.result['registered_limit']
     for key in [
             'service_id', 'region_id', 'resource_name', 'default_limit'
     ]:
         self.assertEqual(registered_limit[key], ref1[key])
Пример #44
0
 def test_create_registered_limit_duplicate(self):
     ref = unit.new_registered_limit_ref(service_id=self.service_id,
                                         region_id=self.region_id)
     self.post('/registered_limits',
               body={'registered_limits': [ref]},
               expected_status=http_client.CREATED)
     self.post('/registered_limits',
               body={'registered_limits': [ref]},
               expected_status=http_client.CONFLICT)
Пример #45
0
    def test_list_registered_limits(self):
        # create two registered limits
        registered_limit_1 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume', default_limit=10, id=uuid.uuid4().hex)
        registered_limit_2 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='snapshot', default_limit=5, id=uuid.uuid4().hex)
        reg_limits_1 = PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit_1, registered_limit_2])

        # list
        reg_limits_2 = PROVIDERS.unified_limit_api.list_registered_limits()
        self.assertEqual(2, len(reg_limits_2))
        self.assertDictEqual(reg_limits_1[0], reg_limits_2[0])
        self.assertDictEqual(reg_limits_1[1], reg_limits_2[1])
Пример #46
0
 def test_create_registered_limit_without_description(self):
     registered_limit = unit.new_registered_limit_ref(
         service_id=self.service_one['id'],
         region_id=self.region_one['id'],
         resource_name='volume', default_limit=10, id=uuid.uuid4().hex)
     registered_limit.pop('description')
     res = PROVIDERS.unified_limit_api.create_registered_limits(
         [registered_limit])
     self.assertIsNone(res[0]['description'])
Пример #47
0
 def test_create_registered_limit_without_description(self):
     registered_limit = unit.new_registered_limit_ref(
         service_id=self.service_one['id'],
         region_id=self.region_one['id'],
         resource_name='volume', default_limit=10, id=uuid.uuid4().hex)
     registered_limit.pop('description')
     res = PROVIDERS.unified_limit_api.create_registered_limits(
         [registered_limit])
     self.assertIsNone(res[0]['description'])
Пример #48
0
 def test_create_registered_limit_without_region(self):
     ref = unit.new_registered_limit_ref(service_id=self.service_id)
     r = self.post('/registered_limits',
                   body={'registered_limits': [ref]},
                   expected_status=http_client.CREATED)
     registered_limits = r.result['registered_limits']
     for key in ['service_id', 'resource_name', 'default_limit']:
         self.assertEqual(registered_limits[0][key], ref[key])
     self.assertIsNone(registered_limits[0].get('region_id'))
Пример #49
0
    def test_list_registered_limits(self):
        # create two registered limits
        registered_limit_1 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume', default_limit=10, id=uuid.uuid4().hex)
        registered_limit_2 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='snapshot', default_limit=5, id=uuid.uuid4().hex)
        reg_limits_1 = PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit_1, registered_limit_2])

        # list
        reg_limits_2 = PROVIDERS.unified_limit_api.list_registered_limits()
        self.assertEqual(2, len(reg_limits_2))
        self.assertDictEqual(reg_limits_1[0], reg_limits_2[0])
        self.assertDictEqual(reg_limits_1[1], reg_limits_2[1])
Пример #50
0
    def test_create_registered_limit_return_count(self):
        ref1 = unit.new_registered_limit_ref(service_id=self.service_id,
                                             region_id=self.region_id)
        r = self.post(
            '/registered_limits',
            body={'registered_limits': [ref1]},
            expected_status=http_client.CREATED)
        registered_limits = r.result['registered_limits']
        self.assertEqual(1, len(registered_limits))

        ref2 = unit.new_registered_limit_ref(service_id=self.service_id2,
                                             region_id=self.region_id2)
        ref3 = unit.new_registered_limit_ref(service_id=self.service_id2)
        r = self.post(
            '/registered_limits',
            body={'registered_limits': [ref2, ref3]},
            expected_status=http_client.CREATED)
        registered_limits = r.result['registered_limits']
        self.assertEqual(2, len(registered_limits))
Пример #51
0
 def test_delete_registered_limit(self):
     ref1 = unit.new_registered_limit_ref(service_id=self.service_id,
                                          region_id=self.region_id)
     ref2 = unit.new_registered_limit_ref(service_id=self.service_id2,
                                          region_id=self.region_id2)
     r = self.post(
         '/registered_limits',
         body={'registered_limits': [ref1, ref2]},
         expected_status=http_client.CREATED)
     id1 = r.result['registered_limits'][0]['id']
     self.delete('/registered_limits/%s' % id1,
                 expected_status=http_client.NO_CONTENT)
     self.delete('/registered_limits/fake_id',
                 expected_status=http_client.NOT_FOUND)
     r = self.get(
         '/registered_limits',
         expected_status=http_client.OK)
     registered_limits = r.result['registered_limits']
     self.assertEqual(len(registered_limits), 1)
Пример #52
0
 def test_create_registered_limit_without_region(self):
     ref = unit.new_registered_limit_ref(service_id=self.service_id)
     r = self.post(
         '/registered_limits',
         body={'registered_limits': [ref]},
         expected_status=http_client.CREATED)
     registered_limits = r.result['registered_limits']
     for key in ['service_id', 'resource_name', 'default_limit']:
         self.assertEqual(registered_limits[0][key], ref[key])
     self.assertIsNone(registered_limits[0].get('region_id'))
Пример #53
0
    def test_update_registered_limit_duplicate(self):
        registered_limit_1 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume', default_limit=10, id=uuid.uuid4().hex)
        registered_limit_2 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_two['id'],
            resource_name='snapshot', default_limit=10, id=uuid.uuid4().hex)
        PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit_1, registered_limit_2])

        # Update registered_limit1 to registered_limit2
        update_ref = {'id': registered_limit_1['id'],
                      'region_id': self.region_two['id'],
                      'resource_name': 'snapshot'}
        self.assertRaises(exception.Conflict,
                          PROVIDERS.unified_limit_api.update_registered_limit,
                          registered_limit_1['id'], update_ref)
Пример #54
0
 def test_create_registered_limit_duplicate(self):
     ref = unit.new_registered_limit_ref(service_id=self.service_id,
                                         region_id=self.region_id)
     self.post(
         '/registered_limits',
         body={'registered_limits': [ref]},
         expected_status=http_client.CREATED)
     self.post(
         '/registered_limits',
         body={'registered_limits': [ref]},
         expected_status=http_client.CONFLICT)
Пример #55
0
    def test_user_can_create_registered_limits(self):
        service = PROVIDERS.catalog_api.create_service(uuid.uuid4().hex,
                                                       unit.new_service_ref())

        create = {
            'registered_limits':
            [unit.new_registered_limit_ref(service_id=service['id'])]
        }

        with self.test_client() as c:
            c.post('/v3/registered_limits', json=create, headers=self.headers)
Пример #56
0
 def test_show_registered_limit(self):
     ref1 = unit.new_registered_limit_ref(service_id=self.service_id,
                                          region_id=self.region_id)
     ref2 = unit.new_registered_limit_ref(service_id=self.service_id2,
                                          region_id=self.region_id2)
     r = self.post(
         '/registered_limits',
         body={'registered_limits': [ref1, ref2]},
         expected_status=http_client.CREATED)
     id1 = r.result['registered_limits'][0]['id']
     self.get(
         '/registered_limits/fake_id',
         expected_status=http_client.NOT_FOUND)
     r = self.get(
         '/registered_limits/%s' % id1,
         expected_status=http_client.OK)
     registered_limit = r.result['registered_limit']
     for key in ['service_id', 'region_id', 'resource_name',
                 'default_limit', 'description']:
         self.assertEqual(registered_limit[key], ref1[key])
Пример #57
0
    def test_delete_registered_limit(self):
        # create two registered limits
        registered_limit_1 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume', default_limit=10, id=uuid.uuid4().hex)
        registered_limit_2 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='snapshot', default_limit=5, id=uuid.uuid4().hex)
        PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit_1, registered_limit_2])

        # delete one
        PROVIDERS.unified_limit_api.delete_registered_limit(
            registered_limit_1['id'])
        self.assertRaises(exception.RegisteredLimitNotFound,
                          PROVIDERS.unified_limit_api.get_registered_limit,
                          registered_limit_1['id'])
        reg_limits = PROVIDERS.unified_limit_api.list_registered_limits()
        self.assertEqual(1, len(reg_limits))
        self.assertEqual(registered_limit_2['id'], reg_limits[0]['id'])
Пример #58
0
    def test_update_registered_limit(self):
        # create two registered limits
        registered_limit_1 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='volume', default_limit=10, id=uuid.uuid4().hex)
        registered_limit_2 = unit.new_registered_limit_ref(
            service_id=self.service_one['id'],
            region_id=self.region_one['id'],
            resource_name='snapshot', default_limit=5, id=uuid.uuid4().hex)
        PROVIDERS.unified_limit_api.create_registered_limits(
            [registered_limit_1, registered_limit_2])

        # update one, return all registered_limits
        registered_limit_update = {'id': registered_limit_1['id'],
                                   'region_id': 'region_two'}
        res = PROVIDERS.unified_limit_api.update_registered_limits(
            [registered_limit_update])
        for re in res:
            if re['id'] == registered_limit_1['id']:
                self.assertEqual('region_two', re['region_id'])
            if re['id'] == registered_limit_2['id']:
                self.assertDictEqual(registered_limit_2, re)
Пример #59
0
    def test_user_can_create_registered_limits(self):
        service = PROVIDERS.catalog_api.create_service(
            uuid.uuid4().hex, unit.new_service_ref()
        )

        create = {
            'registered_limits': [
                unit.new_registered_limit_ref(
                    service_id=service['id']
                )
            ]
        }

        with self.test_client() as c:
            c.post('/v3/registered_limits', json=create, headers=self.headers)
Пример #60
0
 def test_update_multi_registered_limit(self):
     ref = unit.new_registered_limit_ref(service_id=self.service_id,
                                         region_id=self.region_id,
                                         resource_name='volume',
                                         default_limit=10)
     ref2 = unit.new_registered_limit_ref(service_id=self.service_id,
                                          region_id=self.region_id,
                                          resource_name='snapshot',
                                          default_limit=10)
     r = self.post(
         '/registered_limits',
         body={'registered_limits': [ref, ref2]},
         expected_status=http_client.CREATED)
     update_ref = {
         'id': r.result['registered_limits'][0]['id'],
         'service_id': self.service_id2,
         'region_id': self.region_id2,
         'resource_name': 'snapshot',
         'default_limit': 5
     }
     update_ref2 = {
         'id': r.result['registered_limits'][1]['id'],
         'service_id': self.service_id2,
         'region_id': self.region_id2,
         'resource_name': 'volume',
         'default_limit': 5
     }
     r = self.put(
         '/registered_limits',
         body={'registered_limits': [update_ref, update_ref2]},
         expected_status=http_client.OK)
     new_registered_limits = r.result['registered_limits']
     for key in ['id', 'service_id', 'region_id', 'resource_name',
                 'default_limit']:
         self.assertEqual(new_registered_limits[0][key], update_ref[key])
         self.assertEqual(new_registered_limits[1][key], update_ref2[key])