Merge "Rename TestQuotasClient to TestHostsClient"
diff --git a/HACKING.rst b/HACKING.rst
index 5b9c0f1..e767b25 100644
--- a/HACKING.rst
+++ b/HACKING.rst
@@ -349,18 +349,19 @@
 docstrings for the workflow in each test methods can be used instead. A good
 example of this would be::
 
-    class TestVolumeBootPattern(manager.ScenarioTest):
-        """
-        This test case attempts to reproduce the following steps:
+    class TestServerBasicOps(manager.ScenarioTest):
 
-         * Create in Cinder some bootable volume importing a Glance image
-         * Boot an instance from the bootable volume
-         * Write content to the volume
-         * Delete an instance and Boot a new instance from the volume
-         * Check written content in the instance
-         * Create a volume snapshot while the instance is running
-         * Boot an additional instance from the new snapshot based volume
-         * Check written content in the instance booted from snapshot
+        """The test suite for server basic operations
+
+        This smoke test case follows this basic set of operations:
+         * Create a keypair for use in launching an instance
+         * Create a security group to control network access in instance
+         * Add simple permissive rules to the security group
+         * Launch an instance
+         * Perform ssh to instance
+         * Verify metadata service
+         * Verify metadata on config_drive
+         * Terminate the instance
         """
 
 Test Identification with Idempotent ID
diff --git a/tempest/api/compute/admin/test_volume_swap.py b/tempest/api/compute/admin/test_volume_swap.py
index ed8cf20..5439ebe 100644
--- a/tempest/api/compute/admin/test_volume_swap.py
+++ b/tempest/api/compute/admin/test_volume_swap.py
@@ -82,6 +82,11 @@
        is attached to "instance1" and "volume2" is in available state.
     """
 
+    # NOTE(mriedem): This is an uncommon scenario to call the compute API
+    # to swap volumes directly; swap volume is primarily only for volume
+    # live migration and retype callbacks from the volume service, and is slow
+    # so it's marked as such.
+    @decorators.attr(type='slow')
     @decorators.idempotent_id('1769f00d-a693-4d67-a631-6a3496773813')
     @utils.services('volume')
     def test_volume_swap(self):
@@ -136,6 +141,11 @@
         if not CONF.compute_feature_enabled.volume_multiattach:
             raise cls.skipException('Volume multi-attach is not available.')
 
+    # NOTE(mriedem): This is an uncommon scenario to call the compute API
+    # to swap volumes directly; swap volume is primarily only for volume
+    # live migration and retype callbacks from the volume service, and is slow
+    # so it's marked as such.
+    @decorators.attr(type='slow')
     @decorators.idempotent_id('e8f8f9d1-d7b7-4cd2-8213-ab85ef697b6e')
     @utils.services('volume')
     def test_volume_swap_with_multiattach(self):
@@ -146,6 +156,8 @@
         volume1 = self.create_volume(multiattach=True)
         volume2 = self.create_volume(multiattach=True)
 
+        # TODO(mriedem): Speed this up by waiting for both servers to be active
+        # in parallel.
         # Boot server1
         server1 = self.create_test_server(wait_until='ACTIVE')
         # Attach volume1 to server1
diff --git a/tempest/api/compute/base.py b/tempest/api/compute/base.py
index ff2f99c..4e2b59b 100644
--- a/tempest/api/compute/base.py
+++ b/tempest/api/compute/base.py
@@ -331,8 +331,7 @@
         # The compute image proxy APIs were deprecated in 2.35 so
         # use the images client directly if the API microversion being
         # used is >=2.36.
-        if api_version_utils.compare_version_header_to_response(
-                "OpenStack-API-Version", "compute 2.36", image.response, "lt"):
+        if not cls.is_requested_microversion_compatible('2.35'):
             client = cls.images_client
         else:
             client = cls.compute_images_client
@@ -341,6 +340,9 @@
 
         if wait_until is not None:
             try:
+                wait_until = wait_until.upper()
+                if not cls.is_requested_microversion_compatible('2.35'):
+                    wait_until = wait_until.lower()
                 waiters.wait_for_image_status(client, image_id, wait_until)
             except lib_exc.NotFound:
                 if wait_until.upper() == 'ACTIVE':
diff --git a/tempest/api/compute/images/test_images.py b/tempest/api/compute/images/test_images.py
index 29bd6da..c8221c2 100644
--- a/tempest/api/compute/images/test_images.py
+++ b/tempest/api/compute/images/test_images.py
@@ -38,7 +38,10 @@
     @classmethod
     def setup_clients(cls):
         super(ImagesTestJSON, cls).setup_clients()
