diff --git a/tripleoclient/tests/workflows/test_deployment.py b/tripleoclient/tests/workflows/test_deployment.py index 2db5d68b7..9459b379e 100644 --- a/tripleoclient/tests/workflows/test_deployment.py +++ b/tripleoclient/tests/workflows/test_deployment.py @@ -85,3 +85,25 @@ class TestDeploymentWorkflows(utils.TestCommand): # tmpdir should be cleaned up self.assertEqual(1, mock_rmtree.call_count) self.assertEqual('/foo', mock_rmtree.call_args[0][0]) + + @mock.patch('tripleoclient.utils.get_role_net_ip_map') + def test_get_overcloud_hosts(self, mock_role_net_ip_map): + stack = mock.Mock() + mock_role_net_ip_map.return_value = { + 'Controller': { + 'ctlplane': ['1.1.1.1', '2.2.2.2', '3.3.3.3'], + 'external': ['4.4.4.4', '5.5.5.5', '6.6.6.6']}, + 'Compute': { + 'ctlplane': ['7.7.7.7', '8.8.8.8', '9.9.9.9'], + 'external': ['10.10.10.10', '11.11.11.11', '12.12.12.12']}, + } + + ips = deployment.get_overcloud_hosts(stack, 'ctlplane') + expected = ['1.1.1.1', '2.2.2.2', '3.3.3.3', + '7.7.7.7', '8.8.8.8', '9.9.9.9'] + self.assertEqual(sorted(expected), sorted(ips)) + + ips = deployment.get_overcloud_hosts(stack, 'external') + expected = ['4.4.4.4', '5.5.5.5', '6.6.6.6', + '10.10.10.10', '11.11.11.11', '12.12.12.12'] + self.assertEqual(sorted(expected), sorted(ips)) diff --git a/tripleoclient/utils.py b/tripleoclient/utils.py index 2d55ec729..752d9a576 100644 --- a/tripleoclient/utils.py +++ b/tripleoclient/utils.py @@ -378,6 +378,12 @@ def get_role_net_hostname_map(stack): return output['output_value'] +def get_role_net_ip_map(stack): + for output in stack.to_dict().get('outputs', {}): + if output['output_key'] == 'RoleNetIpMap': + return output['output_value'] + + def get_hosts_entry(stack): for output in stack.to_dict().get('outputs', {}): if output['output_key'] == 'HostsEntry': diff --git a/tripleoclient/v1/overcloud_deploy.py b/tripleoclient/v1/overcloud_deploy.py index a6eb6bf4d..d3b79a796 100644 --- a/tripleoclient/v1/overcloud_deploy.py +++ b/tripleoclient/v1/overcloud_deploy.py @@ -633,6 +633,11 @@ class DeployOvercloud(command.Command): os.path.expanduser('~'), '.ssh', 'id_rsa'), help=_('Key path for ssh access to overcloud nodes.') ) + parser.add_argument( + '--overcloud-ssh-network', + help=_('Network name to use for ssh access to overcloud nodes.'), + default='ctlplane' + ) parser.add_argument( '--environment-file', '-e', metavar='', action='append', dest='environment_files', @@ -906,7 +911,8 @@ class DeployOvercloud(command.Command): if parsed_args.config_download: print("Deploying overcloud configuration") - hosts = deployment.get_overcloud_hosts(self.clients, stack) + hosts = deployment.get_overcloud_hosts( + stack, parsed_args.overcloud_ssh_network) deployment.enable_ssh_admin(self.log, self.clients, hosts, parsed_args.overcloud_ssh_user, @@ -915,6 +921,7 @@ class DeployOvercloud(command.Command): parsed_args.templates, parsed_args.overcloud_ssh_user, parsed_args.overcloud_ssh_key, + parsed_args.overcloud_ssh_network, parsed_args.output_dir, verbosity=self.app_args.verbose_level) diff --git a/tripleoclient/workflows/deployment.py b/tripleoclient/workflows/deployment.py index 6cdebf637..65fd0b158 100644 --- a/tripleoclient/workflows/deployment.py +++ b/tripleoclient/workflows/deployment.py @@ -13,7 +13,6 @@ from __future__ import print_function import os import pprint -import re import shutil import socket import subprocess @@ -109,21 +108,13 @@ def overcloudrc(workflow_client, **input_): **input_) -def get_overcloud_hosts(clients, stack): - role_net_hostname_map = utils.get_role_net_hostname_map(stack) - hostnames = [] - for role in role_net_hostname_map: - hostnames.extend(role_net_hostname_map[role].get('ctlplane', [])) +def get_overcloud_hosts(stack, ssh_network): + ips = [] + role_net_ip_map = utils.get_role_net_ip_map(stack) + for net_ip_map in role_net_ip_map.values(): + ips.extend(net_ip_map.get(ssh_network, [])) - hosts = [] - hosts_entry = utils.get_hosts_entry(stack) - for hostname in hostnames: - for line in hosts_entry.split('\n'): - match = re.search('\s*%s\s*' % hostname, line) - if match: - hosts.append(line.split(' ')[0]) - - return hosts + return ips def wait_for_ssh_port(host): @@ -231,13 +222,14 @@ def enable_ssh_admin(log, clients, hosts, ssh_user, ssh_key): def config_download(log, clients, stack, templates, - ssh_user, ssh_key, output_dir, verbosity=1): + ssh_user, ssh_key, ssh_network, output_dir, verbosity=1): workflow_client = clients.workflow_engine tripleoclients = clients.tripleoclient workflow_input = { 'verbosity': verbosity or 1, - 'plan_name': stack.stack_name + 'plan_name': stack.stack_name, + 'ssh_network': ssh_network } if output_dir: workflow_input.update(dict(work_dir=output_dir))