Merge "Add configurable hostname pattern to filter hosts"
diff --git a/releasenotes/notes/add-target-host-filter-94803e93b701d052.yaml b/releasenotes/notes/add-target-host-filter-94803e93b701d052.yaml
new file mode 100644
index 0000000..83a3728
--- /dev/null
+++ b/releasenotes/notes/add-target-host-filter-94803e93b701d052.yaml
@@ -0,0 +1,6 @@
+---
+features:
+ - |
+ Add a new config option `[compute]/target_hosts_to_avoid` which will
+ filter out any hypervisor candidates with a hostname that matches the
+ provided pattern when determining target hosts for migration.
diff --git a/tempest/api/compute/admin/test_hosts.py b/tempest/api/compute/admin/test_hosts.py
index 0d79570..849b535 100644
--- a/tempest/api/compute/admin/test_hosts.py
+++ b/tempest/api/compute/admin/test_hosts.py
@@ -14,8 +14,11 @@
from tempest.api.compute import base
from tempest.common import tempest_fixtures as fixtures
+from tempest import config
from tempest.lib import decorators
+CONF = config.CONF
+
class HostsAdminTestJSON(base.BaseV2ComputeAdminTest):
"""Tests nova hosts API using admin privileges."""
@@ -70,7 +73,7 @@
hosts = [host for host in hosts if (
host['service'] == 'compute' and
- not host['host_name'].endswith('-ironic'))]
+ CONF.compute.target_hosts_to_avoid not in host['host_name'])]
self.assertNotEmpty(hosts)
for host in hosts:
diff --git a/tempest/api/compute/base.py b/tempest/api/compute/base.py
index 8890109..1069e0f 100644
--- a/tempest/api/compute/base.py
+++ b/tempest/api/compute/base.py
@@ -720,7 +720,7 @@
binary='nova-compute')['services']
hosts = []
for svc in svcs:
- if svc['host'].endswith('-ironic'):
+ if CONF.compute.target_hosts_to_avoid in svc['host']:
continue
if svc['state'] == 'up' and svc['status'] == 'enabled':
if CONF.compute.compute_volume_common_az:
diff --git a/tempest/config.py b/tempest/config.py
index 7139143..b1f736c 100644
--- a/tempest/config.py
+++ b/tempest/config.py
@@ -418,7 +418,11 @@
help="Specify destination host for live-migration and cold"
" migration. If option is not set tests will use host"
" automatically."),
-
+ cfg.StrOpt('target_hosts_to_avoid',
+ default='-ironic',
+ help="When aggregating available hypervisors for testing,"
+ " avoid migrating to and booting any test VM on hosts with"
+ " a name that matches the provided pattern"),
]
placement_group = cfg.OptGroup(name='placement',
diff --git a/tempest/scenario/test_instances_with_cinder_volumes.py b/tempest/scenario/test_instances_with_cinder_volumes.py
index b9ac2c8..0ddbec1 100644
--- a/tempest/scenario/test_instances_with_cinder_volumes.py
+++ b/tempest/scenario/test_instances_with_cinder_volumes.py
@@ -80,7 +80,7 @@
for host in zone['hosts']:
if 'nova-compute' in zone['hosts'][host] and \
zone['hosts'][host]['nova-compute']['available'] and \
- not host.endswith('-ironic'):
+ CONF.compute.target_hosts_to_avoid not in host:
hosts.append({'zone': zone['zoneName'],
'host_name': host})
diff --git a/tempest/scenario/test_server_multinode.py b/tempest/scenario/test_server_multinode.py
index fe85234..556b925 100644
--- a/tempest/scenario/test_server_multinode.py
+++ b/tempest/scenario/test_server_multinode.py
@@ -48,7 +48,7 @@
for host in zone['hosts']:
if 'nova-compute' in zone['hosts'][host] and \
zone['hosts'][host]['nova-compute']['available'] and \
- not host.endswith('-ironic'):
+ CONF.compute.target_hosts_to_avoid not in host:
hosts.append({'zone': zone['zoneName'],
'host_name': host})