-        cls.client = cls.compute_images_client
+        if cls.is_requested_microversion_compatible('2.35'):
+            cls.client = cls.compute_images_client
+        else:
+            cls.client = cls.images_client
 
     @decorators.idempotent_id('aa06b52b-2db5-4807-b218-9441f75d74e3')
     def test_delete_saving_image(self):
diff --git a/tempest/api/compute/images/test_images_negative.py b/tempest/api/compute/images/test_images_negative.py
index e292389..2400348 100644
--- a/tempest/api/compute/images/test_images_negative.py
+++ b/tempest/api/compute/images/test_images_negative.py
@@ -22,11 +22,11 @@
 CONF = config.CONF
 
 
-class ImagesNegativeTestJSON(base.BaseV2ComputeTest):
+class ImagesNegativeTestBase(base.BaseV2ComputeTest):
 
     @classmethod
     def skip_checks(cls):
-        super(ImagesNegativeTestJSON, cls).skip_checks()
+        super(ImagesNegativeTestBase, cls).skip_checks()
         if not CONF.service_available.glance:
             skip_msg = ("%s skipped as glance is not available" % cls.__name__)
             raise cls.skipException(skip_msg)
@@ -37,9 +37,12 @@
 
     @classmethod
     def setup_clients(cls):
-        super(ImagesNegativeTestJSON, cls).setup_clients()
+        super(ImagesNegativeTestBase, cls).setup_clients()
         cls.client = cls.compute_images_client
 
+
+class ImagesNegativeTestJSON(ImagesNegativeTestBase):
+
     @decorators.attr(type=['negative'])
     @decorators.idempotent_id('6cd5a89d-5b47-46a7-93bc-3916f0d84973')
     def test_create_image_from_deleted_server(self):
@@ -82,6 +85,10 @@
         self.assertRaises(lib_exc.NotFound, self.client.create_image,
                           test_uuid, name=snapshot_name)
 
+
+class ImagesDeleteNegativeTestJSON(ImagesNegativeTestBase):
+    max_microversion = '2.35'
+
     @decorators.attr(type=['negative'])
     @decorators.idempotent_id('381acb65-785a-4942-94ce-d8f8c84f1f0f')
     def test_delete_image_with_invalid_image_id(self):
diff --git a/tempest/api/compute/images/test_images_oneserver.py b/tempest/api/compute/images/test_images_oneserver.py
index 058e7e6..3c152c9 100644
--- a/tempest/api/compute/images/test_images_oneserver.py
+++ b/tempest/api/compute/images/test_images_oneserver.py
@@ -44,7 +44,10 @@
     @classmethod
     def setup_clients(cls):
         super(ImagesOneServerTestJSON, cls).setup_clients()
-        cls.client = cls.compute_images_client
+        if cls.is_requested_microversion_compatible('2.35'):
+            cls.client = cls.compute_images_client
+        else:
+            cls.client = cls.images_client
 
     def _get_default_flavor_disk_size(self, flavor_id):
         flavor = self.flavors_client.show_flavor(flavor_id)['flavor']
@@ -52,6 +55,13 @@
 
     @decorators.idempotent_id('3731d080-d4c5-4872-b41a-64d0d0021314')
     def test_create_delete_image(self):
+        if self.is_requested_microversion_compatible('2.35'):
+            MIN_DISK = 'minDisk'
+            MIN_RAM = 'minRam'
+        else:
+            MIN_DISK = 'min_disk'
+            MIN_RAM = 'min_ram'
+
         # Create a new image
         name = data_utils.rand_name('image')
         meta = {'image_type': 'test'}
@@ -61,17 +71,22 @@
 
         # Verify the image was created correctly
         self.assertEqual(name, image['name'])
-        self.assertEqual('test', image['metadata']['image_type'])
+        if self.is_requested_microversion_compatible('2.35'):
+            self.assertEqual('test', image['metadata']['image_type'])
+        else:
+            self.assertEqual('test', image['image_type'])
 
-        original_image = self.client.show_image(self.image_ref)['image']
+        original_image = self.client.show_image(self.image_ref)
+        if self.is_requested_microversion_compatible('2.35'):
+            original_image = original_image['image']
 
         # Verify minRAM is the same as the original image
