Use container/disk format settings in glance v1 test

Make the container_formats and disk_formats parameters
used in tempest.api.image.v1.test_images classes.

Change-Id: If82587d396427ef66b2fbc85375b6b0ce1c671d0
Closes-Bug: #1483177
diff --git a/tempest/api/image/v1/test_images.py b/tempest/api/image/v1/test_images.py
index 64f3174..1a84d06 100644
--- a/tempest/api/image/v1/test_images.py
+++ b/tempest/api/image/v1/test_images.py
@@ -18,11 +18,27 @@
 from tempest.api.image import base
 from tempest.common.utils import data_utils
 from tempest import config
+from tempest import exceptions
 from tempest import test
 
 CONF = config.CONF
 
 
+def get_container_and_disk_format():
+    a_formats = ['ami', 'ari', 'aki']
+
+    container_format = CONF.image.container_formats[0]
+    disk_format = CONF.image.disk_formats[0]
+
+    if container_format in a_formats and container_format != disk_format:
+        msg = ("The container format and the disk format don't match. "
+               "Contaiter format: %(container)s, Disk format: %(disk)s." %
+               {'container': container_format, 'disk': disk_format})
+        raise exceptions.InvalidConfiguration(message=msg)
+
+    return container_format, disk_format
+
+
 class CreateRegisterImagesTest(base.BaseV1ImageTest):
     """Here we test the registration and creation of images."""
 
@@ -30,9 +46,10 @@
     def test_register_then_upload(self):
         # Register, then upload an image
         properties = {'prop1': 'val1'}
+        container_format, disk_format = get_container_and_disk_format()
         body = self.create_image(name='New Name',
-                                 container_format='bare',
-                                 disk_format='raw',
+                                 container_format=container_format,
+                                 disk_format=disk_format,
                                  is_public=False,
                                  properties=properties)
         self.assertIn('id', body)
@@ -52,9 +69,10 @@
     @test.idempotent_id('69da74d9-68a9-404b-9664-ff7164ccb0f5')
     def test_register_remote_image(self):
         # Register a new remote image
+        container_format, disk_format = get_container_and_disk_format()
         body = self.create_image(name='New Remote Image',
-                                 container_format='bare',
-                                 disk_format='raw', is_public=False,
+                                 container_format=container_format,
+                                 disk_format=disk_format, is_public=False,
                                  location=CONF.image.http_image,
                                  properties={'key1': 'value1',
                                              'key2': 'value2'})
@@ -68,9 +86,10 @@
 
     @test.idempotent_id('6d0e13a7-515b-460c-b91f-9f4793f09816')
     def test_register_http_image(self):
+        container_format, disk_format = get_container_and_disk_format()
         body = self.create_image(name='New Http Image',
-                                 container_format='bare',
-                                 disk_format='raw', is_public=False,
+                                 container_format=container_format,
+                                 disk_format=disk_format, is_public=False,
                                  copy_from=CONF.image.http_image)
         self.assertIn('id', body)
         image_id = body.get('id')
@@ -82,10 +101,11 @@
     @test.idempotent_id('05b19d55-140c-40d0-b36b-fafd774d421b')
     def test_register_image_with_min_ram(self):
         # Register an image with min ram
+        container_format, disk_format = get_container_and_disk_format()
         properties = {'prop1': 'val1'}
         body = self.create_image(name='New_image_with_min_ram',
-                                 container_format='bare',
-                                 disk_format='raw',
+                                 container_format=container_format,
+                                 disk_format=disk_format,
                                  is_public=False,
                                  min_ram=40,
                                  properties=properties)
@@ -103,22 +123,51 @@
     """Here we test the listing of image information"""
 
     @classmethod
+    def skip_checks(cls):
+        super(ListImagesTest, cls).skip_checks()
+        if (len(CONF.image.container_formats) < 2
+           or len(CONF.image.disk_formats) < 2):
+            skip_msg = ("%s skipped as multiple container formats "
+                        "or disk formats are not available." % cls.__name__)
+            raise cls.skipException(skip_msg)
+
+    @classmethod
     def resource_setup(cls):
         super(ListImagesTest, cls).resource_setup()
         # We add a few images here to test the listing functionality of
         # the images API
