+ def install_pip2(self):
+
+ replacements = [
+ "https://acc.dl.osdn.jp/storage/g/u/un/unitedrpms/32/x86_64/python2-pip-19.1.1-7.fc32.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
+ # f29 and f31: dnf install python2-m2crypto
+ # f33: no longer available but the f31 repos below do the job just fine
+ # note that using pip2 does not look like a viable option because it does
+ # 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",
+ ]
+
+ 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)
+
+ return attempt
+
+ # about pip2:
+ # we can try and use
+ # that qould then need to be mirrored
+ # so the logic goes like this
+ # check for pip2 command
+ # if not, try dnf install python2-pip
+ # if still not, dnf localinstall the above
+
+
+ def sfa_install_all(self):
+ "yum install sfa sfa-plc sfa-sfatables sfa-client"
+
+ # the rpm/dnf packages named in python2-* are getting deprecated
+ # we use pip2 instead
+ # but that's not good for m2crypto
+
+ pip_dependencies = [
+ 'sqlalchemy-migrate',
+ 'lxml',
+ 'python-dateutil',
+ 'psycopg2-binary',
+ ]
+
+ 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")
+ and self.run_in_guest("systemctl enable sfa-registry")==0
+ and self.run_in_guest("systemctl enable sfa-aggregate")==0)
+
+ def sfa_install_core(self):
+ "yum install sfa"
+ return self.dnf_install("sfa")
+
+ def sfa_install_plc(self):
+ "yum install sfa-plc"
+ return self.dnf_install("sfa-plc")
+
+ def sfa_install_sfatables(self):
+ "yum install sfa-sfatables"
+ return self.dnf_install("sfa-sfatables")
+
+ # for some very odd reason, this sometimes fails with the following symptom
+ # # yum install sfa-client
+ # Setting up Install Process
+ # ...
+ # Downloading Packages:
+ # Running rpm_check_debug
+ # Running Transaction Test
+ # Transaction Test Succeeded
+ # Running Transaction
+ # Transaction couldn't start:
+ # installing package sfa-client-2.1-7.onelab.2012.05.23.i686 needs 68KB on the / filesystem
+ # [('installing package sfa-client-2.1-7.onelab.2012.05.23.i686 needs 68KB on the / filesystem', (9, '/', 69632L))]
+ # even though in the same context I have
+ # [2012.05.23--f14-32-sfastd1-1-vplc07] / # df -h
+ # Filesystem Size Used Avail Use% Mounted on
+ # /dev/hdv1 806G 264G 501G 35% /
+ # none 16M 36K 16M 1% /tmp
+ #
+ # so as a workaround, we first try yum install, and then invoke rpm on the cached rpm...
+ def sfa_install_client(self):
+ "yum install sfa-client"
+ first_try = self.dnf_install("sfa-client")
+ if first_try:
+ return True
+ utils.header("********** Regular yum failed - special workaround in place, 2nd chance")
+ code, cached_rpm_path = \
+ utils.output_of(self.actual_command_in_guest('find /var/cache/yum -name sfa-client\*.rpm'))
+ utils.header("rpm_path=<<{}>>".format(rpm_path))
+ # just for checking
+ self.run_in_guest("rpm -i {}".format(cached_rpm_path))
+ return self.dnf_check_installed("sfa-client")
+
+ def sfa_dbclean(self):
+ "thoroughly wipes off the SFA database"
+ return self.run_in_guest("sfaadmin reg nuke") == 0 or \
+ self.run_in_guest("sfa-nuke.py") == 0 or \
+ self.run_in_guest("sfa-nuke-plc.py") == 0 or \
+ self.run_in_guest("sfaadmin registry nuke") == 0
+
+ def sfa_fsclean(self):
+ "cleanup /etc/sfa/trusted_roots and /var/lib/sfa"
+ self.run_in_guest("rm -rf /etc/sfa/trusted_roots /var/lib/sfa/authorities")
+ return True
+
+ def sfa_plcclean(self):
+ "cleans the PLC entries that were created as a side effect of running the script"
+ # ignore result
+ sfa_spec = self.plc_spec['sfa']
+
+ for auth_sfa_spec in sfa_spec['auth_sfa_specs']:
+ login_base = auth_sfa_spec['login_base']
+ try:
+ self.apiserver.DeleteSite(self.auth_root(),login_base)
+ except:
+ print("Site {} already absent from PLC db".format(login_base))
+
+ for spec_name in ['pi_spec', 'user_spec']:
+ user_spec = auth_sfa_spec[spec_name]
+ username = user_spec['email']
+ try:
+ self.apiserver.DeletePerson(self.auth_root(),username)
+ except:
+ # this in fact is expected as sites delete their members
+ #print "User {} already absent from PLC db".format(username)
+ pass
+
+ print("REMEMBER TO RUN sfa_import AGAIN")
+ return True
+
+ def sfa_uninstall(self):
+ "uses rpm to uninstall sfa - ignore result"
+ self.run_in_guest("rpm -e sfa sfa-sfatables sfa-client sfa-plc")
+ self.run_in_guest("rm -rf /var/lib/sfa")
+ self.run_in_guest("rm -rf /etc/sfa")
+ self.run_in_guest("rm -rf /var/log/sfa_access.log /var/log/sfa_import_plc.log /var/log/sfa.daemon")
+ # xxx tmp
+ self.run_in_guest("rpm -e --noscripts sfa-plc")
+ return True
+
+ ### run unit tests for SFA
+ # NOTE: for some reason on f14/i386, yum install sfa-tests fails for no reason
+ # Running Transaction
+ # Transaction couldn't start:
+ # installing package sfa-tests-1.0-21.onelab.i686 needs 204KB on the / filesystem
+ # [('installing package sfa-tests-1.0-21.onelab.i686 needs 204KB on the / filesystem', (9, '/', 208896L))]
+ # no matter how many Gbs are available on the testplc
+ # could not figure out what's wrong, so...
+ # if the yum install phase fails, consider the test is successful
+ # other combinations will eventually run it hopefully
+ def sfa_utest(self):
+ "dnf install sfa-tests and run SFA unittests"
+ self.run_in_guest("dnf -y install sfa-tests")
+ # failed to install - forget it
+ if self.run_in_guest("rpm -q sfa-tests") != 0:
+ utils.header("WARNING: SFA unit tests failed to install, ignoring")
+ return True
+ return self.run_in_guest("/usr/share/sfa/tests/testAll.py") == 0