diff --git a/notificationclient-base/centos/docker/notificationclient-sidecar/notificationclientsdk/common/helpers/hostfile_helper.py b/notificationclient-base/centos/docker/notificationclient-sidecar/notificationclientsdk/common/helpers/hostfile_helper.py index d78d14a..d7ae467 100644 --- a/notificationclient-base/centos/docker/notificationclient-sidecar/notificationclientsdk/common/helpers/hostfile_helper.py +++ b/notificationclient-base/centos/docker/notificationclient-sidecar/notificationclientsdk/common/helpers/hostfile_helper.py @@ -11,19 +11,19 @@ def update_host(hostname, ip): with open(hostsfile) as fd: for line in fd.readlines(): - if line.strip() == '': + if line.strip() == '' or line.startswith('#'): Lines.append(line) else: h_name = line.strip().split()[1] if h_name == hostname: - lin = "{0} {1}".format(ip, hostname) + lin = "{0} {1}\n".format(ip, hostname) Lines.append(lin) replaced = True else: Lines.append(line) if replaced == False: - Lines.append("{0} {1}".format(ip, hostname)) + Lines.append("\n{0} {1}\n".format(ip, hostname)) with open(hostsfile, 'w') as fc: fc.writelines(Lines)