From ee4ea0757fde7f90737b0bde175d8ed34feeebbd Mon Sep 17 00:00:00 2001 From: Simon Pichugin Date: Fri, 29 Jul 2016 17:34:48 +0200 Subject: [PATCH] Ticket 48832 - Add DirSrvTools.getLocalhost() function Description: Some tests require us to know the exact localhost value that is on the first place after 127.0.0.1. (some Directory Server attributes is sensible at this matter) https://fedorahosted.org/389/ticket/48832 Reviewed by: ? --- lib389/tools.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib389/tools.py b/lib389/tools.py index 59649c8..3517143 100644 --- a/lib389/tools.py +++ b/lib389/tools.py @@ -1030,6 +1030,19 @@ class DirSrvTools(object): % (expectedHost, ipPattern)) @staticmethod + def getLocalhost(): + """Get the first host value after 127.0.0.1 + from /etc/hosts file + """ + + with open('/etc/hosts', 'r') as f: + for line in f.readlines(): + if line.startswith('127.0.0.1'): + localhost = line.split()[1] + return localhost + return None + + @staticmethod def testLocalhost(): ''' Checks that the 127.0.0.1 is resolved as localhost.localdomain -- 2.7.4