Esempio n. 1
0
 def test_job_no_tags(self):
     with open(self.filename) as yaml_data:
         alpha_data = yaml.safe_load(yaml_data)
     for vlan_key, _ in alpha_data["protocols"][VlandProtocol.name].items():
         alpha_data["protocols"][VlandProtocol.name][vlan_key] = {
             "tags": []
         }
     # removed tags from original job to simulate job where any interface tags will be acceptable
     self.assertEqual(alpha_data["protocols"][VlandProtocol.name],
                      {"vlan_one": {
                          "tags": []
                      }})
     parser = JobParser()
     job = parser.parse(yaml.dump(alpha_data), self.device, 4212, None, "")
     job.logger = DummyLogger()
     job.validate()
     vprotocol = [
         vprotocol for vprotocol in job.protocols
         if vprotocol.name == VlandProtocol.name
     ][0]
     self.assertTrue(vprotocol.valid)
     self.assertEqual(vprotocol.names, {"vlan_one": "4212vlanone"})
     self.assertFalse(vprotocol.check_timeout(120, {"request": "no call"}))
     self.assertRaises(JobError, vprotocol.check_timeout, 60,
                       "deploy_vlans")
     self.assertRaises(JobError, vprotocol.check_timeout, 60,
                       {"request": "deploy_vlans"})
     self.assertTrue(
         vprotocol.check_timeout(120, {"request": "deploy_vlans"}))
     for vlan_name in job.parameters["protocols"][VlandProtocol.name]:
         self.assertIn(vlan_name, vprotocol.params)
         self.assertIn("switch", vprotocol.params[vlan_name])
         self.assertIn("port", vprotocol.params[vlan_name])
Esempio n. 2
0
    def test_device_environment(self):
        data = """
# YAML syntax.
overrides:
 DEBEMAIL: "*****@*****.**"
 DEBFULLNAME: "Neil Williams"
        """
        factory = Factory()
        job_parser = JobParser()
        (rendered, _) = factory.create_device('bbb-01.jinja2')
        device = NewDevice(yaml.safe_load(rendered))
        sample_job_file = os.path.join(os.path.dirname(__file__), 'sample_jobs/uboot-ramdisk.yaml')
        with open(sample_job_file) as sample_job_data:
            job = job_parser.parse(
                sample_job_data, device, 4212, None, "",
                env_dut=data)
        job.logger = DummyLogger()
        self.assertEqual(
            job.parameters['env_dut'],
            data
        )
        job.validate()
        boot_actions = [
            action.internal_pipeline.actions for action in job.pipeline.actions if action.name == 'uboot-action'][0]
        retry = [action for action in boot_actions if action.name == 'uboot-retry'][0]
        boot_env = [action for action in retry.internal_pipeline.actions if action.name == 'export-device-env'][0]
        found = False
        for line in boot_env.env:
            if 'DEBFULLNAME' in line:
                found = True
                # assert that the string containing a space still contains that space and is quoted
                self.assertIn('\\\'Neil Williams\\\'', line)
        self.assertTrue(found)
Esempio n. 3
0
 def test_job_protocols(self):
     self.factory.ensure_tag('usb-eth')
     self.factory.ensure_tag('sata')
     self.factory.bbb1.tags = Tag.objects.filter(name='usb-eth')
     self.factory.bbb1.save()
     self.factory.cubie1.tags = Tag.objects.filter(name='sata')
     self.factory.cubie1.save()
     target_group = "unit-test-only"
     job_dict = split_multinode_yaml(self.factory.make_vland_job(),
                                     target_group)
     client_job = job_dict['client'][0]
     client_handle, client_file_name = tempfile.mkstemp()
     yaml.dump(client_job, open(client_file_name, 'w'))
     # YAML device file, as required by lava-dispatch --target
     device_yaml_file = os.path.realpath(
         os.path.join(os.path.dirname(__file__), 'devices', 'bbb-01.yaml'))
     self.assertTrue(os.path.exists(device_yaml_file))
     parser = JobParser()
     bbb_device = NewDevice(device_yaml_file)
     with open(client_file_name) as sample_job_data:
         bbb_job = parser.parse(sample_job_data, bbb_device, 4212, None, "")
     os.close(client_handle)
     os.unlink(client_file_name)
     self.assertIn('protocols', bbb_job.parameters)
     self.assertIn(VlandProtocol.name, bbb_job.parameters['protocols'])
     self.assertIn(MultinodeProtocol.name, bbb_job.parameters['protocols'])
Esempio n. 4
0
 def create_download_job(self, filename):  # pylint: disable=no-self-use
     device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/db410c-01.yaml'))
     download_yaml = os.path.join(os.path.dirname(__file__), filename)
     with open(download_yaml) as sample_job_data:
         parser = JobParser()
         job = parser.parse(sample_job_data, device, 4212, None, "")
     return job
Esempio n. 5
0
 def test_primary_interface(self):
     with open(self.filename) as yaml_data:
         alpha_data = yaml.safe_load(yaml_data)
     for interface in self.device['parameters']['interfaces']:
         # jinja2 processing of tags: [] results in tags:
         if self.device['parameters']['interfaces'][interface][
                 'tags'] == []:
             self.device['parameters']['interfaces'][interface][
                 'tags'] = None
     parser = JobParser()
     job = parser.parse(yaml.dump(alpha_data), self.device, 4212, None, "")
     deploy = [
         action for action in job.pipeline.actions
         if action.name == 'tftp-deploy'
     ][0]
     prepare = [
         action for action in 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]
     vland_overlay = [
         action for action in overlay.internal_pipeline.actions
         if action.name == 'lava-vland-overlay'
     ][0]
     vland_overlay.validate()
     job.logger = DummyLogger()
     job.validate()
Esempio n. 6
0
 def create_kvm_job(self, filename, validate=False):
     """
     Custom function to allow for extra exception handling.
     """
     job_ctx = {
         "arch": "amd64",
         "no_kvm": True,
     }  # override to allow unit tests on all types of systems
     (data, device_dict) = self.create_device("kvm01.jinja2", job_ctx)
     device = NewDevice(yaml.safe_load(data))
     if self.debug:
         print("####### Device configuration #######")
         print(data)
         print("#######")
     self.validate_data("hi6220-hikey-01", device_dict)
     kvm_yaml = os.path.join(os.path.dirname(__file__), filename)
     parser = JobParser()
     job_data = ""
     with open(kvm_yaml) as sample_job_data:
         job_data = yaml.safe_load(sample_job_data.read())
     if self.debug:
         print("########## Test Job Submission validation #######")
     if validate:
         validate_job(job_data, strict=False)
     try:
         job = parser.parse(yaml.dump(job_data), device, 4212, None, "")
         job.logger = DummyLogger()
     except LAVAError as exc:
         print(exc)
         # some deployments listed in basics.yaml are not implemented yet
         return None
     return job
