Apply other "get" rule of GET to image v2 client
[GET /resources] methods should be "list_<resource name>s" or "show_<resource name>", so this patch applies the part of the rule to image client. NOTE: This patch renames get_image_file to load_image_file because the method gets the content of file. So show_image_file didn't fit to its meaning. In addition, this renames store_image to store_image_file for consistency. Partially implements blueprint consistent-service-method-names Change-Id: I2b354ff7192bea20339c61bedcd2f11eee455381
This commit is contained in:
parent
0b13c58fa2
commit
66494e9e69
|
@ -44,7 +44,7 @@ class BasicAdminOperationsImagesTest(base.BaseV2ImageAdminTest):
|
|||
self.addCleanup(self.client.delete_image, image_id)
|
||||
# upload an image file
|
||||
image_file = moves.cStringIO(data_utils.random_bytes())
|
||||
self.client.store_image(image_id, image_file)
|
||||
self.client.store_image_file(image_id, image_file)
|
||||
# deactivate image
|
||||
self.admin_client.deactivate_image(image_id)
|
||||
body = self.client.show_image(image_id)
|
||||
|
|
|
@ -56,7 +56,7 @@ class BasicOperationsImagesTest(base.BaseV2ImageTest):
|
|||
# Now try uploading an image file
|
||||
file_content = data_utils.random_bytes()
|
||||
image_file = moves.cStringIO(file_content)
|
||||
self.client.store_image(image_id, image_file)
|
||||
self.client.store_image_file(image_id, image_file)
|
||||
|
||||
# Now try to get image details
|
||||
body = self.client.show_image(image_id)
|
||||
|
@ -67,7 +67,7 @@ class BasicOperationsImagesTest(base.BaseV2ImageTest):
|
|||
self.assertEqual(1024, body.get('size'))
|
||||
|
||||
# Now try get image file
|
||||
body = self.client.get_image_file(image_id)
|
||||
body = self.client.load_image_file(image_id)
|
||||
self.assertEqual(file_content, body.data)
|
||||
|
||||
@test.attr(type='smoke')
|
||||
|
@ -109,7 +109,7 @@ class BasicOperationsImagesTest(base.BaseV2ImageTest):
|
|||
|
||||
# Now try uploading an image file
|
||||
image_file = moves.cStringIO(data_utils.random_bytes())
|
||||
self.client.store_image(image_id, image_file)
|
||||
self.client.store_image_file(image_id, image_file)
|
||||
|
||||
# Update Image
|
||||
new_image_name = data_utils.rand_name('new-image')
|
||||
|
@ -156,7 +156,7 @@ class ListImagesTest(base.BaseV2ImageTest):
|
|||
disk_format=disk_format,
|
||||
visibility='private')
|
||||
image_id = body['id']
|
||||
cls.client.store_image(image_id, data=image_file)
|
||||
cls.client.store_image_file(image_id, data=image_file)
|
||||
|
||||
return image_id
|
||||
|
||||
|
@ -244,12 +244,12 @@ class ListImagesTest(base.BaseV2ImageTest):
|
|||
def test_get_image_schema(self):
|
||||
# Test to get image schema
|
||||
schema = "image"
|
||||
body = self.client.get_schema(schema)
|
||||
body = self.client.show_schema(schema)
|
||||
self.assertEqual("image", body['name'])
|
||||
|
||||
@test.idempotent_id('25c8d7b2-df21-460f-87ac-93130bcdc684')
|
||||
def test_get_images_schema(self):
|
||||
# Test to get images schema
|
||||
schema = "images"
|
||||
body = self.client.get_schema(schema)
|
||||
body = self.client.show_schema(schema)
|
||||
self.assertEqual("images", body['name'])
|
||||
|
|
|
@ -82,10 +82,10 @@ class ImagesMemberTest(base.BaseV2MemberImageTest):
|
|||
|
||||
@test.idempotent_id('634dcc3f-f6e2-4409-b8fd-354a0bb25d83')
|
||||
def test_get_image_member_schema(self):
|
||||
body = self.os_img_client.get_schema("member")
|
||||
body = self.os_img_client.show_schema("member")
|
||||
self.assertEqual("member", body['name'])
|
||||
|
||||
@test.idempotent_id('6ae916ef-1052-4e11-8d36-b3ae14853cbb')
|
||||
def test_get_image_members_schema(self):
|
||||
body = self.os_img_client.get_schema("members")
|
||||
body = self.os_img_client.show_schema("members")
|
||||
self.assertEqual("members", body['name'])
|
||||
|
|
|
@ -67,8 +67,8 @@ class TelemetryNotificationAPITestJSON(base.BaseTelemetryTest):
|
|||
def test_check_glance_v2_notifications(self):
|
||||
body = self.create_image(self.image_client_v2)
|
||||
|
||||
self.image_client_v2.store_image(body['id'], "file")
|
||||
self.image_client_v2.get_image_file(body['id'])
|
||||
self.image_client_v2.store_image_file(body['id'], "file")
|
||||
self.image_client_v2.load_image_file(body['id'])
|
||||
|
||||
query = 'resource', 'eq', body['id']
|
||||
|
||||
|
|
|
@ -651,13 +651,13 @@ def create_images(images):
|
|||
name, fname = _resolve_image(image, 'aki')
|
||||
aki = client.images.create_image(
|
||||
'javelin_' + name, 'aki', 'aki')
|
||||
client.images.store_image(aki.get('id'), open(fname, 'r'))
|
||||
client.images.store_image_file(aki.get('id'), open(fname, 'r'))
|
||||
extras['kernel_id'] = aki.get('id')
|
||||
|
||||
name, fname = _resolve_image(image, 'ari')
|
||||
ari = client.images.create_image(
|
||||
'javelin_' + name, 'ari', 'ari')
|
||||
client.images.store_image(ari.get('id'), open(fname, 'r'))
|
||||
client.images.store_image_file(ari.get('id'), open(fname, 'r'))
|
||||
extras['ramdisk_id'] = ari.get('id')
|
||||
|
||||
_, fname = _resolve_image(image, 'file')
|
||||
|
@ -665,7 +665,7 @@ def create_images(images):
|
|||
image['name'], image['container_format'],
|
||||
image['disk_format'], **extras)
|
||||
image_id = body.get('id')
|
||||
client.images.store_image(image_id, open(fname, 'r'))
|
||||
client.images.store_image_file(image_id, open(fname, 'r'))
|
||||
|
||||
|
||||
def destroy_images(images):
|
||||
|
|
|
@ -52,7 +52,7 @@ class ImageClientV2JSON(service_client.ServiceClient):
|
|||
|
||||
def _validate_schema(self, body, type='image'):
|
||||
if type in ['image', 'images']:
|
||||
schema = self.get_schema(type)
|
||||
schema = self.show_schema(type)
|
||||
else:
|
||||
raise ValueError("%s is not a valid schema type" % type)
|
||||
|
||||
|
@ -145,7 +145,7 @@ class ImageClientV2JSON(service_client.ServiceClient):
|
|||
"""Returns the primary type of resource this client works with."""
|
||||
return 'image'
|
||||
|
||||
def store_image(self, image_id, data):
|
||||
def store_image_file(self, image_id, data):
|
||||
url = 'v2/images/%s/file' % image_id
|
||||
headers = {'Content-Type': 'application/octet-stream'}
|
||||
resp, body = self.http.raw_request('PUT', url, headers=headers,
|
||||
|
@ -153,7 +153,7 @@ class ImageClientV2JSON(service_client.ServiceClient):
|
|||
self.expected_success(204, resp.status)
|
||||
return service_client.ResponseBody(resp, body)
|
||||
|
||||
def get_image_file(self, image_id):
|
||||
def load_image_file(self, image_id):
|
||||
url = 'v2/images/%s/file' % image_id
|
||||
resp, body = self.get(url)
|
||||
self.expected_success(200, resp.status)
|
||||
|
@ -206,7 +206,7 @@ class ImageClientV2JSON(service_client.ServiceClient):
|
|||
self.expected_success(204, resp.status)
|
||||
return service_client.ResponseBody(resp)
|
||||
|
||||
def get_schema(self, schema):
|
||||
def show_schema(self, schema):
|
||||
url = 'v2/schemas/%s' % schema
|
||||
resp, body = self.get(url)
|
||||
self.expected_success(200, resp.status)
|
||||
|
|
|
@ -152,7 +152,7 @@ class TestCreateResources(JavelinUnitTest):
|
|||
self.fake_object['format'],
|
||||
self.fake_object['format'])
|
||||
|
||||
mocked_function = self.fake_client.images.store_image
|
||||
mocked_function = self.fake_client.images.store_image_file
|
||||
fake_image_id = self.fake_object['body'].get('id')
|
||||
mocked_function.assert_called_once_with(fake_image_id, open_mock())
|
||||
|
||||
|
|
Loading…
Reference in New Issue