From 531f2da33d584e362b600e7925e658f718c4d04f Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Fri, 21 Oct 2022 14:00:10 +0200 Subject: [PATCH] try to work around the broken gethostbyaddr more thoroughly --- system/PlcapiUrlScanner.py | 20 +++++++++++--------- system/TestPlc.py | 38 +++++++------------------------------- system/gethostbyaddr.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 40 deletions(-) create mode 100644 system/gethostbyaddr.py diff --git a/system/PlcapiUrlScanner.py b/system/PlcapiUrlScanner.py index e3e8ee8..71d9c73 100755 --- a/system/PlcapiUrlScanner.py +++ b/system/PlcapiUrlScanner.py @@ -10,6 +10,9 @@ import xmlrpc.client import traceback import ssl +from gethostbyaddr import workaround_gethostbyaddr + + class PlcapiUrlScanner: # turns out the config has an ip but no name.. @@ -17,15 +20,14 @@ class PlcapiUrlScanner: self.auth = auth if not hostname and not ip: raise Exception("PlcapiUrlScanner needs _some_ input") - if hostname: - if not ip: - try: - ip = socket.gethostbyname(hostname) - except: - hostname = "{}.pl.sophia.inria.fr".format(hostname) - ip = socket.gethostbyname(hostname) - else: - hostname=socket.gethostbyaddr(ip)[0] + if not hostname: + hostname = workaround_gethostbyaddr(ip) + elif hostname and not ip: + try: + ip = socket.gethostbyname(hostname) + except: + hostname = "{}.pl.sophia.inria.fr".format(hostname) + ip = socket.gethostbyname(hostname) self.hostname = hostname self.ip = ip self.verbose = verbose diff --git a/system/TestPlc.py b/system/TestPlc.py index 9555a99..57543d1 100644 --- a/system/TestPlc.py +++ b/system/TestPlc.py @@ -24,6 +24,8 @@ from PlcapiUrlScanner import PlcapiUrlScanner from TestBonding import TestBonding +from gethostbyaddr import workaround_gethostbyaddr + has_sfa_cache_filename="sfa-cache" # step methods must take (self) and return a boolean (options is a member of the class) @@ -703,28 +705,6 @@ class TestPlc: for level in [ 'arch' ]: repo_url = os.path.dirname(repo_url) - ########## - # on the virsh containers, DNS resolution using gethostbyaddr - # won't work fine, for the hosts under .pl.sophia.inria.fr - # although these IPs can be reversed from virtually everywhere else - # - # this has started with something around fedora35 so I am suspecting python-3.10 - # - # in any case, here's a quick and dirty workaround, as I have bumped my head - # against the screen for two good hours and not found any single clue - # about how to deal with this properly - - import subprocess - - def workaround_gethostaddr(ip): - command = f"host {ip} 8.8.8.8" - completed = subprocess.run(command, shell=True, capture_output=True) - pieces = completed.stdout.decode().split("domain name pointer ") - if len(pieces) == 2: - return pieces[1].replace(".\n", "") - else: - return None - # invoke initvm (drop support for vs) script = "lbuild-initvm.sh" script_options = "" @@ -734,15 +714,11 @@ class TestPlc: script_options += " -f {}".format(self.options.fcdistro) script_options += " -r {}".format(repo_url) vserver_name = self.vservername - try: - vserver_hostname = socket.gethostbyaddr(self.vserverip)[0] - except: - # read more above about this workaround - vserver_hostname = workaround_gethostaddr(self.vserverip) - if not vserver_hostname: - print("Cannot reverse lookup {}".format(self.vserverip)) - print("This is considered fatal, as this might pollute the test results") - return False + vserver_hostname = workaround_gethostbyaddr(self.vserverip) + if not vserver_hostname: + print("Cannot reverse lookup {}".format(self.vserverip)) + print("This is considered fatal, as this might pollute the test results") + return False script_options += " -n {}".format(vserver_hostname) create_vserver="{build_dir}/{script} {script_options} {vserver_name}".format(**locals()) return self.run_in_host(create_vserver) == 0 diff --git a/system/gethostbyaddr.py b/system/gethostbyaddr.py new file mode 100644 index 0000000..199fa59 --- /dev/null +++ b/system/gethostbyaddr.py @@ -0,0 +1,28 @@ +########## +# on the virsh containers, DNS resolution using gethostbyaddr +# won't work fine, for the hosts under .pl.sophia.inria.fr +# although these IPs can be reversed from virtually everywhere else +# +# this has started with something around fedora35 so I am suspecting python-3.10 +# +# in any case, here's a quick and dirty workaround, as I have bumped my head +# against the screen for two good hours and not found any single clue +# about how to deal with this properly + +import socket +import subprocess + +def workaround_gethostbyaddr(ip): + try: + return socket.gethostbyaddr(ip)[0] + except: + # if that fails, try again using the `host` command + # which - surprisingly enough - works quite fine + # inside the containers + command = f"host {ip} 8.8.8.8" + completed = subprocess.run(command, shell=True, capture_output=True) + pieces = completed.stdout.decode().split("domain name pointer ") + if len(pieces) == 2: + return pieces[1].replace(".\n", "") + else: + return None -- 2.43.0