-        self.assertEqual(image['minRam'], original_image['minRam'])
+        self.assertEqual(image[MIN_RAM], original_image[MIN_RAM])
 
         # Verify minDisk is the same as the original image or the flavor size
         flavor_disk_size = self._get_default_flavor_disk_size(self.flavor_ref)
-        self.assertIn(str(image['minDisk']),
-                      (str(original_image['minDisk']), str(flavor_disk_size)))
+        self.assertIn(str(image[MIN_DISK]),
+                      (str(original_image[MIN_DISK]), str(flavor_disk_size)))
 
         # Verify the image was deleted correctly
         self.client.delete_image(image['id'])
@@ -86,7 +101,8 @@
         # will return 400(Bad Request) if we attempt to send a name which has
         # 4 byte utf-8 character.
         utf8_name = data_utils.rand_name(b'\xe2\x82\xa1'.decode('utf-8'))
-        body = self.client.create_image(self.server_id, name=utf8_name)
+        body = self.compute_images_client.create_image(
+            self.server_id, name=utf8_name)
         if api_version_utils.compare_version_header_to_response(
             "OpenStack-API-Version", "compute 2.45", body.response, "lt"):
             image_id = body['image_id']
diff --git a/tempest/api/compute/images/test_images_oneserver_negative.py b/tempest/api/compute/images/test_images_oneserver_negative.py
index bebc6ca..512c9d2 100644
--- a/tempest/api/compute/images/test_images_oneserver_negative.py
+++ b/tempest/api/compute/images/test_images_oneserver_negative.py
@@ -72,7 +72,10 @@
     @classmethod
     def setup_clients(cls):
         super(ImagesOneServerNegativeTestJSON, cls).setup_clients()
-        cls.client = cls.compute_images_client
+        if cls.is_requested_microversion_compatible('2.35'):
+            cls.client = cls.compute_images_client
+        else:
+            cls.client = cls.images_client
 
     @classmethod
     def resource_setup(cls):
@@ -122,7 +125,8 @@
         # Return an error if snapshot name over 255 characters is passed
 
         snapshot_name = ('a' * 256)
-        self.assertRaises(lib_exc.BadRequest, self.client.create_image,
+        self.assertRaises(lib_exc.BadRequest,
+                          self.compute_images_client.create_image,
                           self.server_id, name=snapshot_name)
 
     @decorators.attr(type=['negative'])
diff --git a/tempest/api/compute/images/test_list_image_filters.py b/tempest/api/compute/images/test_list_image_filters.py
index d83d8df..2ac7de3 100644
--- a/tempest/api/compute/images/test_list_image_filters.py
+++ b/tempest/api/compute/images/test_list_image_filters.py
@@ -31,6 +31,7 @@
 
 
 class ListImageFiltersTestJSON(base.BaseV2ComputeTest):
+    max_microversion = '2.35'
 
     @classmethod
     def skip_checks(cls):
diff --git a/tempest/api/compute/images/test_list_image_filters_negative.py b/tempest/api/compute/images/test_list_image_filters_negative.py
index d37f8fc..81c59f9 100644
--- a/tempest/api/compute/images/test_list_image_filters_negative.py
+++ b/tempest/api/compute/images/test_list_image_filters_negative.py
@@ -22,6 +22,7 @@
 
 
 class ListImageFiltersNegativeTestJSON(base.BaseV2ComputeTest):
+    max_microversion = '2.35'
 
     @classmethod
     def skip_checks(cls):
diff --git a/tempest/api/compute/images/test_list_images.py b/tempest/api/compute/images/test_list_images.py
index e2dbd72..cbb65bb 100644
--- a/tempest/api/compute/images/test_list_images.py
+++ b/tempest/api/compute/images/test_list_images.py
@@ -21,6 +21,7 @@
 
 
 class ListImagesTestJSON(base.BaseV2ComputeTest):
+    max_microversion = '2.35'
 
     @classmethod
     def skip_checks(cls):
diff --git a/tempest/api/compute/servers/test_device_tagging.py b/tempest/api/compute/servers/test_device_tagging.py
index 40681cb..d40f937 100644
--- a/tempest/api/compute/servers/test_device_tagging.py
+++ b/tempest/api/compute/servers/test_device_tagging.py
@@ -138,6 +138,9 @@
         except Exception:
             return False
 
+    # NOTE(mriedem): This is really more like a scenario test and is slow so
+    # it's marked as such.
+    @decorators.attr(type='slow')
     @decorators.idempotent_id('a2e65a6c-66f1-4442-aaa8-498c31778d96')
     @utils.services('network', 'volume', 'image')
     def test_tagged_boot_devices(self):
diff --git a/tempest/api/compute/servers/test_server_actions.py b/tempest/api/compute/servers/test_server_actions.py
index f6494b5..f3d7476 100644
--- a/tempest/api/compute/servers/test_server_actions.py
+++ b/tempest/api/compute/servers/test_server_actions.py
@@ -265,6 +265,11 @@
 
         self.client.start_server(self.server_id)
 
+    # NOTE(mriedem): Marked as slow because while rebuild and volume-backed is
+    # common, we don't actually change the image (you can't with volume-backed
+    # rebuild) so this isn't testing much outside normal rebuild
+    # (and it's slow).
+    @decorators.attr(type='slow')
     @decorators.idempotent_id('b68bd8d6-855d-4212-b59b-2e704044dace')
     @utils.services('volume')
     def test_rebuild_server_with_volume_attached(self):
diff --git a/tempest/api/compute/servers/test_server_personality.py b/tempest/api/compute/servers/test_server_personality.py
index 6f32b46..4f484e2 100644
--- a/tempest/api/compute/servers/test_server_personality.py
+++ b/tempest/api/compute/servers/test_server_personality.py
@@ -45,6 +45,10 @@
         super(ServerPersonalityTestJSON, cls).setup_clients()
         cls.client = cls.servers_client
 
+    # NOTE(mriedem): Marked as slow because personality (file injection) is
+    # deprecated in nova so we don't care as much about running this all the
+    # time (and it's slow).
+    @decorators.attr(type='slow')
     @decorators.idempotent_id('3cfe87fd-115b-4a02-b942-7dc36a337fdf')
     def test_create_server_with_personality(self):
         file_contents = 'This is a test file.'
@@ -75,6 +79,10 @@
                              linux_client.exec_command(
                                  'sudo cat %s' % file_path))
 
