Adds disk_format parameter to upload_volume method in volumes client

Adds a third parameter, disk_format, to the upload_volume method of
the volumes client. The parameter is also added to the Tempest
configuration and defaults to "raw" if not set.

Closes-Bug: #1218666
Change-Id: I6c62796161c9219cbd80eb9fecc7fbb0f3a4681a
diff --git a/etc/tempest.conf.sample b/etc/tempest.conf.sample
index 8d96858..064464b 100644
--- a/etc/tempest.conf.sample
+++ b/etc/tempest.conf.sample
@@ -246,6 +246,8 @@
 # Unless you have a custom Keystone service catalog implementation, you
 # probably want to leave this value as "volume"
 catalog_type = volume
+# The disk format to use when copying a volume to image
+disk_format = raw
 # Number of seconds to wait while looping to check the status of a
 # volume that is being made available
 build_interval = 10
diff --git a/tempest/api/volume/test_volumes_actions.py b/tempest/api/volume/test_volumes_actions.py
index 960785d..ab75d4d 100644
--- a/tempest/api/volume/test_volumes_actions.py
+++ b/tempest/api/volume/test_volumes_actions.py
@@ -99,7 +99,9 @@
         # there is no way to delete it from Cinder, so we delete it from Glance
         # using the Glance image_client and from Cinder via tearDownClass.
         image_name = rand_name('Image-')
-        resp, body = self.client.upload_volume(self.volume['id'], image_name)
+        resp, body = self.client.upload_volume(self.volume['id'],
+                                               image_name,
+                                               self.config.volume.disk_format)
         image_id = body["image_id"]
         self.addCleanup(self.image_client.delete_image, image_id)
         self.assertEqual(202, resp.status)
diff --git a/tempest/config.py b/tempest/config.py
index 7245b10..4a77827 100644
--- a/tempest/config.py
+++ b/tempest/config.py
@@ -353,6 +353,9 @@
     cfg.StrOpt('vendor_name',
                default='Open Source',
                help='Backend vendor to target when creating volume types'),
+    cfg.StrOpt('disk_format',
+               default='raw',
+               help='Disk format to use when copying a volume to image'),
 ]
 
 
diff --git a/tempest/services/volume/json/volumes_client.py b/tempest/services/volume/json/volumes_client.py
index 2ae73b1..c35452e 100644
--- a/tempest/services/volume/json/volumes_client.py
+++ b/tempest/services/volume/json/volumes_client.py
@@ -89,10 +89,11 @@
         """Deletes the Specified Volume."""
         return self.delete("volumes/%s" % str(volume_id))
 
-    def upload_volume(self, volume_id, image_name):
+    def upload_volume(self, volume_id, image_name, disk_format):
         """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})
         url = 'volumes/%s/action' % (volume_id)
diff --git a/tempest/services/volume/xml/volumes_client.py b/tempest/services/volume/xml/volumes_client.py
index 936e036..ecbfb19 100644
--- a/tempest/services/volume/xml/volumes_client.py
+++ b/tempest/services/volume/xml/volumes_client.py
@@ -183,10 +183,11 @@
             body = xml_to_json(etree.fromstring(body))
         return resp, body
 
-    def upload_volume(self, volume_id, image_name):
+    def upload_volume(self, volume_id, image_name, disk_format):
         """Uploads a volume in Glance."""
         post_body = Element("os-volume_upload_image",
-                            image_name=image_name)
+                            image_name=image_name,
+                            disk_format=disk_format)
         url = 'volumes/%s/action' % str(volume_id)
         resp, body = self.post(url, str(Document(post_body)), self.headers)
         volume = xml_to_json(etree.fromstring(body))