def setUp(self): super().setUp() self.testdef = os.path.join(os.path.dirname(__file__), "testdefs", "params.yaml") self.res_data = os.path.join(os.path.dirname(__file__), "testdefs", "result-data.txt") self.factory = UBootFactory() self.job = self.factory.create_bbb_job("sample_jobs/bbb-nfs-url.yaml")
def test_deploy_parameters(self): factory = UBootFactory() job = factory.create_bbb_job("sample_jobs/kexec.yaml") self.assertIsNotNone(job) # Check Pipeline description_ref = self.pipeline_reference("kexec.yaml", job=job) self.assertEqual(description_ref, job.pipeline.describe(False)) # Check kexec specific options job.validate() self.assertIsInstance(job.pipeline.actions[2], TestShellRetry) self.assertIsInstance(job.pipeline.actions[3], BootKexecAction) kexec = job.pipeline.actions[3] self.assertIsInstance(kexec.internal_pipeline.actions[0], KexecAction) self.assertIsInstance(kexec.internal_pipeline.actions[1], AutoLoginAction) self.assertIsInstance(kexec.internal_pipeline.actions[2], ExpectShellSession) self.assertIsInstance(kexec.internal_pipeline.actions[3], ExportDeviceEnvironment) self.assertIn("kernel", kexec.parameters) self.assertIn("command", kexec.parameters) self.assertIn("method", kexec.parameters) self.assertIn("dtb", kexec.parameters) self.assertIn("options", kexec.parameters) self.assertIn("kernel-config", kexec.parameters) self.assertTrue(kexec.valid) self.assertEqual( "/sbin/kexec --load /home/vmlinux --dtb /home/dtb --initrd /home/initrd --reuse-cmdline", kexec.internal_pipeline.actions[0].load_command, ) self.assertEqual("/sbin/kexec -e", kexec.internal_pipeline.actions[0].command) self.assertIsNotNone( kexec.internal_pipeline.actions[0].parameters["boot_message"]) self.assertIsNotNone(kexec.internal_pipeline.actions[0].name) self.assertIsNotNone(kexec.internal_pipeline.actions[0].level) self.assertEqual(kexec.internal_pipeline.actions[0].timeout.duration, 45)
class TestDefinitions(StdoutTestCase): """ For compatibility until the V1 code is removed and we can start cleaning up Lava Test Shell. Parsing patterns in the Test Shell Definition YAML are problematic, difficult to debug and rely on internal python syntax. The fixupdict is even more confusing for all concerned. """ def setUp(self): super().setUp() self.testdef = os.path.join(os.path.dirname(__file__), "testdefs", "params.yaml") self.res_data = os.path.join(os.path.dirname(__file__), "testdefs", "result-data.txt") self.factory = UBootFactory() self.job = self.factory.create_bbb_job("sample_jobs/bbb-nfs-url.yaml") def test_pattern(self): self.assertTrue(os.path.exists(self.testdef)) with open(self.testdef, "r") as par: params = yaml.safe_load(par) self.assertIn("parse", params.keys()) line = "test1a: pass" self.assertEqual( r"(?P<test_case_id>.*-*):\s+(?P<result>(pass|fail))", params["parse"]["pattern"], ) match = re.search(params["parse"]["pattern"], line) self.assertIsNotNone(match) self.assertEqual(match.group(), line) self.assertEqual(match.group(1), "test1a") self.assertEqual(match.group(2), "pass") def test_v1_defaults(self): pattern = PatternFixup(testdef=None, count=0) # without a name from a testdef, the pattern is not valid. self.assertFalse(pattern.valid()) with open(self.testdef, "r") as par: params = yaml.safe_load(par) pattern = PatternFixup(testdef=params, count=0) self.assertTrue(pattern.valid()) @unittest.skipIf(check_rpcinfo(), "rpcinfo returns non-zero for nfs") def test_definition_lists(self): # pylint: disable=too-many-locals self.job.validate() tftp_deploy = [ action for action in self.job.pipeline.actions if action.name == "tftp-deploy" ][0] prepare = [ action for action in tftp_deploy.internal_pipeline.actions if action.name == "prepare-tftp-overlay" ][0] overlay = [ action for action in prepare.internal_pipeline.actions if action.name == "lava-overlay" ][0] apply_o = [ action for action in prepare.internal_pipeline.actions if action.name == "apply-overlay-tftp" ][0] self.assertIsInstance(apply_o.parameters.get("persistent_nfs"), dict) self.assertIsInstance( apply_o.parameters["persistent_nfs"].get("address"), str) definition = [ action for action in overlay.internal_pipeline.actions if action.name == "test-definition" ][0] git_repos = [ action for action in definition.internal_pipeline.actions if action.name == "git-repo-action" ] self.assertIn("common", self.job.context) self.assertIn("test-definition", self.job.context["common"]) self.assertIsNotNone( definition.get_namespace_data(action=definition.name, label="test-definition", key="testdef_index")) self.assertEqual( definition.get_namespace_data(action=definition.name, label="test-definition", key="testdef_index"), ["smoke-tests", "singlenode-advanced"], ) self.assertEqual( git_repos[0].get_namespace_data( action="test-runscript-overlay", label="test-runscript-overlay", key="testdef_levels", ), { "1.3.2.4.4": "0_smoke-tests", "1.3.2.4.8": "1_singlenode-advanced" }, ) self.assertEqual({repo.uuid for repo in git_repos}, {"4999_1.3.2.4.1", "4999_1.3.2.4.5"}) self.assertEqual( set(git_repos[0].get_namespace_data( action="test-runscript-overlay", label="test-runscript-overlay", key="testdef_levels", ).values()), {"1_singlenode-advanced", "0_smoke-tests"}, ) # fake up a run step with open(self.testdef, "r") as par: params = yaml.safe_load(par) self.assertEqual( r"(?P<test_case_id>.*-*):\s+(?P<result>(pass|fail))", params["parse"]["pattern"], ) self.job.context.setdefault("test", {}) for git_repo in git_repos: self.job.context["test"].setdefault(git_repo.uuid, {}) self.job.context["test"][git_repo.uuid]["testdef_pattern"] = { "pattern": params["parse"]["pattern"] } self.assertEqual( self.job.context["test"], { "4999_1.3.2.4.5": { "testdef_pattern": { "pattern": "(?P<test_case_id>.*-*):\\s+(?P<result>(pass|fail))" } }, "4999_1.3.2.4.1": { "testdef_pattern": { "pattern": "(?P<test_case_id>.*-*):\\s+(?P<result>(pass|fail))" } }, }, ) testdef_index = self.job.context["common"]["test-definition"][ "test-definition"]["testdef_index"] start_run = "0_smoke-tests" uuid_list = definition.get_namespace_data(action="repo-action", label="repo-action", key="uuid-list") self.assertIsNotNone(uuid_list) for key, value in enumerate(testdef_index): if start_run == "%s_%s" % (key, value): self.assertEqual("4999_1.3.2.4.1", uuid_list[key]) self.assertEqual( self.job.context["test"][uuid_list[key]]["testdef_pattern"] ["pattern"], "(?P<test_case_id>.*-*):\\s+(?P<result>(pass|fail))", ) def test_defined_pattern(self): """ For python3 support, need to resolve: TypeError: cannot use a bytes pattern on a string-like object TypeError: cannot use a string pattern on a bytes-like object whilst retaining re_pat as a compiled regular expression in the pexpect support. """ data = """test1a: pass test2a: fail test3a: skip \"test4a:\" \"unknown\" """ with open(self.testdef, "r") as par: params = yaml.safe_load(par) pattern = params["parse"]["pattern"] re_pat = re.compile(pattern, re.M) match = re.search(re_pat, data) if match: self.assertEqual(match.groupdict(), { "test_case_id": "test1a", "result": "pass" }) child = pexpect.spawn("cat", [self.res_data], encoding="utf-8") child.expect([re_pat, pexpect.EOF]) self.assertEqual(child.after.encode("utf-8"), b"test1a: pass") child.expect([re_pat, pexpect.EOF]) self.assertEqual(child.after.encode("utf-8"), b"test2a: fail") child.expect([re_pat, pexpect.EOF]) self.assertEqual(child.after, pexpect.EOF) @unittest.skipIf( infrastructure_error_multi_paths(["lxc-info", "img2simg", "simg2img"]), "lxc or img2simg or simg2img not installed", ) def test_deployment_data(self): job = self.factory.create_job("hi960-hikey-01.jinja2", "sample_jobs/hikey960-oe-aep.yaml") job.validate() description_ref = self.pipeline_reference("hikey960-oe-aep.yaml", job=job) self.assertEqual(description_ref, job.pipeline.describe(False)) lxc_deploy = [ action for action in job.pipeline.actions if action.name == "lxc-deploy" ][0] lxc_overlay = [ action for action in lxc_deploy.internal_pipeline.actions if action.name == "lava-overlay" ][0] lxc_defs = [ action for action in lxc_overlay.internal_pipeline.actions if action.name == "test-definition" ][0] lxc_installscript = [ action for action in lxc_defs.internal_pipeline.actions if action.name == "test-install-overlay" ][0] fastboot_deploy = [ action for action in job.pipeline.actions if action.name == "fastboot-deploy" ][0] fastboot_overlay = [ action for action in fastboot_deploy.internal_pipeline.actions if action.name == "lava-overlay" ][0] fastboot_defs = [ action for action in fastboot_overlay.internal_pipeline.actions if action.name == "test-definition" ][0] fastboot_installscript = [ action for action in fastboot_defs.internal_pipeline.actions if action.name == "test-install-overlay" ][0] self.assertIn("distro", lxc_installscript.parameters["deployment_data"].keys()) self.assertIn( "distro", list(lxc_installscript.parameters["deployment_data"].keys())) self.assertIn("distro", list(lxc_installscript.parameters["deployment_data"])) self.assertIn("distro", dict(lxc_installscript.parameters["deployment_data"])) self.assertEqual( "debian", lxc_installscript.parameters["deployment_data"]["distro"]) self.assertIn( "distro", fastboot_installscript.parameters["deployment_data"].keys()) self.assertIn( "distro", list(fastboot_installscript.parameters["deployment_data"].keys())) self.assertIn("distro", fastboot_installscript.parameters["deployment_data"]) self.assertIn( "distro", dict(fastboot_installscript.parameters["deployment_data"])) self.assertEqual( "oe", fastboot_installscript.parameters["deployment_data"]["distro"])
def setUp(self): super().setUp() factory = UBootFactory() self.job = factory.create_bbb_job("sample_jobs/bbb-skip-install.yaml")
def setUp(self): super().setUp() factory = UBootFactory() self.job = factory.create_bbb_job("sample_jobs/uboot-ramdisk.yaml") self.assertIsNotNone(self.job)
def setUp(self): super().setUp() factory = UBootFactory() self.job = factory.create_bbb_job("sample_jobs/uboot-multiple.yaml") self.assertIsNotNone(self.job) self.assertIsNone(self.job.validate())