+    # NOTE(mriedem): Marked as slow because personality (file injection) is
+    # deprecated in nova so we don't care as much about running this all the
+    # time (and it's slow).
+    @decorators.attr(type='slow')
     @decorators.idempotent_id('128966d8-71fc-443c-8cab-08e24114ecc9')
     def test_rebuild_server_with_personality(self):
         validation_resources = self.get_test_validation_resources(
@@ -117,6 +125,10 @@
         self.assertRaises((lib_exc.Forbidden, lib_exc.OverLimit),
                           self.create_test_server, personality=personality)
 
+    # NOTE(mriedem): Marked as slow because personality (file injection) is
+    # deprecated in nova so we don't care as much about running this all the
+    # time (and it's slow).
+    @decorators.attr(type='slow')
     @decorators.idempotent_id('52f12ee8-5180-40cc-b417-31572ea3d555')
     def test_can_create_server_with_max_number_personality_files(self):
         # Server should be created successfully if maximum allowed number of
diff --git a/tempest/api/compute/servers/test_servers_negative.py b/tempest/api/compute/servers/test_servers_negative.py
index 0c1c05c..6cabf65 100644
--- a/tempest/api/compute/servers/test_servers_negative.py
+++ b/tempest/api/compute/servers/test_servers_negative.py
@@ -488,8 +488,11 @@
 
         server = self.client.show_server(self.server_id)['server']
         image_name = server['name'] + '-shelved'
-        params = {'name': image_name}
-        images = self.compute_images_client.list_images(**params)['images']
+        if CONF.image_feature_enabled.api_v1:
+            kwargs = {'name': image_name}
+        else:
+            kwargs = {'params': {'name': image_name}}
+        images = self.images_client.list_images(**kwargs)['images']
         self.assertEqual(1, len(images))
         self.assertEqual(image_name, images[0]['name'])
 
diff --git a/tempest/api/compute/volumes/test_attach_volume.py b/tempest/api/compute/volumes/test_attach_volume.py
index caa445d..811b521 100644
--- a/tempest/api/compute/volumes/test_attach_volume.py
+++ b/tempest/api/compute/volumes/test_attach_volume.py
@@ -160,6 +160,9 @@
 
     This test checks the attaching and detaching volumes from
     a shelved or shelved offload instance.
+
+    Note that these are uncommon scenarios until blueprint detach-boot-volume
+    is implemented in the compute service.
     """
 
     min_microversion = '2.20'
@@ -220,6 +223,9 @@
                 server, validation_resources)
             self.assertEqual(number_of_volumes, counted_volumes)
 
+    # NOTE(mriedem): Marked as slow since this is an uncommon scenario until
+    # attach/detach root volume is supported in nova, and it's slow.
+    @decorators.attr(type='slow')
     @decorators.idempotent_id('13a940b6-3474-4c3c-b03f-29b89112bfee')
     def test_attach_volume_shelved_or_offload_server(self):
         # Create server, count number of volumes on it, shelve
@@ -245,6 +251,9 @@
         # case of shelved_offloaded.
         self.assertIsNotNone(volume_attachment['device'])
 
+    # NOTE(mriedem): Marked as slow since this is an uncommon scenario until
+    # attach/detach root volume is supported in nova, and it's slow.
+    @decorators.attr(type='slow')
     @decorators.idempotent_id('b54e86dd-a070-49c4-9c07-59ae6dae15aa')
     def test_detach_volume_shelved_or_offload_server(self):
         # Count number of volumes on instance, shelve
diff --git a/tempest/api/volume/admin/test_backends_capabilities.py b/tempest/api/volume/admin/test_backends_capabilities.py
index 607fc43..affed6b 100644
--- a/tempest/api/volume/admin/test_backends_capabilities.py
+++ b/tempest/api/volume/admin/test_backends_capabilities.py
@@ -72,8 +72,8 @@
         ]
 
         # Returns a tuple of VOLUME_STATS values
-        expected_list = list(map(operator.itemgetter(*VOLUME_STATS),
-                             cinder_pools))
-        observed_list = list(map(operator.itemgetter(*VOLUME_STATS),
-                             capabilities))
+        expected_list = sorted(list(map(operator.itemgetter(*VOLUME_STATS),
+                                        cinder_pools)))
+        observed_list = sorted(list(map(operator.itemgetter(*VOLUME_STATS),
+                                        capabilities)))
         self.assertEqual(expected_list, observed_list)
diff --git a/tempest/cmd/cleanup_service.py b/tempest/cmd/cleanup_service.py
index 83cf42c..1a08246 100644
--- a/tempest/cmd/cleanup_service.py
+++ b/tempest/cmd/cleanup_service.py
@@ -720,11 +720,11 @@
 class ImageService(BaseService):
     def __init__(self, manager, **kwargs):
         super(ImageService, self).__init__(kwargs)
-        self.client = manager.compute_images_client
+        self.client = manager.image_client_v2
 
     def list(self):
         client = self.client
-        images = client.list_images({"all_tenants": True})['images']
+        images = client.list_images(params={"all_tenants": True})['images']
         if not self.is_save_state:
             images = [image for image in images if image['id']
                       not in self.saved_state_json['images'].keys()]
diff --git a/tempest/scenario/manager.py b/tempest/scenario/manager.py
index dff50a9..00d45cd 100644
--- a/tempest/scenario/manager.py
+++ b/tempest/scenario/manager.py
@@ -225,8 +225,12 @@
         if size is None:
             size = CONF.volume.volume_size
         if imageRef:
-            image = self.compute_images_client.show_image(imageRef)['image']
-            min_disk = image.get('minDisk')
+            if CONF.image_feature_enabled.api_v1:
+                resp = self.image_client.check_image(imageRef)
+                image = common_image.get_image_meta_from_headers(resp)
+            else:
+                image = self.image_client.show_image(imageRef)
+            min_disk = image.get('min_disk')
             size = max(size, min_disk)
         if name is None:
             name = data_utils.rand_name(self.__class__.__name__ + "-volume")
diff --git a/tempest/tests/api/compute/test_base.py b/tempest/tests/api/compute/test_base.py
index 47f4ad6..1593464 100644
--- a/tempest/tests/api/compute/test_base.py
+++ b/tempest/tests/api/compute/test_base.py
@@ -131,8 +131,13 @@
             self.assertIn(fault, six.text_type(ex))
         else:
             self.assertNotIn(fault, six.text_type(ex))
+        if compute_base.BaseV2ComputeTest.is_requested_microversion_compatible(
+            '2.35'):
+            status = 'ACTIVE'
+        else:
+            status = 'active'
         wait_for_image_status.assert_called_once_with(
-            compute_images_client, image_id, 'active')
+            compute_images_client, image_id, status)
         servers_client.show_server.assert_called_once_with(
             mock.sentinel.server_id)