Make volume volume_client to use **kwargs-part1
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 volume volume_client use **kwargs for
create/upload/attach volume methods.
Partially implements blueprint consistent-service-method-names
Change-Id: I42fead6092b24d6bdc852c5fa276974a7b2e7120
diff --git a/tempest/api/compute/volumes/test_attach_volume.py b/tempest/api/compute/volumes/test_attach_volume.py
index b4837f7..468c79a 100644
--- a/tempest/api/compute/volumes/test_attach_volume.py
+++ b/tempest/api/compute/volumes/test_attach_volume.py
@@ -75,7 +75,7 @@
# Create a volume and wait for it to become ready
self.volume = self.volumes_client.create_volume(
- CONF.volume.volume_size, display_name='test')['volume']
+ size=CONF.volume.volume_size, display_name='test')['volume']
self.addCleanup(self._delete_volume)
self.volumes_client.wait_for_volume_status(self.volume['id'],
'available')
diff --git a/tempest/api/volume/base.py b/tempest/api/volume/base.py
index 12e6761..e32999c 100644
--- a/tempest/api/volume/base.py
+++ b/tempest/api/volume/base.py
@@ -106,14 +106,14 @@
super(BaseVolumeTest, cls).resource_cleanup()
@classmethod
- def create_volume(cls, size=None, **kwargs):
+ def create_volume(cls, **kwargs):
"""Wrapper utility that returns a test volume."""
name = data_utils.rand_name('Volume')
name_field = cls.special_fields['name_field']
kwargs[name_field] = name
- volume = cls.volumes_client.create_volume(size, **kwargs)['volume']
+ volume = cls.volumes_client.create_volume(**kwargs)['volume']
cls.volumes.append(volume)
cls.volumes_client.wait_for_volume_status(volume['id'], 'available')
diff --git a/tempest/api/volume/test_volumes_actions.py b/tempest/api/volume/test_volumes_actions.py
index d4636ee..5a6d215 100644
--- a/tempest/api/volume/test_volumes_actions.py
+++ b/tempest/api/volume/test_volumes_actions.py
@@ -62,8 +62,8 @@
# Volume is attached and detached successfully from an instance
mountpoint = '/dev/vdc'
self.client.attach_volume(self.volume['id'],
- self.server['id'],
- mountpoint)
+ instance_uuid=self.server['id'],
+ mountpoint=mountpoint)
self.client.wait_for_volume_status(self.volume['id'], 'in-use')
self.client.detach_volume(self.volume['id'])
self.client.wait_for_volume_status(self.volume['id'], 'available')
@@ -88,8 +88,8 @@
# Verify that a volume's attachment information is retrieved
mountpoint = '/dev/vdc'
self.client.attach_volume(self.volume['id'],
- self.server['id'],
- mountpoint)
+ instance_uuid=self.server['id'],
+ mountpoint=mountpoint)
self.client.wait_for_volume_status(self.volume['id'], 'in-use')
# NOTE(gfidente): added in reverse order because functions will be
# called in reverse order to the order they are added (LIFO)
@@ -114,8 +114,8 @@
# using the Glance image_client and from Cinder via tearDownClass.
image_name = data_utils.rand_name('Image')
body = self.client.upload_volume(
- self.volume['id'], image_name,
- CONF.volume.disk_format)['os-volume_upload_image']
+ self.volume['id'], image_name=image_name,
+ disk_format=CONF.volume.disk_format)['os-volume_upload_image']
image_id = body["image_id"]
self.addCleanup(self.image_client.delete_image, image_id)
self.image_client.wait_for_image_status(image_id, 'active')
diff --git a/tempest/api/volume/test_volumes_negative.py b/tempest/api/volume/test_volumes_negative.py
index 0af40ea..16398ed 100644
--- a/tempest/api/volume/test_volumes_negative.py
+++ b/tempest/api/volume/test_volumes_negative.py
@@ -190,8 +190,8 @@
self.assertRaises(lib_exc.NotFound,
self.client.attach_volume,
str(uuid.uuid4()),
- server['id'],
- self.mountpoint)
+ instance_uuid=server['id'],
+ mountpoint=self.mountpoint)
@test.attr(type=['negative'])
@test.idempotent_id('9f9c24e4-011d-46b5-b992-952140ce237a')
diff --git a/tempest/cmd/javelin.py b/tempest/cmd/javelin.py
index cdd0044..19c4a55 100755
--- a/tempest/cmd/javelin.py
+++ b/tempest/cmd/javelin.py
@@ -1022,7 +1022,9 @@
server_id = _get_server_by_name(client, volume['server'])['id']
volume_id = _get_volume_by_name(client, volume['name'])['id']
device = volume['device']
- client.volumes.attach_volume(volume_id, server_id, device)
+ client.volumes.attach_volume(volume_id,
+ instance_uuid=server_id,
+ mountpoint=device)
#######################
diff --git a/tempest/scenario/manager.py b/tempest/scenario/manager.py
index c2159c3..684eb86 100644
--- a/tempest/scenario/manager.py
+++ b/tempest/scenario/manager.py
@@ -259,9 +259,13 @@
imageRef=None, volume_type=None, wait_on_delete=True):
if name is None:
name = data_utils.rand_name(self.__class__.__name__)
- volume = self.volumes_client.create_volume(
- size=size, display_name=name, snapshot_id=snapshot_id,
- imageRef=imageRef, volume_type=volume_type)['volume']
+ kwargs = {'display_name': name,
+ 'snapshot_id': snapshot_id,
+ 'imageRef': imageRef,
+ 'volume_type': volume_type}
+ if size is not None:
+ kwargs.update({'size': size})
+ volume = self.volumes_client.create_volume(**kwargs)['volume']
if wait_on_delete:
self.addCleanup(self.volumes_client.wait_for_resource_deletion,
diff --git a/tempest/services/volume/base/base_volumes_client.py b/tempest/services/volume/base/base_volumes_client.py
index c7302e8..179fb4e 100644
--- a/tempest/services/volume/base/base_volumes_client.py
+++ b/tempest/services/volume/base/base_volumes_client.py
@@ -71,23 +71,15 @@
self.expected_success(200, resp.status)
return service_client.ResponseBody(resp, body)
- def create_volume(self, size=None, **kwargs):
+ def create_volume(self, **kwargs):
"""Creates a new Volume.
- size: Size of volume in GB.
- Following optional keyword arguments are accepted:
- display_name: Optional Volume Name(only for V1).
- name: Optional Volume Name(only for V2).
- metadata: A dictionary of values to be used as metadata.
- volume_type: Optional Name of volume_type for the volume
- snapshot_id: When specified the volume is created from this snapshot
- imageRef: When specified the volume is created from this image
+ Available params: see http://developer.openstack.org/
+ api-ref-blockstorage-v2.html#createVolume
"""
- if size is None:
- size = self.default_volume_size
- post_body = {'size': size}
- post_body.update(kwargs)
- post_body = json.dumps({'volume': post_body})
+ if 'size' not in kwargs:
+ kwargs['size'] = self.default_volume_size
+ post_body = json.dumps({'volume': kwargs})
resp, body = self.post('volumes', post_body)
body = json.loads(body)
self.expected_success(self.create_resp, resp.status)
@@ -107,26 +99,18 @@
self.expected_success(202, resp.status)
return service_client.ResponseBody(resp, body)
- def upload_volume(self, volume_id, image_name, disk_format):
+ def upload_volume(self, volume_id, **kwargs):
"""Uploads a volume in Glance."""
- post_body = {
- 'image_name': image_name,
- 'disk_format': disk_format
- }
- post_body = json.dumps({'os-volume_upload_image': post_body})
+ post_body = json.dumps({'os-volume_upload_image': kwargs})
url = 'volumes/%s/action' % (volume_id)
resp, body = self.post(url, post_body)
body = json.loads(body)
self.expected_success(202, resp.status)
return service_client.ResponseBody(resp, body)
- def attach_volume(self, volume_id, instance_uuid, mountpoint):
+ def attach_volume(self, volume_id, **kwargs):
"""Attaches a volume to a given instance on a given mountpoint."""
- post_body = {
- 'instance_uuid': instance_uuid,
- 'mountpoint': mountpoint,
- }
- post_body = json.dumps({'os-attach': post_body})
+ post_body = json.dumps({'os-attach': kwargs})
url = 'volumes/%s/action' % (volume_id)
resp, body = self.post(url, post_body)
self.expected_success(202, resp.status)
diff --git a/tempest/tests/cmd/test_javelin.py b/tempest/tests/cmd/test_javelin.py
index 56bc96c..62409bf 100644
--- a/tempest/tests/cmd/test_javelin.py
+++ b/tempest/tests/cmd/test_javelin.py
@@ -78,8 +78,8 @@
mocked_function = self.fake_client.volumes.attach_volume
mocked_function.assert_called_once_with(
self.fake_object.volume['id'],
- self.fake_object.server['id'],
- self.fake_object['device'])
+ instance_uuid=self.fake_object.server['id'],
+ mountpoint=self.fake_object['device'])
class TestCreateResources(JavelinUnitTest):