Test creating multiple volumes from image simultaneously

This test aims to help find issues in volume drivers and
Cinder's image download internals.

It creates five volumes simultaneously from the same image.

Depends-On: I2ae36c4e90bd7b3340861ceec23dee406ea48214
Change-Id: I72d73c3e0e6160126a95103e36ab073a78ff8b3f
diff --git a/cinder_tempest_plugin/api/volume/test_create_from_image.py b/cinder_tempest_plugin/api/volume/test_create_from_image.py
new file mode 100644
index 0000000..12e6c8e
--- /dev/null
+++ b/cinder_tempest_plugin/api/volume/test_create_from_image.py
@@ -0,0 +1,77 @@
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+
+from tempest.common import waiters
+from tempest import config
+from tempest.lib.common.utils import data_utils
+from tempest.lib.common.utils import test_utils
+from tempest.lib import decorators
+
+from cinder_tempest_plugin.api.volume import base
+
+CONF = config.CONF
+
+
+class VolumeFromImageTest(base.BaseVolumeTest):
+
+    @classmethod
+    def skip_checks(cls):
+        super(VolumeFromImageTest, cls).skip_checks()
+
+    @classmethod
+    def create_volume_no_wait(cls, **kwargs):
+        """Returns a test volume.
+
+        This does not wait for volume creation to finish,
+        so that multiple operations can happen on the
+        Cinder server in parallel.
+        """
+        if 'size' not in kwargs:
+            kwargs['size'] = CONF.volume.volume_size
+
+        if 'imageRef' in kwargs:
+            image = cls.os_primary.image_client_v2.show_image(
+                kwargs['imageRef'])
+            min_disk = image['min_disk']
+            kwargs['size'] = max(kwargs['size'], min_disk)
+
+        if 'name' not in kwargs:
+            name = data_utils.rand_name(cls.__name__ + '-Volume')
+            kwargs['name'] = name
+
+        volume = cls.volumes_client.create_volume(**kwargs)['volume']
+        cls.addClassResourceCleanup(
+            cls.volumes_client.wait_for_resource_deletion, volume['id'])
+        cls.addClassResourceCleanup(test_utils.call_and_ignore_notfound_exc,
+                                    cls.volumes_client.delete_volume,
+                                    volume['id'])
+
+        return volume
+
+    @decorators.idempotent_id('8976a11b-1ddc-49b6-b66f-8c26adf3fa9e')
+    def test_create_from_image_multiple(self):
+        """Create a handful of volumes from the same image at once.
+
+        The purpose of this test is to stress volume drivers,
+        image download, the image cache, etc., within Cinder.
+        """
+
+        img_uuid = CONF.compute.image_ref
+
+        vols = []
+        for v in range(0, 5):
+            vols.append(self.create_volume_no_wait(imageRef=img_uuid))
+
+        for v in vols:
+            waiters.wait_for_volume_resource_status(self.volumes_client,
+                                                    v['id'],
+                                                    'available')