CI: fix function that prepare the hosts file before CI run

Without this fix function removed 2 lines from hosts file.

Reviewed-By: Oleg Fayans <ofayans@redhat.com>
This commit is contained in:
Martin Basti 2015-12-06 18:44:43 +01:00
parent a11cddd75b
commit e4259d5b49

View File

@ -115,12 +115,14 @@ def fix_etc_hosts(host):
backup_file(host, paths.HOSTS)
contents = host.get_file_contents(paths.HOSTS)
# Remove existing mentions of the host's FQDN, short name, and IP
# Removing of IP must be done as first, otherwise hosts file may be
# corrupted
contents = re.sub('^%s.*' % re.escape(host.ip), '', contents,
flags=re.MULTILINE)
contents = re.sub('\s%s(\s|$)' % re.escape(host.hostname), ' ', contents,
flags=re.MULTILINE)
contents = re.sub('\s%s(\s|$)' % re.escape(host.shortname), ' ', contents,
flags=re.MULTILINE)
contents = re.sub('^%s.*' % re.escape(host.ip), '', contents,
flags=re.MULTILINE)
# Add the host's info again
contents += '\n%s %s %s\n' % (host.ip, host.hostname, host.shortname)
log.debug('Writing the following to /etc/hosts:\n%s', contents)