Merge "Cleanup UndercloudHostsEntries"
This commit is contained in:
commit
1761eba808
|
@ -1703,12 +1703,20 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
|
|||
@mock.patch('subprocess.Popen', autospec=True)
|
||||
def test__get_undercloud_host_entry(self, mock_popen):
|
||||
mock_process = mock.Mock()
|
||||
mock_process.communicate.return_value = (
|
||||
'fd12::1 uc.ctlplane.localdomain uc.ctlplane', '')
|
||||
mock_process.returncode = 0
|
||||
mock_popen.return_value = mock_process
|
||||
expected = ('fd12::1 uc.ctlplane.localdomain uc.ctlplane')
|
||||
self.assertEqual(expected, self.cmd._get_undercloud_host_entry())
|
||||
mock_hosts = {
|
||||
'fd12::1 uc.ctlplane.localdomain uc.ctlplane':
|
||||
'fd12::1 uc.ctlplane.localdomain uc.ctlplane',
|
||||
'fd12::1 uc.ctlplane.localdomain uc.ctlplane\n'
|
||||
'fd12::1 uc.ctlplane.localdomain uc.ctlplane':
|
||||
'fd12::1 uc.ctlplane.localdomain uc.ctlplane',
|
||||
'1.2.3.4 uc.ctlplane foo uc.ctlplane bar uc.ctlplane':
|
||||
'1.2.3.4 uc.ctlplane foo bar'
|
||||
}
|
||||
for value, expected in mock_hosts.items():
|
||||
mock_process.communicate.return_value = (value, '')
|
||||
mock_process.returncode = 0
|
||||
mock_popen.return_value = mock_process
|
||||
self.assertEqual(expected, self.cmd._get_undercloud_host_entry())
|
||||
|
||||
def test_check_limit_warning(self):
|
||||
mock_warning = mock.MagicMock()
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#
|
||||
|
||||
import argparse
|
||||
from collections import OrderedDict
|
||||
import logging
|
||||
import os
|
||||
import os.path
|
||||
|
@ -101,6 +102,20 @@ class DeployOvercloud(command.Command):
|
|||
|
||||
return parameters
|
||||
|
||||
def _cleanup_host_entry(self, entry):
|
||||
# remove any tab or space excess
|
||||
entry_stripped = re.sub('[ \t]+', ' ', str(entry).rstrip())
|
||||
# removes any duplicate identical lines
|
||||
unique_lines = list(set(entry_stripped.splitlines()))
|
||||
ret = ''
|
||||
for line in unique_lines:
|
||||
# remove any duplicate word
|
||||
hosts_unique = (' '.join(
|
||||
OrderedDict((w, w) for w in line.split()).keys()))
|
||||
if hosts_unique != '':
|
||||
ret += hosts_unique + '\n'
|
||||
return ret.rstrip('\n')
|
||||
|
||||
def _get_undercloud_host_entry(self):
|
||||
"""Get hosts entry for undercloud ctlplane network
|
||||
|
||||
|
@ -114,8 +129,7 @@ class DeployOvercloud(command.Command):
|
|||
if process.returncode != 0:
|
||||
raise exceptions.DeploymentError('No entry for %s in /etc/hosts'
|
||||
% ctlplane_hostname)
|
||||
|
||||
return re.sub(' +', ' ', str(out).rstrip())
|
||||
return self._cleanup_host_entry(out)
|
||||
|
||||
def _create_breakpoint_cleanup_env(self, tht_root, container_name):
|
||||
bp_env = {}
|
||||
|
|
Loading…
Reference in New Issue