try to avoid being fooled when detecting a no-sfa build
[tests.git] / system / TestPlc.py
index 7a90588..633fde2 100644 (file)
@@ -245,7 +245,7 @@ class TestPlc:
         # warning, we're now building 'sface' so let's be a bit more picky
         # full builds are expected to return with 0 here
         utils.header("Checking if build provides SFA package...")
-        retcod = utils.system("curl --silent {}/ | grep -q sfa-".format(rpms_url)) == 0
+        retcod = utils.system("curl --silent {}/ | grep -q sfa-4".format(rpms_url)) == 0
         encoded = 'yes' if retcod else 'no'
         with open(has_sfa_cache_filename,'w') as cache:
             cache.write(encoded)
@@ -359,7 +359,7 @@ class TestPlc:
         return self.dnf_check_installed(rpms)
 
     def pip3_install(self, package):
-        return self.run_in_guest("pip3 install {}".format(package)) == 0
+        return self.run_in_guest(f"pip3 install {package} || pip install {package}") == 0
 
     def auth_root(self):
         return {'Username'   : self.plc_spec['settings']['PLC_ROOT_USER'],
@@ -1519,6 +1519,18 @@ class TestPlc:
     # in particular runs with --preserve (dont cleanup) and without --check
     # also it gets run twice, once with the --foreign option for creating fake foreign entries
 
+    def install_pip2(self):
+
+        replacements = [
+            "http://mirror.onelab.eu/third-party/python2-pip-19.1.1-7.fc33.noarch.rpm",
+        ]
+
+        return (
+               self.run_in_guest("pip2 --version") == 0
+            or self.run_in_guest("dnf install python2-pip") == 0
+            or self.run_in_guest("dnf localinstall -y " + " ".join(replacements)) == 0)
+
+
     def install_m2crypto(self):
 
         # installing m2crypto for python2 is increasingly difficult
@@ -1528,22 +1540,17 @@ class TestPlc:
         # an install from sources and that's quite awkward
 
         replacements = [
-            "http://mirror.onelab.eu/fedora/releases/31/Everything/x86_64/os/Packages/p/python2-typing-3.6.2-5.fc31.noarch.rpm",
-            "http://mirror.onelab.eu/fedora/releases/31/Everything/x86_64/os/Packages/p/python2-m2crypto-0.35.2-2.fc31.x86_64.rpm",
+            # no longer on our mirror
+            "https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/31/Everything/x86_64/os/Packages/p/python2-typing-3.6.2-5.fc31.noarch.rpm",
+            "https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/31/Everything/x86_64/os/Packages/p/python2-m2crypto-0.35.2-2.fc31.x86_64.rpm",
         ]
 
-        attempt = self.run_in_guest("pip2 install python2-m2crypto")
-
-        if not attempt:
-            attempt = self.run_in_guest("dnf localinstall -y " + " ".join(replacements))
-
-        return attempt
+        return (
+               self.run_in_guest('python2 -c "import M2Crypto"', backslash=True) == 0
+            or self.run_in_guest("pip2 install python2-m2crypto") == 0
+            or self.run_in_guest("dnf localinstall -y " + " ".join(replacements)) == 0)
 
-        # about pip2:
-        # we can try and use
-        # https://acc.dl.osdn.jp/storage/g/u/un/unitedrpms/32/x86_64/python2-pip-19.1.1-7.fc32.noarch.rpm
-        # that qould then need to be mirrored
-        # so the logic goes like this
+        # about pip2: the logic goes like this
         # check for pip2 command
         # if not, try dnf install python2-pip
         # if still not, dnf localinstall the above
@@ -1561,9 +1568,12 @@ class TestPlc:
             'lxml',
             'python-dateutil',
             'psycopg2-binary',
+            'pyOpenSSL',
         ]
 
-        return (self.install_m2crypto()
+        return (
+                    self.install_pip2()
+                and self.install_m2crypto()
                 and all((self.run_in_guest(f"pip2 install {dep}") == 0)
                         for dep in pip_dependencies)
                 and self.dnf_install("sfa sfa-plc sfa-sfatables sfa-client")