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
This commit is contained in:
Eoghan Glynn 2013-07-17 15:27:39 +00:00
parent 1d0b6397d4
commit 80afaac4b6
13 changed files with 54 additions and 54 deletions

View File

@ -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')

View File

@ -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']))

View File

@ -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']))

View File

@ -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'])

View File

@ -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']))

View File

@ -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'])

View File

@ -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):

View File

@ -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):

View File

@ -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):

View File

@ -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):

View File

@ -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',
},

View File

@ -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)

View File

@ -78,7 +78,7 @@ class TestPostSamples(FunctionalTest):
headers={
"X-Roles": "Member",
"X-Tenant-Name": "lu-tenant",
"X-Tenant-Id":
"X-Project-Id":
"bc23a9d531064583ace8f67dad60f6bb",
})