From 56c85c15fcdf2615a5914436aa02c445039b2986 Mon Sep 17 00:00:00 2001 From: Jan Scotka Date: Jul 12 2017 14:16:39 +0000 Subject: [PATCH 1/7] added few fixes with timeouts (reverted some changes) and clean up of using more apostrophes and commands inside --- diff --git a/moduleframework/module_framework.py b/moduleframework/module_framework.py index 440306b..1e86a6e 100755 --- a/moduleframework/module_framework.py +++ b/moduleframework/module_framework.py @@ -422,7 +422,7 @@ class ContainerHelper(CommonFunctions): """ self.start() return self.runHost( - 'docker exec %s bash -c "%s"' % + """docker exec %s bash -c "%s" """ % (self.docker_id, sanitize_cmd(command)), **kwargs) @@ -675,7 +675,7 @@ gpgcheck=0 :param kwargs: dict from avocado.process.run :return: avocado.process.run """ - return self.runHost('bash -c "%s"' % + return self.runHost("""bash -c "%s" """ % sanitize_cmd(command), **kwargs) def copyTo(self, src, dest): @@ -769,7 +769,7 @@ class NspawnHelper(RpmHelper): def __is_killed(self): for foo in range(DEFAULTRETRYTIMEOUT): - time.sleep(1) + time.sleep(foo) out = self.runHost("machinectl status %s" % self.jmeno, verbose=is_debug(), ignore_status=True) if out.exit_status != 0: print_debug("NSPAWN machine %s stopped" % self.jmeno) @@ -778,10 +778,9 @@ class NspawnHelper(RpmHelper): def __is_booted(self): for foo in range(DEFAULTRETRYTIMEOUT): - time.sleep(1) + time.sleep(foo) out = self.runHost("machinectl status %s" % self.jmeno, verbose=is_debug(), ignore_status=True) if "systemd-logind" in out.stdout: - time.sleep(2) print_debug("NSPAWN machine %s booted" % self.jmeno) return True raise NspawnExc("Unable to start machine %s within %d" % (self.jmeno, DEFAULTRETRYTIMEOUT)) From db59434077783b3587b2be1e144eb3d5f6248a31 Mon Sep 17 00:00:00 2001 From: Jan Scotka Date: Jul 13 2017 09:26:39 +0000 Subject: [PATCH 2/7] removed relic in tests using get_correct_profile --- diff --git a/examples/multios_testing/sanity1.py b/examples/multios_testing/sanity1.py index 7de8f11..51739bf 100644 --- a/examples/multios_testing/sanity1.py +++ b/examples/multios_testing/sanity1.py @@ -54,11 +54,11 @@ class SanityCheck1(module_framework.AvocadoTest): self.runHost("nohup nc -l %d > %s 2>&1 &" % (PORT, TFILE), shell=True, ignore_bg_processes=True) time.sleep(2) a = self.run("cat /etc/redhat-release").stdout.strip() - self.run("cat /etc/redhat-release | nc localhost %d" % PORT, shell=True) + self.run("echo Im host | nc localhost %d" % PORT, shell=True) time.sleep(2) b = self.runHost("cat %s" %TFILE).stdout.strip() self.assertEqual(a,b) - self.assertIn("26", b) + self.assertIn("Im host", b) if __name__ == '__main__': main() diff --git a/examples/testing-module/skipTest.py b/examples/testing-module/skipTest.py index 5c91ca8..2ec7c64 100644 --- a/examples/testing-module/skipTest.py +++ b/examples/testing-module/skipTest.py @@ -39,12 +39,12 @@ class SkipTest(module_framework.AvocadoTest): self.start() self.run("gcc -v") - @skipIf(module_framework.get_correct_profile() == "default") + @skipIf(module_framework.get_profile() == "default") def testDecoratorNotSkippedForDefault(self): self.start() self.run("echo for default profile") - @skipUnless(module_framework.get_correct_profile() == "gcc") + @skipUnless(module_framework.get_profile() == "gcc") def testDecoratorSkip(self): self.start() self.run("gcc -v") From 6289927d0b521d1c89dedb8e11570da5890acf70 Mon Sep 17 00:00:00 2001 From: Jan Scotka Date: Jul 13 2017 09:29:29 +0000 Subject: [PATCH 3/7] fixed multihost checks --- diff --git a/examples/multios_testing/sanity1.py b/examples/multios_testing/sanity1.py index 51739bf..1d228b8 100644 --- a/examples/multios_testing/sanity1.py +++ b/examples/multios_testing/sanity1.py @@ -39,11 +39,11 @@ class SanityCheck1(module_framework.AvocadoTest): self.run(" nohup nc -l %d > %s 2>&1 &" % (PORT, TFILE), shell=True, ignore_bg_processes=True) time.sleep(2) a = self.runHost("cat /etc/redhat-release").stdout.strip() - self.runHost("cat /etc/redhat-release | nc localhost %d" % PORT, shell=True) + self.runHost("Im Host | nc localhost %d" % PORT, shell=True) time.sleep(2) b = self.run("cat %s" %TFILE).stdout.strip() self.assertEqual(a,b) - self.assertIn("26", b) + self.assertIn("Im Host", b) @@ -54,11 +54,11 @@ class SanityCheck1(module_framework.AvocadoTest): self.runHost("nohup nc -l %d > %s 2>&1 &" % (PORT, TFILE), shell=True, ignore_bg_processes=True) time.sleep(2) a = self.run("cat /etc/redhat-release").stdout.strip() - self.run("echo Im host | nc localhost %d" % PORT, shell=True) + self.run("echo Im guest | nc localhost %d" % PORT, shell=True) time.sleep(2) b = self.runHost("cat %s" %TFILE).stdout.strip() self.assertEqual(a,b) - self.assertIn("Im host", b) + self.assertIn("Im guest", b) if __name__ == '__main__': main() From edf8108860f709d92b73dbf2733bf5e4c2909b52 Mon Sep 17 00:00:00 2001 From: Jan Scotka Date: Jul 13 2017 12:03:06 +0000 Subject: [PATCH 4/7] removed some workarounds --- diff --git a/moduleframework/module_framework.py b/moduleframework/module_framework.py index 1e86a6e..d6e0dbc 100755 --- a/moduleframework/module_framework.py +++ b/moduleframework/module_framework.py @@ -769,7 +769,7 @@ class NspawnHelper(RpmHelper): def __is_killed(self): for foo in range(DEFAULTRETRYTIMEOUT): - time.sleep(foo) + time.sleep(1) out = self.runHost("machinectl status %s" % self.jmeno, verbose=is_debug(), ignore_status=True) if out.exit_status != 0: print_debug("NSPAWN machine %s stopped" % self.jmeno) @@ -778,7 +778,7 @@ class NspawnHelper(RpmHelper): def __is_booted(self): for foo in range(DEFAULTRETRYTIMEOUT): - time.sleep(foo) + time.sleep(1) out = self.runHost("machinectl status %s" % self.jmeno, verbose=is_debug(), ignore_status=True) if "systemd-logind" in out.stdout: print_debug("NSPAWN machine %s booted" % self.jmeno) @@ -883,7 +883,7 @@ gpgcheck=0 def __bootMachine(self): - @Retry(attempts=DEFAULTRETRYCOUNT, timeout=DEFAULTRETRYTIMEOUT, delay=21, + @Retry(attempts=DEFAULTRETRYCOUNT, timeout=DEFAULTRETRYTIMEOUT, error=NspawnExc("RETRY: Unable to start nspawn machine")) def tempfnc(): print_debug("starting container via command:", @@ -960,6 +960,8 @@ gpgcheck=0 should_ignore = kwargs.get("ignore_status") kwargs["ignore_status"] = True + # workaound, try to stop shell in case already running (it sometimes happened) + # self.runHost("systemctl -M {machine} stop container-shell@0.service".format(machine=self.jmeno), ignore_status=True, verbose=is_debug()) comout = self.runHost("""machinectl shell root@{machine} /bin/bash -c "({comm})>{pin}/stdout 2>{pin}/stderr; echo $?>{pin}/retcode; sleep 1" """.format( machine=self.jmeno, comm=sanitize_cmd(command), @@ -1041,7 +1043,6 @@ gpgcheck=0 self.__is_killed() except Exception as poweroffexterm: print_info("Unable to stop machine via terminate, STRANGE", poweroffexterm) - time.sleep(DEFAULTRETRYTIMEOUT) pass pass From 271bf8379a291e608d6e4637c965d680c8557675 Mon Sep 17 00:00:00 2001 From: Jan Scotka Date: Jul 13 2017 13:13:17 +0000 Subject: [PATCH 5/7] all changes --- diff --git a/moduleframework/module_framework.py b/moduleframework/module_framework.py index d6e0dbc..7321416 100755 --- a/moduleframework/module_framework.py +++ b/moduleframework/module_framework.py @@ -126,7 +126,7 @@ class CommonFunctions(object): # fall back to mistyped test dependency section packages = self.config.get('testdependecies', {}).get('rpms') - if packages: + if packages and self.runHost("rpm -q %s" % " ".join(packages),ignore_status=True, verbose=is_not_silent()).exit_status == 1: self.runHost( "{HOSTPACKAGER} install " + " ".join(packages), @@ -364,21 +364,14 @@ class ContainerHelper(CommonFunctions): if self.getPackageList(): a = self.run( "%s install %s" % - (trans_dict["HOSTPACKAGER"], " ".join( - self.getPackageList())), - ignore_status=True, verbose=False) - b = self.run( - "%s install %s" % (trans_dict["GUESTPACKAGER"], " ".join( self.getPackageList())), ignore_status=True, verbose=False) if a.exit_status == 0: - print_info("Packages installed via {HOSTPACKAGER}", a.stdout) - elif b.exit_status == 0: - print_info("Packages installed via {GUESTPACKAGER}", b.stdout) + print_info("Packages installed via {GUESTPACKAGER}", a.stdout) else: print_info( - "Nothing installed (nor via {HOSTPACKAGER} nor {GUESTPACKAGER}), but package list is not empty", + "Nothing installed via {GUESTPACKAGER}), but package list is not empty", self.getPackageList()) if self.status() is False: raise ContainerExc( From 5a431948b52bbacf770080d2c3b4d018b00dfeb1 Mon Sep 17 00:00:00 2001 From: Jan Scotka Date: Jul 13 2017 14:08:02 +0000 Subject: [PATCH 6/7] check if already installed packages, to avoid to run installation commands (it takes longer time) --- diff --git a/moduleframework/module_framework.py b/moduleframework/module_framework.py index 7321416..26a0fe5 100755 --- a/moduleframework/module_framework.py +++ b/moduleframework/module_framework.py @@ -104,6 +104,17 @@ class CommonFunctions(object): trans_dict) return process.run("%s" % formattedcommand, **kwargs) + def PackagesInstalled(self,packagelist, func="runHost"): + """ + Check if package list is already installed on Host + + :param packagelist: list + :return: bool + """ + rpmout = getattr(self, func)("rpm -q %s" % " ".join(packagelist), ignore_status=True, verbose=is_not_silent()) + return bool(rpmout.exit_status) + + def installTestDependencies(self, packages=None): """ Which packages install to host system to satisfy environment @@ -126,7 +137,7 @@ class CommonFunctions(object): # fall back to mistyped test dependency section packages = self.config.get('testdependecies', {}).get('rpms') - if packages and self.runHost("rpm -q %s" % " ".join(packages),ignore_status=True, verbose=is_not_silent()).exit_status == 1: + if packages and not self.PackagesInstalled(packages): self.runHost( "{HOSTPACKAGER} install " + " ".join(packages), @@ -361,7 +372,7 @@ class ContainerHelper(CommonFunctions): "docker run %s %s %s" % (args, self.jmeno, command), shell=True, ignore_bg_processes=True, verbose=is_not_silent()).stdout self.docker_id = self.docker_id.strip() - if self.getPackageList(): + if self.getPackageList() and not self.PackagesInstalled(self.getPackageList(),"run"): a = self.run( "%s install %s" % (trans_dict["GUESTPACKAGER"], " ".join( @@ -805,7 +816,8 @@ class NspawnHelper(RpmHelper): """ self.__do_smart_start_cleanup() if not os.path.exists(os.path.join(self.chrootpath, "usr")): - self.runHost("{HOSTPACKAGER} install systemd-container", verbose=is_not_silent(), sudo=True) + if not self.PackagesInstalled(["systemd-container"]): + self.runHost("{HOSTPACKAGER} install systemd-container", verbose=is_not_silent(), sudo=True) # workaround in case machined blocked by selinux, disabled for now # self.runHost("sudo systemctl restart systemd-machined", verbose=is_not_silent(), sudo=True) repos_to_use = "" From 3865f5632745e261b03d4cf6bd2e303249050c12 Mon Sep 17 00:00:00 2001 From: Jan Scotka Date: Jul 14 2017 10:17:19 +0000 Subject: [PATCH 7/7] commented out check for packages, seems to have side effect --- diff --git a/moduleframework/module_framework.py b/moduleframework/module_framework.py index 26a0fe5..ca33735 100755 --- a/moduleframework/module_framework.py +++ b/moduleframework/module_framework.py @@ -111,8 +111,9 @@ class CommonFunctions(object): :param packagelist: list :return: bool """ - rpmout = getattr(self, func)("rpm -q %s" % " ".join(packagelist), ignore_status=True, verbose=is_not_silent()) - return bool(rpmout.exit_status) + return True + #rpmout = getattr(self, func)("rpm -q %s" % " ".join(packagelist), ignore_status=True, verbose=is_not_silent()) + #return bool(rpmout.exit_status) def installTestDependencies(self, packages=None):