Merge "Apply a naming rule of GET to compute clients([ik])"

This commit is contained in:
Jenkins 2015-06-26 04:59:09 +00:00 committed by Gerrit Code Review
commit b12cb81abb
13 changed files with 35 additions and 41 deletions

View File

@ -44,7 +44,7 @@ class InstanceUsageAuditLogTestJSON(base.BaseV2ComputeAdminTest):
def test_get_instance_usage_audit_log(self):
# Get instance usage audit log before specified time
now = datetime.datetime.now()
body = self.adm_client.get_instance_usage_audit_log(
body = self.adm_client.show_instance_usage_audit_log(
urllib.quote(now.strftime("%Y-%m-%d %H:%M:%S")))
expected_items = ['total_errors', 'total_instances', 'log',

View File

@ -39,12 +39,12 @@ class InstanceUsageAuditLogNegativeTestJSON(base.BaseV2ComputeAdminTest):
now = datetime.datetime.now()
self.assertRaises(lib_exc.Forbidden,
self.instance_usages_audit_log_client.
get_instance_usage_audit_log,
show_instance_usage_audit_log,
urllib.quote(now.strftime("%Y-%m-%d %H:%M:%S")))
@test.attr(type=['negative'])
@test.idempotent_id('9b952047-3641-41c7-ba91-a809fc5974c8')
def test_get_instance_usage_audit_logs_with_invalid_time(self):
self.assertRaises(lib_exc.BadRequest,
self.adm_client.get_instance_usage_audit_log,
self.adm_client.show_instance_usage_audit_log,
"invalid_time")

View File

@ -93,8 +93,8 @@ class ImagesMetadataTestJSON(base.BaseV2ComputeTest):
@test.idempotent_id('4f5db52f-6685-4c75-b848-f4bb363f9aa6')
def test_get_image_metadata_item(self):
# The value for a specific metadata key should be returned
meta = self.client.get_image_metadata_item(self.image_id,
'os_distro')
meta = self.client.show_image_metadata_item(self.image_id,
'os_distro')
self.assertEqual('value2', meta['os_distro'])
@test.idempotent_id('f2de776a-4778-4d90-a5da-aae63aee64ae')

View File

@ -49,7 +49,7 @@ class ImagesMetadataTestJSON(base.BaseV2ComputeTest):
def test_get_nonexistent_image_metadata_item(self):
# Negative test: Get on non-existent image should not happen
self.assertRaises(lib_exc.NotFound,
self.client.get_image_metadata_item,
self.client.show_image_metadata_item,
data_utils.rand_uuid(), 'os_version')
@test.attr(type=['negative'])

View File

@ -105,7 +105,7 @@ class ListImageFiltersTestJSON(base.BaseV2ComputeTest):
# The list of images should contain only images with the
# provided status
params = {'status': 'ACTIVE'}
images = self.client.list_images(params)
images = self.client.list_images(**params)
self.assertTrue(any([i for i in images if i['id'] == self.image1_id]))
self.assertTrue(any([i for i in images if i['id'] == self.image2_id]))
@ -116,7 +116,7 @@ class ListImageFiltersTestJSON(base.BaseV2ComputeTest):
# List of all images should contain the expected images filtered
# by name
params = {'name': self.image1['name']}
images = self.client.list_images(params)
images = self.client.list_images(**params)
self.assertTrue(any([i for i in images if i['id'] == self.image1_id]))
self.assertFalse(any([i for i in images if i['id'] == self.image2_id]))
@ -128,7 +128,7 @@ class ListImageFiltersTestJSON(base.BaseV2ComputeTest):
def test_list_images_filter_by_server_id(self):
# The images should contain images filtered by server id
params = {'server': self.server1['id']}
images = self.client.list_images(params)
images = self.client.list_images(**params)
self.assertTrue(any([i for i in images
if i['id'] == self.snapshot1_id]),
@ -149,7 +149,7 @@ class ListImageFiltersTestJSON(base.BaseV2ComputeTest):
# Try all server link types
for link in server_links:
params = {'server': link['href']}
images = self.client.list_images(params)
images = self.client.list_images(**params)
self.assertFalse(any([i for i in images
if i['id'] == self.snapshot1_id]))
@ -164,7 +164,7 @@ class ListImageFiltersTestJSON(base.BaseV2ComputeTest):
def test_list_images_filter_by_type(self):
# The list of servers should be filtered by image type
params = {'type': 'snapshot'}
images = self.client.list_images(params)
images = self.client.list_images(**params)
self.assertTrue(any([i for i in images
if i['id'] == self.snapshot1_id]))
@ -179,7 +179,7 @@ class ListImageFiltersTestJSON(base.BaseV2ComputeTest):
def test_list_images_limit_results(self):
# Verify only the expected number of results are returned
params = {'limit': '1'}
images = self.client.list_images(params)
images = self.client.list_images(**params)
self.assertEqual(1, len([x for x in images if 'id' in x]))
@test.idempotent_id('18bac3ae-da27-436c-92a9-b22474d13aab')
@ -189,7 +189,7 @@ class ListImageFiltersTestJSON(base.BaseV2ComputeTest):
# Becoming ACTIVE will modify the updated time
# Filter by the image's created time
params = {'changes-since': self.image3['created']}
images = self.client.list_images(params)
images = self.client.list_images(**params)
found = any([i for i in images if i['id'] == self.image3_id])
self.assertTrue(found)
@ -198,7 +198,7 @@ class ListImageFiltersTestJSON(base.BaseV2ComputeTest):
# Detailed list of all images should only contain images
# with the provided status
params = {'status': 'ACTIVE'}
images = self.client.list_images_with_detail(params)
images = self.client.list_images(detail=True, **params)
self.assertTrue(any([i for i in images if i['id'] == self.image1_id]))
self.assertTrue(any([i for i in images if i['id'] == self.image2_id]))
@ -209,7 +209,7 @@ class ListImageFiltersTestJSON(base.BaseV2ComputeTest):
# Detailed list of all images should contain the expected
# images filtered by name
params = {'name': self.image1['name']}
images = self.client.list_images_with_detail(params)
images = self.client.list_images(detail=True, **params)
self.assertTrue(any([i for i in images if i['id'] == self.image1_id]))
self.assertFalse(any([i for i in images if i['id'] == self.image2_id]))
@ -220,7 +220,7 @@ class ListImageFiltersTestJSON(base.BaseV2ComputeTest):
# Verify only the expected number of results (with full details)
# are returned
params = {'limit': '1'}
images = self.client.list_images_with_detail(params)
images = self.client.list_images(detail=True, **params)
self.assertEqual(1, len(images))
@test.idempotent_id('8c78f822-203b-4bf6-8bba-56ebd551cf84')
@ -233,7 +233,7 @@ class ListImageFiltersTestJSON(base.BaseV2ComputeTest):
# Try all server link types
for link in server_links:
params = {'server': link['href']}
images = self.client.list_images_with_detail(params)
images = self.client.list_images(detail=True, **params)
self.assertFalse(any([i for i in images
if i['id'] == self.snapshot1_id]))
@ -248,7 +248,7 @@ class ListImageFiltersTestJSON(base.BaseV2ComputeTest):
def test_list_images_with_detail_filter_by_type(self):
# The detailed list of servers should be filtered by image type
params = {'type': 'snapshot'}
images = self.client.list_images_with_detail(params)
images = self.client.list_images(detail=True, **params)
self.client.show_image(self.image_ref)
self.assertTrue(any([i for i in images
@ -267,5 +267,5 @@ class ListImageFiltersTestJSON(base.BaseV2ComputeTest):
# Becoming ACTIVE will modify the updated time
# Filter by the image's created time
params = {'changes-since': self.image1['created']}
images = self.client.list_images_with_detail(params)
images = self.client.list_images(detail=True, **params)
self.assertTrue(any([i for i in images if i['id'] == self.image1_id]))

View File

@ -50,6 +50,6 @@ class ListImagesTestJSON(base.BaseV2ComputeTest):
@test.idempotent_id('9f94cb6b-7f10-48c5-b911-a0b84d7d4cd6')
def test_list_images_with_detail(self):
# Detailed list of all images should contain the expected images
images = self.client.list_images_with_detail()
images = self.client.list_images(detail=True)
found = any([i for i in images if i['id'] == self.image_ref])
self.assertTrue(found)

View File

@ -82,7 +82,7 @@ class KeyPairsV2TestJSON(base.BaseComputeTest):
# Keypair should be created, Got details by name and deleted
k_name = data_utils.rand_name('keypair')
self._create_keypair(k_name)
keypair_detail = self.client.get_keypair(k_name)
keypair_detail = self.client.show_keypair(k_name)
self.assertIn('name', keypair_detail)
self.assertIn('public_key', keypair_detail)
self.assertEqual(keypair_detail['name'], k_name,

View File

@ -430,7 +430,7 @@ class ServerActionsTestJSON(base.BaseV2ComputeTest):
server = self.client.get_server(self.server_id)
image_name = server['name'] + '-shelved'
params = {'name': image_name}
images = self.images_client.list_images(params)
images = self.images_client.list_images(**params)
self.assertEqual(1, len(images))
self.assertEqual(image_name, images[0]['name'])

View File

@ -475,7 +475,7 @@ class ServersNegativeTestJSON(base.BaseV2ComputeTest):
server = self.client.get_server(self.server_id)
image_name = server['name'] + '-shelved'
params = {'name': image_name}
images = self.images_client.list_images(params)
images = self.images_client.list_images(**params)
self.assertEqual(1, len(images))
self.assertEqual(image_name, images[0]['name'])

View File

@ -219,7 +219,7 @@ class AuthorizationTestJSON(base.BaseV2ComputeTest):
def test_get_keypair_of_alt_account_fails(self):
# A GET request for another user's keypair should fail
self.assertRaises(lib_exc.NotFound,
self.alt_keypairs_client.get_keypair,
self.alt_keypairs_client.show_keypair,
self.keypairname)
@test.idempotent_id('6d841683-a8e0-43da-a1b8-b339f7692b61')
@ -356,7 +356,7 @@ class AuthorizationTestJSON(base.BaseV2ComputeTest):
self.images_client.set_image_metadata(self.image['id'],
req_metadata)
self.assertRaises(lib_exc.NotFound,
self.alt_images_client.get_image_metadata_item,
self.alt_images_client.show_image_metadata_item,
self.image['id'], 'meta1')
@test.idempotent_id('79531e2e-e721-493c-8b30-a35db36fdaa6')

View File

@ -43,26 +43,20 @@ class ImagesClientJSON(service_client.ServiceClient):
self.validate_response(schema.create_image, resp, body)
return service_client.ResponseBody(resp, body)
def list_images(self, params=None):
def list_images(self, detail=False, **params):
"""Returns a list of all images filtered by any parameters."""
url = 'images'
_schema = schema.list_images
if detail:
url += '/detail'
_schema = schema.list_images_details
if params:
url += '?%s' % urllib.urlencode(params)
resp, body = self.get(url)
body = json.loads(body)
self.validate_response(schema.list_images, resp, body)
return service_client.ResponseBodyList(resp, body['images'])
def list_images_with_detail(self, params=None):
"""Returns a detailed list of images filtered by any parameters."""
url = 'images/detail'
if params:
url += '?%s' % urllib.urlencode(params)
resp, body = self.get(url)
body = json.loads(body)
self.validate_response(schema.list_images_details, resp, body)
self.validate_response(_schema, resp, body)
return service_client.ResponseBodyList(resp, body['images'])
def show_image(self, image_id):
@ -106,7 +100,7 @@ class ImagesClientJSON(service_client.ServiceClient):
self.validate_response(schema.image_metadata, resp, body)
return service_client.ResponseBody(resp, body['metadata'])
def get_image_metadata_item(self, image_id, key):
def show_image_metadata_item(self, image_id, key):
"""Returns the value for a specific image metadata key."""
resp, body = self.get("images/%s/metadata/%s" % (str(image_id), key))
body = json.loads(body)

View File

@ -31,7 +31,7 @@ class InstanceUsagesAuditLogClientJSON(service_client.ServiceClient):
return service_client.ResponseBody(resp,
body["instance_usage_audit_logs"])
def get_instance_usage_audit_log(self, time_before):
def show_instance_usage_audit_log(self, time_before):
url = 'os-instance_usage_audit_log/%s' % time_before
resp, body = self.get(url)
body = json.loads(body)

View File

@ -32,7 +32,7 @@ class KeyPairsClientJSON(service_client.ServiceClient):
self.validate_response(schema.list_keypairs, resp, body)
return service_client.ResponseBodyList(resp, body['keypairs'])
def get_keypair(self, key_name):
def show_keypair(self, key_name):
resp, body = self.get("os-keypairs/%s" % str(key_name))
body = json.loads(body)
self.validate_response(schema.get_keypair, resp, body)