Merge "Remove unused arguments from _error_checker()"
diff --git a/tempest/api/compute/images/test_images_oneserver.py b/tempest/api/compute/images/test_images_oneserver.py
index 7fd23fc..6c417f1 100644
--- a/tempest/api/compute/images/test_images_oneserver.py
+++ b/tempest/api/compute/images/test_images_oneserver.py
@@ -19,6 +19,7 @@
 from tempest.common.utils import data_utils
 from tempest.common import waiters
 from tempest import config
+from tempest.lib.common.utils import test_utils
 from tempest import test
 
 CONF = config.CONF
@@ -75,6 +76,8 @@
         body = self.client.create_image(self.server_id, name=name,
                                         metadata=meta)
         image_id = data_utils.parse_image_id(body.response['location'])
+        self.addCleanup(test_utils.call_and_ignore_notfound_exc,
+                        self.client.delete_image, image_id)
         waiters.wait_for_image_status(self.client, image_id, 'ACTIVE')
 
         # Verify the image was created correctly
diff --git a/tempest/api/compute/servers/test_availability_zone.py b/tempest/api/compute/servers/test_availability_zone.py
index 76da317..00df86b 100644
--- a/tempest/api/compute/servers/test_availability_zone.py
+++ b/tempest/api/compute/servers/test_availability_zone.py
@@ -29,4 +29,4 @@
     def test_get_availability_zone_list_with_non_admin_user(self):
         # List of availability zone with non-administrator user
         availability_zone = self.client.list_availability_zones()
-        self.assertTrue(len(availability_zone['availabilityZoneInfo']) > 0)
+        self.assertGreater(len(availability_zone['availabilityZoneInfo']), 0)
diff --git a/tempest/api/compute/servers/test_instance_actions.py b/tempest/api/compute/servers/test_instance_actions.py
index 1367629..a229df8 100644
--- a/tempest/api/compute/servers/test_instance_actions.py
+++ b/tempest/api/compute/servers/test_instance_actions.py
@@ -40,9 +40,9 @@
 
         body = (self.client.list_instance_actions(self.server_id)
                 ['instanceActions'])
-        self.assertTrue(len(body) == 2, str(body))
-        self.assertTrue(any([i for i in body if i['action'] == 'create']))
-        self.assertTrue(any([i for i in body if i['action'] == 'reboot']))
+        self.assertEqual(len(body), 2, str(body))
+        self.assertEqual(sorted([i['action'] for i in body]),
+                         ['create', 'reboot'])
 
     @test.idempotent_id('aacc71ca-1d70-4aa5-bbf6-0ff71470e43c')
     def test_get_instance_action(self):
@@ -51,3 +51,27 @@
             self.server_id, self.request_id)['instanceAction']
         self.assertEqual(self.server_id, body['instance_uuid'])
         self.assertEqual('create', body['action'])
+
+
+class InstanceActionsV221TestJSON(base.BaseV2ComputeTest):
+
+    min_microversion = '2.21'
+    max_microversion = 'latest'
+
+    @classmethod
+    def setup_clients(cls):
+        super(InstanceActionsV221TestJSON, cls).setup_clients()
+        cls.client = cls.servers_client
+
+    @test.idempotent_id('0a0f85d4-10fa-41f6-bf80-a54fb4aa2ae1')
+    def test_get_list_deleted_instance_actions(self):
+
+        # List actions of the deleted server
+        server = self.create_test_server(wait_until='ACTIVE')
+        self.client.delete_server(server['id'])
+        waiters.wait_for_server_termination(self.client, server['id'])
+        body = (self.client.list_instance_actions(server['id'])
+                ['instanceActions'])
+        self.assertEqual(len(body), 2, str(body))
+        self.assertEqual(sorted([i['action'] for i in body]),
+                         ['create', 'delete'])
diff --git a/tempest/api/compute/volumes/test_attach_volume.py b/tempest/api/compute/volumes/test_attach_volume.py
index c48169f..d4831b1 100644
--- a/tempest/api/compute/volumes/test_attach_volume.py
+++ b/tempest/api/compute/volumes/test_attach_volume.py
@@ -17,7 +17,6 @@
 
 from tempest.api.compute import base
 from tempest.common import compute
