From 80afaac4b6e7a2da926189c220f4fbda92a458b9 Mon Sep 17 00:00:00 2001 From: Eoghan Glynn Date: Wed, 17 Jul 2013 15:27:39 +0000 Subject: [PATCH] Standardize on X-Project-Id over X-Tenant-Id. Both X-Project-Id and X-Tenant-Id headers are set to the same value by the keystoneclient authtoken middleware. However the latter is deprecated, so instead of referring to a mix of the two headers, we standardize on X-Project-Id. Change-Id: I0fcdc1944ea12d0e997627c5740b57a0bd58dbe8 --- ceilometer/api/acl.py | 2 +- tests/api/v1/list_events.py | 20 ++++++++++---------- tests/api/v1/list_meters.py | 20 ++++++++++---------- tests/api/v1/list_projects.py | 4 ++-- tests/api/v1/list_resources.py | 22 +++++++++++----------- tests/api/v1/list_users.py | 4 ++-- tests/api/v1/max_project_volume.py | 4 ++-- tests/api/v1/max_resource_volume.py | 4 ++-- tests/api/v1/sum_project_volume.py | 4 ++-- tests/api/v1/sum_resource_volume.py | 4 ++-- tests/api/v2/acl.py | 14 +++++++------- tests/api/v2/list_resources.py | 4 ++-- tests/api/v2/post_samples.py | 2 +- 13 files changed, 54 insertions(+), 54 deletions(-) diff --git a/ceilometer/api/acl.py b/ceilometer/api/acl.py index 8618547ef..2021426e6 100644 --- a/ceilometer/api/acl.py +++ b/ceilometer/api/acl.py @@ -52,4 +52,4 @@ def get_limited_to_project(headers): if not _ENFORCER.enforce('context_is_admin', {}, {'roles': headers.get('X-Roles', "").split(",")}): - return headers.get('X-Tenant-Id') + return headers.get('X-Project-Id') diff --git a/tests/api/v1/list_events.py b/tests/api/v1/list_events.py index 8830ec86c..1d2ffe24e 100644 --- a/tests/api/v1/list_events.py +++ b/tests/api/v1/list_events.py @@ -88,13 +88,13 @@ class TestListEvents(tests_api.TestBase): def test_by_project_non_admin(self): data = self.get('/projects/project1/meters/instance', headers={"X-Roles": "Member", - "X-Tenant-Id": "project1"}) + "X-Project-Id": "project1"}) self.assertEquals(2, len(data['events'])) def test_by_project_wrong_tenant(self): resp = self.get('/projects/project1/meters/instance', headers={"X-Roles": "Member", - "X-Tenant-Id": "this-is-my-project"}) + "X-Project-Id": "this-is-my-project"}) self.assertEquals(404, resp.status_code) def test_by_project_with_timestamps(self): @@ -113,13 +113,13 @@ class TestListEvents(tests_api.TestBase): def test_by_resource_non_admin(self): data = self.get('/resources/resource-id-alternate/meters/instance', headers={"X-Roles": "Member", - "X-Tenant-Id": "project2"}) + "X-Project-Id": "project2"}) self.assertEquals(1, len(data['events'])) def test_by_resource_some_tenant(self): data = self.get('/resources/resource-id/meters/instance', headers={"X-Roles": "Member", - "X-Tenant-Id": "project2"}) + "X-Project-Id": "project2"}) self.assertEquals(0, len(data['events'])) def test_empty_source(self): @@ -133,7 +133,7 @@ class TestListEvents(tests_api.TestBase): def test_by_source_non_admin(self): data = self.get('/sources/source1/meters/instance', headers={"X-Roles": "Member", - "X-Tenant-Id": "project2"}) + "X-Project-Id": "project2"}) self.assertEquals(1, len(data['events'])) def test_by_source_with_timestamps(self): @@ -152,13 +152,13 @@ class TestListEvents(tests_api.TestBase): def test_by_user_non_admin(self): data = self.get('/users/user-id/meters/instance', headers={"X-Roles": "Member", - "X-Tenant-Id": "project1"}) + "X-Project-Id": "project1"}) self.assertEquals(2, len(data['events'])) def test_by_user_wrong_tenant(self): data = self.get('/users/user-id/meters/instance', headers={"X-Roles": "Member", - "X-Tenant-Id": "project2"}) + "X-Project-Id": "project2"}) self.assertEquals(0, len(data['events'])) def test_by_user_with_timestamps(self): @@ -185,7 +185,7 @@ class TestListEventsMetaquery(TestListEvents): q = '/sources/source1/meters/instance' data = self.get('%s?metadata.tag=self.counter2' % q, headers={"X-Roles": "Member", - "X-Tenant-Id": "project1"}) + "X-Project-Id": "project1"}) self.assertEquals(0, len(data['events'])) def test_metaquery2(self): @@ -197,7 +197,7 @@ class TestListEventsMetaquery(TestListEvents): q = '/sources/source1/meters/instance' data = self.get('%s?metadata.tag=self.counter' % q, headers={"X-Roles": "Member", - "X-Tenant-Id": "project1"}) + "X-Project-Id": "project1"}) self.assertEquals(2, len(data['events'])) def test_metaquery3(self): @@ -209,5 +209,5 @@ class TestListEventsMetaquery(TestListEvents): q = '/sources/source1/meters/instance' data = self.get('%s?metadata.display_name=test-server' % q, headers={"X-Roles": "Member", - "X-Tenant-Id": "project2"}) + "X-Project-Id": "project2"}) self.assertEquals(1, len(data['events'])) diff --git a/tests/api/v1/list_meters.py b/tests/api/v1/list_meters.py index bbc0c3b28..65d4b1946 100644 --- a/tests/api/v1/list_meters.py +++ b/tests/api/v1/list_meters.py @@ -121,7 +121,7 @@ class TestListMeters(tests_api.TestBase): def test_list_meters_non_admin(self): data = self.get('/meters', headers={"X-Roles": "Member", - "X-Tenant-Id": "project-id"}) + "X-Project-Id": "project-id"}) self.assertEquals(2, len(data['meters'])) self.assertEquals(set(r['resource_id'] for r in data['meters']), set(['resource-id', @@ -146,7 +146,7 @@ class TestListMeters(tests_api.TestBase): def test_with_source_non_admin(self): data = self.get('/sources/test_list_resources/meters', headers={"X-Roles": "Member", - "X-Tenant-Id": "project-id2"}) + "X-Project-Id": "project-id2"}) ids = set(r['resource_id'] for r in data['meters']) self.assertEquals(set(['resource-id3', 'resource-id4']), ids) @@ -167,7 +167,7 @@ class TestListMeters(tests_api.TestBase): def test_with_user_non_admin(self): data = self.get('/users/user-id/meters', headers={"X-Roles": "Member", - "X-Tenant-Id": "project-id"}) + "X-Project-Id": "project-id"}) nids = set(r['name'] for r in data['meters']) self.assertEquals(set(['meter.mine', 'meter.test']), nids) @@ -177,7 +177,7 @@ class TestListMeters(tests_api.TestBase): def test_with_user_wrong_tenant(self): data = self.get('/users/user-id/meters', headers={"X-Roles": "Member", - "X-Tenant-Id": "project666"}) + "X-Project-Id": "project666"}) self.assertEquals(data['meters'], []) @@ -193,14 +193,14 @@ class TestListMeters(tests_api.TestBase): def test_with_project_non_admin(self): data = self.get('/projects/project-id2/meters', headers={"X-Roles": "Member", - "X-Tenant-Id": "project-id2"}) + "X-Project-Id": "project-id2"}) ids = set(r['resource_id'] for r in data['meters']) self.assertEquals(set(['resource-id3', 'resource-id4']), ids) def test_with_project_wrong_tenant(self): data = self.get('/projects/project-id2/meters', headers={"X-Roles": "Member", - "X-Tenant-Id": "project-id"}) + "X-Project-Id": "project-id"}) self.assertEqual(data.status_code, 404) def test_with_project_non_existent(self): @@ -217,13 +217,13 @@ class TestListMetersMetaquery(TestListMeters): def test_metaquery1_non_admin(self): data = self.get('/meters?metadata.tag=self.counter', headers={"X-Roles": "Member", - "X-Tenant-Id": "project-id"}) + "X-Project-Id": "project-id"}) self.assertEquals(1, len(data['meters'])) def test_metaquery1_wrong_tenant(self): data = self.get('/meters?metadata.tag=self.counter', headers={"X-Roles": "Member", - "X-Tenant-Id": "project-666"}) + "X-Project-Id": "project-666"}) self.assertEquals(0, len(data['meters'])) def test_metaquery2(self): @@ -233,11 +233,11 @@ class TestListMetersMetaquery(TestListMeters): def test_metaquery2_non_admin(self): data = self.get('/meters?metadata.tag=four.counter', headers={"X-Roles": "Member", - "X-Tenant-Id": "project-id2"}) + "X-Project-Id": "project-id2"}) self.assertEquals(1, len(data['meters'])) def test_metaquery2_non_admin_wrong_project(self): data = self.get('/meters?metadata.tag=four.counter', headers={"X-Roles": "Member", - "X-Tenant-Id": "project-666"}) + "X-Project-Id": "project-666"}) self.assertEquals(0, len(data['meters'])) diff --git a/tests/api/v1/list_projects.py b/tests/api/v1/list_projects.py index 8c391b52b..ab8960ecd 100644 --- a/tests/api/v1/list_projects.py +++ b/tests/api/v1/list_projects.py @@ -88,7 +88,7 @@ class TestListProjects(tests_api.TestBase): def test_projects_non_admin(self): data = self.get('/projects', headers={"X-Roles": "Member", - "X-Tenant-Id": "project-id"}) + "X-Project-Id": "project-id"}) self.assertEquals(['project-id'], data['projects']) def test_with_source(self): @@ -98,5 +98,5 @@ class TestListProjects(tests_api.TestBase): def test_with_source_non_admin(self): data = self.get('/sources/test_list_users/projects', headers={"X-Roles": "Member", - "X-Tenant-Id": "project-id2"}) + "X-Project-Id": "project-id2"}) self.assertEquals(['project-id2'], data['projects']) diff --git a/tests/api/v1/list_resources.py b/tests/api/v1/list_resources.py index a6722cc88..d95c0fc1b 100644 --- a/tests/api/v1/list_resources.py +++ b/tests/api/v1/list_resources.py @@ -113,7 +113,7 @@ class TestListResources(TestListResourcesBase): def test_list_resources_non_admin(self): data = self.get('/resources', headers={"X-Roles": "Member", - "X-Tenant-Id": "project-id"}) + "X-Project-Id": "project-id"}) self.assertEquals(2, len(data['resources'])) self.assertEquals(set(r['resource_id'] for r in data['resources']), set(['resource-id', @@ -136,7 +136,7 @@ class TestListResources(TestListResourcesBase): end_timestamp=datetime.datetime( 2012, 7, 2, 10, 43).isoformat(), headers={"X-Roles": "Member", - "X-Tenant-Id": "project-id"}) + "X-Project-Id": "project-id"}) self.assertEquals(set(r['resource_id'] for r in data['resources']), set(['resource-id-alternate'])) @@ -150,7 +150,7 @@ class TestListResources(TestListResourcesBase): def test_with_source_non_admin(self): data = self.get('/sources/test_list_resources/resources', headers={"X-Roles": "Member", - "X-Tenant-Id": "project-id"}) + "X-Project-Id": "project-id"}) ids = set(r['resource_id'] for r in data['resources']) self.assertEquals(set(['resource-id', 'resource-id-alternate']), ids) @@ -168,7 +168,7 @@ class TestListResources(TestListResourcesBase): def test_with_source_with_timestamps_non_admin(self): data = self.get('/sources/test_list_resources/resources', headers={"X-Roles": "Member", - "X-Tenant-Id": "project-id"}, + "X-Project-Id": "project-id"}, start_timestamp=datetime.datetime( 2012, 7, 2, 10, 41).isoformat(), end_timestamp=datetime.datetime( @@ -188,14 +188,14 @@ class TestListResources(TestListResourcesBase): def test_with_user_non_admin(self): data = self.get('/users/user-id/resources', headers={"X-Roles": "Member", - "X-Tenant-Id": "project-id"}) + "X-Project-Id": "project-id"}) ids = set(r['resource_id'] for r in data['resources']) self.assertEquals(set(['resource-id', 'resource-id-alternate']), ids) def test_with_user_wrong_tenant(self): data = self.get('/users/user-id/resources', headers={"X-Roles": "Member", - "X-Tenant-Id": "project-jd"}) + "X-Project-Id": "project-jd"}) ids = set(r['resource_id'] for r in data['resources']) self.assertEquals(set(), ids) @@ -211,7 +211,7 @@ class TestListResources(TestListResourcesBase): def test_with_user_with_timestamps_non_admin(self): data = self.get('/users/user-id/resources', headers={"X-Roles": "Member", - "X-Tenant-Id": "project-id"}, + "X-Project-Id": "project-id"}, start_timestamp=datetime.datetime( 2012, 7, 2, 10, 42).isoformat(), end_timestamp=datetime.datetime( @@ -231,7 +231,7 @@ class TestListResources(TestListResourcesBase): def test_with_project_non_admin(self): data = self.get('/projects/project-id/resources', headers={"X-Roles": "Member", - "X-Tenant-Id": "project-id"}) + "X-Project-Id": "project-id"}) ids = set(r['resource_id'] for r in data['resources']) self.assertEquals(set(['resource-id', 'resource-id-alternate']), ids) @@ -247,7 +247,7 @@ class TestListResources(TestListResourcesBase): def test_with_project_with_timestamp_non_admin(self): data = self.get('/projects/project-id/resources', headers={"X-Roles": "Member", - "X-Tenant-Id": "project-id"}, + "X-Project-Id": "project-id"}, start_timestamp=datetime.datetime( 2012, 7, 2, 10, 40).isoformat(), end_timestamp=datetime.datetime( @@ -271,7 +271,7 @@ class TestListResourcesMetaquery(TestListResourcesBase): q = '/sources/test_list_resources/resources' data = self.get('%s?metadata.display_name=test-server' % q, headers={"X-Roles": "Member", - "X-Tenant-Id": "project-id"}) + "X-Project-Id": "project-id"}) self.assertEquals(2, len(data['resources'])) def test_metaquery2(self): @@ -283,5 +283,5 @@ class TestListResourcesMetaquery(TestListResourcesBase): q = '/sources/test_list_resources/resources' data = self.get('%s?metadata.tag=self.counter4' % q, headers={"X-Roles": "Member", - "X-Tenant-Id": "project-id"}) + "X-Project-Id": "project-id"}) self.assertEquals(1, len(data['resources'])) diff --git a/tests/api/v1/list_users.py b/tests/api/v1/list_users.py index f15b5369e..0dcec8d5f 100644 --- a/tests/api/v1/list_users.py +++ b/tests/api/v1/list_users.py @@ -92,7 +92,7 @@ class TestListUsers(tests_api.TestBase): data = self.get('/users', headers={"X-Roles": "Member", "X-User-Id": "user-id", - "X-Tenant-Id": "project-id"}) + "X-Project-Id": "project-id"}) self.assertEquals(['user-id'], data['users']) def test_with_source(self): @@ -103,5 +103,5 @@ class TestListUsers(tests_api.TestBase): data = self.get('/sources/test_list_users/users', headers={"X-Roles": "Member", "X-User-Id": "user-id", - "X-Tenant-Id": "project-id"}) + "X-Project-Id": "project-id"}) self.assertEquals(['user-id'], data['users']) diff --git a/tests/api/v1/max_project_volume.py b/tests/api/v1/max_project_volume.py index 20c9672ff..1ce269992 100644 --- a/tests/api/v1/max_project_volume.py +++ b/tests/api/v1/max_project_volume.py @@ -65,13 +65,13 @@ class TestMaxProjectVolume(tests_api.TestBase): def test_no_time_bounds_non_admin(self): data = self.get('/projects/project1/meters/volume.size/volume/max', headers={"X-Roles": "Member", - "X-Tenant-Id": "project1"}) + "X-Project-Id": "project1"}) self.assertEqual(data, {'volume': 7}) def test_no_time_bounds_wrong_tenant(self): resp = self.get('/projects/project1/meters/volume.size/volume/max', headers={"X-Roles": "Member", - "X-Tenant-Id": "?"}) + "X-Project-Id": "?"}) self.assertEqual(resp.status_code, 404) def test_start_timestamp(self): diff --git a/tests/api/v1/max_resource_volume.py b/tests/api/v1/max_resource_volume.py index 478fb74ce..9b3e27ea5 100644 --- a/tests/api/v1/max_resource_volume.py +++ b/tests/api/v1/max_resource_volume.py @@ -64,13 +64,13 @@ class TestMaxResourceVolume(tests_api.TestBase): def test_no_time_bounds_non_admin(self): data = self.get('/resources/resource-id/meters/volume.size/volume/max', headers={"X-Roles": "Member", - "X-Tenant-Id": "project1"}) + "X-Project-Id": "project1"}) self.assertEqual(data, {'volume': 7}) def test_no_time_bounds_wrong_tenant(self): data = self.get('/resources/resource-id/meters/volume.size/volume/max', headers={"X-Roles": "Member", - "X-Tenant-Id": "??"}) + "X-Project-Id": "??"}) self.assertEqual(data, {'volume': None}) def test_start_timestamp(self): diff --git a/tests/api/v1/sum_project_volume.py b/tests/api/v1/sum_project_volume.py index e8d57b189..72a0f70c9 100644 --- a/tests/api/v1/sum_project_volume.py +++ b/tests/api/v1/sum_project_volume.py @@ -65,13 +65,13 @@ class TestSumProjectVolume(tests_api.TestBase): def test_no_time_bounds_non_admin(self): data = self.get('/projects/project1/meters/volume.size/volume/sum', headers={"X-Roles": "Member", - "X-Tenant-Id": "project1"}) + "X-Project-Id": "project1"}) self.assertEqual(data, {'volume': 5 + 6 + 7}) def test_no_time_bounds_wrong_tenant(self): resp = self.get('/projects/project1/meters/volume.size/volume/sum', headers={"X-Roles": "Member", - "X-Tenant-Id": "???"}) + "X-Project-Id": "???"}) self.assertEqual(resp.status_code, 404) def test_start_timestamp(self): diff --git a/tests/api/v1/sum_resource_volume.py b/tests/api/v1/sum_resource_volume.py index 0c3fe03ed..352e3e2ac 100644 --- a/tests/api/v1/sum_resource_volume.py +++ b/tests/api/v1/sum_resource_volume.py @@ -65,13 +65,13 @@ class TestSumResourceVolume(tests_api.TestBase): def test_no_time_bounds_non_admin(self): data = self.get('/resources/resource-id/meters/volume.size/volume/sum', headers={"X-Roles": "Member", - "X-Tenant-Id": "project1"}) + "X-Project-Id": "project1"}) self.assertEqual(data, {'volume': 5 + 6 + 7}) def test_no_time_bounds_wrong_tenant(self): data = self.get('/resources/resource-id/meters/volume.size/volume/sum', headers={"X-Roles": "Member", - "X-Tenant-Id": "?"}) + "X-Project-Id": "?"}) self.assertEqual(data, {'volume': None}) def test_start_timestamp(self): diff --git a/tests/api/v2/acl.py b/tests/api/v2/acl.py index 006740a82..4d4fe373b 100644 --- a/tests/api/v2/acl.py +++ b/tests/api/v2/acl.py @@ -127,7 +127,7 @@ class TestAPIACL(FunctionalTest): headers={ "X-Roles": "Member", "X-Tenant-Name": "admin", - "X-Tenant-Id": + "X-Project-Id": "bc23a9d531064583ace8f67dad60f6bb", }) self.assertEqual(response.status_int, 401) @@ -143,7 +143,7 @@ class TestAPIACL(FunctionalTest): # headers={ # "X-Roles": "admin", # "X-Tenant-Name": "achoo", - # "X-Tenant-Id": "bc23a9d531064583ace8f67dad60f6bb", + # "X-Project-Id": "bc23a9d531064583ace8f67dad60f6bb", # }) # self.assertEqual(response.status_int, 401) @@ -152,7 +152,7 @@ class TestAPIACL(FunctionalTest): headers={"X-Auth-Token": VALID_TOKEN, "X-Roles": "admin", "X-Tenant-Name": "admin", - "X-Tenant-Id": + "X-Project-Id": "bc23a9d531064583ace8f67dad60f6bb", }) ids = set(r['resource_id'] for r in data) @@ -162,7 +162,7 @@ class TestAPIACL(FunctionalTest): data = self.get_json('/meters', headers={"X-Roles": "Member", "X-Auth-Token": VALID_TOKEN2, - "X-Tenant-Id": "project-good"}) + "X-Project-Id": "project-good"}) ids = set(r['resource_id'] for r in data) self.assertEquals(set(['resource-good', 'resource-56']), ids) @@ -170,7 +170,7 @@ class TestAPIACL(FunctionalTest): data = self.get_json('/meters', headers={"X-Roles": "Member", "X-Auth-Token": VALID_TOKEN2, - "X-Tenant-Id": "project-good"}, + "X-Project-Id": "project-good"}, q=[{'field': 'project_id', 'value': 'project-good', }]) @@ -182,7 +182,7 @@ class TestAPIACL(FunctionalTest): expect_errors=True, headers={"X-Roles": "Member", "X-Auth-Token": VALID_TOKEN2, - "X-Tenant-Id": "project-good"}, + "X-Project-Id": "project-good"}, q=[{'field': 'project_id', 'value': 'project-wrong', }]) @@ -195,7 +195,7 @@ class TestAPIACL(FunctionalTest): expect_errors=True, headers={"X-Roles": "Member", "X-Auth-Token": VALID_TOKEN2, - "X-Tenant-Id": "project-good"}, + "X-Project-Id": "project-good"}, q=[{'field': 'project_id', 'value': 'project-good', }, diff --git a/tests/api/v2/list_resources.py b/tests/api/v2/list_resources.py index f10145f17..626a33862 100644 --- a/tests/api/v2/list_resources.py +++ b/tests/api/v2/list_resources.py @@ -363,7 +363,7 @@ class TestListResources(FunctionalTest): data = self.get_json('/resources', headers={"X-Roles": "Member", - "X-Tenant-Id": "project-id2"}) + "X-Project-Id": "project-id2"}) ids = set(r['resource_id'] for r in data) self.assertEquals(set(['resource-id-alternate']), ids) @@ -390,7 +390,7 @@ class TestListResources(FunctionalTest): data = self.get_json('/resources', headers={"X-Roles": "Member", - "X-Tenant-Id": "project-wrong"}) + "X-Project-Id": "project-wrong"}) ids = set(r['resource_id'] for r in data) self.assertEquals(set(), ids) diff --git a/tests/api/v2/post_samples.py b/tests/api/v2/post_samples.py index 3bb40cb0a..6a50409d8 100644 --- a/tests/api/v2/post_samples.py +++ b/tests/api/v2/post_samples.py @@ -78,7 +78,7 @@ class TestPostSamples(FunctionalTest): headers={ "X-Roles": "Member", "X-Tenant-Name": "lu-tenant", - "X-Tenant-Id": + "X-Project-Id": "bc23a9d531064583ace8f67dad60f6bb", })