Fix invalid /etc/hosts edit
When the hostname was written to /etc/hosts, it resulted in an invalid /etc/hosts file due to 127.0.0.1 being specified twice on different lines. That issue is now corrected such that the hostnames will be added to the existing line for 127.0.0.1, which results in valid syntax for /etc/hosts. Change-Id: I8cd262b26708bd282e1b8623317e9e48f37e527d Closes-Bug: #1709460
This commit is contained in:
parent
88c3b8529b
commit
04ac069f4b
|
@ -196,7 +196,8 @@ class TestCheckHostname(BaseTestCase):
|
|||
undercloud._check_hostname()
|
||||
mock_run_command.assert_called_with([
|
||||
'sudo', '/bin/bash', '-c',
|
||||
'echo 127.0.0.1 test.hostname test >> /etc/hosts'],
|
||||
'sed -i "s/127.0.0.1\(\s*\)/127.0.0.1\\1test.hostname test /" '
|
||||
'/etc/hosts'],
|
||||
name='hostname-to-etc-hosts')
|
||||
|
||||
@mock.patch('instack_undercloud.undercloud._run_command')
|
||||
|
@ -212,7 +213,8 @@ class TestCheckHostname(BaseTestCase):
|
|||
undercloud._check_hostname()
|
||||
mock_run_command.assert_called_with([
|
||||
'sudo', '/bin/bash', '-c',
|
||||
'echo 127.0.0.1 test.hostname test >> /etc/hosts'],
|
||||
'sed -i "s/127.0.0.1\(\s*\)/127.0.0.1\\1test.hostname test /" '
|
||||
'/etc/hosts'],
|
||||
name='hostname-to-etc-hosts')
|
||||
|
||||
@mock.patch('instack_undercloud.undercloud._run_command')
|
||||
|
@ -230,7 +232,9 @@ class TestCheckHostname(BaseTestCase):
|
|||
undercloud._check_hostname()
|
||||
mock_run_command.assert_called_with([
|
||||
'sudo', '/bin/bash', '-c',
|
||||
'echo 127.0.0.1 test-hostname.domain test-hostname >> /etc/hosts'],
|
||||
'sed -i "s/127.0.0.1\(\s*\)/'
|
||||
'127.0.0.1\\1test-hostname.domain test-hostname /" '
|
||||
'/etc/hosts'],
|
||||
name='hostname-to-etc-hosts')
|
||||
|
||||
@mock.patch('instack_undercloud.undercloud._run_command')
|
||||
|
|
|
@ -631,9 +631,10 @@ def _check_hostname():
|
|||
if short_hostname == detected_static_hostname:
|
||||
raise RuntimeError('Configured hostname is not fully '
|
||||
'qualified.')
|
||||
echo_cmd = ('echo 127.0.0.1 %s %s >> /etc/hosts' %
|
||||
sed_cmd = ('sed -i "s/127.0.0.1\(\s*\)/127.0.0.1\\1%s %s /" '
|
||||
'/etc/hosts' %
|
||||
(detected_static_hostname, short_hostname))
|
||||
args = ['sudo', '/bin/bash', '-c', echo_cmd]
|
||||
args = ['sudo', '/bin/bash', '-c', sed_cmd]
|
||||
_run_command(args, name='hostname-to-etc-hosts')
|
||||
LOG.info('Added hostname %s to /etc/hosts',
|
||||
detected_static_hostname)
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
fixes:
|
||||
- When the hostname was written to /etc/hosts, it resulted in an invalid
|
||||
/etc/hosts file due to 127.0.0.1 being specified twice on different lines.
|
||||
That issue is now corrected such that the hostnames will be added to the
|
||||
existing line for 127.0.0.1, which results in valid syntax for /etc/hosts.
|
||||
See https://bugs.launchpad.net/tripleo/+bug/1709460
|
Loading…
Reference in New Issue