Esempio n. 7
0
 def test_parameter_support(self):  # pylint: disable=too-many-locals
     data = self.factory.make_job_data()
     test_block = [block for block in data['actions'] if 'test' in block][0]
     smoke = test_block['test']['definitions'][0]
     smoke['parameters'] = {
         'VARIABLE_NAME_1': "first variable value",
         'VARIABLE_NAME_2': "second value"
     }
     job = TestJob.from_yaml_and_user(yaml.dump(data), self.user)
     job_def = yaml.load(job.definition)
     job_ctx = job_def.get('context', {})
     job_ctx.update({'no_kvm': True})  # override to allow unit tests on all types of systems
     device = Device.objects.get(hostname='fakeqemu1')
     device_config = device.load_configuration(job_ctx)  # raw dict
     parser = JobParser()
     obj = PipelineDevice(device_config)
     pipeline_job = parser.parse(job.definition, obj, job.id, None, "")
     allow_missing_path(pipeline_job.pipeline.validate_actions, self,
                        'qemu-system-x86_64')
     pipeline = pipeline_job.describe()
     device_values = _get_device_metadata(pipeline['device'])
     try:
         testdata, _ = TestData.objects.get_or_create(testjob=job)
     except (MultipleObjectsReturned):
         self.fail('multiple objects')
     for key, value in device_values.items():
         if not key or not value:
             continue
         testdata.attributes.create(name=key, value=value)
     retval = _get_action_metadata(pipeline['job']['actions'])
     self.assertIn('test.0.common.definition.parameters.VARIABLE_NAME_2', retval)
     self.assertIn('test.0.common.definition.parameters.VARIABLE_NAME_1', retval)
     self.assertEqual(retval['test.0.common.definition.parameters.VARIABLE_NAME_1'], 'first variable value')
     self.assertEqual(retval['test.0.common.definition.parameters.VARIABLE_NAME_2'], 'second value')
Esempio n. 8
0
    def test_device_environment_validity(self):  # pylint: disable=invalid-name
        """
        Use non-YAML syntax a bit like existing device config syntax.
        Ensure this syntax is picked up as invalid.
        """
        data = """
# YAML syntax.
overrides:
 DEBEMAIL = "*****@*****.**"
 DEBFULLNAME: "Neil Williams"
        """
        job_parser = JobParser()
        device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/bbb-01.yaml'))
        sample_job_file = os.path.join(os.path.dirname(__file__), 'sample_jobs/uboot-ramdisk.yaml')
        with open(sample_job_file) as sample_job_data:
            job = job_parser.parse(
                sample_job_data, device, 4212, None, "",
                env_dut=data)
        job.logger = DummyLogger()
        self.assertEqual(
            job.parameters['env_dut'],
            data
        )
        with self.assertRaises(JobError):
            job.validate()
 def create_b2260_job(self, filename):
     device = NewDevice(os.path.join(os.path.dirname(__file__), "../devices/b2260-01.yaml"))
     with open(os.path.join(os.path.dirname(__file__), filename)) as f_in:
         parser = JobParser()
         job = parser.parse(f_in, device, 456, None, "")
     job.logger = DummyLogger()
     return job
Esempio n. 10
0
    def test_device_environment(self):
        data = """
# YAML syntax.
overrides:
 DEBEMAIL: "*****@*****.**"
 DEBFULLNAME: "Neil Williams"
        """
        job_parser = JobParser()
        device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/bbb-01.yaml'))
        sample_job_file = os.path.join(os.path.dirname(__file__), 'sample_jobs/uboot-ramdisk.yaml')
        with open(sample_job_file) as sample_job_data:
            job = job_parser.parse(
                sample_job_data, device, 4212, None, "",
                env_dut=data)
        job.logger = DummyLogger()
        self.assertEqual(
            job.parameters['env_dut'],
            data
        )
        job.validate()
        boot_actions = [
            action.internal_pipeline.actions for action in job.pipeline.actions if action.name == 'uboot-action'][0]
        retry = [action for action in boot_actions if action.name == 'uboot-retry'][0]
        boot_env = [action for action in retry.internal_pipeline.actions if action.name == 'export-device-env'][0]
        found = False
        for line in boot_env.env:
            if 'DEBFULLNAME' in line:
                found = True
                # assert that the string containing a space still contains that space and is quoted
                self.assertIn('\\\'Neil Williams\\\'', line)
        self.assertTrue(found)
Esempio n. 11
0
    def test_prompt_from_job(self):  # pylint: disable=too-many-locals
        """
        Support setting the prompt after login via the job

        Loads a known YAML, adds a prompt to the dict and re-parses the job.
        Checks that the prompt is available in the expect_shell_connection action.
        """
        job = self.factory.create_job('sample_jobs/ipxe-ramdisk.yaml')
        job.validate()
        bootloader = [action for action in job.pipeline.actions if action.name == 'bootloader-action'][0]
        retry = [action for action in bootloader.internal_pipeline.actions
                 if action.name == 'bootloader-retry'][0]
        expect = [action for action in retry.internal_pipeline.actions
                  if action.name == 'expect-shell-connection'][0]
        check = expect.parameters
        device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/x86-01.yaml'))
        extra_yaml = os.path.join(os.path.dirname(__file__), 'sample_jobs/ipxe.yaml')
        with open(extra_yaml) as data:
            sample_job_string = data.read()
        parser = JobParser()
        sample_job_data = yaml.load(sample_job_string)
        boot = [item['boot'] for item in sample_job_data['actions'] if 'boot' in item][0]
        self.assertIsNotNone(boot)
        sample_job_string = yaml.dump(sample_job_data)
        job = parser.parse(sample_job_string, device, 4212, None, "")
        job.logger = DummyLogger()
        job.validate()
        bootloader = [action for action in job.pipeline.actions if action.name == 'bootloader-action'][0]
        retry = [action for action in bootloader.internal_pipeline.actions
                 if action.name == 'bootloader-retry'][0]
        expect = [action for action in retry.internal_pipeline.actions
                  if action.name == 'expect-shell-connection'][0]
Esempio n. 12
0
    def test_device_environment_validity(self):  # pylint: disable=invalid-name
        """
        Use non-YAML syntax a bit like existing device config syntax.
        Ensure this syntax is picked up as invalid.
        """
        data = """
# YAML syntax.
overrides:
 DEBEMAIL = "*****@*****.**"
 DEBFULLNAME: "Neil Williams"
        """
        job_parser = JobParser()
        device = NewDevice(
            os.path.join(os.path.dirname(__file__), '../devices/bbb-01.yaml'))
        sample_job_file = os.path.join(os.path.dirname(__file__),
                                       'sample_jobs/uboot-ramdisk.yaml')
        with open(sample_job_file) as sample_job_data:
            job = job_parser.parse(sample_job_data,
                                   device,
                                   4212,
                                   None,
                                   "",
                                   env_dut=data)
        job.logger = DummyLogger()
        self.assertEqual(job.parameters['env_dut'], data)
        with self.assertRaises(JobError):
            job.validate()
Esempio n. 13
0
 def test_job_no_tags(self):
     with open(self.filename) as yaml_data:
         alpha_data = yaml.safe_load(yaml_data)
     for vlan_key, _ in alpha_data['protocols'][VlandProtocol.name].items():
         alpha_data['protocols'][VlandProtocol.name][vlan_key] = {
             'tags': []
         }
     # removed tags from original job to simulate job where any interface tags will be acceptable
     self.assertEqual(alpha_data['protocols'][VlandProtocol.name],
                      {'vlan_one': {
                          'tags': []
                      }})
     parser = JobParser()
     job = parser.parse(yaml.dump(alpha_data), self.device, 4212, None, "")
     job.logger = DummyLogger()
     job.validate()
     vprotocol = [
         vprotocol for vprotocol in job.protocols
         if vprotocol.name == VlandProtocol.name
     ][0]
     self.assertTrue(vprotocol.valid)
     self.assertEqual(vprotocol.names, {'vlan_one': '4212vlanone'})
     self.assertFalse(vprotocol.check_timeout(120, {'request': 'no call'}))
     self.assertRaises(JobError, vprotocol.check_timeout, 60,
                       'deploy_vlans')
     self.assertRaises(JobError, vprotocol.check_timeout, 60,
                       {'request': 'deploy_vlans'})
     self.assertTrue(
         vprotocol.check_timeout(120, {'request': 'deploy_vlans'}))
     for vlan_name in job.parameters['protocols'][VlandProtocol.name]:
         if vlan_name == 'yaml_line':
             continue
         self.assertIn(vlan_name, vprotocol.params)
         self.assertIn('switch', vprotocol.params[vlan_name])
         self.assertIn('port', vprotocol.params[vlan_name])
