Add --overcloud-ssh-network

In some cases, we may not want to always assume the ctlplane as the
network to use for both ssh access to the overcloud nodes, and for
generating the ansible inventory. This patches adds a new cli argument,
--overcloud-ssh-network that can be used to set the network name to be
used. Defaults to ctlplane.

Depends-On: I1e3f9a5142bff5e4f77e5e40df164089d9144652
Change-Id: I767984623c7d2402b10bae3d30b695783166f6bf
This commit is contained in:
James Slagle 2018-05-16 14:29:59 -04:00
parent 4ad7dff959
commit a1c01dfc7a
4 changed files with 45 additions and 18 deletions

View File

@ -85,3 +85,25 @@ class TestDeploymentWorkflows(utils.TestCommand):
# tmpdir should be cleaned up # tmpdir should be cleaned up
self.assertEqual(1, mock_rmtree.call_count) self.assertEqual(1, mock_rmtree.call_count)
self.assertEqual('/foo', mock_rmtree.call_args[0][0]) 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))

View File

@ -378,6 +378,12 @@ def get_role_net_hostname_map(stack):
return output['output_value'] 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): def get_hosts_entry(stack):
for output in stack.to_dict().get('outputs', {}): for output in stack.to_dict().get('outputs', {}):
if output['output_key'] == 'HostsEntry': if output['output_key'] == 'HostsEntry':

View File

@ -633,6 +633,11 @@ class DeployOvercloud(command.Command):
os.path.expanduser('~'), '.ssh', 'id_rsa'), os.path.expanduser('~'), '.ssh', 'id_rsa'),
help=_('Key path for ssh access to overcloud nodes.') 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( parser.add_argument(
'--environment-file', '-e', metavar='<HEAT ENVIRONMENT FILE>', '--environment-file', '-e', metavar='<HEAT ENVIRONMENT FILE>',
action='append', dest='environment_files', action='append', dest='environment_files',
@ -906,7 +911,8 @@ class DeployOvercloud(command.Command):
if parsed_args.config_download: if parsed_args.config_download:
print("Deploying overcloud configuration") 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, deployment.enable_ssh_admin(self.log, self.clients,
hosts, hosts,
parsed_args.overcloud_ssh_user, parsed_args.overcloud_ssh_user,
@ -915,6 +921,7 @@ class DeployOvercloud(command.Command):
parsed_args.templates, parsed_args.templates,
parsed_args.overcloud_ssh_user, parsed_args.overcloud_ssh_user,
parsed_args.overcloud_ssh_key, parsed_args.overcloud_ssh_key,
parsed_args.overcloud_ssh_network,
parsed_args.output_dir, parsed_args.output_dir,
verbosity=self.app_args.verbose_level) verbosity=self.app_args.verbose_level)

View File

@ -13,7 +13,6 @@ from __future__ import print_function
import os import os
import pprint import pprint
import re
import shutil import shutil
import socket import socket
import subprocess import subprocess
@ -109,21 +108,13 @@ def overcloudrc(workflow_client, **input_):
**input_) **input_)
def get_overcloud_hosts(clients, stack): def get_overcloud_hosts(stack, ssh_network):
role_net_hostname_map = utils.get_role_net_hostname_map(stack) ips = []
hostnames = [] role_net_ip_map = utils.get_role_net_ip_map(stack)
for role in role_net_hostname_map: for net_ip_map in role_net_ip_map.values():
hostnames.extend(role_net_hostname_map[role].get('ctlplane', [])) ips.extend(net_ip_map.get(ssh_network, []))
hosts = [] return ips
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
def wait_for_ssh_port(host): 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, 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 workflow_client = clients.workflow_engine
tripleoclients = clients.tripleoclient tripleoclients = clients.tripleoclient
workflow_input = { workflow_input = {
'verbosity': verbosity or 1, 'verbosity': verbosity or 1,
'plan_name': stack.stack_name 'plan_name': stack.stack_name,
'ssh_network': ssh_network
} }
if output_dir: if output_dir:
workflow_input.update(dict(work_dir=output_dir)) workflow_input.update(dict(work_dir=output_dir))