Merge "add caller name to _log_request_full log" into mcp/ussuri
diff --git a/tempest/api/volume/test_volumes_filters.py b/tempest/api/volume/test_volumes_filters.py
index ac164eb..74ba9cb 100644
--- a/tempest/api/volume/test_volumes_filters.py
+++ b/tempest/api/volume/test_volumes_filters.py
@@ -28,6 +28,10 @@
         "InstanceLocalityFilter" in CONF.volume.scheduler_default_filters,
         "Cinder InstanceLocalityFilter is disabled",
     )
+    @testtools.skipUnless(
+        CONF.volume_feature_enabled.instance_locality_enabled,
+        "InstanceLocalityFilter test is disabled",
+    )
     @decorators.idempotent_id("5c13f4f7-5add-4fad-8ef7-dccca0f76295")
     def test_instancelocalityfilter(self):
         # 1. Create instance
diff --git a/tempest/config.py b/tempest/config.py
index fdd4842..5e5bece 100644
--- a/tempest/config.py
+++ b/tempest/config.py
@@ -1011,7 +1011,11 @@
     cfg.BoolOpt('cluster_active_active',
                 default=False,
                 help='The boolean flag to indicate if active-active mode '
-                     'is used by volume backend.')
+                     'is used by volume backend.'),
+    cfg.BoolOpt('instance_locality_enabled',
+                default=False,
+                help='The boolean flag to run instance locality  tests '
+                     'on environment.')
 ]
 
 
diff --git a/tempest/scenario/test_aggregates_basic_ops.py b/tempest/scenario/test_aggregates_basic_ops.py
index b515639..58e234f 100644
--- a/tempest/scenario/test_aggregates_basic_ops.py
+++ b/tempest/scenario/test_aggregates_basic_ops.py
@@ -51,10 +51,27 @@
         return aggregate
 
     def _get_host_name(self):
+        # Find a host that has not been added to other availability zone,
+        # for one host can't be added to different availability zones.
         svc_list = self.services_client.list_services(
             binary='nova-compute')['services']
         self.assertNotEmpty(svc_list)
-        return svc_list[0]['host']
+        hosts_available = []
+        for host in svc_list:
+            if (host['state'] == 'up' and host['status'] == 'enabled'):
+                hosts_available.append(host['host'])
+        aggregates = self.aggregates_client.list_aggregates()['aggregates']
+        hosts_in_zone = []
+        for agg in aggregates:
+            if agg['availability_zone']:
+                hosts_in_zone.extend(agg['hosts'])
+        hosts = [v for v in hosts_available if v not in hosts_in_zone]
+        if not hosts:
+            raise self.skipException("All hosts are already in other "
+                                     "availability zones, so can't add "
+                                     "host to aggregate. \nAggregates list: "
+                                     "%s" % aggregates)
+        return hosts[0]
 
     def _add_host(self, aggregate_id, host):
         aggregate = (self.aggregates_client.add_host(aggregate_id, host=host)