Esempio n. 14
0
 def test_extra_options(self):
     device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/kvm01.yaml'))
     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.load(sample_job_data)
     device['actions']['boot']['methods']['qemu']['parameters']['extra'] = yaml.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.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.internal_pipeline.actions if action.name == 'boot-qemu-image'][0]
     qemu = [action for action in boot_qemu.internal_pipeline.actions if action.name == 'execute-qemu'][0]
     self.assertIsInstance(qemu.sub_command, list)
     [self.assertIsInstance(item, str) for item in qemu.sub_command]  # pylint: disable=expression-not-assigned
     self.assertIn('virtio-blk-device.scsi=off', qemu.sub_command)
     self.assertIn('1', qemu.sub_command)
     self.assertNotIn(1, qemu.sub_command)
Esempio n. 15
0
 def test_uboot_checksum(self):
     device = NewDevice(
         os.path.join(os.path.dirname(__file__), '../devices/bbb-01.yaml'))
     bbb_yaml = os.path.join(os.path.dirname(__file__),
                             'sample_jobs/bbb-ramdisk-nfs.yaml')
     with open(bbb_yaml) as sample_job_data:
         parser = JobParser()
         job = parser.parse(sample_job_data, device, 4212, None, "")
     deploy = [
         action for action in job.pipeline.actions
         if action.name == 'tftp-deploy'
     ][0]
     download = [
         action for action in deploy.internal_pipeline.actions
         if action.name == 'download-retry'
     ][0]
     helper = [
         action for action in download.internal_pipeline.actions
         if action.name == 'file-download'
     ][0]
     remote = helper.parameters[helper.key]
     md5sum = remote.get('md5sum', None)
     self.assertIsNone(md5sum)
     sha256sum = remote.get('sha256sum', None)
     self.assertIsNotNone(sha256sum)
Esempio n. 16
0
    def test_device_environment_validity(self):
        """
        Use non-YAML syntax a bit like existing device config syntax.
        Ensure this syntax is picked up as invalid.
        """
        data = """
# YAML syntax.
overrides:
 DEBEMAIL = "*****@*****.**"
 DEBFULLNAME: "Neil Williams"
        """
        factory = Factory()
        job_parser = JobParser()
        (rendered, _) = factory.create_device("bbb-01.jinja2")
        device = NewDevice(yaml_safe_load(rendered))
        sample_job_file = os.path.join(
            os.path.dirname(__file__), "sample_jobs/uboot-ramdisk.yaml"
        )
        with open(sample_job_file) as sample_job_data:
            job = job_parser.parse(
                sample_job_data, device, 4212, None, "", env_dut=data
            )
        job.logger = DummyLogger()
        self.assertEqual(job.parameters["env_dut"], data)
        with self.assertRaises(JobError):
            job.validate()
Esempio n. 17
0
 def test_secondary_media(self):
     """
     Test UBootSecondaryMedia validation
     """
     job_parser = JobParser()
     cubie = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/cubie1.yaml'))
     sample_job_file = os.path.join(os.path.dirname(__file__), 'sample_jobs/cubietruck-removable.yaml')
     sample_job_data = open(sample_job_file)
     job = job_parser.parse(sample_job_data, cubie, 4212, None, "")
     job.logger = DummyLogger()
     job.validate()
     sample_job_data.close()
     uboot_action = [action for action in job.pipeline.actions if action.name == 'uboot-action' and action.parameters['namespace'] == 'boot2'][0]
     u_boot_media = [action for action in uboot_action.internal_pipeline.actions if action.name == 'uboot-from-media' and action.parameters['namespace'] == 'boot2'][0]
     self.assertIsInstance(u_boot_media, UBootSecondaryMedia)
     self.assertEqual([], u_boot_media.errors)
     self.assertEqual(u_boot_media.parameters['kernel'], '/boot/vmlinuz-3.16.0-4-armmp-lpae')
     self.assertEqual(u_boot_media.parameters['kernel'], u_boot_media.get_namespace_data(
         action='download-action', label='file', key='kernel'))
     self.assertEqual(u_boot_media.parameters['ramdisk'], u_boot_media.get_namespace_data(
         action='compress-ramdisk', label='file', key='ramdisk'))
     self.assertEqual(u_boot_media.parameters['dtb'], u_boot_media.get_namespace_data(
         action='download-action', label='file', key='dtb'))
     # use the base class name so that uboot-from-media can pick up the value reliably.
     self.assertEqual(u_boot_media.parameters['root_uuid'], u_boot_media.get_namespace_data(
         action='bootloader-from-media', label='uuid', key='root'))
     device = u_boot_media.get_namespace_data(action='storage-deploy', label='u-boot', key='device')
     self.assertIsNotNone(device)
     part_reference = '%s:%s' % (
         job.device['parameters']['media']['usb'][device]['device_id'],
         u_boot_media.parameters['boot_part']
     )
     self.assertEqual(part_reference, u_boot_media.get_namespace_data(
         action=u_boot_media.name, label='uuid', key='boot_part'))
     self.assertEqual(part_reference, "0:1")
Esempio n. 18
0
 def test_job_no_tags(self):
     with open(self.filename) as yaml_data:
         alpha_data = yaml.load(yaml_data)
     for vlan_key, _ in alpha_data['protocols'][VlandProtocol.name].items():
         alpha_data['protocols'][VlandProtocol.name][vlan_key] = {'tags': []}
     # removed tags from original job to simulate job where any interface tags will be acceptable
     self.assertEqual(
         alpha_data['protocols'][VlandProtocol.name],
         {'vlan_one': {'tags': []}}
     )
     parser = JobParser()
     job = parser.parse(yaml.dump(alpha_data), self.device, 4212, None, "")
     job.logger = DummyLogger()
     job.validate()
     vprotocol = [vprotocol for vprotocol in job.protocols if vprotocol.name == VlandProtocol.name][0]
     self.assertTrue(vprotocol.valid)
     self.assertEqual(vprotocol.names, {'vlan_one': '4212vlanone'})
     self.assertFalse(vprotocol.check_timeout(120, {'request': 'no call'}))
     self.assertRaises(JobError, vprotocol.check_timeout, 60, 'deploy_vlans')
     self.assertRaises(JobError, vprotocol.check_timeout, 60, {'request': 'deploy_vlans'})
     self.assertTrue(vprotocol.check_timeout(120, {'request': 'deploy_vlans'}))
     for vlan_name in job.parameters['protocols'][VlandProtocol.name]:
         if vlan_name == 'yaml_line':
             continue
         self.assertIn(vlan_name, vprotocol.params)
         self.assertIn('switch', vprotocol.params[vlan_name])
         self.assertIn('port', vprotocol.params[vlan_name])
Esempio n. 19
0
 def create_custom_job(self,
                       template,
                       job_data,
                       job_ctx=None,
                       validate=True):
     if validate:
         validate_job(job_data, strict=False)
     if job_ctx:
         job_data["context"] = job_ctx
     else:
         job_ctx = job_data.get("context")
     (data, device_dict) = self.create_device(template, job_ctx)
     device = NewDevice(yaml_safe_load(data))
     print("####### Device configuration #######")
     print(data)
     print("#######")
     try:
         parser = JobParser()
         job = parser.parse(yaml.dump(job_data), device, 4999, None, "")
     except (ConfigurationError, TypeError) as exc:
         print("####### Parser exception ########")
         print(device)
         print("#######")
         raise ConfigurationError("Invalid device: %s" % exc)
     job.logger = DummyLogger()
     return job
