def test_statuses(self): os.chdir(BASE_DIR) test_path = os.path.join(data_dir.get_test_providers_dir(), "downloads", "io-github-autotest-qemu", "generic", "tests", "test_statuses.py") self.assertTrue(os.path.exists(os.path.dirname(test_path)), "The qemu providers dir does not exists, Avocado-vt " "is probably not configured properly.") self.rm_files.append(test_path) script.make_script(test_path, TEST_STATUSES_PY) cfg = script.make_script(os.path.join(self.tmpdir, "test_statuses.cfg"), TEST_STATUSES_CFG) result = process.run("avocado --show all run --vt-config %s " "--job-results-dir %s" % (cfg, self.tmpdir), ignore_status=True) self.assertEqual(result.exit_status, 1, "Exit status is not 1:\n%s" % result) status = json.load(open(os.path.join(self.tmpdir, "latest", "results.json"))) act_statuses = [_["status"] for _ in status["tests"]] statuses_master = ["SKIP", "PASS", "FAIL", "ERROR", "CANCEL", "PASS", "FAIL", "ERROR", "ERROR"] statuses_36lts = ["SKIP", "PASS", "FAIL", "ERROR", "SKIP", "PASS", "FAIL", "ERROR", "ERROR"] if not (act_statuses == statuses_master or act_statuses == statuses_36lts): self.fail("Test statuses does not match any of expected results:" "\nmaster: %s\n36lts: %s\nactual: %s\n\noutput:\n%s" % (statuses_master, statuses_36lts, act_statuses, result))
def setUp(self): vm_domain = self.params.get("vm_domain", default=None) vm_host = self.params.get("vm_host", default=None) if vm_domain is None or vm_host is None: self.skip('Either "vm_domain" or "vm_host" parameters have not ' 'been given. Please edit the "vm-cleanup.yaml" file ' 'with the appropriate parameters') self.tmpdir = tempfile.mkdtemp() clean_test = os.path.join(self.tmpdir, 'clean.py') self.clean_test_path = script.make_script(clean_test, CLEAN_TEST) dirty_test = os.path.join(self.tmpdir, 'dirty.py') self.dirty_test_path = script.make_script(dirty_test, DIRTY_TEST)
def setUp(self): vm_domain = self.params.get("vm_domain", default=None) vm_host = self.params.get("vm_host", default=None) if vm_domain is None or vm_host is None: self.skip('Either "vm_domain" or "vm_host" parameters have not ' 'been given. Please edit the "vm-cleanup.yaml" file ' 'with the appropriate parameters') self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__) clean_test = os.path.join(self.tmpdir, 'clean.py') self.clean_test_path = script.make_script(clean_test, CLEAN_TEST) dirty_test = os.path.join(self.tmpdir, 'dirty.py') self.dirty_test_path = script.make_script(dirty_test, DIRTY_TEST)
def run_sysinfo_interrupted(self, sleep, timeout, exp_duration): commands_path = os.path.join(self.tmpdir.name, "commands") script.make_script(commands_path, f"sleep {sleep}") config_path = os.path.join(self.tmpdir.name, "config.conf") script.make_script(config_path, COMMANDS_TIMEOUT_CONF % (timeout, commands_path)) cmd_line = (f"{AVOCADO} --show all --config {config_path} run " f"--job-results-dir {self.tmpdir.name} " f"examples/tests/passtest.py") result = process.run(cmd_line) if timeout > 0: self.assertLess( result.duration, exp_duration, (f"Execution took " f"longer than {exp_duration}s which is likely " f"due to malfunctioning commands_timeout " f"sysinfo.collect feature:\n{result}"), ) else: self.assertGreater( result.duration, exp_duration, (f"Execution took " f"less than {exp_duration}s which is likely " f"due to malfunctioning commands_timeout " f"sysinfo.collect feature:\n{result}"), ) expected_rc = exit_codes.AVOCADO_ALL_OK self.assertEqual( result.exit_status, expected_rc, f"Avocado did not return rc {expected_rc}:\n{result}", ) sleep_log = os.path.join(self.tmpdir.name, "latest", "sysinfo", "pre", f"sleep {sleep}") if not os.path.exists(sleep_log): path = os.path.abspath(sleep_log) while not os.path.exists(path): tmp = os.path.split(path)[0] if tmp == path: break path = tmp raise AssertionError(f"Sleep output not recorded in '{sleep_log}'," f"first existing location '{path}' contains:" f"\n{os.listdir(path)}")
def test_syntax_error_plugin(self): self.syntax_err_plugin = script.make_script( os.path.join(self.base_sourcedir, 'avocado_syntax_err.py'), SYNTAX_ERROR_PLUGIN_CONTENTS) os.chdir(basedir) cmd_line = './scripts/avocado --plugins %s' % self.base_sourcedir result = process.run(cmd_line, ignore_status=True) expected_output = 'invalid syntax' self.assertIn(expected_output, result.stderr)
def test_hello_plugin(self): self.hello_plugin = script.make_script( os.path.join(self.base_sourcedir, 'avocado_hello.py'), HELLO_PLUGIN_CONTENTS) os.chdir(basedir) cmd_line = './scripts/avocado --plugins %s hello' % self.base_sourcedir result = process.run(cmd_line, ignore_status=True) expected_output = 'Hello World!' self.assertIn(expected_output, result.stdout)
def test_void_plugin(self): self.void_plugin = script.make_script( os.path.join(self.base_sourcedir, 'avocado_void.py'), VOID_PLUGIN_CONTENTS) os.chdir(basedir) cmd_line = './scripts/avocado --plugins %s plugins' % self.base_sourcedir result = process.run(cmd_line, ignore_status=True) expected_output = 'noname' self.assertIn(expected_output, result.stdout)
def test_invalid_python(self): test = script.make_script(os.path.join(self.tmpdir.name, 'test.py'), INVALID_PYTHON_TEST) cmd_line = (f'{AVOCADO} run --disable-sysinfo ' f'--job-results-dir {self.tmpdir.name} {test}') result = process.run(cmd_line, ignore_status=True) expected_rc = exit_codes.AVOCADO_TESTS_FAIL self.assertEqual( result.exit_status, expected_rc, f"Avocado did not return rc {expected_rc}:\n{result}") self.assertIn(f'{test}:MyTest.test_my_name: ERROR', result.stdout_text)
def run_sysinfo_interrupted(self, sleep, timeout, exp_duration): os.chdir(BASEDIR) commands_path = os.path.join(self.tmpdir, "commands") script.make_script(commands_path, "sleep %s" % sleep) config_path = os.path.join(self.tmpdir, "config.conf") script.make_script(config_path, COMMANDS_TIMEOUT_CONF % (timeout, commands_path)) cmd_line = ("%s --show all --config %s run --job-results-dir %s " "--sysinfo=on passtest.py" % (AVOCADO, config_path, self.tmpdir)) result = process.run(cmd_line) if timeout > 0: self.assertLess(result.duration, exp_duration, "Execution took " "longer than %ss which is likely due to " "malfunctioning commands_timeout " "sysinfo.collect feature:\n%s" % (exp_duration, result)) else: self.assertGreater(result.duration, exp_duration, "Execution took " "less than %ss which is likely due to " "malfunctioning commands_timeout " "sysinfo.collect feature:\n%s" % (exp_duration, result)) expected_rc = exit_codes.AVOCADO_ALL_OK self.assertEqual(result.exit_status, expected_rc, 'Avocado did not return rc %d:\n%s' % (expected_rc, result)) sleep_log = os.path.join(self.tmpdir, "latest", "sysinfo", "pre", "sleep %s" % sleep) if not os.path.exists(sleep_log): path = os.path.abspath(sleep_log) while not os.path.exists(path): tmp = os.path.split(path)[0] if tmp == path: break path = tmp raise AssertionError("Sleep output not recorded in '%s', first " "existing location '%s' contains:\n%s" % (sleep_log, path, os.listdir(path)))
def test_invalid_python(self): os.chdir(basedir) test = script.make_script(os.path.join(self.tmpdir, 'test.py'), INVALID_PYTHON_TEST) cmd_line = './scripts/avocado --show test run --sysinfo=off '\ '--job-results-dir %s %s' % (self.tmpdir, test) result = process.run(cmd_line, ignore_status=True) expected_rc = exit_codes.AVOCADO_TESTS_FAIL self.assertEqual( result.exit_status, expected_rc, "Avocado did not return rc %d:\n%s" % (expected_rc, result)) self.assertIn('1-%s:MyTest.test_my_name -> TestError' % test, result.stdout)
def setUp(self): super(ReplayExtRunnerTests, self).setUp() test = script.make_script(os.path.join(self.tmpdir.name, 'test'), 'exit 0') cmd_line = ('%s run %s ' '--external-runner /bin/bash ' '--job-results-dir %s --disable-sysinfo --json -' % (AVOCADO, test, self.tmpdir.name)) expected_rc = exit_codes.AVOCADO_ALL_OK self.run_and_check(cmd_line, expected_rc) self.jobdir = ''.join(glob.glob(os.path.join(self.tmpdir.name, 'job-*'))) idfile = ''.join(os.path.join(self.jobdir, 'id')) with open(idfile, 'r') as f: self.jobid = f.read().strip('\n')
def run_sysinfo_interrupted(self, sleep, timeout, exp_duration): os.chdir(BASEDIR) commands_path = os.path.join(self.tmpdir, "commands") script.make_script(commands_path, "sleep %s" % sleep) config_path = os.path.join(self.tmpdir, "config.conf") script.make_script(config_path, COMMANDS_TIMEOUT_CONF % (timeout, commands_path)) cmd_line = ("%s --show all --config %s run --job-results-dir %s " "--sysinfo=on passtest.py" % (AVOCADO, config_path, self.tmpdir)) result = process.run(cmd_line) if timeout > 0: self.assertLess( result.duration, exp_duration, "Execution took " "longer than %ss which is likely due to " "malfunctioning commands_timeout " "sysinfo.collect feature:\n%s" % (exp_duration, result)) else: self.assertGreater( result.duration, exp_duration, "Execution took " "less than %ss which is likely due to " "malfunctioning commands_timeout " "sysinfo.collect feature:\n%s" % (exp_duration, result)) expected_rc = exit_codes.AVOCADO_ALL_OK self.assertEqual( result.exit_status, expected_rc, 'Avocado did not return rc %d:\n%s' % (expected_rc, result)) sleep_log = os.path.join(self.tmpdir, "latest", "sysinfo", "pre", "sleep %s" % sleep) if not os.path.exists(sleep_log): path = os.path.abspath(sleep_log) while not os.path.exists(path): tmp = os.path.split(path)[0] if tmp == path: break path = tmp raise AssertionError("Sleep output not recorded in '%s', first " "existing location '%s' contains:\n%s" % (sleep_log, path, os.listdir(path)))
def test_invalid_python(self): os.chdir(basedir) test = script.make_script(os.path.join(self.tmpdir, 'test.py'), INVALID_PYTHON_TEST) cmd_line = './scripts/avocado --show test run --sysinfo=off '\ '--job-results-dir %s %s' % (self.tmpdir, test) result = process.run(cmd_line, ignore_status=True) expected_rc = exit_codes.AVOCADO_TESTS_FAIL self.assertEqual(result.exit_status, expected_rc, "Avocado did not return rc %d:\n%s" % (expected_rc, result)) self.assertIn('1-%s:MyTest.test_my_name -> TestError' % test, result.stdout)
def setUp(self): self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__) test = script.make_script(os.path.join(self.tmpdir, 'test'), 'exit 0') cmd_line = ('./scripts/avocado run %s ' '-m examples/tests/sleeptest.py.data/sleeptest.yaml ' '--external-runner /bin/bash ' '--job-results-dir %s --sysinfo=off --json -' % (test, self.tmpdir)) expected_rc = exit_codes.AVOCADO_ALL_OK self.run_and_check(cmd_line, expected_rc) self.jobdir = ''.join(glob.glob(os.path.join(self.tmpdir, 'job-*'))) idfile = ''.join(os.path.join(self.jobdir, 'id')) with open(idfile, 'r') as f: self.jobid = f.read().strip('\n')
def setUp(self): self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__) test = script.make_script(os.path.join(self.tmpdir, 'test'), 'exit 0') cmd_line = ('%s run %s ' '-m examples/tests/sleeptest.py.data/sleeptest.yaml ' '--external-runner /bin/bash ' '--job-results-dir %s --sysinfo=off --json -' % (AVOCADO, test, self.tmpdir)) expected_rc = exit_codes.AVOCADO_ALL_OK self.run_and_check(cmd_line, expected_rc) self.jobdir = ''.join(glob.glob(os.path.join(self.tmpdir, 'job-*'))) idfile = ''.join(os.path.join(self.jobdir, 'id')) with open(idfile, 'r') as f: self.jobid = f.read().strip('\n')
def setUp(self): prefix = temp_dir_prefix(__name__, self, 'setUp') self.tmpdir = tempfile.TemporaryDirectory(prefix=prefix) test = script.make_script(os.path.join(self.tmpdir.name, 'test'), 'exit 0') cmd_line = ('%s run %s ' '--external-runner /bin/bash ' '--job-results-dir %s --sysinfo=off --json -' % (AVOCADO, test, self.tmpdir.name)) expected_rc = exit_codes.AVOCADO_ALL_OK self.run_and_check(cmd_line, expected_rc) self.jobdir = ''.join( glob.glob(os.path.join(self.tmpdir.name, 'job-*'))) idfile = ''.join(os.path.join(self.jobdir, 'id')) with open(idfile, 'r') as f: self.jobid = f.read().strip('\n')
def setUp(self): self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__) test = script.make_script(os.path.join(self.tmpdir, 'test'), 'exit 0') cmd_line = ('./scripts/avocado run %s ' '--external-runner /bin/bash ' '--job-results-dir %s --sysinfo=off --json -' % (test, self.tmpdir)) expected_rc = exit_codes.AVOCADO_ALL_OK self.run_and_check(cmd_line, expected_rc) self.jobdir = ''.join(glob.glob(os.path.join(self.tmpdir, 'job-*'))) self.tmpdir2 = tempfile.mkdtemp(prefix='avocado_' + __name__) cmd_line = ('./scripts/avocado run %s ' '--external-runner /bin/bash ' '--job-results-dir %s --sysinfo=off --json -' % (test, self.tmpdir2)) expected_rc = exit_codes.AVOCADO_ALL_OK self.run_and_check(cmd_line, expected_rc) self.jobdir2 = ''.join(glob.glob(os.path.join(self.tmpdir2, 'job-*')))
def setUp(self): super(DiffTests, self).setUp() test = script.make_script(os.path.join(self.tmpdir.name, 'test'), 'exit 0') cmd_line = ('%s run %s ' '--external-runner /bin/bash ' '--job-results-dir %s --disable-sysinfo --json -' % (AVOCADO, test, self.tmpdir.name)) expected_rc = exit_codes.AVOCADO_ALL_OK self.run_and_check(cmd_line, expected_rc) self.jobdir = ''.join( glob.glob(os.path.join(self.tmpdir.name, 'job-*'))) self.tmpdir2 = tempfile.TemporaryDirectory(prefix=self.tmpdir.name) cmd_line = ('%s run %s ' '--external-runner /bin/bash ' '--job-results-dir %s --disable-sysinfo --json -' % (AVOCADO, test, self.tmpdir2.name)) expected_rc = exit_codes.AVOCADO_ALL_OK self.run_and_check(cmd_line, expected_rc) self.jobdir2 = ''.join( glob.glob(os.path.join(self.tmpdir2.name, 'job-*')))