Skip adding host to aggregate with az if host already in other zone

Running test_aggregate_basic_ops fails if the selected host is
already in an other zone:

"Cannot add host to aggregate 1773. Reason: One or more hosts already
in availability zone(s)"

This is to find an up and enabled host that has not been added to
other zone, and skip test_aggregate_basic_ops if all hosts in
the system are already in other zones.

Change-Id: I2c196ca22c963af976b256016c36f4095ccf8f61
BARTRA, RICK 2019-07-29 12:55:59 -04:00 committed by Rick Bartra
parent 9ddee691f3
commit 4de3d536b0
1 changed files with 18 additions and 1 deletions

View File

@ -51,10 +51,27 @@ class TestAggregatesBasicOps(manager.ScenarioTest):
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(
return svc_list[0]['host']
hosts_available = []
for host in svc_list:
if (host['state'] == 'up' and host['status'] == 'enabled'):
aggregates = self.aggregates_client.list_aggregates()['aggregates']
hosts_in_zone = []
for agg in aggregates:
if agg['availability_zone']:
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)