Esempio n. 20
0
 def test_lxc_without_lxctest(self):
     lxc_yaml = os.path.join(os.path.dirname(__file__),
                             "sample_jobs/bbb-lxc-notest.yaml")
     with open(lxc_yaml) as sample_job_data:
         data = yaml_safe_load(sample_job_data)
     parser = JobParser()
     (rendered, _) = self.factory.create_device("bbb-01.jinja2")
     device = NewDevice(yaml_safe_load(rendered))
     job = parser.parse(yaml_safe_dump(data), device, 4577, None, "")
     job.logger = DummyLogger()
     job.validate()
     lxc_deploy = [
         action for action in job.pipeline.actions
         if action.name == "lxc-deploy"
     ][0]
     names = [action.name for action in lxc_deploy.pipeline.actions]
     self.assertNotIn("prepare-tftp-overlay", names)
     namespace1 = lxc_deploy.parameters.get("namespace")
     tftp_deploy = [
         action for action in job.pipeline.actions
         if action.name == "tftp-deploy"
     ][0]
     prepare = [
         action for action in tftp_deploy.pipeline.actions
         if action.name == "prepare-tftp-overlay"
     ][0]
     overlay = [
         action for action in prepare.pipeline.actions
         if action.name == "lava-overlay"
     ][0]
     test_def = [
         action for action in overlay.pipeline.actions
         if action.name == "test-definition"
     ][0]
     namespace = test_def.parameters.get("namespace")
     self.assertIsNotNone(namespace)
     self.assertIsNotNone(namespace1)
     self.assertNotEqual(namespace, namespace1)
     self.assertNotEqual(self.job.pipeline.describe(False),
                         job.pipeline.describe(False))
     test_actions = [
         action for action in job.parameters["actions"] if "test" in action
     ]
     for action in test_actions:
         if "namespace" in action["test"]:
             if action["test"]["namespace"] == namespace:
                 self.assertEqual(action["test"]["definitions"][0]["name"],
                                  "smoke-tests-bbb")
         else:
             self.fail("Found a test action not from the tftp boot")
     namespace_tests = [
         action["test"]["definitions"] for action in test_actions
         if "namespace" in action["test"]
         and action["test"]["namespace"] == namespace
     ]
     self.assertEqual(len(namespace_tests), 1)
     self.assertEqual(len(test_actions), 1)
     description_ref = self.pipeline_reference("bbb-lxc-notest.yaml",
                                               job=job)
     self.assertEqual(description_ref, job.pipeline.describe(False))
Esempio n. 21
0
 def test_uboot_checksum(self):
     (rendered, _) = self.factory.create_device("bbb-01.jinja2")
     device = NewDevice(yaml.safe_load(rendered))
     bbb_yaml = os.path.join(os.path.dirname(__file__),
                             "sample_jobs/bbb-ramdisk-nfs.yaml")
     with open(bbb_yaml) as sample_job_data:
         parser = JobParser()
         job = parser.parse(sample_job_data, device, 4212, None, "")
     deploy = [
         action for action in job.pipeline.actions
         if action.name == "tftp-deploy"
     ][0]
     download = [
         action for action in deploy.internal_pipeline.actions
         if action.name == "download-retry"
     ][0]
     helper = [
         action for action in download.internal_pipeline.actions
         if action.name == "file-download"
     ][0]
     remote = helper.parameters[helper.key]
     md5sum = remote.get("md5sum")
     self.assertIsNone(md5sum)
     sha256sum = remote.get("sha256sum")
     self.assertIsNotNone(sha256sum)
Esempio n. 22
0
    def test_panda_lxc_template(self):
        logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
        logger = logging.getLogger('unittests')
        logger.disabled = True
        logger.propagate = False
        logger = logging.getLogger('dispatcher')
        logging.disable(logging.DEBUG)
        logger.disabled = True
        logger.propagate = False
        data = """{% extends 'panda.jinja2' %}
{% set power_off_command = '/usr/local/lab-scripts/snmp_pdu_control --hostname pdu15 --command off --port 07' %}
{% set hard_reset_command = '/usr/local/lab-scripts/snmp_pdu_control --hostname pdu15 --command reboot --port 07' %}
{% set connection_command = 'telnet serial4 7010' %}
{% set power_on_command = '/usr/local/lab-scripts/snmp_pdu_control --hostname pdu15 --command on --port 07' %}"""
        self.assertTrue(self.validate_data('staging-panda-01', data))
        template_dict = prepare_jinja_template('staging-panda-01',
                                               data,
                                               raw=False)
        fdesc, device_yaml = tempfile.mkstemp()
        os.write(fdesc, yaml.dump(template_dict).encode())
        panda = NewDevice(device_yaml)
        lxc_yaml = os.path.join(os.path.dirname(__file__), 'devices',
                                'panda-lxc-aep.yaml')
        with open(lxc_yaml) as sample_job_data:
            parser = JobParser()
            job = parser.parse(sample_job_data, panda, 4577, None, "")
        os.close(fdesc)
        job.logger = DummyLogger()
        job.logger.disabled = True
        job.logger.propagate = False
        job.validate()
Esempio n. 23
0
    def test_configure(self):
        with open(self.filename) as yaml_data:
            alpha_data = yaml_safe_load(yaml_data)
        self.assertIn("protocols", alpha_data)
        self.assertTrue(VlandProtocol.accepts(alpha_data))
        vprotocol = VlandProtocol(alpha_data, self.job_id)
        vprotocol.set_up()
        with open(self.filename) as sample_job_data:
            parser = JobParser()
            job = parser.parse(sample_job_data, self.device, 4212, None, "")
        ret = vprotocol.configure(self.device, job)
        if not ret:
            print(vprotocol.errors)
        self.assertTrue(ret)
        nodes = {}
        for name in vprotocol.names:
            vlan = vprotocol.params[name]
            # self.assertNotIn('tags', vlan)
            uid = " ".join([vlan["switch"], str(vlan["port"])])
            nodes[uid] = name
        self.assertEqual(len(nodes.keys()), len(vprotocol.names))
        self.assertIn("vlan_one", vprotocol.names)
        self.assertNotIn("vlan_two", vprotocol.names)
        self.assertIn("switch", vprotocol.params["vlan_one"])
        self.assertIn("port", vprotocol.params["vlan_one"])
        self.assertIsNotNone(vprotocol.multinode_protocol)

        (rendered, _) = self.factory.create_device("bbb-01.jinja2")
        bbb2 = NewDevice(yaml_safe_load(rendered))
        bbb2["parameters"]["interfaces"]["eth0"]["switch"] = "192.168.0.2"
        bbb2["parameters"]["interfaces"]["eth0"]["port"] = "6"
        bbb2["parameters"]["interfaces"]["eth1"]["switch"] = "192.168.0.2"
        bbb2["parameters"]["interfaces"]["eth1"]["port"] = "4"
        self.assertEqual(
            vprotocol.params,
            {
                "vlan_one": {
                    "switch": "192.168.0.2",
                    "iface": "eth1",
                    "port": 7,
                    "tags": ["100M", "RJ45", "10M"],
                }
            },
        )
        # already configured the vland protocol in the same job
        self.assertTrue(vprotocol.configure(bbb2, job))
        self.assertEqual(
            vprotocol.params,
            {
                "vlan_one": {
                    "switch": "192.168.0.2",
                    "iface": "eth1",
                    "port": 7,
                    "tags": ["100M", "RJ45", "10M"],
                }
            },
        )
        self.assertTrue(vprotocol.valid)
        self.assertEqual(vprotocol.names, {"vlan_one": "4212vlanone"})
Esempio n. 24
0
 def create_job(self, sample_job, device_file):  # pylint: disable=no-self-use
     device = NewDevice(os.path.join(os.path.dirname(__file__), device_file))
     j_yaml = os.path.join(os.path.dirname(__file__), sample_job)
     with open(j_yaml) as sample_job_data:
         parser = JobParser()
         job = parser.parse(sample_job_data, device, 4212, None, "")
     job.logger = DummyLogger()
     return job
