From 25b3016f401f4d68ea0af4790d6029be247b9478 Mon Sep 17 00:00:00 2001 From: Ken'ichi Ohmichi Date: Mon, 30 Nov 2015 11:27:13 +0000 Subject: [PATCH] Make create_image use **kwargs As we discussed on http://lists.openstack.org/pipermail/openstack-dev/2015-July/068864.html All http POST/PUT methods need to contain **kwargs as their arguments. This patch makes create_image use **kwargs. NOTE: We cannot make update_image use **kwargs because the API requires a list body, not dict body. Partially implements blueprint consistent-service-method-names Change-Id: Ic525e341712149699644ba39cafa5f91a700737f --- tempest/api/image/base.py | 8 +++--- tempest/api/image/v2/test_images_negative.py | 6 +++-- tempest/api/telemetry/base.py | 2 +- .../services/image/v2/json/images_client.py | 25 ++++++++----------- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/tempest/api/image/base.py b/tempest/api/image/base.py index da0ce83668..c3205ce8e8 100644 --- a/tempest/api/image/base.py +++ b/tempest/api/image/base.py @@ -70,8 +70,10 @@ class BaseImageTest(tempest.test.BaseTestCase): container_format = kwargs.pop('container_format') disk_format = kwargs.pop('disk_format') - image = cls.client.create_image(name, container_format, - disk_format, **kwargs) + image = cls.client.create_image(name=name, + container_format=container_format, + disk_format=disk_format, + **kwargs) # Image objects returned by the v1 client have the image # data inside a dict that is keyed against 'image'. if 'image' in image: @@ -156,7 +158,7 @@ class BaseV2MemberImageTest(BaseV2ImageTest): def _create_image(self): name = data_utils.rand_name('image') - image = self.os_img_client.create_image(name, + image = self.os_img_client.create_image(name=name, container_format='bare', disk_format='raw') image_id = image['id'] diff --git a/tempest/api/image/v2/test_images_negative.py b/tempest/api/image/v2/test_images_negative.py index 71c8c7ac5e..485942e952 100644 --- a/tempest/api/image/v2/test_images_negative.py +++ b/tempest/api/image/v2/test_images_negative.py @@ -90,10 +90,12 @@ class ImagesNegativeTest(base.BaseV2ImageTest): def test_register_with_invalid_container_format(self): # Negative tests for invalid data supplied to POST /images self.assertRaises(lib_exc.BadRequest, self.client.create_image, - 'test', 'wrong', 'vhd') + name='test', container_format='wrong', + disk_format='vhd') @test.attr(type=['negative']) @test.idempotent_id('70c6040c-5a97-4111-9e13-e73665264ce1') def test_register_with_invalid_disk_format(self): self.assertRaises(lib_exc.BadRequest, self.client.create_image, - 'test', 'bare', 'wrong') + name='test', container_format='bare', + disk_format='wrong') diff --git a/tempest/api/telemetry/base.py b/tempest/api/telemetry/base.py index bbd01f0a3b..8b617ac3cd 100644 --- a/tempest/api/telemetry/base.py +++ b/tempest/api/telemetry/base.py @@ -77,7 +77,7 @@ class BaseTelemetryTest(tempest.test.BaseTestCase): @classmethod def create_image(cls, client): body = client.create_image( - data_utils.rand_name('image'), container_format='bare', + name=data_utils.rand_name('image'), container_format='bare', disk_format='raw', visibility='private') # TODO(jswarren) Move ['image'] up to initial body value assignment # once both v1 and v2 glance clients include the full response diff --git a/tempest/services/image/v2/json/images_client.py b/tempest/services/image/v2/json/images_client.py index 44062eaff7..72b203a27b 100644 --- a/tempest/services/image/v2/json/images_client.py +++ b/tempest/services/image/v2/json/images_client.py @@ -55,6 +55,11 @@ class ImagesClientV2(service_client.ServiceClient): return self._http def update_image(self, image_id, patch): + """Update an image. + + Available params: see http://developer.openstack.org/ + api-ref-image-v2.html#updateImage-v2 + """ data = json.dumps(patch) headers = {"Content-Type": "application/openstack-images-v2.0" "-json-patch"} @@ -63,21 +68,13 @@ class ImagesClientV2(service_client.ServiceClient): body = json.loads(body) return service_client.ResponseBody(resp, body) - def create_image(self, name, container_format, disk_format, **kwargs): - params = { - "name": name, - "container_format": container_format, - "disk_format": disk_format, - } + def create_image(self, **kwargs): + """Create an image. - for option in kwargs: - value = kwargs.get(option) - if isinstance(value, dict) or isinstance(value, tuple): - params.update(value) - else: - params[option] = value - - data = json.dumps(params) + Available params: see http://developer.openstack.org/ + api-ref-image-v2.html#createImage-v2 + """ + data = json.dumps(kwargs) resp, body = self.post('v2/images', data) self.expected_success(201, resp.status) body = json.loads(body)