-from tempest.common.utils import data_utils
 from tempest.common.utils.linux import remote_client
 from tempest.common import waiters
 from tempest import config
@@ -72,12 +71,8 @@
 
     def _create_and_attach_volume(self, server):
         # Create a volume and wait for it to become ready
-        vol_name = data_utils.rand_name(self.__class__.__name__ + '-volume')
-        volume = self.volumes_client.create_volume(
-            size=CONF.volume.volume_size, display_name=vol_name)['volume']
+        volume = self.create_volume()
         self.addCleanup(self.delete_volume, volume['id'])
-        waiters.wait_for_volume_status(self.volumes_client,
-                                       volume['id'], 'available')
 
         # Attach the volume to the server
         self.attachment = self.servers_client.attach_volume(
diff --git a/tempest/api/compute/volumes/test_volume_snapshots.py b/tempest/api/compute/volumes/test_volume_snapshots.py
index e96982d..460c882 100644
--- a/tempest/api/compute/volumes/test_volume_snapshots.py
+++ b/tempest/api/compute/volumes/test_volume_snapshots.py
@@ -40,13 +40,9 @@
 
     @test.idempotent_id('cd4ec87d-7825-450d-8040-6e2068f2da8f')
     def test_volume_snapshot_create_get_list_delete(self):
-        v_name = data_utils.rand_name(self.__class__.__name__ + '-Volume')
-        volume = self.volumes_client.create_volume(
-            size=CONF.volume.volume_size,
-            display_name=v_name)['volume']
+        volume = self.create_volume()
         self.addCleanup(self.delete_volume, volume['id'])
-        waiters.wait_for_volume_status(self.volumes_client, volume['id'],
-                                       'available')
+
         s_name = data_utils.rand_name(self.__class__.__name__ + '-Snapshot')
         # Create snapshot
         snapshot = self.snapshots_client.create_snapshot(
diff --git a/tempest/api/image/base.py b/tempest/api/image/base.py
index 26b88b0..1cc3fa2 100644
--- a/tempest/api/image/base.py
+++ b/tempest/api/image/base.py
@@ -60,7 +60,7 @@
         """Wrapper that returns a test image."""
 
         if 'name' not in kwargs:
-            name = data_utils.rand_name(cls.__name__ + "-instance")
+            name = data_utils.rand_name(cls.__name__ + "-image")
             kwargs['name'] = name
 
         params = cls._get_create_params(**kwargs)
diff --git a/tempest/api/image/v2/test_images.py b/tempest/api/image/v2/test_images.py
index aff8a78..6f8d239 100644
--- a/tempest/api/image/v2/test_images.py
+++ b/tempest/api/image/v2/test_images.py
@@ -157,9 +157,7 @@
         """
         size = random.randint(1024, 4096)
         image_file = six.BytesIO(data_utils.random_bytes(size))
-        name = data_utils.rand_name('image')
-        image = cls.create_image(name=name,
-                                 container_format=container_format,
+        image = cls.create_image(container_format=container_format,
                                  disk_format=disk_format,
                                  visibility='private')
         cls.client.store_image_file(image['id'], data=image_file)
diff --git a/tempest/api/network/admin/test_floating_ips_admin_actions.py b/tempest/api/network/admin/test_floating_ips_admin_actions.py
index 2686af2..a32e7da 100644
--- a/tempest/api/network/admin/test_floating_ips_admin_actions.py
+++ b/tempest/api/network/admin/test_floating_ips_admin_actions.py
@@ -14,7 +14,6 @@
 #    under the License.
 
 from tempest.api.network import base
-from tempest.common.utils import data_utils
 from tempest import config
 from tempest import test
 
@@ -44,8 +43,7 @@
         cls.floating_ip = cls.create_floatingip(cls.ext_net_id)
         cls.network = cls.create_network()
         cls.subnet = cls.create_subnet(cls.network)
-        cls.router = cls.create_router(data_utils.rand_name('router-'),
-                                       external_network_id=cls.ext_net_id)
+        cls.router = cls.create_router(external_network_id=cls.ext_net_id)
         cls.create_router_interface(cls.router['id'], cls.subnet['id'])
         cls.port = cls.create_port(cls.network)
 
diff --git a/tempest/api/network/admin/test_l3_agent_scheduler.py b/tempest/api/network/admin/test_l3_agent_scheduler.py
index dca4523..c2ff038 100644
--- a/tempest/api/network/admin/test_l3_agent_scheduler.py
+++ b/tempest/api/network/admin/test_l3_agent_scheduler.py
@@ -13,7 +13,6 @@
 #    under the License.
 
 from tempest.api.network import base
-from tempest.common.utils import data_utils
 from tempest import config
 from tempest.lib import exceptions
 from tempest import test
@@ -66,7 +65,7 @@
         else:
             msg = "L3 Agent Scheduler enabled in conf, but L3 Agent not found"
             raise exceptions.InvalidConfiguration(msg)
-        cls.router = cls.create_router(data_utils.rand_name('router'))
+        cls.router = cls.create_router()
 
         if CONF.network.dvr_extra_resources:
             # NOTE(armax): If DVR is an available extension, and the created
diff --git a/tempest/api/network/base.py b/tempest/api/network/base.py
index 5c67d68..629926d 100644
--- a/tempest/api/network/base.py
+++ b/tempest/api/network/base.py
@@ -26,7 +26,7 @@
 
 
 class BaseNetworkTest(tempest.test.BaseTestCase):
-    """Base class for the Neutron tests
+    """Base class for the Neutron tests.
 
     Per the Neutron API Guide, API v1.x was removed from the source code tree
     (docs.openstack.org/api/openstack-network/2.0/content/Overview-d1e71.html)
@@ -137,7 +137,8 @@
     @classmethod
     def create_network(cls, network_name=None):
         """Wrapper utility that returns a test network."""
-        network_name = network_name or data_utils.rand_name('test-network-')
+        network_name = network_name or data_utils.rand_name(
+            cls.__name__ + "-network")
 
         body = cls.networks_client.create_network(name=network_name)
         network = body['network']
@@ -148,7 +149,6 @@
     def create_subnet(cls, network, gateway='', cidr=None, mask_bits=None,
                       ip_version=None, client=None, **kwargs):
         """Wrapper utility that returns a test subnet."""
-
         # allow tests to use admin client
         if not client:
             client = cls.subnets_client
@@ -208,6 +208,9 @@
     def create_router(cls, router_name=None, admin_state_up=False,
                       external_network_id=None, enable_snat=None,
                       **kwargs):
+        router_name = router_name or data_utils.rand_name(
+            cls.__name__ + "-router")
+
         ext_gw_info = {}
         if external_network_id:
             ext_gw_info['network_id'] = external_network_id
diff --git a/tempest/api/network/base_routers.py b/tempest/api/network/base_routers.py
index 807257f..5fb5232 100644
--- a/tempest/api/network/base_routers.py
+++ b/tempest/api/network/base_routers.py
@@ -25,7 +25,7 @@
         self.delete_router(router)
         self.routers.remove(router)
 
-    def _create_router(self, name, admin_state_up=False,
+    def _create_router(self, name=None, admin_state_up=False,
                        external_network_id=None, enable_snat=None):
         # associate a cleanup with created routers to avoid quota limits
         router = self.create_router(name, admin_state_up,
diff --git a/tempest/api/network/test_floating_ips.py b/tempest/api/network/test_floating_ips.py
index c64b01e..efe8982 100644
--- a/tempest/api/network/test_floating_ips.py
+++ b/tempest/api/network/test_floating_ips.py
@@ -14,7 +14,6 @@
 #    under the License.
 
 from tempest.api.network import base
-from tempest.common.utils import data_utils
 from tempest.common.utils import net_utils
 from tempest import config
 from tempest import test
@@ -55,8 +54,7 @@
         # Create network, subnet, router and add interface
         cls.network = cls.create_network()
         cls.subnet = cls.create_subnet(cls.network, enable_dhcp=False)
-        cls.router = cls.create_router(data_utils.rand_name('router-'),
-                                       external_network_id=cls.ext_net_id)
+        cls.router = cls.create_router(external_network_id=cls.ext_net_id)
         cls.create_router_interface(cls.router['id'], cls.subnet['id'])
         # Create two ports one each for Creation and Updating of floatingIP
         for i in range(2):
@@ -156,8 +154,7 @@
         self.assertEqual(created_floating_ip['router_id'], self.router['id'])
         network2 = self.create_network()
         subnet2 = self.create_subnet(network2)
-        router2 = self.create_router(data_utils.rand_name('router-'),
-                                     external_network_id=self.ext_net_id)
+        router2 = self.create_router(external_network_id=self.ext_net_id)
         self.create_router_interface(router2['id'], subnet2['id'])
         port_other_router = self.create_port(network2)
         # Associate floating IP to the other port on another router
diff --git a/tempest/api/network/test_networks.py b/tempest/api/network/test_networks.py
index 819ef90..dadaaba 100644
--- a/tempest/api/network/test_networks.py
+++ b/tempest/api/network/test_networks.py
@@ -175,8 +175,7 @@
     @test.idempotent_id('0e269138-0da6-4efc-a46d-578161e7b221')
     def test_create_update_delete_network_subnet(self):
         # Create a network
-        name = data_utils.rand_name('network-')
-        network = self.create_network(network_name=name)
+        network = self.create_network()
         self.addCleanup(self._delete_network, network)
         net_id = network['id']
         self.assertEqual('ACTIVE', network['status'])
@@ -525,8 +524,7 @@
     def test_create_delete_subnet_with_gw(self):
         net = netaddr.IPNetwork(CONF.network.project_network_v6_cidr)
         gateway = str(netaddr.IPAddress(net.first + 2))
-        name = data_utils.rand_name('network-')
-        network = self.create_network(network_name=name)
+        network = self.create_network()
         subnet = self.create_subnet(network, gateway)
         # Verifies Subnet GW in IPv6
         self.assertEqual(subnet['gateway_ip'], gateway)
@@ -535,16 +533,14 @@
     def test_create_delete_subnet_with_default_gw(self):
         net = netaddr.IPNetwork(CONF.network.project_network_v6_cidr)
         gateway_ip = str(netaddr.IPAddress(net.first + 1))
-        name = data_utils.rand_name('network-')
-        network = self.create_network(network_name=name)
+        network = self.create_network()
         subnet = self.create_subnet(network)
         # Verifies Subnet GW in IPv6
         self.assertEqual(subnet['gateway_ip'], gateway_ip)
 
     @test.idempotent_id('a9653883-b2a4-469b-8c3c-4518430a7e55')
     def test_create_list_subnet_with_no_gw64_one_network(self):
-        name = data_utils.rand_name('network-')
-        network = self.create_network(name)
+        network = self.create_network()
         ipv6_gateway = self.subnet_dict(['gateway'])['gateway']
         subnet1 = self.create_subnet(network,
                                      ip_version=6,
diff --git a/tempest/api/network/test_ports.py b/tempest/api/network/test_ports.py
index 12539ba..2979f7d 100644
--- a/tempest/api/network/test_ports.py
+++ b/tempest/api/network/test_ports.py
@@ -72,8 +72,7 @@
     @test.idempotent_id('67f1b811-f8db-43e2-86bd-72c074d4a42c')
     def test_create_bulk_port(self):
         network1 = self.network
-        name = data_utils.rand_name('network-')
-        network2 = self.create_network(network_name=name)
+        network2 = self.create_network()
         network_list = [network1['id'], network2['id']]
         port_list = [{'network_id': net_id} for net_id in network_list]
         body = self.ports_client.create_bulk_ports(ports=port_list)
diff --git a/tempest/api/network/test_routers.py b/tempest/api/network/test_routers.py
index 98a4f63..de2e71f 100644
--- a/tempest/api/network/test_routers.py
+++ b/tempest/api/network/test_routers.py
@@ -106,9 +106,8 @@
     @test.requires_ext(extension='ext-gw-mode', service='network')
     def test_create_router_with_default_snat_value(self):
         # Create a router with default snat rule
-        name = data_utils.rand_name('router')
         router = self._create_router(
-            name, external_network_id=CONF.network.public_network_id)
+            external_network_id=CONF.network.public_network_id)
         self._verify_router_gateway(
             router['id'], {'network_id': CONF.network.public_network_id,
                            'enable_snat': True})
@@ -136,7 +135,7 @@
     def test_add_remove_router_interface_with_subnet_id(self):
         network = self.create_network()
         subnet = self.create_subnet(network)
-        router = self._create_router(data_utils.rand_name('router-'))
+        router = self._create_router()
         # Add router interface with subnet id
         interface = self.routers_client.add_router_interface(
             router['id'], subnet_id=subnet['id'])
@@ -155,7 +154,7 @@
     def test_add_remove_router_interface_with_port_id(self):
         network = self.create_network()
         self.create_subnet(network)
-        router = self._create_router(data_utils.rand_name('router-'))
+        router = self._create_router()
         port_body = self.ports_client.create_port(
             network_id=network['id'])
         # add router interface to port created above
@@ -201,7 +200,7 @@
 
     @test.idempotent_id('6cc285d8-46bf-4f36-9b1a-783e3008ba79')
     def test_update_router_set_gateway(self):
-        router = self._create_router(data_utils.rand_name('router-'))
+        router = self._create_router()
         self.routers_client.update_router(
             router['id'],
             external_gateway_info={
@@ -215,7 +214,7 @@
     @test.idempotent_id('b386c111-3b21-466d-880c-5e72b01e1a33')
     @test.requires_ext(extension='ext-gw-mode', service='network')
     def test_update_router_set_gateway_with_snat_explicit(self):
-        router = self._create_router(data_utils.rand_name('router-'))
+        router = self._create_router()
         self.admin_routers_client.update_router(
             router['id'],
             external_gateway_info={
@@ -230,7 +229,7 @@
     @test.idempotent_id('96536bc7-8262-4fb2-9967-5c46940fa279')
     @test.requires_ext(extension='ext-gw-mode', service='network')
     def test_update_router_set_gateway_without_snat(self):
-        router = self._create_router(data_utils.rand_name('router-'))
+        router = self._create_router()
         self.admin_routers_client.update_router(
             router['id'],
             external_gateway_info={
@@ -245,7 +244,6 @@
     @test.idempotent_id('ad81b7ee-4f81-407b-a19c-17e623f763e8')
     def test_update_router_unset_gateway(self):
         router = self._create_router(
-            data_utils.rand_name('router-'),
             external_network_id=CONF.network.public_network_id)
         self.routers_client.update_router(router['id'],
                                           external_gateway_info={})
@@ -260,7 +258,6 @@
     @test.requires_ext(extension='ext-gw-mode', service='network')
     def test_update_router_reset_gateway_without_snat(self):
         router = self._create_router(
-            data_utils.rand_name('router-'),
             external_network_id=CONF.network.public_network_id)
         self.admin_routers_client.update_router(
             router['id'],
@@ -283,8 +280,7 @@
         test_routes = []
         routes_num = 4
         # Create a router
-        router = self._create_router(
-            data_utils.rand_name('router-'), True)
+        router = self._create_router(admin_state_up=True)
         self.addCleanup(
             self._delete_extra_routes,
             router['id'])
@@ -338,7 +334,7 @@
 
     @test.idempotent_id('a8902683-c788-4246-95c7-ad9c6d63a4d9')
     def test_update_router_admin_state(self):
-        router = self._create_router(data_utils.rand_name('router-'))
+        router = self._create_router()
         self.assertFalse(router['admin_state_up'])
         # Update router admin state
         update_body = self.routers_client.update_router(router['id'],
@@ -357,7 +353,7 @@
         subnet01 = self.create_subnet(network01)
         sub02_cidr = netaddr.IPNetwork(self.tenant_cidr).next()
         subnet02 = self.create_subnet(network02, cidr=sub02_cidr)
-        router = self._create_router(data_utils.rand_name('router-'))
+        router = self._create_router()
         interface01 = self._add_router_interface_with_subnet_id(router['id'],
                                                                 subnet01['id'])
         self._verify_router_interface(router['id'], subnet01['id'],
@@ -371,7 +367,7 @@
     def test_router_interface_port_update_with_fixed_ip(self):
         network = self.create_network()
         subnet = self.create_subnet(network)
-        router = self._create_router(data_utils.rand_name('router-'))
+        router = self._create_router()
         fixed_ip = [{'subnet_id': subnet['id']}]
         interface = self._add_router_interface_with_subnet_id(router['id'],
                                                               subnet['id'])
@@ -417,7 +413,7 @@
 
     @test.idempotent_id('644d7a4a-01a1-4b68-bb8d-0c0042cb1729')
     def test_convert_centralized_router(self):
-        router = self._create_router(data_utils.rand_name('router'))
+        router = self._create_router()
         self.assertNotIn('distributed', router)
         update_body = self.admin_routers_client.update_router(router['id'],
                                                               distributed=True)
diff --git a/tempest/api/network/test_routers_negative.py b/tempest/api/network/test_routers_negative.py
index cd9f6ad..354e6d1 100644
--- a/tempest/api/network/test_routers_negative.py
+++ b/tempest/api/network/test_routers_negative.py
@@ -36,7 +36,7 @@
     @classmethod
     def resource_setup(cls):
         super(RoutersNegativeTest, cls).resource_setup()
-        cls.router = cls.create_router(data_utils.rand_name('router-'))
+        cls.router = cls.create_router()
         cls.network = cls.create_network()
         cls.subnet = cls.create_subnet(cls.network)
         cls.tenant_cidr = (CONF.network.project_network_cidr
@@ -55,8 +55,7 @@
     @test.attr(type=['negative'])
     @test.idempotent_id('11836a18-0b15-4327-a50b-f0d9dc66bddd')
     def test_router_add_gateway_net_not_external_returns_400(self):
-        alt_network = self.create_network(
-            network_name=data_utils.rand_name('router-negative-'))
+        alt_network = self.create_network()
         sub_cidr = netaddr.IPNetwork(self.tenant_cidr).next()
         self.create_subnet(alt_network, cidr=sub_cidr)
         self.assertRaises(lib_exc.BadRequest,
@@ -128,7 +127,7 @@
     @classmethod
     def resource_setup(cls):
         super(DvrRoutersNegativeTest, cls).resource_setup()
-        cls.router = cls.create_router(data_utils.rand_name('router'))
+        cls.router = cls.create_router()
         cls.network = cls.create_network()
         cls.subnet = cls.create_subnet(cls.network)
 
diff --git a/tempest/api/volume/test_volumes_list.py b/tempest/api/volume/test_volumes_list.py
index b5ef7c0..40793ec 100644
--- a/tempest/api/volume/test_volumes_list.py
+++ b/tempest/api/volume/test_volumes_list.py
@@ -32,6 +32,11 @@
     VOLUME_FIELDS = ('id', 'name')
 
     def assertVolumesIn(self, fetched_list, expected_list, fields=None):
+        """Check out the list.
+
+        This function is aim at check out whether all of the volumes in
+        expected_list are in fetched_list.
+        """
         if fields:
             fieldsgetter = operator.itemgetter(*fields)
             expected_list = map(fieldsgetter, expected_list)
@@ -58,7 +63,6 @@
     def resource_setup(cls):
         super(VolumesV2ListTestJSON, cls).resource_setup()
         cls.name = cls.VOLUME_FIELDS[1]
-
         # Create 3 test volumes
         cls.volume_list = []
         cls.metadata = {'Type': 'work'}
@@ -146,6 +150,28 @@
             self.assertEqual('available', volume['status'])
         self.assertVolumesIn(fetched_list, self.volume_list)
 
+    @test.idempotent_id('2016a942-3020-40d7-95ce-7613bf8407ce')
+    def test_volumes_list_by_bootable(self):
+        """Check out volumes.
+
+        This test function is aim at check out whether all of the volumes
+        in volume_list are not a bootable volume.
+        """
+        params = {'bootable': 'false'}
+        fetched_list = self.client.list_volumes(params=params)['volumes']
+        self._list_by_param_value_and_assert(params)
+        self.assertVolumesIn(fetched_list, self.volume_list,
+                             fields=self.VOLUME_FIELDS)
+
+    @test.idempotent_id('2016a939-72ec-482a-bf49-d5ca06216b9f')
+    def test_volumes_list_details_by_bootable(self):
+        params = {'bootable': 'false'}
+        fetched_list = self.client.list_volumes(
+            detail=True, params=params)['volumes']
+        for volume in fetched_list:
+            self.assertEqual('false', volume['bootable'])
+        self.assertVolumesIn(fetched_list, self.volume_list)
+
     @test.idempotent_id('c0cfa863-3020-40d7-b587-e35f597d5d87')
     def test_volumes_list_by_availability_zone(self):
         volume = self.volume_list[data_utils.rand_int_id(0, 2)]