summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--glance/api/common.py6
-rw-r--r--glance/api/v2/image_data.py2
-rw-r--r--glance/context.py13
-rw-r--r--glance/notifier.py4
-rw-r--r--glance/registry/client/v1/api.py4
-rw-r--r--glance/tests/functional/db/base.py10
-rw-r--r--glance/tests/functional/v2/registry_data_api.py8
-rw-r--r--glance/tests/functional/v2/test_images.py18
-rw-r--r--glance/tests/unit/fixtures.py5
-rw-r--r--glance/tests/unit/test_context_middleware.py12
-rw-r--r--glance/tests/unit/utils.py8
-rw-r--r--glance/tests/unit/v2/test_image_data_resource.py2
-rw-r--r--glance/tests/unit/v2/test_images_resource.py4
-rw-r--r--glance/tests/unit/v2/test_tasks_resource.py2
14 files changed, 56 insertions, 42 deletions
diff --git a/glance/api/common.py b/glance/api/common.py
index 2d0699e..f2f7141 100644
--- a/glance/api/common.py
+++ b/glance/api/common.py
@@ -76,8 +76,8 @@ def image_send_notification(bytes_written, expected_size, image_meta, request,
76 'bytes_sent': bytes_written, 76 'bytes_sent': bytes_written,
77 'image_id': image_meta['id'], 77 'image_id': image_meta['id'],
78 'owner_id': image_meta['owner'], 78 'owner_id': image_meta['owner'],
79 'receiver_tenant_id': context.tenant, 79 'receiver_tenant_id': context.project_id,
80 'receiver_user_id': context.user, 80 'receiver_user_id': context.user_id,
81 'destination_ip': request.remote_addr, 81 'destination_ip': request.remote_addr,
82 } 82 }
83 if bytes_written != expected_size: 83 if bytes_written != expected_size:
@@ -156,7 +156,7 @@ def check_quota(context, image_size, db_api, image_id=None):
156 if remaining is None: 156 if remaining is None:
157 return 157 return
158 158
159 user = getattr(context, 'user', '<unknown>') 159 user = getattr(context, 'user_id', '<unknown>')
160 160
161 if image_size is None: 161 if image_size is None:
162 # NOTE(jbresnah) When the image size is None it means that it is 162 # NOTE(jbresnah) When the image size is None it means that it is
diff --git a/glance/api/v2/image_data.py b/glance/api/v2/image_data.py
index b67604c..227ea42 100644
--- a/glance/api/v2/image_data.py
+++ b/glance/api/v2/image_data.py
@@ -133,7 +133,7 @@ class ImageDataController(object):
133 'keystone.token_info')['token']['roles']: 133 'keystone.token_info')['token']['roles']:
134 roles.append(role_info['name']) 134 roles.append(role_info['name'])
135 refresher = trust_auth.TokenRefresher(user_plugin, 135 refresher = trust_auth.TokenRefresher(user_plugin,
136 cxt.tenant, 136 cxt.project_id,
137 roles) 137 roles)
138 except Exception as e: 138 except Exception as e:
139 LOG.info(_LI("Unable to create trust: %s " 139 LOG.info(_LI("Unable to create trust: %s "
diff --git a/glance/context.py b/glance/context.py
index 83bdd35..01c26b4 100644
--- a/glance/context.py
+++ b/glance/context.py
@@ -28,6 +28,15 @@ class RequestContext(context.RequestContext):
28 28
29 def __init__(self, owner_is_tenant=True, service_catalog=None, 29 def __init__(self, owner_is_tenant=True, service_catalog=None,
30 policy_enforcer=None, **kwargs): 30 policy_enforcer=None, **kwargs):
31 # TODO(mriedem): Remove usage of user and tenant from old tests.
32 if 'tenant' in kwargs:
33 # Prefer project_id if passed, otherwise alias tenant as project_id
34 tenant = kwargs.pop('tenant')
35 kwargs['project_id'] = kwargs.get('project_id', tenant)
36 if 'user' in kwargs:
37 # Prefer user_id if passed, otherwise alias user as user_id
38 user = kwargs.pop('user')
39 kwargs['user_id'] = kwargs.get('user_id', user)
31 super(RequestContext, self).__init__(**kwargs) 40 super(RequestContext, self).__init__(**kwargs)
32 self.owner_is_tenant = owner_is_tenant 41 self.owner_is_tenant = owner_is_tenant
33 self.service_catalog = service_catalog 42 self.service_catalog = service_catalog
@@ -45,8 +54,8 @@ class RequestContext(context.RequestContext):
45 54
46 def to_policy_values(self): 55 def to_policy_values(self):
47 pdict = super(RequestContext, self).to_policy_values() 56 pdict = super(RequestContext, self).to_policy_values()
48 pdict['user'] = self.user_id 57 pdict['user_id'] = self.user_id
49 pdict['tenant'] = self.project_id 58 pdict['project_id'] = self.project_id
50 return pdict 59 return pdict
51 60
52 @classmethod 61 @classmethod
diff --git a/glance/notifier.py b/glance/notifier.py
index 1d16495..7e5a44e 100644
--- a/glance/notifier.py
+++ b/glance/notifier.py
@@ -394,8 +394,8 @@ class ImageProxy(NotificationProxy, domain_proxy.Image):
394 'bytes_sent': bytes_sent, 394 'bytes_sent': bytes_sent,
395 'image_id': self.repo.image_id, 395 'image_id': self.repo.image_id,
396 'owner_id': self.repo.owner, 396 'owner_id': self.repo.owner,
397 'receiver_tenant_id': self.context.tenant, 397 'receiver_tenant_id': self.context.project_id,
398 'receiver_user_id': self.context.user, 398 'receiver_user_id': self.context.user_id,
399 } 399 }
400 400
401 def _get_chunk_data_iterator(self, data, chunk_size=None): 401 def _get_chunk_data_iterator(self, data, chunk_size=None):
diff --git a/glance/registry/client/v1/api.py b/glance/registry/client/v1/api.py
index 2c260d2..5cbc127 100644
--- a/glance/registry/client/v1/api.py
+++ b/glance/registry/client/v1/api.py
@@ -153,8 +153,8 @@ def get_registry_client(cxt):
153 153
154 if CONF.send_identity_headers: 154 if CONF.send_identity_headers:
155 identity_headers = { 155 identity_headers = {
156 'X-User-Id': cxt.user or '', 156 'X-User-Id': cxt.user_id or '',
157 'X-Tenant-Id': cxt.tenant or '', 157 'X-Tenant-Id': cxt.project_id or '',
158 'X-Roles': ','.join(cxt.roles), 158 'X-Roles': ','.join(cxt.roles),
159 'X-Identity-Status': 'Confirmed', 159 'X-Identity-Status': 'Confirmed',
160 'X-Service-Catalog': jsonutils.dumps(cxt.service_catalog), 160 'X-Service-Catalog': jsonutils.dumps(cxt.service_catalog),
diff --git a/glance/tests/functional/db/base.py b/glance/tests/functional/db/base.py
index 6d8a4dd..87cdb8a 100644
--- a/glance/tests/functional/db/base.py
+++ b/glance/tests/functional/db/base.py
@@ -1580,7 +1580,7 @@ class TaskTests(test_utils.BaseTestCase):
1580 db_tests.reset_db(self.db_api) 1580 db_tests.reset_db(self.db_api)
1581 1581
1582 def build_task_fixtures(self): 1582 def build_task_fixtures(self):
1583 self.context.tenant = str(uuid.uuid4()) 1583 self.context.project_id = str(uuid.uuid4())
1584 fixtures = [ 1584 fixtures = [
1585 { 1585 {
1586 'owner': self.context.owner, 1586 'owner': self.context.owner,
@@ -1816,7 +1816,7 @@ class TaskTests(test_utils.BaseTestCase):
1816 1816
1817 def test_task_create(self): 1817 def test_task_create(self):
1818 task_id = str(uuid.uuid4()) 1818 task_id = str(uuid.uuid4())
1819 self.context.tenant = self.context.owner 1819 self.context.project_id = self.context.owner
1820 values = { 1820 values = {
1821 'id': task_id, 1821 'id': task_id,
1822 'owner': self.context.owner, 1822 'owner': self.context.owner,
@@ -1834,7 +1834,7 @@ class TaskTests(test_utils.BaseTestCase):
1834 1834
1835 def test_task_create_with_all_task_info_null(self): 1835 def test_task_create_with_all_task_info_null(self):
1836 task_id = str(uuid.uuid4()) 1836 task_id = str(uuid.uuid4())
1837 self.context.tenant = str(uuid.uuid4()) 1837 self.context.project_id = str(uuid.uuid4())
1838 values = { 1838 values = {
1839 'id': task_id, 1839 'id': task_id,
1840 'owner': self.context.owner, 1840 'owner': self.context.owner,
@@ -1856,7 +1856,7 @@ class TaskTests(test_utils.BaseTestCase):
1856 self.assertIsNone(task['message']) 1856 self.assertIsNone(task['message'])
1857 1857
1858 def test_task_update(self): 1858 def test_task_update(self):
1859 self.context.tenant = str(uuid.uuid4()) 1859 self.context.project_id = str(uuid.uuid4())
1860 result = {'foo': 'bar'} 1860 result = {'foo': 'bar'}
1861 task_values = build_task_fixture(owner=self.context.owner, 1861 task_values = build_task_fixture(owner=self.context.owner,
1862 result=result) 1862 result=result)
@@ -1883,7 +1883,7 @@ class TaskTests(test_utils.BaseTestCase):
1883 self.assertGreater(task['updated_at'], task['created_at']) 1883 self.assertGreater(task['updated_at'], task['created_at'])
1884 1884
1885 def test_task_update_with_all_task_info_null(self): 1885 def test_task_update_with_all_task_info_null(self):
1886 self.context.tenant = str(uuid.uuid4()) 1886 self.context.project_id = str(uuid.uuid4())
1887 task_values = build_task_fixture(owner=self.context.owner, 1887 task_values = build_task_fixture(owner=self.context.owner,
1888 input=None, 1888 input=None,
1889 result=None, 1889 result=None,
diff --git a/glance/tests/functional/v2/registry_data_api.py b/glance/tests/functional/v2/registry_data_api.py
index 0ba9ef6..e9560c3 100644
--- a/glance/tests/functional/v2/registry_data_api.py
+++ b/glance/tests/functional/v2/registry_data_api.py
@@ -29,10 +29,10 @@ def patched_bulk_request(self, commands):
29 # present) 29 # present)
30 body = self._serializer.to_json(commands) 30 body = self._serializer.to_json(commands)
31 headers = {"X-Identity-Status": "Confirmed", 'X-Roles': 'member'} 31 headers = {"X-Identity-Status": "Confirmed", 'X-Roles': 'member'}
32 if self.context.user is not None: 32 if self.context.user_id is not None:
33 headers['X-User-Id'] = self.context.user 33 headers['X-User-Id'] = self.context.user_id
34 if self.context.tenant is not None: 34 if self.context.project_id is not None:
35 headers['X-Tenant-Id'] = self.context.tenant 35 headers['X-Tenant-Id'] = self.context.project_id
36 response = super(RPCClient, self).do_request('POST', 36 response = super(RPCClient, self).do_request('POST',
37 self.base_path, 37 self.base_path,
38 body, 38 body,
diff --git a/glance/tests/functional/v2/test_images.py b/glance/tests/functional/v2/test_images.py
index 7d6d933..43e20c4 100644
--- a/glance/tests/functional/v2/test_images.py
+++ b/glance/tests/functional/v2/test_images.py
@@ -1653,7 +1653,7 @@ class TestImages(functional.FunctionalTest):
1653 "default": "", 1653 "default": "",
1654 "add_image": "", 1654 "add_image": "",
1655 "get_image": "", 1655 "get_image": "",
1656 "modify_image": "tenant:%(owner)s", 1656 "modify_image": "project_id:%(owner)s",
1657 "upload_image": "", 1657 "upload_image": "",
1658 "get_image_location": "", 1658 "get_image_location": "",
1659 "delete_image": "", 1659 "delete_image": "",
@@ -1744,7 +1744,7 @@ class TestImages(functional.FunctionalTest):
1744 "restricted": 1744 "restricted":
1745 "not ('aki':%(container_format)s and role:_member_)", 1745 "not ('aki':%(container_format)s and role:_member_)",
1746 "download_image": "role:admin or rule:restricted", 1746 "download_image": "role:admin or rule:restricted",
1747 "add_member": "tenant:%(owner)s", 1747 "add_member": "project_id:%(owner)s",
1748 } 1748 }
1749 1749
1750 self.set_policy_rules(rules) 1750 self.set_policy_rules(rules)
@@ -1809,7 +1809,7 @@ class TestImages(functional.FunctionalTest):
1809 "context_is_admin": "role:admin", 1809 "context_is_admin": "role:admin",
1810 "default": "", 1810 "default": "",
1811 "add_image": "", 1811 "add_image": "",
1812 "get_image": "tenant:%(owner)s", 1812 "get_image": "project_id:%(owner)s",
1813 "modify_image": "", 1813 "modify_image": "",
1814 "upload_image": "", 1814 "upload_image": "",
1815 "get_image_location": "", 1815 "get_image_location": "",
@@ -1858,8 +1858,8 @@ class TestImages(functional.FunctionalTest):
1858 "context_is_admin": "role:admin", 1858 "context_is_admin": "role:admin",
1859 "default": "", 1859 "default": "",
1860 "add_image": "", 1860 "add_image": "",
1861 "publicize_image": "tenant:%(owner)s", 1861 "publicize_image": "project_id:%(owner)s",
1862 "get_image": "tenant:%(owner)s", 1862 "get_image": "project_id:%(owner)s",
1863 "modify_image": "", 1863 "modify_image": "",
1864 "upload_image": "", 1864 "upload_image": "",
1865 "get_image_location": "", 1865 "get_image_location": "",
@@ -1900,8 +1900,8 @@ class TestImages(functional.FunctionalTest):
1900 "context_is_admin": "role:admin", 1900 "context_is_admin": "role:admin",
1901 "default": "", 1901 "default": "",
1902 "add_image": "", 1902 "add_image": "",
1903 "communitize_image": "tenant:%(owner)s", 1903 "communitize_image": "project_id:%(owner)s",
1904 "get_image": "tenant:%(owner)s", 1904 "get_image": "project_id:%(owner)s",
1905 "modify_image": "", 1905 "modify_image": "",
1906 "upload_image": "", 1906 "upload_image": "",
1907 "get_image_location": "", 1907 "get_image_location": "",
@@ -1942,8 +1942,8 @@ class TestImages(functional.FunctionalTest):
1942 "context_is_admin": "role:admin", 1942 "context_is_admin": "role:admin",
1943 "default": "", 1943 "default": "",
1944 "add_image": "", 1944 "add_image": "",
1945 "publicize_image": "tenant:%(owner)s", 1945 "publicize_image": "project_id:%(owner)s",
1946 "get_image": "tenant:%(owner)s", 1946 "get_image": "project_id:%(owner)s",
1947 "modify_image": "", 1947 "modify_image": "",
1948 "upload_image": "", 1948 "upload_image": "",
1949 "get_image_location": "", 1949 "get_image_location": "",
diff --git a/glance/tests/unit/fixtures.py b/glance/tests/unit/fixtures.py
index 423e3eb..420135f 100644
--- a/glance/tests/unit/fixtures.py
+++ b/glance/tests/unit/fixtures.py
@@ -131,4 +131,9 @@ class WarningsFixture(pyfixtures.Fixture):
131 ' This key is deprecated. Please update your policy ' 131 ' This key is deprecated. Please update your policy '
132 'file to use the standard policy values.') 132 'file to use the standard policy values.')
133 133
134 # NOTE(mriedem): user/tenant is deprecated in oslo.context so don't
135 # let anything new use it
136 warnings.filterwarnings(
137 'error', message="Property '.*' has moved to '.*'")
138
134 self.addCleanup(warnings.resetwarnings) 139 self.addCleanup(warnings.resetwarnings)
diff --git a/glance/tests/unit/test_context_middleware.py b/glance/tests/unit/test_context_middleware.py
index a35355c..abd03f9 100644
--- a/glance/tests/unit/test_context_middleware.py
+++ b/glance/tests/unit/test_context_middleware.py
@@ -41,8 +41,8 @@ class TestContextMiddleware(base.IsolatedUnitTest):
41 req = self._build_request() 41 req = self._build_request()
42 self._build_middleware().process_request(req) 42 self._build_middleware().process_request(req)
43 self.assertEqual('token1', req.context.auth_token) 43 self.assertEqual('token1', req.context.auth_token)
44 self.assertEqual('user1', req.context.user) 44 self.assertEqual('user1', req.context.user_id)
45 self.assertEqual('tenant1', req.context.tenant) 45 self.assertEqual('tenant1', req.context.project_id)
46 self.assertEqual(['role1', 'role2'], req.context.roles) 46 self.assertEqual(['role1', 'role2'], req.context.roles)
47 47
48 def test_is_admin_flag(self): 48 def test_is_admin_flag(self):
@@ -93,8 +93,8 @@ class TestContextMiddleware(base.IsolatedUnitTest):
93 middleware = self._build_middleware() 93 middleware = self._build_middleware()
94 middleware.process_request(req) 94 middleware.process_request(req)
95 self.assertIsNone(req.context.auth_token) 95 self.assertIsNone(req.context.auth_token)
96 self.assertIsNone(req.context.user) 96 self.assertIsNone(req.context.user_id)
97 self.assertIsNone(req.context.tenant) 97 self.assertIsNone(req.context.project_id)
98 self.assertEqual([], req.context.roles) 98 self.assertEqual([], req.context.roles)
99 self.assertFalse(req.context.is_admin) 99 self.assertFalse(req.context.is_admin)
100 self.assertTrue(req.context.read_only) 100 self.assertTrue(req.context.read_only)
@@ -141,8 +141,8 @@ class TestUnauthenticatedContextMiddleware(base.IsolatedUnitTest):
141 req = webob.Request.blank('/') 141 req = webob.Request.blank('/')
142 middleware.process_request(req) 142 middleware.process_request(req)
143 self.assertIsNone(req.context.auth_token) 143 self.assertIsNone(req.context.auth_token)
144 self.assertIsNone(req.context.user) 144 self.assertIsNone(req.context.user_id)
145 self.assertIsNone(req.context.tenant) 145 self.assertIsNone(req.context.project_id)
146 self.assertEqual([], req.context.roles) 146 self.assertEqual([], req.context.roles)
147 self.assertTrue(req.context.is_admin) 147 self.assertTrue(req.context.is_admin)
148 148
diff --git a/glance/tests/unit/utils.py b/glance/tests/unit/utils.py
index 6f30f66..92cf3156 100644
--- a/glance/tests/unit/utils.py
+++ b/glance/tests/unit/utils.py
@@ -230,9 +230,9 @@ class FakeStoreAPI(object):
230 size = len(data.data.fd) 230 size = len(data.data.fd)
231 if (current_store_size + size) > store_max_size: 231 if (current_store_size + size) > store_max_size:
232 raise exception.StorageFull() 232 raise exception.StorageFull()
233 if context.user == USER2: 233 if context.user_id == USER2:
234 raise exception.Forbidden() 234 raise exception.Forbidden()
235 if context.user == USER3: 235 if context.user_id == USER3:
236 raise exception.StorageWriteDenied() 236 raise exception.StorageWriteDenied()
237 self.data[image_id] = (data, size) 237 self.data[image_id] = (data, size)
238 checksum = 'Z' 238 checksum = 'Z'
@@ -253,9 +253,9 @@ class FakeStoreAPI(object):
253 size = len(data.data.fd) 253 size = len(data.data.fd)
254 if (current_store_size + size) > store_max_size: 254 if (current_store_size + size) > store_max_size:
255 raise exception.StorageFull() 255 raise exception.StorageFull()
256 if context.user == USER2: 256 if context.user_id == USER2:
257 raise exception.Forbidden() 257 raise exception.Forbidden()
258 if context.user == USER3: 258 if context.user_id == USER3:
259 raise exception.StorageWriteDenied() 259 raise exception.StorageWriteDenied()
260 self.data[image_id] = (data, size) 260 self.data[image_id] = (data, size)
261 checksum = 'Z' 261 checksum = 'Z'
diff --git a/glance/tests/unit/v2/test_image_data_resource.py b/glance/tests/unit/v2/test_image_data_resource.py
index cd76fe5..8ce7f9f 100644
--- a/glance/tests/unit/v2/test_image_data_resource.py
+++ b/glance/tests/unit/v2/test_image_data_resource.py
@@ -403,7 +403,7 @@ class TestImagesController(base.StoreClearingUnitTest):
403 # check that token has been correctly acquired and deleted 403 # check that token has been correctly acquired and deleted
404 mock_refresher.assert_called_once_with( 404 mock_refresher.assert_called_once_with(
405 request.environ['keystone.token_auth'], 405 request.environ['keystone.token_auth'],
406 request.context.tenant, ['FakeRole']) 406 request.context.project_id, ['FakeRole'])
407 refresher.refresh_token.assert_called_once_with() 407 refresher.refresh_token.assert_called_once_with()
408 refresher.release_resources.assert_called_once_with() 408 refresher.release_resources.assert_called_once_with()
409 self.assertEqual("fake_token", request.context.auth_token) 409 self.assertEqual("fake_token", request.context.auth_token)
diff --git a/glance/tests/unit/v2/test_images_resource.py b/glance/tests/unit/v2/test_images_resource.py
index 45b7951..854ee88 100644
--- a/glance/tests/unit/v2/test_images_resource.py
+++ b/glance/tests/unit/v2/test_images_resource.py
@@ -651,7 +651,7 @@ class TestImagesController(base.IsolatedUnitTest):
651 651
652 def test_show_not_allowed(self): 652 def test_show_not_allowed(self):
653 request = unit_test_utils.get_fake_request() 653 request = unit_test_utils.get_fake_request()
654 self.assertEqual(TENANT1, request.context.tenant) 654 self.assertEqual(TENANT1, request.context.project_id)
655 self.assertRaises(webob.exc.HTTPNotFound, 655 self.assertRaises(webob.exc.HTTPNotFound,
656 self.controller.show, request, UUID4) 656 self.controller.show, request, UUID4)
657 657
@@ -2669,7 +2669,7 @@ class TestImagesController(base.IsolatedUnitTest):
2669 request = unit_test_utils.get_fake_request() 2669 request = unit_test_utils.get_fake_request()
2670 # NOTE(abhishekk): For coverage purpose setting tenant to 2670 # NOTE(abhishekk): For coverage purpose setting tenant to
2671 # None. It is not expected to do in normal scenarios. 2671 # None. It is not expected to do in normal scenarios.
2672 request.context.tenant = None 2672 request.context.project_id = None
2673 with mock.patch.object( 2673 with mock.patch.object(
2674 glance.api.authorization.ImageRepoProxy, 'get') as mock_get: 2674 glance.api.authorization.ImageRepoProxy, 'get') as mock_get:
2675 mock_get.return_value = FakeImage(status='uploading') 2675 mock_get.return_value = FakeImage(status='uploading')
diff --git a/glance/tests/unit/v2/test_tasks_resource.py b/glance/tests/unit/v2/test_tasks_resource.py
index 43f2ead..c15cb98 100644
--- a/glance/tests/unit/v2/test_tasks_resource.py
+++ b/glance/tests/unit/v2/test_tasks_resource.py
@@ -288,7 +288,7 @@ class TestTasksController(test_utils.BaseTestCase):
288 288
289 def test_get_not_allowed(self): 289 def test_get_not_allowed(self):
290 request = unit_test_utils.get_fake_request() 290 request = unit_test_utils.get_fake_request()
291 self.assertEqual(TENANT1, request.context.tenant) 291 self.assertEqual(TENANT1, request.context.project_id)
292 self.assertRaises(webob.exc.HTTPNotFound, 292 self.assertRaises(webob.exc.HTTPNotFound,
293 self.controller.get, request, UUID4) 293 self.controller.get, request, UUID4)
294 294