-        img1 = cls._create_remote_image('one', 'bare', 'raw')
-        img2 = cls._create_remote_image('two', 'ami', 'ami')
-        img3 = cls._create_remote_image('dup', 'bare', 'raw')
-        img4 = cls._create_remote_image('dup', 'bare', 'raw')
-        img5 = cls._create_standard_image('1', 'ami', 'ami', 42)
-        img6 = cls._create_standard_image('2', 'ami', 'ami', 142)
-        img7 = cls._create_standard_image('33', 'bare', 'raw', 142)
-        img8 = cls._create_standard_image('33', 'bare', 'raw', 142)
+        a_formats = ['ami', 'ari', 'aki']
+
+        (cls.container_format,
+         cls.container_format_alt) = CONF.image.container_formats[:2]
+        cls.disk_format, cls.disk_format_alt = CONF.image.disk_formats[:2]
+        if cls.container_format in a_formats:
+            cls.disk_format = cls.container_format
+        if cls.container_format_alt in a_formats:
+            cls.disk_format_alt = cls.container_format_alt
+
+        img1 = cls._create_remote_image('one', cls.container_format,
+                                        cls.disk_format)
+        img2 = cls._create_remote_image('two', cls.container_format_alt,
+                                        cls.disk_format_alt)
+        img3 = cls._create_remote_image('dup', cls.container_format,
+                                        cls.disk_format)
+        img4 = cls._create_remote_image('dup', cls.container_format,
+                                        cls.disk_format)
+        img5 = cls._create_standard_image('1', cls.container_format_alt,
+                                          cls.disk_format_alt, 42)
+        img6 = cls._create_standard_image('2', cls.container_format_alt,
+                                          cls.disk_format_alt, 142)
+        img7 = cls._create_standard_image('33', cls.container_format,
+                                          cls.disk_format, 142)
+        img8 = cls._create_standard_image('33', cls.container_format,
+                                          cls.disk_format, 142)
         cls.created_set = set(cls.created_images)
-        # 5x bare, 3x ami
-        cls.bare_set = set((img1, img3, img4, img7, img8))
-        cls.ami_set = set((img2, img5, img6))
+        # same container format
+        cls.same_container_format_set = set((img1, img3, img4, img7, img8))
+        # same disk format
+        cls.same_disk_format_set = set((img2, img5, img6))
+
         # 1x with size 42
         cls.size42_set = set((img5,))
         # 3x with size 142
@@ -167,22 +216,25 @@
 
     @test.idempotent_id('f1755589-63d6-4468-b098-589820eb4031')
     def test_index_disk_format(self):
-        images_list = self.client.list_images(disk_format='ami')['images']
+        images_list = self.client.list_images(
+            disk_format=self.disk_format_alt)['images']
         for image in images_list:
-            self.assertEqual(image['disk_format'], 'ami')
+            self.assertEqual(image['disk_format'], self.disk_format_alt)
         result_set = set(map(lambda x: x['id'], images_list))
-        self.assertTrue(self.ami_set <= result_set)
-        self.assertFalse(self.created_set - self.ami_set <= result_set)
+        self.assertTrue(self.same_disk_format_set <= result_set)
+        self.assertFalse(self.created_set - self.same_disk_format_set
+                         <= result_set)
 
     @test.idempotent_id('2143655d-96d9-4bec-9188-8674206b4b3b')
     def test_index_container_format(self):
-        images_list = (self.client.list_images(container_format='bare')
-                       ['images'])
+        images_list = self.client.list_images(
+            container_format=self.container_format)['images']
         for image in images_list:
-            self.assertEqual(image['container_format'], 'bare')
+            self.assertEqual(image['container_format'], self.container_format)
         result_set = set(map(lambda x: x['id'], images_list))
-        self.assertTrue(self.bare_set <= result_set)
-        self.assertFalse(self.created_set - self.bare_set <= result_set)
+        self.assertTrue(self.same_container_format_set <= result_set)
+        self.assertFalse(self.created_set - self.same_container_format_set
+                         <= result_set)
 
     @test.idempotent_id('feb32ac6-22bb-4a16-afd8-9454bb714b14')
     def test_index_max_size(self):
@@ -231,7 +283,9 @@
     @classmethod
     def resource_setup(cls):
         super(UpdateImageMetaTest, cls).resource_setup()
-        cls.image_id = cls._create_standard_image('1', 'ami', 'ami', 42)
+        container_format, disk_format = get_container_and_disk_format()
+        cls.image_id = cls._create_standard_image('1', container_format,
+                                                  disk_format, 42)
 
     @classmethod
     def _create_standard_image(cls, name, container_format,