diff --git a/zun/api/controllers/experimental/capsules.py b/zun/api/controllers/experimental/capsules.py index 194d4d5ea..7895366e9 100644 --- a/zun/api/controllers/experimental/capsules.py +++ b/zun/api/controllers/experimental/capsules.py @@ -87,8 +87,8 @@ class CapsuleController(base.Controller): def _get_capsules_collection(self, **kwargs): context = pecan.request.context - if utils.is_all_tenants(kwargs): - context.all_tenants = True + if utils.is_all_projects(kwargs): + context.all_projects = True limit = api_utils.validate_limit(kwargs.get('limit')) sort_dir = api_utils.validate_sort_dir(kwargs.get('sort_dir', 'asc')) sort_key = kwargs.get('sort_key', 'id') @@ -255,10 +255,10 @@ class CapsuleController(base.Controller): :param capsule_ident: UUID or Name of a capsule. """ context = pecan.request.context - if utils.is_all_tenants(kwargs): - policy.enforce(context, "capsule:delete_all_tenants", - action="capsule:delete_all_tenants") - context.all_tenants = True + if utils.is_all_projects(kwargs): + policy.enforce(context, "capsule:delete_all_projects", + action="capsule:delete_all_projects") + context.all_projects = True capsule = _get_capsule(capsule_ident) check_policy_on_capsule(capsule.as_dict(), "capsule:delete") compute_api = pecan.request.compute_api diff --git a/zun/api/controllers/v1/containers.py b/zun/api/controllers/v1/containers.py index 17ab6e848..fad769b7f 100644 --- a/zun/api/controllers/v1/containers.py +++ b/zun/api/controllers/v1/containers.py @@ -113,10 +113,10 @@ class ContainersController(base.Controller): def _get_containers_collection(self, **kwargs): context = pecan.request.context - if utils.is_all_tenants(kwargs): - policy.enforce(context, "container:get_all_all_tenants", - action="container:get_all_all_tenants") - context.all_tenants = True + if utils.is_all_projects(kwargs): + policy.enforce(context, "container:get_all_all_projects", + action="container:get_all_all_projects") + context.all_projects = True limit = api_utils.validate_limit(kwargs.get('limit')) sort_dir = api_utils.validate_sort_dir(kwargs.get('sort_dir', 'asc')) sort_key = kwargs.get('sort_key', 'id') @@ -152,10 +152,10 @@ class ContainersController(base.Controller): :param container_ident: UUID or name of a container. """ context = pecan.request.context - if utils.is_all_tenants(kwargs): - policy.enforce(context, "container:get_one_all_tenants", - action="container:get_one_all_tenants") - context.all_tenants = True + if utils.is_all_projects(kwargs): + policy.enforce(context, "container:get_one_all_projects", + action="container:get_one_all_projects") + context.all_projects = True container = utils.get_container(container_ident) check_policy_on_container(container.as_dict(), "container:get_one") compute_api = pecan.request.compute_api @@ -532,10 +532,10 @@ class ContainersController(base.Controller): :param force: If True, allow to force delete the container. """ context = pecan.request.context - if utils.is_all_tenants(kwargs): - policy.enforce(context, "container:delete_all_tenants", - action="container:delete_all_tenants") - context.all_tenants = True + if utils.is_all_projects(kwargs): + policy.enforce(context, "container:delete_all_projects", + action="container:delete_all_projects") + context.all_projects = True container = utils.get_container(container_ident) check_policy_on_container(container.as_dict(), "container:delete") try: diff --git a/zun/api/controllers/v1/schemas/containers.py b/zun/api/controllers/v1/schemas/containers.py index 4d65b3ffe..152dc803f 100644 --- a/zun/api/controllers/v1/schemas/containers.py +++ b/zun/api/controllers/v1/schemas/containers.py @@ -75,6 +75,7 @@ query_param_delete = { 'properties': { 'force': parameter_types.boolean_extended, 'all_tenants': parameter_types.boolean_extended, + 'all_projects': parameter_types.boolean_extended, 'stop': parameter_types.boolean_extended }, 'additionalProperties': False diff --git a/zun/common/context.py b/zun/common/context.py index 56bb00b13..8241dbd3e 100644 --- a/zun/common/context.py +++ b/zun/common/context.py @@ -29,7 +29,7 @@ class RequestContext(context.RequestContext): project_name=None, project_id=None, roles=None, is_admin=None, read_only=False, show_deleted=False, request_id=None, trust_id=None, auth_token_info=None, - all_tenants=False, password=None, timestamp=None, **kwargs): + all_projects=False, password=None, timestamp=None, **kwargs): """Stores several additional request parameters: :param domain_id: The ID of the domain. @@ -60,7 +60,7 @@ class RequestContext(context.RequestContext): self.auth_url = auth_url self.auth_token_info = auth_token_info self.trust_id = trust_id - self.all_tenants = all_tenants + self.all_projects = all_projects self.password = password if is_admin is None: self.is_admin = policy.check_is_admin(self) @@ -93,7 +93,7 @@ class RequestContext(context.RequestContext): 'trust_id': self.trust_id, 'auth_token_info': self.auth_token_info, 'password': self.password, - 'all_tenants': self.all_tenants, + 'all_projects': self.all_projects, 'timestamp': timeutils.strtime(self.timestamp) if hasattr(self, 'timestamp') else None }) @@ -155,7 +155,7 @@ def make_context(*args, **kwargs): return RequestContext(*args, **kwargs) -def get_admin_context(show_deleted=False, all_tenants=False): +def get_admin_context(show_deleted=False, all_projects=False): """Create an administrator context. :param show_deleted: if True, will show deleted items when query db @@ -164,7 +164,7 @@ def get_admin_context(show_deleted=False, all_tenants=False): project=None, is_admin=True, show_deleted=show_deleted, - all_tenants=all_tenants) + all_projects=all_projects) return context diff --git a/zun/common/policies/capsule.py b/zun/common/policies/capsule.py index c82fa6e79..623015a85 100644 --- a/zun/common/policies/capsule.py +++ b/zun/common/policies/capsule.py @@ -49,9 +49,9 @@ rules = [ # reference: # https://developer.openstack.org/api-ref/application-container/ policy.DocumentedRuleDefault( - name=CAPSULE % 'delete_all_tenants', + name=CAPSULE % 'delete_all_projects', check_str=base.RULE_ADMIN_API, - description='Delete a container in any tenant.', + description='Delete a container in any project.', operations=[ { 'path': '/v1/capsules/{capsule_ident}', @@ -77,9 +77,9 @@ rules = [ # reference: # https://developer.openstack.org/api-ref/application-container/ policy.DocumentedRuleDefault( - name=CAPSULE % 'get_one_all_tenants', + name=CAPSULE % 'get_one_all_projects', check_str=base.RULE_ADMIN_API, - description='Retrieve the details of a capsule in any tenant.', + description='Retrieve the details of a capsule in any project.', operations=[ { 'path': '/v1/capsules/{capsule_ident}', @@ -105,9 +105,9 @@ rules = [ # reference: # https://developer.openstack.org/api-ref/application-container/ policy.DocumentedRuleDefault( - name=CAPSULE % 'get_all_all_tenants', + name=CAPSULE % 'get_all_all_projects', check_str=base.RULE_ADMIN_API, - description='List all capsules across tenants.', + description='List all capsules across projects.', operations=[ { 'path': '/v1/capsules/', diff --git a/zun/common/policies/container.py b/zun/common/policies/container.py index 00f9503cc..bd3752f50 100644 --- a/zun/common/policies/container.py +++ b/zun/common/policies/container.py @@ -40,9 +40,9 @@ rules = [ ] ), policy.DocumentedRuleDefault( - name=CONTAINER % 'delete_all_tenants', + name=CONTAINER % 'delete_all_projects', check_str=base.RULE_ADMIN_API, - description='Delete a container from all tenants.', + description='Delete a container from all projects.', operations=[ { 'path': '/v1/containers/{container_ident}', @@ -73,10 +73,10 @@ rules = [ ] ), policy.DocumentedRuleDefault( - name=CONTAINER % 'get_one_all_tenants', + name=CONTAINER % 'get_one_all_projects', check_str=base.RULE_ADMIN_API, description=('Retrieve the details of a specific container from ' - 'all tenants.'), + 'all projects.'), operations=[ { 'path': '/v1/containers/{container_ident}', @@ -96,9 +96,9 @@ rules = [ ] ), policy.DocumentedRuleDefault( - name=CONTAINER % 'get_all_all_tenants', + name=CONTAINER % 'get_all_all_projects', check_str=base.RULE_ADMIN_API, - description='Retrieve the details of all containers across tenants.', + description='Retrieve the details of all containers across projects.', operations=[ { 'path': '/v1/containers', diff --git a/zun/common/rpc_service.py b/zun/common/rpc_service.py index 776103c4d..157ffb49d 100644 --- a/zun/common/rpc_service.py +++ b/zun/common/rpc_service.py @@ -66,11 +66,11 @@ class Service(service.Service): for endpoint in self.endpoints: if isinstance(endpoint, compute_manager.Manager): endpoint.init_containers( - context.get_admin_context(all_tenants=True)) + context.get_admin_context(all_projects=True)) self.tg.add_dynamic_timer( endpoint.run_periodic_tasks, periodic_interval_max=CONF.periodic_interval_max, - context=context.get_admin_context(all_tenants=True) + context=context.get_admin_context(all_projects=True) ) self._server.start() diff --git a/zun/common/utils.py b/zun/common/utils.py index f8cf4ca36..d3aa78f38 100644 --- a/zun/common/utils.py +++ b/zun/common/utils.py @@ -361,16 +361,17 @@ def check_capsule_template(tpl): return containers_spec -def is_all_tenants(search_opts): - all_tenants = search_opts.get('all_tenants') - if all_tenants: +def is_all_projects(search_opts): + all_projects = search_opts.get('all_projects') or \ + search_opts.get('all_tenants') + if all_projects: try: - all_tenants = strutils.bool_from_string(all_tenants, True) + all_projects = strutils.bool_from_string(all_projects, True) except ValueError as err: raise exception.InvalidValue(six.text_type(err)) else: - all_tenants = False - return all_tenants + all_projects = False + return all_projects def get_container(container_ident): diff --git a/zun/db/etcd/api.py b/zun/db/etcd/api.py index eb800746d..3bc9d5f84 100644 --- a/zun/db/etcd/api.py +++ b/zun/db/etcd/api.py @@ -112,9 +112,9 @@ class EtcdAPI(object): six.text_type(e)) raise - def _add_tenant_filters(self, context, filters): + def _add_project_filters(self, context, filters): filters = filters or {} - if context.is_admin and context.all_tenants: + if context.is_admin and context.all_projects: return filters if context.project_id: @@ -166,7 +166,7 @@ class EtcdAPI(object): for c in res: if c.value is not None: containers.append(translate_etcd_result(c, 'container')) - filters = self._add_tenant_filters(context, filters) + filters = self._add_project_filters(context, filters) filtered_containers = self._filter_resources( containers, filters) return self._process_list_result(filtered_containers, @@ -219,7 +219,7 @@ class EtcdAPI(object): res = self.client.read('/containers/' + container_uuid) container = translate_etcd_result(res, 'container') filtered_containers = self._filter_resources( - [container], self._add_tenant_filters(context, {})) + [container], self._add_project_filters(context, {})) if len(filtered_containers) > 0: return filtered_containers[0] else: @@ -233,7 +233,7 @@ class EtcdAPI(object): def get_container_by_name(self, context, container_name): try: - filters = self._add_tenant_filters( + filters = self._add_project_filters( context, {'name': container_name}) containers = self.list_containers(context, filters=filters) except etcd.EtcdKeyNotFound: @@ -415,7 +415,7 @@ class EtcdAPI(object): for i in res: if i.value is not None: images.append(translate_etcd_result(i, 'image')) - filters = self._add_tenant_filters(context, filters) + filters = self._add_project_filters(context, filters) filtered_images = self._filter_resources(images, filters) return self._process_list_result(filtered_images, @@ -426,7 +426,7 @@ class EtcdAPI(object): res = self.client.read('/images/' + image_uuid) image = translate_etcd_result(res, 'image') filtered_images = self._filter_resources( - [image], self._add_tenant_filters(context, {})) + [image], self._add_project_filters(context, {})) if len(filtered_images) > 0: return filtered_images[0] else: @@ -662,7 +662,7 @@ class EtcdAPI(object): for c in res: if c.value is not None: capsules.append(translate_etcd_result(c, 'capsule')) - filters = self._add_tenant_filters(context, filters) + filters = self._add_project_filters(context, filters) filtered_capsules = self._filter_resources( capsules, filters) return self._process_list_result(filtered_capsules, @@ -687,7 +687,7 @@ class EtcdAPI(object): res = self.client.read('/capsules/' + capsule_uuid) capsule = translate_etcd_result(res, 'capsule') filtered_capsules = self._filter_resources( - [capsule], self._add_tenant_filters(context, {})) + [capsule], self._add_project_filters(context, {})) if len(filtered_capsules) > 0: return filtered_capsules[0] else: @@ -701,7 +701,7 @@ class EtcdAPI(object): def get_capsule_by_meta_name(self, context, capsule_meta_name): try: - filters = self._add_tenant_filters( + filters = self._add_project_filters( context, {'meta_name': capsule_meta_name}) capsules = self.list_capsules(context, filters=filters) except etcd.EtcdKeyNotFound: @@ -882,7 +882,7 @@ class EtcdAPI(object): if vm.value is not None: volume_mappings.append( translate_etcd_result(vm, 'volume_mapping')) - filters = self._add_tenant_filters(context, filters) + filters = self._add_project_filters(context, filters) filtered_vms = self._filter_resources(volume_mappings, filters) return self._process_list_result(filtered_vms, limit=limit, sort_key=sort_key) @@ -906,7 +906,7 @@ class EtcdAPI(object): res = self.client.read('/volume_mappings/' + volume_mapping_uuid) volume_mapping = translate_etcd_result(res, 'volume_mapping') filtered_vms = self._filter_resources( - [volume_mapping], self._add_tenant_filters(context, {})) + [volume_mapping], self._add_project_filters(context, {})) if filtered_vms: return filtered_vms[0] else: diff --git a/zun/db/sqlalchemy/api.py b/zun/db/sqlalchemy/api.py index 8a1b5a141..2e8adbfa6 100644 --- a/zun/db/sqlalchemy/api.py +++ b/zun/db/sqlalchemy/api.py @@ -118,8 +118,8 @@ class Connection(object): def __init__(self): pass - def _add_tenant_filters(self, context, query): - if context.is_admin and context.all_tenants: + def _add_project_filters(self, context, query): + if context.is_admin and context.all_projects: return query if context.project_id: @@ -145,7 +145,7 @@ class Connection(object): def list_containers(self, context, filters=None, limit=None, marker=None, sort_key=None, sort_dir=None): query = model_query(models.Container) - query = self._add_tenant_filters(context, query) + query = self._add_project_filters(context, query) query = self._add_containers_filters(query, filters) return _paginate_query(models.Container, limit, marker, sort_key, sort_dir, query) @@ -187,7 +187,7 @@ class Connection(object): def get_container_by_uuid(self, context, container_uuid): query = model_query(models.Container) - query = self._add_tenant_filters(context, query) + query = self._add_project_filters(context, query) query = query.filter_by(uuid=container_uuid) try: return query.one() @@ -196,7 +196,7 @@ class Connection(object): def get_container_by_name(self, context, container_name): query = model_query(models.Container) - query = self._add_tenant_filters(context, query) + query = self._add_project_filters(context, query) query = query.filter_by(name=container_name) try: return query.one() @@ -255,7 +255,7 @@ class Connection(object): def list_volume_mappings(self, context, filters=None, limit=None, marker=None, sort_key=None, sort_dir=None): query = model_query(models.VolumeMapping) - query = self._add_tenant_filters(context, query) + query = self._add_project_filters(context, query) query = self._add_volume_mappings_filters(query, filters) return _paginate_query(models.VolumeMapping, limit, marker, sort_key, sort_dir, query) @@ -276,7 +276,7 @@ class Connection(object): def get_volume_mapping_by_uuid(self, context, volume_mapping_uuid): query = model_query(models.VolumeMapping) - query = self._add_tenant_filters(context, query) + query = self._add_project_filters(context, query) query = query.filter_by(uuid=volume_mapping_uuid) try: return query.one() @@ -430,14 +430,14 @@ class Connection(object): def list_images(self, context, filters=None, limit=None, marker=None, sort_key=None, sort_dir=None): query = model_query(models.Image) - query = self._add_tenant_filters(context, query) + query = self._add_project_filters(context, query) query = self._add_image_filters(query, filters) return _paginate_query(models.Image, limit, marker, sort_key, sort_dir, query) def get_image_by_id(self, context, image_id): query = model_query(models.Image) - query = self._add_tenant_filters(context, query) + query = self._add_project_filters(context, query) query = query.filter_by(id=image_id) try: return query.one() @@ -446,7 +446,7 @@ class Connection(object): def get_image_by_uuid(self, context, image_uuid): query = model_query(models.Image) - query = self._add_tenant_filters(context, query) + query = self._add_project_filters(context, query) query = query.filter_by(uuid=image_uuid) try: return query.one() @@ -825,7 +825,7 @@ class Connection(object): def list_capsules(self, context, filters=None, limit=None, marker=None, sort_key=None, sort_dir=None): query = model_query(models.Capsule) - query = self._add_tenant_filters(context, query) + query = self._add_project_filters(context, query) query = self._add_capsules_filters(query, filters) return _paginate_query(models.Capsule, limit, marker, sort_key, sort_dir, query) @@ -846,7 +846,7 @@ class Connection(object): def get_capsule_by_uuid(self, context, capsule_uuid): query = model_query(models.Capsule) - query = self._add_tenant_filters(context, query) + query = self._add_project_filters(context, query) query = query.filter_by(uuid=capsule_uuid) try: return query.one() @@ -855,7 +855,7 @@ class Connection(object): def get_capsule_by_meta_name(self, context, capsule_name): query = model_query(models.Capsule) - query = self._add_tenant_filters(context, query) + query = self._add_project_filters(context, query) query = query.filter_by(meta_name=capsule_name) try: return query.one() diff --git a/zun/service/periodic.py b/zun/service/periodic.py index b8a0656bd..eefffa707 100644 --- a/zun/service/periodic.py +++ b/zun/service/periodic.py @@ -27,7 +27,7 @@ def set_context(func): @functools.wraps(func) def handler(self, ctx): if ctx is None: - ctx = context.get_admin_context(all_tenants=True) + ctx = context.get_admin_context(all_projects=True) func(self, ctx) return handler diff --git a/zun/tests/unit/api/controllers/experimental/test_capsules.py b/zun/tests/unit/api/controllers/experimental/test_capsules.py index b37604d6e..596327836 100644 --- a/zun/tests/unit/api/controllers/experimental/test_capsules.py +++ b/zun/tests/unit/api/controllers/experimental/test_capsules.py @@ -168,7 +168,7 @@ class TestCapsuleController(api_base.FunctionalTest): response = self.get('/capsules/%s/' % test_capsule['uuid']) context = mock_capsule_get_by_uuid.call_args[0][0] - self.assertIs(False, context.all_tenants) + self.assertIs(False, context.all_projects) self.assertEqual(200, response.status_int) self.assertEqual(test_capsule['uuid'], response.json['uuid']) @@ -176,9 +176,9 @@ class TestCapsuleController(api_base.FunctionalTest): @patch('zun.compute.api.API.container_show') @patch('zun.objects.Capsule.get_by_uuid') @patch('zun.objects.Container.get_by_uuid') - def test_get_one_by_uuid_all_tenants(self, mock_container_get_by_uuid, - mock_capsule_get_by_uuid, - mock_container_show): + def test_get_one_by_uuid_all_projects(self, mock_container_get_by_uuid, + mock_capsule_get_by_uuid, + mock_container_show): test_container = utils.get_test_container() test_container_obj = objects.Container(self.context, **test_container) mock_container_get_by_uuid.return_value = test_container_obj @@ -188,11 +188,11 @@ class TestCapsuleController(api_base.FunctionalTest): test_capsule_obj = objects.Capsule(self.context, **test_capsule) mock_capsule_get_by_uuid.return_value = test_capsule_obj - response = self.get('/capsules/%s/?all_tenants=1' % + response = self.get('/capsules/%s/?all_projects=1' % test_capsule['uuid']) context = mock_capsule_get_by_uuid.call_args[0][0] - self.assertIs(False, context.all_tenants) + self.assertIs(False, context.all_projects) self.assertEqual(200, response.status_int) self.assertEqual(test_capsule['uuid'], response.json['uuid']) @@ -222,19 +222,19 @@ class TestCapsuleController(api_base.FunctionalTest): self.assertTrue(mock_capsule_delete.called) self.assertEqual(204, response.status_int) context = mock_capsule_save.call_args[0][0] - self.assertIs(False, context.all_tenants) + self.assertIs(False, context.all_projects) @patch('zun.common.policy.enforce') @patch('zun.compute.api.API.capsule_delete') @patch('zun.objects.Capsule.get_by_uuid') @patch('zun.objects.Container.get_by_uuid') @patch('zun.objects.Capsule.save') - def test_delete_capsule_by_uuid_all_tenants(self, - mock_capsule_save, - mock_container_get_by_uuid, - mock_capsule_get_by_uuid, - mock_capsule_delete, - mock_policy): + def test_delete_capsule_by_uuid_all_projects(self, + mock_capsule_save, + mock_container_get_by_uuid, + mock_capsule_get_by_uuid, + mock_capsule_delete, + mock_policy): mock_policy.return_value = True test_container = utils.get_test_container() test_container_obj = objects.Container(self.context, **test_container) @@ -249,12 +249,12 @@ class TestCapsuleController(api_base.FunctionalTest): capsule_uuid = test_capsule.get('uuid') response = self.app.delete( - '/capsules/%s/?all_tenants=1' % capsule_uuid) + '/capsules/%s/?all_projects=1' % capsule_uuid) self.assertTrue(mock_capsule_delete.called) self.assertEqual(204, response.status_int) context = mock_capsule_save.call_args[0][0] - self.assertIs(True, context.all_tenants) + self.assertIs(True, context.all_projects) def test_delete_capsule_with_uuid_not_found(self): uuid = uuidutils.generate_uuid() @@ -287,7 +287,7 @@ class TestCapsuleController(api_base.FunctionalTest): self.assertTrue(mock_capsule_delete.called) self.assertEqual(204, response.status_int) context = mock_capsule_save.call_args[0][0] - self.assertIs(False, context.all_tenants) + self.assertIs(False, context.all_projects) @patch('zun.compute.api.API.container_show') @patch('zun.objects.Capsule.list') @@ -311,7 +311,7 @@ class TestCapsuleController(api_base.FunctionalTest): 1000, None, 'id', 'asc', filters=None) context = mock_capsule_list.call_args[0][0] - self.assertIs(False, context.all_tenants) + self.assertIs(False, context.all_projects) self.assertEqual(200, response.status_int) actual_capsules = response.json['capsules'] self.assertEqual(1, len(actual_capsules)) @@ -321,10 +321,10 @@ class TestCapsuleController(api_base.FunctionalTest): @patch('zun.compute.api.API.container_show') @patch('zun.objects.Capsule.list') @patch('zun.objects.Container.get_by_uuid') - def test_get_all_capsules_all_tenants(self, - mock_container_get_by_uuid, - mock_capsule_list, - mock_container_show): + def test_get_all_capsules_all_projects(self, + mock_container_get_by_uuid, + mock_capsule_list, + mock_container_show): test_container = utils.get_test_container() test_container_obj = objects.Container(self.context, **test_container) @@ -335,13 +335,13 @@ class TestCapsuleController(api_base.FunctionalTest): mock_capsule_list.return_value = [test_capsule_obj] mock_container_show.return_value = test_container_obj - response = self.app.get('/capsules/?all_tenants=1') + response = self.app.get('/capsules/?all_projects=1') mock_capsule_list.assert_called_once_with(mock.ANY, 1000, None, 'id', 'asc', filters=None) context = mock_capsule_list.call_args[0][0] - self.assertIs(True, context.all_tenants) + self.assertIs(True, context.all_projects) self.assertEqual(200, response.status_int) actual_capsules = response.json['capsules'] self.assertEqual(1, len(actual_capsules)) @@ -368,7 +368,7 @@ class TestCapsuleController(api_base.FunctionalTest): 1000, None, 'id', 'asc', filters=None) context = mock_capsule_list.call_args[0][0] - self.assertIs(False, context.all_tenants) + self.assertIs(False, context.all_projects) self.assertEqual(200, response.status_int) actual_capsules = response.json['capsules'] self.assertEqual(1, len(actual_capsules)) diff --git a/zun/tests/unit/api/controllers/v1/test_containers.py b/zun/tests/unit/api/controllers/v1/test_containers.py index 49a90fcdc..2a5e8731d 100644 --- a/zun/tests/unit/api/controllers/v1/test_containers.py +++ b/zun/tests/unit/api/controllers/v1/test_containers.py @@ -784,7 +784,7 @@ class TestContainerController(api_base.FunctionalTest): 1000, None, 'id', 'asc', filters=None) context = mock_container_list.call_args[0][0] - self.assertIs(False, context.all_tenants) + self.assertIs(False, context.all_projects) self.assertEqual(200, response.status_int) actual_containers = response.json['containers'] self.assertEqual(1, len(actual_containers)) @@ -794,21 +794,21 @@ class TestContainerController(api_base.FunctionalTest): @patch('zun.common.policy.enforce') @patch('zun.compute.api.API.container_show') @patch('zun.objects.Container.list') - def test_get_all_containers_all_tenants(self, mock_container_list, - mock_container_show, mock_policy): + def test_get_all_containers_all_projects(self, mock_container_list, + mock_container_show, mock_policy): mock_policy.return_value = True test_container = utils.get_test_container() containers = [objects.Container(self.context, **test_container)] mock_container_list.return_value = containers mock_container_show.return_value = containers[0] - response = self.get('/v1/containers/?all_tenants=1') + response = self.get('/v1/containers/?all_projects=1') mock_container_list.assert_called_once_with(mock.ANY, 1000, None, 'id', 'asc', filters=None) context = mock_container_list.call_args[0][0] - self.assertIs(True, context.all_tenants) + self.assertIs(True, context.all_projects) self.assertEqual(200, response.status_int) actual_containers = response.json['containers'] self.assertEqual(1, len(actual_containers)) @@ -888,7 +888,7 @@ class TestContainerController(api_base.FunctionalTest): mock.ANY, test_container['uuid']) context = mock_container_get_by_uuid.call_args[0][0] - self.assertIs(False, context.all_tenants) + self.assertIs(False, context.all_projects) self.assertEqual(200, response.status_int) self.assertEqual(test_container['uuid'], response.json['uuid']) @@ -896,22 +896,22 @@ class TestContainerController(api_base.FunctionalTest): @patch('zun.common.policy.enforce') @patch('zun.compute.api.API.container_show') @patch('zun.objects.Container.get_by_uuid') - def test_get_one_by_uuid_all_tenants(self, mock_container_get_by_uuid, - mock_container_show, mock_policy): + def test_get_one_by_uuid_all_projects(self, mock_container_get_by_uuid, + mock_container_show, mock_policy): mock_policy.return_value = True test_container = utils.get_test_container() test_container_obj = objects.Container(self.context, **test_container) mock_container_get_by_uuid.return_value = test_container_obj mock_container_show.return_value = test_container_obj - response = self.get('/v1/containers/%s/?all_tenants=1' % + response = self.get('/v1/containers/%s/?all_projects=1' % test_container['uuid']) mock_container_get_by_uuid.assert_called_once_with( mock.ANY, test_container['uuid']) context = mock_container_get_by_uuid.call_args[0][0] - self.assertIs(True, context.all_tenants) + self.assertIs(True, context.all_projects) self.assertEqual(200, response.status_int) self.assertEqual(test_container['uuid'], response.json['uuid']) @@ -1257,29 +1257,29 @@ class TestContainerController(api_base.FunctionalTest): mock_container_delete.assert_called_once_with( mock.ANY, test_container_obj, False) context = mock_container_delete.call_args[0][0] - self.assertIs(False, context.all_tenants) + self.assertIs(False, context.all_projects) @patch('zun.common.policy.enforce') @patch('zun.common.utils.validate_container_state') @patch('zun.compute.api.API.container_delete') @patch('zun.objects.Container.get_by_uuid') - def test_delete_container_by_uuid_all_tenants(self, mock_get_by_uuid, - mock_container_delete, - mock_validate, mock_policy): + def test_delete_container_by_uuid_all_projects(self, mock_get_by_uuid, + mock_container_delete, + mock_validate, mock_policy): mock_policy.return_value = True test_container = utils.get_test_container() test_container_obj = objects.Container(self.context, **test_container) mock_get_by_uuid.return_value = test_container_obj container_uuid = test_container.get('uuid') - response = self.delete('/v1/containers/%s/?all_tenants=1' % + response = self.delete('/v1/containers/%s/?all_projects=1' % container_uuid) self.assertEqual(204, response.status_int) mock_container_delete.assert_called_once_with( mock.ANY, test_container_obj, False) context = mock_container_delete.call_args[0][0] - self.assertIs(True, context.all_tenants) + self.assertIs(True, context.all_projects) @patch('zun.common.utils.validate_container_state') @patch('zun.compute.api.API.container_stop') @@ -1813,10 +1813,10 @@ class TestContainerEnforcement(api_base.FunctionalTest): 'container:get_all', self.get, '/v1/containers/', expect_errors=True) - def test_policy_disallow_get_all_all_tenants(self): + def test_policy_disallow_get_all_all_projects(self): self._common_policy_check( - 'container:get_all_all_tenants', - self.get, '/v1/containers/?all_tenants=1', + 'container:get_all_all_projects', + self.get, '/v1/containers/?all_projects=1', expect_errors=True, bypass_rules={'container:get_all': 'project_id:fake_project'}) @@ -1827,11 +1827,11 @@ class TestContainerEnforcement(api_base.FunctionalTest): '/v1/containers/%s/' % container.uuid, expect_errors=True) - def test_policy_disallow_get_one_all_tenants(self): + def test_policy_disallow_get_one_all_projects(self): container = obj_utils.create_test_container(self.context) self._common_policy_check( - 'container:get_one_all_tenants', self.get, - '/v1/containers/%s/?all_tenants=1' % container.uuid, + 'container:get_one_all_projects', self.get, + '/v1/containers/%s/?all_projects=1' % container.uuid, expect_errors=True) def test_policy_disallow_update(self): @@ -1859,11 +1859,11 @@ class TestContainerEnforcement(api_base.FunctionalTest): '/v1/containers/%s/' % container.uuid, expect_errors=True) - def test_policy_disallow_delete_all_tenants(self): + def test_policy_disallow_delete_all_projects(self): container = obj_utils.create_test_container(self.context) self._common_policy_check( - 'container:delete_all_tenants', self.delete, - '/v1/containers/%s/?all_tenants=1' % container.uuid, + 'container:delete_all_projects', self.delete, + '/v1/containers/%s/?all_projects=1' % container.uuid, expect_errors=True) def test_policy_disallow_delete_force(self): diff --git a/zun/websocket/websocketproxy.py b/zun/websocket/websocketproxy.py index 72838be90..b5b89e71d 100644 --- a/zun/websocket/websocketproxy.py +++ b/zun/websocket/websocketproxy.py @@ -191,7 +191,7 @@ class ZunProxyRequestHandlerBase(object): uuid = urlparse.parse_qs(query).get("uuid", [""]).pop() dbapi = db_api._get_dbdriver_instance() - ctx = context.get_admin_context(all_tenants=True) + ctx = context.get_admin_context(all_projects=True) if uuidutils.is_uuid_like(uuid): container = dbapi.get_container_by_uuid(ctx, uuid)