Esempio n. 25
0
 def create_k64f_job_with_power(self, filename):  # pylint: disable=no-self-use
     device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/frdm-k64f-01-with-power.yaml'))
     y_file = os.path.join(os.path.dirname(__file__), filename)
     with open(y_file) as sample_job_data:
         parser = JobParser()
         job = parser.parse(sample_job_data, device, 5999, None, "")
     job.logger = DummyLogger()
     return job
Esempio n. 26
0
 def create_zcu102_job(self, filename):  # pylint: disable=no-self-use
     device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/xilinx-zcu102.yaml'))
     zcu_yaml = os.path.join(os.path.dirname(__file__), filename)
     with open(zcu_yaml) as sample_job_data:
         parser = JobParser()
         job = parser.parse(sample_job_data, device, 4212, None, "")
         job.logger = DummyLogger()
     return job
Esempio n. 27
0
 def create_ssh_job(self, filename):  # pylint: disable=no-self-use
     device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/ssh-host-01.yaml'))
     kvm_yaml = os.path.join(os.path.dirname(__file__), filename)
     with open(kvm_yaml) as sample_job_data:
         parser = JobParser()
         job = parser.parse(sample_job_data, device, 0, None, dispatcher_config="")
         job.logger = DummyLogger()
     return job
Esempio n. 28
0
 def create_job(self, sample_job, device_file):  # pylint: disable=no-self-use
     device = NewDevice(os.path.join(os.path.dirname(__file__), device_file))
     yaml = os.path.join(os.path.dirname(__file__), sample_job)
     with open(yaml) as sample_job_data:
         parser = JobParser()
         job = parser.parse(sample_job_data, device, 4212, None, "")
     job.logger = DummyLogger()
     return job
Esempio n. 29
0
 def create_job(self, filename):  # pylint: disable=no-self-use
     device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/x86-01.yaml'))
     y_file = os.path.join(os.path.dirname(__file__), filename)
     with open(y_file) as sample_job_data:
         parser = JobParser()
         job = parser.parse(sample_job_data, device, 4212, None, "")
     job.logger = DummyLogger()
     return job
Esempio n. 30
0
 def create_mustang_job(self, filename):  # pylint: disable=no-self-use
     device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/mustang-grub-efi.yaml'))
     y_file = os.path.join(os.path.dirname(__file__), filename)
     with open(y_file) as sample_job_data:
         parser = JobParser()
         job = parser.parse(sample_job_data, device, 4212, None, "")
     job.logger = DummyLogger()
     return job
Esempio n. 31
0
 def create_job(self, filename, output_dir='/tmp'):  # pylint: disable=no-self-use
     device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/mps2plus_01.yaml'))
     y_file = os.path.join(os.path.dirname(__file__), filename)
     with open(y_file) as sample_job_data:
         parser = JobParser()
         job = parser.parse(sample_job_data, device, 4212, None, "")
     job.logger = DummyLogger()
     return job
Esempio n. 32
0
 def create_nexus5x_job(self, filename):  # pylint: disable=no-self-use
     device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/nexus5x-01.yaml'))
     fastboot_yaml = os.path.join(os.path.dirname(__file__), filename)
     with open(fastboot_yaml) as sample_job_data:
         parser = JobParser()
         job = parser.parse(sample_job_data, device, 4212, None, "")
         job.logger = DummyLogger()
     return job
 def create_b2260_job(self, filename):
     device = NewDevice(
         os.path.join(os.path.dirname(__file__),
                      "../devices/b2260-01.yaml"))
     with open(os.path.join(os.path.dirname(__file__), filename)) as f_in:
         parser = JobParser()
         job = parser.parse(f_in, device, 456, None, "")
     job.logger = DummyLogger()
     return job
Esempio n. 34
0
 def create_hikey_aep_job(self, filename):  # pylint: disable=no-self-use
     device = NewDevice(os.path.join(os.path.dirname(__file__),
                                     '../devices/hi6220-hikey-01.yaml'))
     job_yaml = os.path.join(os.path.dirname(__file__), filename)
     with open(job_yaml) as sample_job_data:
         parser = JobParser()
         job = parser.parse(sample_job_data, device, 4577, None, "")
     job.logger = DummyLogger()
     return job
Esempio n. 35
0
 def create_b2260_job(self, filename):
     # FIXME: b2260 Jinja2 template does not have flasher support.
     device = NewDevice(
         os.path.join(os.path.dirname(__file__), "devices/b2260-01.yaml"))
     with open(os.path.join(os.path.dirname(__file__), filename)) as f_in:
         parser = JobParser()
         job = parser.parse(f_in, device, 456, None, "")
     job.logger = DummyLogger()
     return job
Esempio n. 36
0
 def create_jaq_job(self, filename):
     device = NewDevice(
         os.path.join(os.path.dirname(__file__), "devices/jaq-01.yaml"))
     yaml = os.path.join(os.path.dirname(__file__), filename)
     with open(yaml) as sample_job_data:
         parser = JobParser()
         job = parser.parse(sample_job_data, device, 4212, None, "")
         job.logger = DummyLogger()
     return job
Esempio n. 37
0
 def create_adb_nuc_job(self, filename):  # pylint: disable=no-self-use
     device = NewDevice(
         os.path.join(os.path.dirname(__file__), "devices/adb-nuc-01.yaml"))
     job_yaml = os.path.join(os.path.dirname(__file__), filename)
     with open(job_yaml) as sample_job_data:
         parser = JobParser()
         job = parser.parse(sample_job_data, device, 4577, None, "")
     job.logger = DummyLogger()
     return job
Esempio n. 38
0
 def create_jaq_job(self, filename):
     device = NewDevice(os.path.join(
         os.path.dirname(__file__), '../devices/jaq-01.yaml'))
     yaml = os.path.join(os.path.dirname(__file__), filename)
     with open(yaml) as sample_job_data:
         parser = JobParser()
         job = parser.parse(sample_job_data, device, 4212, None, "")
         job.logger = DummyLogger()
     return job
Esempio n. 39
0
 def test_job(self):
     MetaType.objects.all().delete()
     TestJob.objects.all().delete()
     job = TestJob.from_yaml_and_user(self.factory.make_job_yaml(), self.user)
     job_def = yaml_safe_load(job.definition)
     job_ctx = job_def.get("context", {})
     job_ctx.update(
         {"no_kvm": True}
     )  # override to allow unit tests on all types of systems
     device = Device.objects.get(hostname="fakeqemu1")
     device_config = device.load_configuration(job_ctx)  # raw dict
     parser = JobParser()
     obj = PipelineDevice(device_config)
     pipeline_job = parser.parse(job.definition, obj, job.id, None, "")
     allow_missing_path(
         pipeline_job.pipeline.validate_actions, self, "qemu-system-x86_64"
     )
     pipeline = pipeline_job.describe()
     map_metadata(yaml_dump(pipeline), job)
     self.assertEqual(
         MetaType.objects.filter(metatype=MetaType.DEPLOY_TYPE).count(), 1
     )
     self.assertEqual(
         MetaType.objects.filter(metatype=MetaType.BOOT_TYPE).count(), 1
     )
     count = ActionData.objects.all().count()
     self.assertEqual(TestData.objects.all().count(), 1)
     testdata = TestData.objects.all()[0]
     self.assertEqual(testdata.testjob, job)
     for actionlevel in ActionData.objects.all():
         self.assertEqual(actionlevel.testdata, testdata)
     action_levels = []
     action_levels.extend(job.testdata.actionlevels.all())
     self.assertEqual(count, len(action_levels))
     count = ActionData.objects.filter(
         meta_type__metatype=MetaType.DEPLOY_TYPE
     ).count()
     self.assertNotEqual(
         ActionData.objects.filter(meta_type__metatype=MetaType.BOOT_TYPE).count(), 0
     )
     self.assertEqual(
         ActionData.objects.filter(
             meta_type__metatype=MetaType.UNKNOWN_TYPE
         ).count(),
         0,
     )
     for actionlevel in ActionData.objects.filter(
         meta_type__metatype=MetaType.BOOT_TYPE
     ):
         self.assertEqual(actionlevel.testdata.testjob.id, job.id)
     self.assertEqual(
         ActionData.objects.filter(
             meta_type__metatype=MetaType.DEPLOY_TYPE, testdata__testjob=job
         ).count(),
         count,
     )
