quick and dirty hack around a misbehaving gethostbyaddr()
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 21 Oct 2022 09:49:01 +0000 (11:49 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 21 Oct 2022 09:49:01 +0000 (11:49 +0200)
with the IPs under .pl.sophia.inria.fr domain, when requested from the containers....

system/TestPlc.py

index 633fde2..9555a99 100644 (file)
@@ -703,6 +703,28 @@ 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 = ""
@@ -714,11 +736,14 @@ class TestPlc:
         vserver_name = self.vservername
         try:
             vserver_hostname = socket.gethostbyaddr(self.vserverip)[0]
-            script_options += " -n {}".format(vserver_hostname)
         except:
-            print("Cannot reverse lookup {}".format(self.vserverip))
-            print("This is considered fatal, as this might pollute the test results")
-            return False
+            # 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
+        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