Generate os-faults.yaml using new topology API

Change-Id: Ica3b7b24729a18dec46ec66d12fb5d9e4147bd96
This commit is contained in:
Federico Ressi 2019-10-10 10:28:29 +02:00
parent 360bbadd1f
commit 2476f78009
3 changed files with 33 additions and 38 deletions
tobiko/openstack/os_faults

@ -20,7 +20,7 @@ import jinja2
from oslo_log import log
import tobiko
from tobiko.tripleo import overcloud
from tobiko.openstack import topology
from tobiko.shell import ssh
@ -149,35 +149,33 @@ class OsFaultsConfigFileFixture(tobiko.SharedFixture):
def list_nodes(self):
"""Returns a list of dictionaries with nodes name and address."""
nodes = self.config.nodes
if nodes:
return [parse_config_node(node_string)
for node_string in nodes]
elif overcloud.has_overcloud():
nodes = []
overcloud_nodes = overcloud.list_overcloud_nodes()
for overcloud_node in overcloud_nodes:
overcloud_host_config = overcloud.overcloud_host_config(
overcloud_node.name)
address = str(overcloud_host_config.hostname)
os_faults_node = dict(
name=overcloud_node.name,
address=address,
username=overcloud_host_config.username,
private_key_file=overcloud_host_config.key_filename)
host_config = ssh.ssh_host_config(host=address)
if host_config.proxy_jump:
proxy_config = ssh.ssh_host_config(
host=host_config.proxy_jump)
os_faults_node['jump'] = dict(
username=proxy_config.username,
return [self._node_from_topology(node)
for node in topology.list_openstack_nodes()]
def _node_from_topology(self, node):
auth = self._node_auth_from_topology(node)
return dict(fqdn=node.name,
ip=str(node.public_ip),
auth=auth)
def _node_auth_from_topology(self, node):
jump = self._node_auth_jump_from_topology(node)
ssh_parameters = node.ssh_parameters
return dict(username=ssh_parameters['username'],
private_key_file=os.path.expanduser(
ssh_parameters['key_filename']),
jump=jump)
def _node_auth_jump_from_topology(self, node):
host_config = ssh.ssh_host_config(str(node.public_ip))
if host_config.proxy_jump:
proxy_config = ssh.ssh_host_config(host_config.proxy_jump)
return dict(username=proxy_config.username,
host=proxy_config.hostname,
private_key_file=os.path.expanduser(
proxy_config.key_filename))
nodes.append(os_faults_node)
return nodes
raise NotImplementedError("Cloud node listing not configured.")
else:
return None
def parse_config_node(node):

@ -67,9 +67,6 @@ OPTIONS = [
cfg.ListOpt('containers',
default=OS_FAULTS_CONTAINERS,
help="List of containers to be handler with os-faults"),
cfg.ListOpt('nodes',
default=None,
help="List of cloud nodes to be handled with os-faults")
]

@ -5,16 +5,16 @@ node_discover:
driver: node_list
args:
{% for node in nodes %}
- fqdn: {{ node['name'] }}
ip: {{ node['address'] }}
- fqdn: {{ node['fqdn'] }}
ip: {{ node['ip'] }}
auth:
username: {{ node['username'] }}
private_key_file: {{ node['private_key_file'] }}
{% if 'jump' in node %}
username: {{ node['auth']['username'] }}
private_key_file: {{ node['auth']['private_key_file'] }}
{% if 'jump' in node['auth'] %}
jump:
host: {{ node['jump']['host'] }}
username: {{ node['jump']['username'] }}
private_key_file: {{ node['jump']['private_key_file'] }}
host: {{ node['auth']['jump']['host'] }}
username: {{ node['auth']['jump']['username'] }}
private_key_file: {{ node['auth']['jump']['private_key_file'] }}
{% endif %}
{% endfor %}