Skip adding host to aggregate with az if host already in other zone
Running test_aggregate_add_host_create_server_with_az fails if all
hosts are already in other zones, with error info like:
"conflictingRequest":
{"message": "Cannot add host to aggregate 62.
Reason: One or more hosts already in availability
zone(s)[u'rally_test'].", "code": 409}
This is to find a host that has not been added to other zone, and
skip test_aggregate_add_host_create_server_with_az if all hosts in
the system are already in other zones.
Change-Id: I996d257e089f0676e316f2b14207c343063ccf8e
Closes-Bug: #1748377
diff --git a/tempest/api/compute/admin/test_aggregates.py b/tempest/api/compute/admin/test_aggregates.py
index 57d3983..d8faa33 100644
--- a/tempest/api/compute/admin/test_aggregates.py
+++ b/tempest/api/compute/admin/test_aggregates.py
@@ -48,11 +48,11 @@
if (hyper['hypervisor_type'] ==
CONF.compute.hypervisor_type)]
- hosts_available = [hyper['service']['host'] for hyper in hypers
- if (hyper['state'] == 'up' and
- hyper['status'] == 'enabled')]
- if hosts_available:
- cls.host = hosts_available[0]
+ cls.hosts_available = [hyper['service']['host'] for hyper in hypers
+ if (hyper['state'] == 'up' and
+ hyper['status'] == 'enabled')]
+ if cls.hosts_available:
+ cls.host = cls.hosts_available[0]
else:
msg = "no available compute node found"
if CONF.compute.hypervisor_type:
@@ -206,11 +206,23 @@
az_name = data_utils.rand_name(self.az_name_prefix)
aggregate = self._create_test_aggregate(availability_zone=az_name)
- self.client.add_host(aggregate['id'], host=self.host)
- self.addCleanup(self.client.remove_host, aggregate['id'],
- host=self.host)
+ # Find a host that has not been added to other zone,
+ # for one host can't be added to different zones.
+ aggregates = self.client.list_aggregates()['aggregates']
+ hosts_in_zone = []
+ for v in aggregates:
+ if v['availability_zone']:
+ hosts_in_zone.extend(v['hosts'])
+ hosts = [v for v in self.hosts_available if v not in hosts_in_zone]
+ if not hosts:
+ raise self.skipException("All hosts are already in other zones, "
+ "so can't add host to aggregate.")
+ host = hosts[0]
+
+ self.client.add_host(aggregate['id'], host=host)
+ self.addCleanup(self.client.remove_host, aggregate['id'], host=host)
admin_servers_client = self.os_admin.servers_client
server = self.create_test_server(availability_zone=az_name,
wait_until='ACTIVE')
body = admin_servers_client.show_server(server['id'])['server']
- self.assertEqual(self.host, body['OS-EXT-SRV-ATTR:host'])
+ self.assertEqual(host, body['OS-EXT-SRV-ATTR:host'])