Introduce a get_groups function openstack topology and let list_openstack_nodes accept group lists

Currently some tests wrongfully call list_openstack_nodes(group='controller')
in order to run tests on the whole control plane. That assumption does not
hold true in case of composable HA where the control plane consists of
3 controller nodes (w/ haproxy+vip), 3 database nodes and 3 messaging nodes.
In such cases we'd have to filter three times for the group of the node
(aka resource class).

Let's allow list_openstack_nodes to have a list of group, so all its users
are allowed to pass a list of groups instead.

Instead of overloading the get_group() function directly, we add a simple
get_groups() function and use that inside list_openstack_nodes() when group is
a list.

Tested this on a composable HA and we correctly get all the nodes when
calling the following:
  groups = ['controller', 'messaging', 'database']
  nodes = topology.list_openstack_nodes(group=groups)

Co-Authored-By: Luca Miccini <lmiccini@redhat.com>
Change-Id: I6995a73c482ba7b654d089316f47668d86c495e1
This commit is contained in:
Michele Baldessari 2020-04-09 15:23:30 +02:00
parent 7b59745844
commit 608ceab04b
1 changed files with 11 additions and 2 deletions

View File

@ -51,10 +51,13 @@ def get_openstack_topology(topology_class=None):
def list_openstack_nodes(topology=None, group=None, hostnames=None, **kwargs):
topology = topology or get_openstack_topology()
if group:
if group is None:
nodes = topology.nodes
elif isinstance(group, str):
nodes = topology.get_group(group=group)
else:
nodes = topology.nodes
nodes = topology.get_groups(groups=group)
if hostnames:
names = {node_name_from_hostname(hostname)
for hostname in hostnames}
@ -297,6 +300,12 @@ class OpenStackTopology(tobiko.SharedFixture):
except KeyError:
raise _exception.NoSuchOpenStackTopologyNodeGroup(group=group)
def get_groups(self, groups):
nodes = []
for i in groups:
nodes.extend(self.get_group(i))
return nodes
@property
def groups(self):
return list(self._nodes_by_group)