Honor blacklist during temp key injection

The server blacklist also needs to be honored when getting the list
of hosts that we use to check for the ssh port being available, and
injecting the temporary ssh key.

Change-Id: I7ea9201f39af17bb43b7a1b8a9d8d1064e365c14
Closes-Bug: #1797572
This commit is contained in:
James Slagle 2018-10-12 10:21:43 -04:00
parent 71f51369a0
commit 7cef36bc9b
3 changed files with 61 additions and 2 deletions

View File

@ -115,8 +115,10 @@ class TestDeploymentWorkflows(utils.TestCommand):
'overcloud',
hosts, ssh_user, ssh_key)
@mock.patch('tripleoclient.utils.get_blacklisted_ip_addresses')
@mock.patch('tripleoclient.utils.get_role_net_ip_map')
def test_get_overcloud_hosts(self, mock_role_net_ip_map):
def test_get_overcloud_hosts(self, mock_role_net_ip_map,
mock_blacklisted_ip_addresses):
stack = mock.Mock()
mock_role_net_ip_map.return_value = {
'Controller': {
@ -126,6 +128,7 @@ class TestDeploymentWorkflows(utils.TestCommand):
'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']},
}
mock_blacklisted_ip_addresses.return_value = []
ips = deployment.get_overcloud_hosts(stack, 'ctlplane')
expected = ['1.1.1.1', '2.2.2.2', '3.3.3.3',
@ -136,3 +139,35 @@ class TestDeploymentWorkflows(utils.TestCommand):
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))
@mock.patch('tripleoclient.utils.get_blacklisted_ip_addresses')
@mock.patch('tripleoclient.utils.get_role_net_ip_map')
def test_get_overcloud_hosts_with_blacklist(
self, mock_role_net_ip_map,
mock_blacklisted_ip_addresses):
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']},
}
mock_blacklisted_ip_addresses.return_value = ['8.8.8.8']
ips = deployment.get_overcloud_hosts(stack, 'ctlplane')
expected = ['1.1.1.1', '2.2.2.2', '3.3.3.3',
'7.7.7.7', '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', '12.12.12.12']
self.assertEqual(sorted(expected), sorted(ips))
mock_blacklisted_ip_addresses.return_value = ['7.7.7.7', '9.9.9.9',
'2.2.2.2']
ips = deployment.get_overcloud_hosts(stack, 'external')
expected = ['4.4.4.4', '6.6.6.6', '11.11.11.11']
self.assertEqual(sorted(expected), sorted(ips))

View File

@ -452,6 +452,12 @@ def get_role_net_hostname_map(stack):
return output['output_value']
def get_blacklisted_ip_addresses(stack):
for output in stack.to_dict().get('outputs', {}):
if output['output_key'] == 'BlacklistedIpAddresses':
return output['output_value']
def get_role_net_ip_map(stack):
for output in stack.to_dict().get('outputs', {}):
if output['output_key'] == 'RoleNetIpMap':

View File

@ -11,6 +11,7 @@
# under the License.
from __future__ import print_function
import copy
import os
import pprint
import shutil
@ -131,8 +132,25 @@ def create_overcloudrc(clients, **workflow_input):
def get_overcloud_hosts(stack, ssh_network):
ips = []
role_net_ip_map = utils.get_role_net_ip_map(stack)
blacklisted_ips = utils.get_blacklisted_ip_addresses(stack)
for net_ip_map in role_net_ip_map.values():
ips.extend(net_ip_map.get(ssh_network, []))
# get a copy of the lists of ssh_network and ctlplane ips
# as blacklisted_ips will only be the ctlplane ips, we need
# both lists to determine which to actually blacklist
net_ips = copy.copy(net_ip_map.get(ssh_network, []))
ctlplane_ips = copy.copy(net_ip_map.get('ctlplane', []))
blacklisted_ctlplane_ips = \
[ip for ip in ctlplane_ips if ip in blacklisted_ips]
# for each blacklisted ctlplane ip, remove the corresponding
# ssh_network ip at that same index in the net_ips list
for bcip in blacklisted_ctlplane_ips:
index = ctlplane_ips.index(bcip)
ctlplane_ips.pop(index)
net_ips.pop(index)
ips.extend(net_ips)
return ips