def setUp(self): """ Attempt to setup a valid group with clients and test the protocol """ super().setUp() factory = Factory() self.client_job = factory.create_kvm_job( "sample_jobs/kvm-multinode-client.yaml") self.server_job = factory.create_kvm_job( "sample_jobs/kvm-multinode-server.yaml") self.client_job.logger = DummyLogger() self.server_job.logger = DummyLogger() self.job_id = "100" self.coord = TestCoordinator()
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" ) factory = Factory() self.job = factory.create_kvm_job("sample_jobs/qemu-reboot.yaml", validate=True) self.job.logger = DummyLogger() self.job.validate() self.ret = False test_retry = [ action for action in self.job.pipeline.actions if action.name == "lava-test-retry" ][0] self.skipped_shell = [ action for action in test_retry.pipeline.actions if action.name == "lava-test-shell" ][0] print(self.skipped_shell.parameters["timeout"]) self.skipped_shell.logger = DummyLogger() test_retry = [ action for action in self.job.pipeline.actions if action.name == "lava-test-retry" ][1] self.fatal_shell = [ action for action in test_retry.pipeline.actions if action.name == "lava-test-shell" ][0]
class TestDefinitionHandlers(StdoutTestCase): def setUp(self): super().setUp() self.factory = Factory() self.job = self.factory.create_kvm_job("sample_jobs/kvm.yaml") def test_testshell(self): testshell = None for action in self.job.pipeline.actions: self.assertIsNotNone(action.name) if isinstance(action, TestShellRetry): testshell = action.pipeline.actions[0] break self.assertIsInstance(testshell, TestShellAction) self.assertTrue(testshell.valid) if "timeout" in testshell.parameters: time_int = Timeout.parse(testshell.parameters["timeout"]) else: time_int = Timeout.default_duration() self.assertEqual( datetime.timedelta(seconds=time_int).total_seconds(), testshell.timeout.duration, ) def test_missing_handler(self): (rendered, _) = self.factory.create_device("kvm01.jinja2") device = NewDevice(yaml_safe_load(rendered)) kvm_yaml = os.path.join(os.path.dirname(__file__), "sample_jobs/kvm.yaml") parser = JobParser() with open(kvm_yaml) as sample_job_data: data = yaml_safe_load(sample_job_data) data["actions"][2]["test"]["definitions"][0][ "from"] = "unusable-handler" try: job = parser.parse(yaml_safe_dump(data), device, 4212, None, "") job.logger = DummyLogger() except JobError: pass except Exception as exc: self.fail(exc) else: self.fail("JobError not raised") def test_eventpatterns(self): testshell = None for action in self.job.pipeline.actions: self.assertIsNotNone(action.name) if isinstance(action, TestShellRetry): testshell = action.pipeline.actions[0] break self.assertTrue(testshell.valid) self.assertFalse(testshell.check_patterns("exit", None, "")) self.assertRaises(InfrastructureError, testshell.check_patterns, "eof", None, "") self.assertTrue(testshell.check_patterns("timeout", None, ""))
def test_qemu_notest(self): factory = Factory() job = factory.create_kvm_job("sample_jobs/kvm-notest.yaml") job.validate() self.assertIsNotNone(job) self.assertIsNotNone(job.pipeline) self.assertIsNotNone(job.pipeline.actions) for action in job.pipeline.actions: action.validate() self.assertTrue(action.valid) self.assertTrue(find_autologin(job))
def test_qemu_monitor_zephyr_job(self): factory = Factory() job = factory.create_kvm_job("sample_jobs/zephyr-qemu-test-task.yaml") job.validate() self.assertIsNotNone(job) self.assertIsNotNone(job.pipeline) self.assertIsNotNone(job.pipeline.actions) for action in job.pipeline.actions: action.validate() self.assertTrue(action.valid) self.assertFalse(find_autologin(job))
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" ) factory = Factory() self.job = factory.create_kvm_job("sample_jobs/kvm.yaml") self.job.logger = DummyLogger() self.job.validate() self.ret = False test_retry = [ action for action in self.job.pipeline.actions if action.name == "lava-test-retry" ][0] self.test_shell = [ action for action in test_retry.pipeline.actions if action.name == "lava-test-shell" ][0] self.test_shell.logger = DummyLogger()
class TestDefinitionParams(StdoutTestCase): def setUp(self): super().setUp() self.factory = Factory() self.job = self.factory.create_kvm_job("sample_jobs/kvm-params.yaml") def test_job_without_tests(self): boot = finalize = None allow_missing_path(self.job.pipeline.validate_actions, self, "qemu-system-x86_64") deploy = [ action for action in self.job.pipeline.actions if action.name == "deployimages" ][0] overlay = [ action for action in deploy.pipeline.actions if action.name == "lava-overlay" ][0] testdef = [ action for action in overlay.pipeline.actions if action.name == "test-definition" ][0] for action in self.job.pipeline.actions: self.assertNotIsInstance(action, TestDefinitionAction) self.assertNotIsInstance(action, OverlayAction) boot = self.job.pipeline.actions[1] finalize = self.job.pipeline.actions[3] self.assertIsInstance(overlay, OverlayAction) self.assertIsInstance(testdef, TestDefinitionAction) test = testdef.pipeline.actions[1] install = testdef.pipeline.actions[2] runsh = testdef.pipeline.actions[3] self.assertIsInstance(deploy, DeployImagesAction) self.assertEqual(boot.section, "boot") self.assertIsInstance(finalize, FinalizeAction) self.assertEqual(len(self.job.pipeline.actions), 4) # deploy, boot, test, finalize self.assertNotIn("test_params", testdef.parameters) self.assertIsInstance(install, TestInstallAction) self.assertIsInstance(runsh, TestRunnerAction) self.assertIsNot(list(install.parameters.items()), []) testdef = { "params": { "VARIABLE_NAME_1": "value_1", "VARIABLE_NAME_2": "value_2" } } content = test.handle_parameters(testdef) self.assertEqual( set(content), { "###default parameters from test definition###\n", "VARIABLE_NAME_1='value_1'\n", "VARIABLE_NAME_2='value_2'\n", "######\n", "###test parameters from job submission###\n", "VARIABLE_NAME_1='eth2'\n", "VARIABLE_NAME_2='wlan0'\n", "######\n", }, ) testdef = { "parameters": { "VARIABLE_NAME_1": "value_1", "VARIABLE_NAME_2": "value_2" } } content = test.handle_parameters(testdef) self.assertEqual( set(content), { "###default parameters from test definition###\n", "VARIABLE_NAME_1='value_1'\n", "VARIABLE_NAME_2='value_2'\n", "######\n", "###test parameters from job submission###\n", "VARIABLE_NAME_1='eth2'\n", "VARIABLE_NAME_2='wlan0'\n", "######\n", }, ) @unittest.skipIf(infrastructure_error("git"), "git not installed") def test_install_repos(self): job = self.factory.create_kvm_job("sample_jobs/kvm-install.yaml") allow_missing_path(self.job.pipeline.validate_actions, self, "qemu-system-x86_64") deploy = [ action for action in job.pipeline.actions if action.name == "deployimages" ][0] overlay = [ action for action in deploy.pipeline.actions if action.name == "lava-overlay" ][0] testdef = [ action for action in overlay.pipeline.actions if action.name == "test-definition" ][0] test_install = [ action for action in testdef.pipeline.actions if action.name == "test-install-overlay" ][0] self.assertIsNotNone(test_install) yaml_file = os.path.join(os.path.dirname(__file__), "./testdefs/install.yaml") self.assertTrue(os.path.exists(yaml_file)) with open(yaml_file, "r") as test_file: testdef = yaml_safe_load(test_file) repos = testdef["install"].get("git-repos", []) self.assertIsNotNone(repos) self.assertIsInstance(repos, list) for repo in repos: self.assertIsNotNone(repo) runner_path = tempfile.mkdtemp() test_install.install_git_repos(testdef, runner_path) shutil.rmtree(runner_path)
def setUp(self): super().setUp() factory = Factory() self.job = factory.create_kvm_job("sample_jobs/kvm-notest.yaml")
def setUp(self): super().setUp() factory = Factory() self.job = factory.create_kvm_job("sample_jobs/qemu-monitor.yaml")
def setUp(self): super().setUp() factory = Factory() self.job = factory.create_kvm_job("sample_jobs/kvm-inline.yaml") self.job.logger = DummyLogger() self.max_end_time = time.time() + 30
def test_kvm_simulation(self): """ Build a pipeline which simulates a KVM LAVA job without using the formal objects (to avoid validating data known to be broken). The details are entirely arbitrary. """ factory = Factory() job = factory.create_kvm_job("sample_jobs/kvm.yaml") pipe = Pipeline() action = Action() action.name = "deploy_linaro_image" action.description = "deploy action using preset subactions in an internal pipe" action.summary = "deploy_linaro_image" action.job = job # deliberately unlikely location # a successful validation would need to use the cwd action.parameters = {"image": "file:///none/images/bad-kvm-debian-wheezy.img"} pipe.add_action(action) self.assertEqual(action.level, "1") deploy_pipe = Pipeline(action) action = Action() action.name = "downloader" action.description = "download image wrapper, including an internal retry pipe" action.summary = "downloader" action.job = job deploy_pipe.add_action(action) self.assertEqual(action.level, "1.1") # a formal RetryAction would contain a pre-built pipeline which can be inserted directly retry_pipe = Pipeline(action) action = Action() action.name = "wget" action.description = "do the download with retries" action.summary = "wget" action.job = job retry_pipe.add_action(action) self.assertEqual(action.level, "1.1.1") action = Action() action.name = "checksum" action.description = "checksum the downloaded file" action.summary = "md5sum" action.job = job deploy_pipe.add_action(action) self.assertEqual(action.level, "1.2") action = Action() action.name = "overlay" action.description = "apply lava overlay" action.summary = "overlay" action.job = job deploy_pipe.add_action(action) self.assertEqual(action.level, "1.3") action = Action() action.name = "boot" action.description = "boot image" action.summary = "qemu" action.job = job # cmd_line built from device configuration action.parameters = { "cmd_line": [ "qemu-system-x86_64", "-machine accel=kvm:tcg", "-hda" "%s" % "tbd", "-nographic", "-net", "nic,model=virtio", "-net user", ] } pipe.add_action(action) self.assertEqual(action.level, "2") action = Action() action.name = "simulated" action.description = "lava test shell" action.summary = "simulated" action.job = job # a formal lava test shell action would include an internal pipe # which would handle the run.sh pipe.add_action(action) self.assertEqual(action.level, "3") # just a fake action action = Action() action.name = "fake" action.description = "faking results" action.summary = "fake action" action.job = job pipe.add_action(action) self.assertEqual(action.level, "4") self.assertEqual(len(pipe.describe()), 4)
class TestKVMInlineTestDeploy(StdoutTestCase): def setUp(self): super().setUp() self.factory = Factory() self.job = self.factory.create_kvm_job("sample_jobs/kvm-inline.yaml") def test_deploy_job(self): self.assertEqual(self.job.pipeline.job, self.job) for action in self.job.pipeline.actions: if isinstance(action, DeployAction): self.assertEqual(action.job, self.job) def test_validate(self): try: self.job.pipeline.validate_actions() except JobError as exc: self.fail(exc) except InfrastructureError: pass for action in self.job.pipeline.actions: self.assertEqual([], action.errors) def test_extra_options(self): (rendered, _) = self.factory.create_device("kvm01.jinja2") device = NewDevice(yaml_safe_load(rendered)) kvm_yaml = os.path.join( os.path.dirname(__file__), "sample_jobs/kvm-inline.yaml" ) with open(kvm_yaml) as sample_job_data: job_data = yaml_safe_load(sample_job_data) device["actions"]["boot"]["methods"]["qemu"]["parameters"][ "extra" ] = yaml_safe_load( """ - -smp - 1 - -global - virtio-blk-device.scsi=off - -device virtio-scsi-device,id=scsi - --append "console=ttyAMA0 root=/dev/vda rw" """ ) self.assertIsInstance( device["actions"]["boot"]["methods"]["qemu"]["parameters"]["extra"][1], int ) parser = JobParser() job = parser.parse(yaml_safe_dump(job_data), device, 4212, None, "") job.logger = DummyLogger() job.validate() boot_image = [ action for action in job.pipeline.actions if action.name == "boot-image-retry" ][0] boot_qemu = [ action for action in boot_image.pipeline.actions if action.name == "boot-qemu-image" ][0] qemu = [ action for action in boot_qemu.pipeline.actions if action.name == "execute-qemu" ][0] self.assertIsInstance(qemu.sub_command, list) [self.assertIsInstance(item, str) for item in qemu.sub_command] self.assertIn("virtio-blk-device.scsi=off", qemu.sub_command) self.assertIn("1", qemu.sub_command) self.assertNotIn(1, qemu.sub_command) def test_pipeline(self): description_ref = self.pipeline_reference("kvm-inline.yaml", job=self.job) self.assertEqual(description_ref, self.job.pipeline.describe(False)) self.assertEqual(len(self.job.pipeline.describe()), 4) inline_repo = None for action in self.job.pipeline.actions: if isinstance(action, DeployAction): self.assertIsNotNone(action.pipeline.actions[1]) overlay = action.pipeline.actions[1] self.assertIsNotNone(overlay.pipeline.actions[1]) testdef = overlay.pipeline.actions[2] self.assertIsNotNone(testdef.pipeline.actions[0]) inline_repo = testdef.pipeline.actions[0] break # Test the InlineRepoAction directly self.assertIsNotNone(inline_repo) location = mkdtemp() # other actions have not been run, so fake up inline_repo.set_namespace_data( action="test", label="results", key="lava_test_results_dir", value=location ) inline_repo.set_namespace_data( action="test", label="test-definition", key="overlay_dir", value=location ) inline_repo.set_namespace_data( action="test", label="shared", key="location", value=location ) inline_repo.set_namespace_data( action="test", label="test-definiton", key="overlay_dir", value=location ) inline_repo.run(None, None) yaml_file = os.path.join( location, "0/tests/0_smoke-tests-inline/inline/smoke-tests-basic.yaml" ) self.assertTrue(os.path.exists(yaml_file)) with open(yaml_file, "r") as f_in: testdef = yaml_safe_load(f_in) expected_testdef = { "metadata": { "description": "Basic system test command for Linaro Ubuntu images", "devices": [ "panda", "panda-es", "arndale", "vexpress-a9", "vexpress-tc2", ], "format": "Lava-Test Test Definition 1.0", "name": "smoke-tests-basic", "os": ["ubuntu"], "scope": ["functional"], }, "run": { "steps": [ "lava-test-case linux-INLINE-pwd --shell pwd", "lava-test-case linux-INLINE-uname --shell uname -a", "lava-test-case linux-INLINE-vmstat --shell vmstat", "lava-test-case linux-INLINE-ifconfig --shell ifconfig -a", "lava-test-case linux-INLINE-lscpu --shell lscpu", "lava-test-case linux-INLINE-lsusb --shell lsusb", "lava-test-case linux-INLINE-lsb_release --shell lsb_release -a", ] }, } self.assertEqual(set(testdef), set(expected_testdef))
def setUp(self): super().setUp() factory = Factory() self.job = factory.create_kvm_job("sample_jobs/compression.yaml") self.job.validate()
def test_autologin_normal_kvm(self): factory = Factory() job = factory.create_kvm_job("sample_jobs/kvm.yaml") job.validate() self.assertTrue(find_autologin(job))