Esempio n. 40
0
 def create_hikey_aep_job(self, filename):  # pylint: disable=no-self-use
     device = NewDevice(
         os.path.join(os.path.dirname(__file__),
                      '../devices/hi6220-hikey-01.yaml'))
     job_yaml = os.path.join(os.path.dirname(__file__), filename)
     with open(job_yaml) as sample_job_data:
         parser = JobParser()
         job = parser.parse(sample_job_data, device, 4577, None, "")
     job.logger = DummyLogger()
     return job
Esempio n. 41
0
 def create_x15_bl_job(self, filename):
     (data, device_dict) = self.create_x15_bl_device("x15-bl-01")
     device = NewDevice(yaml.safe_load(data))
     self.validate_data("x15-bl-01", device_dict)
     uboot_yaml = os.path.join(os.path.dirname(__file__), filename)
     with open(uboot_yaml) as sample_job_data:
         parser = JobParser()
         job = parser.parse(sample_job_data, device, 4213, None, "")
         job.logger = DummyLogger()
     return job
Esempio n. 42
0
 def create_hikey_bl_job(self, filename):
     (data, device_dict) = self.create_hikey_bl_device('hi6220-hikey-01')
     device = NewDevice(yaml.load(data))
     self.validate_data('hi6220-hikey-01', device_dict)
     fastboot_yaml = os.path.join(os.path.dirname(__file__), filename)
     with open(fastboot_yaml) as sample_job_data:
         parser = JobParser()
         job = parser.parse(sample_job_data, device, 4212, None, "")
         job.logger = DummyLogger()
     return job
Esempio n. 43
0
 def test_job(self, which_mock):
     with open(self.filename) as yaml_data:
         alpha_data = yaml_safe_load(yaml_data)
     self.assertIn("protocols", alpha_data)
     self.assertIn(VlandProtocol.name, alpha_data["protocols"])
     with open(self.filename) as sample_job_data:
         parser = JobParser()
         job = parser.parse(sample_job_data, self.device, 4212, None, "")
     job.logger = DummyLogger()
     description_ref = self.pipeline_reference("bbb-group-vland-alpha.yaml", job=job)
     self.assertEqual(description_ref, job.pipeline.describe(False))
     job.validate()
     self.assertNotEqual(
         [],
         [
             protocol.name
             for protocol in job.protocols
             if protocol.name == MultinodeProtocol.name
         ],
     )
     ret = {
         "message": {"kvm01": {"vlan_name": "name", "vlan_tag": 6}},
         "response": "ack",
     }
     self.assertEqual(
         ("name", 6),
         (ret["message"]["kvm01"]["vlan_name"], ret["message"]["kvm01"]["vlan_tag"]),
     )
     self.assertIn("protocols", job.parameters)
     self.assertIn(VlandProtocol.name, job.parameters["protocols"])
     self.assertIn(MultinodeProtocol.name, job.parameters["protocols"])
     vprotocol = [
         vprotocol
         for vprotocol in job.protocols
         if vprotocol.name == VlandProtocol.name
     ][0]
     self.assertTrue(vprotocol.valid)
     self.assertEqual(vprotocol.names, {"vlan_one": "4212vlanone"})
     self.assertFalse(vprotocol.check_timeout(120, {"request": "no call"}))
     self.assertRaises(JobError, vprotocol.check_timeout, 60, "deploy_vlans")
     self.assertRaises(
         JobError, vprotocol.check_timeout, 60, {"request": "deploy_vlans"}
     )
     self.assertTrue(vprotocol.check_timeout(120, {"request": "deploy_vlans"}))
     for vlan_name in job.parameters["protocols"][VlandProtocol.name]:
         self.assertIn(vlan_name, vprotocol.params)
         self.assertIn("switch", vprotocol.params[vlan_name])
         self.assertIn("port", vprotocol.params[vlan_name])
         self.assertIn("iface", vprotocol.params[vlan_name])
     params = job.parameters["protocols"][vprotocol.name]
     names = []
     for key, _ in params.items():
         names.append(",".join([key, vprotocol.params[key]["iface"]]))
     # this device only has one interface with interface tags
     self.assertEqual(names, ["vlan_one,eth1"])
Esempio n. 44
0
    def test_device_parser(self):
        job_parser = JobParser()
        device = NewDevice(
            os.path.join(os.path.dirname(__file__), '../devices/bbb-01.yaml'))
        self.assertIn('power_state', device)
        self.assertFalse(hasattr(device, 'power_state'))
        sample_job_file = os.path.join(os.path.dirname(__file__),
                                       'sample_jobs/uboot-ramdisk.yaml')
        with open(sample_job_file) as sample_job_data:
            job = job_parser.parse(sample_job_data, device, 4212, None, "")
        uboot_action = None
        for action in job.pipeline.actions:
            if isinstance(action, DeployAction):
                self.assertIn('ramdisk', action.parameters)
            if isinstance(action, BootAction):
                self.assertIn('method', action.parameters)
                self.assertEqual('u-boot', action.parameters['method'])

                methods = device['actions']['boot']['methods']
                self.assertIn('ramdisk', methods['u-boot'])
                self.assertIn('bootloader_prompt',
                              methods['u-boot']['parameters'])
                self.assertIsNotNone(methods[action.parameters['method']][
                    action.parameters['commands']]['commands'])
                for line in methods[action.parameters['method']][
                        action.parameters['commands']]['commands']:
                    self.assertIsNotNone(line)
                self.assertIsInstance(action, UBootAction)
                uboot_action = action
        self.assertIsNotNone(uboot_action)
        uboot_action.validate()
        self.assertTrue(uboot_action.valid)
        for action in uboot_action.internal_pipeline.actions:
            if isinstance(action, BootloaderInterruptAction):
                self.assertIn('power-on', action.job.device['commands'])
                self.assertIn('hard_reset', action.job.device['commands'])
                self.assertIn('connect', action.job.device['commands'])
                self.assertEqual(
                    action.job.device['commands']['connect'].split(' ')[0],
                    'telnet')
            if isinstance(action, UBootAction):
                self.assertIn('method', action.parameters)
                self.assertIn('commands', action.parameters)
                self.assertIn('ramdisk', action.parameters['u-boot'])
                self.assertIn(action.parameters['commands'],
                              action.parameters[action.parameters['method']])
                self.assertIn(
                    'commands', action.parameters[action.parameters['method']][
                        action.parameters['commands']])
                self.assertIsNotNone(action.parameters['u-boot']['ramdisk'])
                self.assertIsInstance(
                    action.parameters['u-boot']['ramdisk']['commands'], list)
                self.assertTrue(
                    len(action.parameters['u-boot']['ramdisk']['commands']) > 2
                )
Esempio n. 45
0
 def create_x86_job(self, filename, device):  # pylint: disable=no-self-use
     kvm_yaml = os.path.join(os.path.dirname(__file__), filename)
     parser = JobParser()
     try:
         with open(kvm_yaml) as sample_job_data:
             job = parser.parse(sample_job_data, device, 4212, None, "")
         job.logger = DummyLogger()
     except LAVAError as exc:
         print(exc)
         # some deployments listed in basics.yaml are not implemented yet
         return None
     return job
