Merge "Make create_image use **kwargs"

This commit is contained in:
Jenkins 2015-12-18 05:01:57 +00:00 committed by Gerrit Code Review
commit 8ceb030317
4 changed files with 21 additions and 20 deletions

View File

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

View File

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

View File

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

View File

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