Esempio n. 46
0
 def test_lxc_with_device(self):  # pylint: disable=too-many-locals
     self.assertIsNotNone(self.job)
     # validate with two test actions, lxc and device
     self.job.validate()
     lxc_yaml = os.path.join(os.path.dirname(__file__), 'sample_jobs/bbb-lxc.yaml')
     with open(lxc_yaml) as sample_job_data:
         data = yaml.load(sample_job_data)
     lxc_deploy = [action for action in self.job.pipeline.actions if action.name == 'lxc-deploy'][0]
     overlay = [action for action in lxc_deploy.internal_pipeline.actions if action.name == 'lava-overlay'][0]
     test_def = [action for action in overlay.internal_pipeline.actions if action.name == 'test-definition'][0]
     self.assertIsNotNone(test_def.level, test_def.test_list)
     runner = [action for action in test_def.internal_pipeline.actions if action.name == 'test-runscript-overlay'][0]
     self.assertIsNotNone(runner.testdef_levels)
     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]
     test_def = [action for action in overlay.internal_pipeline.actions if action.name == 'test-definition'][0]
     namespace = test_def.parameters.get('namespace', None)
     self.assertIsNotNone(namespace)
     test_actions = [action for action in self.job.parameters['actions'] if 'test' in action]
     for action in test_actions:
         if 'namespace' in action['test']:
             if action['test']['namespace'] == namespace:
                 self.assertEqual(action['test']['definitions'][0]['name'], 'smoke-tests-bbb')
     namespace_tests = [action['test']['definitions'] for action in test_actions
                        if 'namespace' in action['test'] and action['test']['namespace'] == namespace]
     self.assertEqual(len(namespace_tests), 1)
     self.assertEqual(len(test_actions), 2)
     self.assertEqual('smoke-tests-bbb', namespace_tests[0][0]['name'])
     self.assertEqual(
         'smoke-tests-bbb',
         test_def.test_list[0][0]['name'])
     self.assertIsNotNone(test_def.level, test_def.test_list)
     runner = [action for action in test_def.internal_pipeline.actions if action.name == 'test-runscript-overlay'][0]
     self.assertIsNotNone(runner.testdef_levels)
     # remove the second test action
     data['actions'].pop()
     test_actions = [action for action in data['actions'] if 'test' in action]
     self.assertEqual(len(test_actions), 1)
     self.assertEqual(test_actions[0]['test']['namespace'], 'probe')
     parser = JobParser()
     device = NewDevice(os.path.join(os.path.dirname(__file__),
                                     '../devices/bbb-01.yaml'))
     job = parser.parse(yaml.dump(data), device, 4577, None, "")
     job.logger = DummyLogger()
     job.validate()
     lxc_deploy = [action for action in self.job.pipeline.actions if action.name == 'lxc-deploy'][0]
     overlay = [action for action in lxc_deploy.internal_pipeline.actions if action.name == 'lava-overlay'][0]
     test_def = [action for action in overlay.internal_pipeline.actions if action.name == 'test-definition'][0]
     self.assertIsNotNone(test_def.level, test_def.test_list)
     runner = [action for action in test_def.internal_pipeline.actions if action.name == 'test-runscript-overlay'][0]
     self.assertIsNotNone(runner.testdef_levels)
Esempio n. 47
0
 def test_empty_device_environment(self):
     data = None
     job_parser = JobParser()
     device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/bbb-01.yaml'))
     sample_job_file = os.path.join(os.path.dirname(__file__), 'sample_jobs/uboot-ramdisk.yaml')
     with open(sample_job_file) as sample_job_data:
         job = job_parser.parse(
             sample_job_data, device, 4212, None, "",
             env_dut=data)
     self.assertEqual(
         job.parameters['env_dut'],
         None
     )
Esempio n. 48
0
 def test_primary_media(self):
     """
     Test that definitions of secondary media do not block submissions using primary media
     """
     job_parser = JobParser()
     bbb = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/bbb-01.yaml'))
     sample_job_file = os.path.join(os.path.dirname(__file__), 'sample_jobs/uboot-ramdisk.yaml')
     with open(sample_job_file) as sample_job_data:
         job = job_parser.parse(sample_job_data, bbb, 4212, None, "")
     job.logger = DummyLogger()
     job.validate()
     self.assertEqual(job.pipeline.errors, [])
     self.assertIn('usb', bbb['parameters']['media'].keys())
Esempio n. 49
0
 def setUp(self):
     super(TestQemuNFS, self).setUp()
     device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/kvm03.yaml'))
     kvm_yaml = os.path.join(os.path.dirname(__file__), 'sample_jobs/qemu-nfs.yaml')
     parser = JobParser()
     try:
         with open(kvm_yaml) as sample_job_data:
             job = parser.parse(sample_job_data, device, 4212, None, "")
     except NotImplementedError as exc:
         print(exc)
         # some deployments listed in basics.yaml are not implemented yet
         return None
     self.job = job
     self.job.logger = DummyLogger()
Esempio n. 50
0
 def test_uboot_checksum(self):
     device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/bbb-01.yaml'))
     bbb_yaml = os.path.join(os.path.dirname(__file__), 'sample_jobs/bbb-ramdisk-nfs.yaml')
     with open(bbb_yaml) as sample_job_data:
         parser = JobParser()
         job = parser.parse(sample_job_data, device, 4212, None, "")
     deploy = [action for action in job.pipeline.actions if action.name == 'tftp-deploy'][0]
     download = [action for action in deploy.internal_pipeline.actions if action.name == 'download-retry'][0]
     helper = [action for action in download.internal_pipeline.actions if action.name == 'file-download'][0]
     remote = helper.parameters[helper.key]
     md5sum = remote.get('md5sum', None)
     self.assertIsNone(md5sum)
     sha256sum = remote.get('sha256sum', None)
     self.assertIsNotNone(sha256sum)
Esempio n. 51
0
 def test_job_bad_tags(self):
     with open(self.filename) as yaml_data:
         alpha_data = yaml.load(yaml_data)
     for vlan_key, _ in alpha_data['protocols'][VlandProtocol.name].items():
         alpha_data['protocols'][VlandProtocol.name][vlan_key] = {'tags': ['spurious']}
     # replaced tags from original job to simulate job where an unsupported tag is specified
     self.assertEqual(
         alpha_data['protocols'][VlandProtocol.name],
         {'vlan_one': {'tags': ['spurious']}}
     )
     parser = JobParser()
     job = parser.parse(yaml.dump(alpha_data), self.device, 4212, None, "")
     job.logger = DummyLogger()
     self.assertRaises(JobError, job.validate)
Esempio n. 52
0
 def _check_valid_job(self, device, test_file):
     self.maxDiff = None  # pylint: disable=invalid-name
     job_parser = JobParser()
     sample_job_file = os.path.join(os.path.dirname(__file__), 'sample_jobs/{}'.format(test_file))
     with open(sample_job_file) as sample_job_data:
         job = job_parser.parse(sample_job_data, device, 4212, None, "")
     job.logger = DummyLogger()
     try:
         job.validate()
     except JobError:
         self.fail(job.pipeline.errors)
     description_ref = self.pipeline_reference(test_file, job=job)
     self.assertEqual(description_ref, job.pipeline.describe(False))
     return job
Esempio n. 53
0
 def test_primary_interface(self):
     with open(self.filename) as yaml_data:
         alpha_data = yaml.load(yaml_data)
     for interface in self.device['parameters']['interfaces']:
         # jinja2 processing of tags: [] results in tags:
         if self.device['parameters']['interfaces'][interface]['tags'] == []:
             self.device['parameters']['interfaces'][interface]['tags'] = None
     parser = JobParser()
     job = parser.parse(yaml.dump(alpha_data), self.device, 4212, None, "")
     deploy = [action for action in job.pipeline.actions if action.name == 'tftp-deploy'][0]
     prepare = [action for action in 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]
     vland_overlay = [action for action in overlay.internal_pipeline.actions if action.name == 'lava-vland-overlay'][0]
     vland_overlay.validate()
     job.logger = DummyLogger()
     job.validate()
Esempio n. 54
0
 def test_missing_handler(self):
     device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/kvm01.yaml'))
     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.load(sample_job_data)
     data['actions'][2]['test']['definitions'][0]['from'] = 'unusable-handler'
     try:
         job = parser.parse(yaml.dump(data), device, 4212, None, "")
         job.logger = DummyLogger()
     except JobError:
         pass
     except Exception as exc:  # pylint: disable=broad-except
         self.fail(exc)
     else:
         self.fail('JobError not raised')
Esempio n. 55
0
    def test_configure(self):
        with open(self.filename) as yaml_data:
            alpha_data = yaml.load(yaml_data)
        self.assertIn('protocols', alpha_data)
        self.assertTrue(VlandProtocol.accepts(alpha_data))
        vprotocol = VlandProtocol(alpha_data, self.job_id)
        vprotocol.set_up()
        with open(self.filename) as sample_job_data:
            parser = JobParser()
            job = parser.parse(sample_job_data, self.device, 4212, None, "")
        ret = vprotocol.configure(self.device, job)
        if not ret:
            print(vprotocol.errors)
        self.assertTrue(ret)
        nodes = {}
        for name in vprotocol.names:
            vlan = vprotocol.params[name]
            # self.assertNotIn('tags', vlan)
            uid = ' '.join([vlan['switch'], str(vlan['port'])])
            nodes[uid] = name
        self.assertEqual(len(nodes.keys()), len(vprotocol.names))
        self.assertIn('vlan_one', vprotocol.names)
        self.assertNotIn('vlan_two', vprotocol.names)
        self.assertIn('switch', vprotocol.params['vlan_one'])
        self.assertIn('port', vprotocol.params['vlan_one'])
        self.assertIsNotNone(vprotocol.multinode_protocol)

        bbb2 = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/bbb-01.yaml'))
        bbb2['parameters']['interfaces']['eth0']['switch'] = '192.168.0.2'
        bbb2['parameters']['interfaces']['eth0']['port'] = '6'
        bbb2['parameters']['interfaces']['eth1']['switch'] = '192.168.0.2'
        bbb2['parameters']['interfaces']['eth1']['port'] = '4'
        self.assertEqual(
            vprotocol.params, {
                'vlan_one': {'switch': '192.168.0.1', 'iface': 'eth1', 'port': 7, 'tags': ['100M', 'RJ45', '10M']}
            }
        )
        # already configured the vland protocol in the same job
        self.assertTrue(vprotocol.configure(bbb2, job))
        self.assertEqual(
            vprotocol.params, {
                'vlan_one': {
                    'switch': '192.168.0.1', 'iface': 'eth1', 'port': 7, 'tags': ['100M', 'RJ45', '10M']}
            }
        )
        self.assertTrue(vprotocol.valid)
        self.assertEqual(vprotocol.names, {'vlan_one': '4212vlanone'})
Esempio n. 56
0
 def test_repositories(self):  # pylint: disable=too-many-locals
     job = TestJob.from_yaml_and_user(
         self.factory.make_job_yaml(), self.user)
     job_def = yaml.load(job.definition)
     job_ctx = job_def.get('context', {})
     job_ctx.update({'no_kvm': True})  # override to allow unit tests on all types of systems
     device = Device.objects.get(hostname='fakeqemu1')
     device_config = device.load_configuration(job_ctx)  # raw dict
     parser = JobParser()
     obj = PipelineDevice(device_config)
     pipeline_job = parser.parse(job.definition, obj, job.id, None, "")
     allow_missing_path(pipeline_job.pipeline.validate_actions, self,
                        'qemu-system-x86_64')
     pipeline = pipeline_job.describe()
     device_values = _get_device_metadata(pipeline['device'])
     self.assertEqual(
         device_values,
         {'target.device_type': 'qemu'}
     )
     del pipeline['device']['device_type']
     self.assertNotIn('device_type', pipeline['device'])
     device_values = _get_device_metadata(pipeline['device'])
     try:
         testdata, _ = TestData.objects.get_or_create(testjob=job)
     except (MultipleObjectsReturned):
         self.fail('multiple objects')
     for key, value in device_values.items():
         if not key or not value:
             continue
         testdata.attributes.create(name=key, value=value)
     retval = _get_action_metadata(pipeline['job']['actions'])
     self.assertEqual(
         retval,
         {
             'test.1.common.definition.from': 'git',
             'test.0.common.definition.repository': 'git://git.linaro.org/lava-team/lava-functional-tests.git',
             'test.0.common.definition.name': 'smoke-tests',
             'test.1.common.definition.repository': 'http://git.linaro.org/lava-team/lava-functional-tests.git',
             'boot.0.common.method': 'qemu',
             'test.1.common.definition.name': 'singlenode-advanced',
             'test.0.common.definition.from': 'git',
             'test.0.common.definition.path': 'lava-test-shell/smoke-tests-basic.yaml',
             'test.1.common.definition.path': 'lava-test-shell/single-node/singlenode03.yaml'}
     )
Esempio n. 57
0
    def test_device_parser(self):
        job_parser = JobParser()
        device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/bbb-01.yaml'))
        self.assertIn('power_state', device)
        self.assertFalse(hasattr(device, 'power_state'))
        sample_job_file = os.path.join(os.path.dirname(__file__), 'sample_jobs/uboot-ramdisk.yaml')
        with open(sample_job_file) as sample_job_data:
            job = job_parser.parse(sample_job_data, device, 4212, None, "")
        uboot_action = None
        for action in job.pipeline.actions:
            if isinstance(action, DeployAction):
                self.assertIn('ramdisk', action.parameters)
            if isinstance(action, BootAction):
                self.assertIn('method', action.parameters)
                self.assertEqual('u-boot', action.parameters['method'])

                methods = device['actions']['boot']['methods']
                self.assertIn('ramdisk', methods['u-boot'])
                self.assertIn('bootloader_prompt', methods['u-boot']['parameters'])
                self.assertIsNotNone(
                    methods[action.parameters['method']][action.parameters['commands']]['commands'])
                for line in methods[action.parameters['method']][action.parameters['commands']]['commands']:
                    self.assertIsNotNone(line)
                self.assertIsInstance(action, UBootAction)
                uboot_action = action
        self.assertIsNotNone(uboot_action)
        uboot_action.validate()
        self.assertTrue(uboot_action.valid)
        for action in uboot_action.internal_pipeline.actions:
            if isinstance(action, BootloaderInterruptAction):
                self.assertIn('power-on', action.job.device['commands'])
                self.assertIn('hard_reset', action.job.device['commands'])
                self.assertIn('connect', action.job.device['commands'])
                self.assertEqual(action.job.device['commands']['connect'].split(' ')[0], 'telnet')
            if isinstance(action, UBootAction):
                self.assertIn('method', action.parameters)
                self.assertIn('commands', action.parameters)
                self.assertIn('ramdisk', action.parameters['u-boot'])
                self.assertIn(action.parameters['commands'], action.parameters[action.parameters['method']])
                self.assertIn('commands', action.parameters[action.parameters['method']][action.parameters['commands']])
                self.assertIsNotNone(action.parameters['u-boot']['ramdisk'])
                self.assertIsInstance(action.parameters['u-boot']['ramdisk']['commands'], list)
                self.assertTrue(len(action.parameters['u-boot']['ramdisk']['commands']) > 2)