Beispiel #1
0
 def test_device_power(self):
     device = NewDevice(
         os.path.join(os.path.dirname(__file__), '../devices/bbb-01.yaml'))
     self.assertNotEqual(device.hard_reset_command, '')
     device = NewDevice(
         os.path.join(os.path.dirname(__file__), '../devices/kvm01.yaml'))
     self.assertEqual(device.hard_reset_command, '')
Beispiel #2
0
 def test_device_constants(self):
     device = NewDevice(
         os.path.join(os.path.dirname(__file__), '../devices/bbb-01.yaml'))
     self.assertIn('constants', device)
     self.assertEqual(device.get_constant('kernel-start-message'),
                      "Linux version [0-9]")
     self.assertRaises(ConfigurationError, device.get_constant,
                       ('non-existing-const'))
Beispiel #3
0
 def test_device_constants(self):
     factory = Factory()
     (rendered, _) = factory.create_device('bbb-01.jinja2')
     device = NewDevice(yaml.safe_load(rendered))
     self.assertIn('constants', device)
     self.assertEqual(device.get_constant('kernel-start-message'), "Linux version [0-9]")
     self.assertRaises(ConfigurationError,
                       device.get_constant, ('non-existing-const'))
Beispiel #4
0
 def test_device_constants(self):
     factory = Factory()
     (rendered, _) = factory.create_device("bbb-01.jinja2")
     device = NewDevice(yaml_safe_load(rendered))
     self.assertIn("constants", device)
     self.assertEqual(device.get_constant("kernel-start-message"),
                      "Linux version [0-9]")
     self.assertRaises(ConfigurationError, device.get_constant,
                       ("non-existing-const"))
Beispiel #5
0
 def setUp(self):
     super(TestMultiNodeOverlay, self).setUp()
     factory = X86Factory()
     lng1 = NewDevice(
         os.path.join(os.path.dirname(__file__),
                      '../devices/lng-generator-01.yaml'))
     lng2 = NewDevice(
         os.path.join(os.path.dirname(__file__),
                      '../devices/lng-generator-02.yaml'))
     self.server_job = factory.create_x86_job(
         'sample_jobs/test_action-1.yaml', lng1)
     self.client_job = factory.create_x86_job(
         'sample_jobs/test_action-2.yaml', lng2)
Beispiel #6
0
    def test_overlay_noramdisk(self, which_mock):
        parameters = {
            "dispatcher": {},  # fake dispatcher parameter. Normally added by parser
            "device_type": "beaglebone-black",
            "job_name": "uboot-pipeline",
            "job_timeout": "15m",
            "action_timeout": "5m",
            "priority": "medium",
            "actions": {
                "boot": {
                    "namespace": "common",
                    "method": "u-boot",
                    "commands": "ramdisk",
                    "prompts": ["linaro-test", "root@debian:~#"],
                },
                "deploy": {
                    "namespace": "common",
                    "ramdisk": {"url": ""},
                    "kernel": {"url": "zImage", "type": "zimage"},
                    "dtb": {"url": "broken.dtb"},
                },
            },
        }
        data = yaml_safe_load(Factory().create_device("bbb-01.jinja2")[0])
        device = NewDevice(data)
        ip_addr = dispatcher_ip(None)
        parsed = []
        kernel_addr = "0x83000000"
        ramdisk_addr = "0x83000000"
        dtb_addr = "0x88000000"
        kernel = parameters["actions"]["deploy"]["kernel"]["url"]
        ramdisk = parameters["actions"]["deploy"]["ramdisk"]["url"]
        dtb = parameters["actions"]["deploy"]["dtb"]["url"]

        substitution_dictionary = {
            "{SERVER_IP}": ip_addr,
            # the addresses need to be hexadecimal
            "{KERNEL_ADDR}": kernel_addr,
            "{DTB_ADDR}": dtb_addr,
            "{RAMDISK_ADDR}": ramdisk_addr,
            "{BOOTX}": "%s %s %s %s" % ("bootz", kernel_addr, ramdisk_addr, dtb_addr),
            "{RAMDISK}": ramdisk,
            "{KERNEL}": kernel,
            "{DTB}": dtb,
        }
        params = device["actions"]["boot"]["methods"]
        params["u-boot"]["ramdisk"]["commands"] = substitute(
            params["u-boot"]["ramdisk"]["commands"], substitution_dictionary, drop=True
        )

        commands = params["u-boot"]["ramdisk"]["commands"]
        self.assertIs(type(commands), list)
        self.assertIn("tftp 0x83000000 zImage", commands)
        self.assertNotIn("tftp 0x83000000 {RAMDISK}", commands)
        self.assertNotIn("tftp 0x83000000 ", commands)
        self.assertIn("setenv initrd_size ${filesize}", commands)
        self.assertIn("tftp 0x88000000 broken.dtb", commands)
        self.assertNotIn("setenv kernel_addr_r '{KERNEL_ADDR}'", commands)
        self.assertNotIn("setenv initrd_addr_r '{RAMDISK_ADDR}'", commands)
        self.assertNotIn("setenv fdt_addr_r '{DTB_ADDR}'", commands)
    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]
Beispiel #8
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)
Beispiel #9
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)
Beispiel #10
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'])
Beispiel #11
0
    def test_compatibility(self):
        """
        Test compatibility support.

        The class to use in the comparison will change according to which class
        is related to the change which caused the compatibility to be modified.
        """
        factory = Factory()
        job = factory.create_kvm_job('sample_jobs/kvm.yaml')
        pipe = job.describe()
        self.assertEqual(pipe['compatibility'], DeployImages.compatibility)
        self.assertEqual(job.compatibility, DeployImages.compatibility)
        kvm_yaml = os.path.join(os.path.dirname(__file__), 'sample_jobs/kvm.yaml')
        with open(kvm_yaml, 'r') as kvm_yaml:
            job_def = yaml.load(kvm_yaml)
        job_def['compatibility'] = job.compatibility
        parser = JobParser()
        device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/kvm01.yaml'))
        try:
            job = parser.parse(yaml.dump(job_def), device, 4212, None, "")
        except NotImplementedError:
            # some deployments listed in basics.yaml are not implemented yet
            pass
        self.assertIsNotNone(job)
        job_def['compatibility'] = job.compatibility + 1
        self.assertRaises(
            JobError, parser.parse, yaml.dump(job_def), device, 4212, None, ""
        )
        job_def['compatibility'] = 0
        try:
            job = parser.parse(yaml.dump(job_def), device, 4212, None, "")
        except NotImplementedError:
            # some deployments listed in basics.yaml are not implemented yet
            pass
        self.assertIsNotNone(job)
Beispiel #12
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)
Beispiel #13
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"
        """
        factory = Factory()
        job_parser = JobParser()
        (rendered, _) = factory.create_device('bbb-01.jinja2')
        device = NewDevice(yaml.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()
Beispiel #14
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__), "sample_jobs", "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()
Beispiel #15
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))
     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())
     print("########## Test Job Submission validation #######")
     if validate:
         validate_job(job_data, strict=False)
     try:
         job = parser.parse(yaml_safe_dump(job_data), device, 4212, None,
                            "")
         job.logger = DummyLogger()
     except LAVAError as exc:
         print(exc)
         return None
     return job
Beispiel #16
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))
Beispiel #17
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_safe_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
Beispiel #18
0
 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.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)
Beispiel #19
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
Beispiel #20
0
 def create_kvm_job(self, filename, check_job=False):  # pylint: disable=no-self-use
     """
     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 check_job:  # FIXME: all submissions should validate.
         validate_submission(job_data)
     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
Beispiel #21
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"})
Beispiel #22
0
 def test_job_parameters(self):
     """
     Test that the job parameters match expected structure
     """
     cubie = NewDevice(
         os.path.join(os.path.dirname(__file__), '../devices/cubie1.yaml'))
     job = self._check_valid_job(cubie, 'cubietruck-removable.yaml')
     self._check_job_parameters(cubie, job, 'download')
Beispiel #23
0
 def setUp(self):
     super().setUp()
     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/uboot-nfs.yaml')
     with open(bbb_yaml) as sample_job_data:
         self.job_data = yaml.load(sample_job_data)
Beispiel #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
Beispiel #25
0
 def test_writer_job_parameters(self):
     """
     Test that the job parameters with a writer tool match expected structure
     """
     (rendered, _) = self.factory.create_device('cubie1.jinja2')
     cubie = NewDevice(yaml.safe_load(rendered))
     job = self._check_valid_job(cubie, 'cubietruck-removable-with-writer.yaml')
     self._check_job_parameters(cubie, job, 'writer')
 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
 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
Beispiel #28
0
 def setUp(self):
     super().setUp()
     data = yaml_safe_load(Factory().create_device("bbb-01.jinja2")[0])
     self.device = NewDevice(data)
     bbb_yaml = os.path.join(os.path.dirname(__file__),
                             "sample_jobs/uboot-nfs.yaml")
     with open(bbb_yaml) as sample_job_data:
         self.job_data = yaml_safe_load(sample_job_data)
Beispiel #29
0
 def test_job_parameters(self):
     """
     Test that the job parameters match expected structure
     """
     (rendered, _) = self.factory.create_device("cubie1.jinja2")
     cubie = NewDevice(yaml_safe_load(rendered))
     job = self._check_valid_job(cubie, "cubietruck-removable.yaml")
     self._check_job_parameters(cubie, job, "download")
Beispiel #30
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
 def test_device_parameters(self):
     """
     Test that the correct parameters have been set for the device
     """
     cubie = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/cubie1.yaml'))
     self.assertIsNotNone(cubie['parameters']['media'].get('usb', None))
     self.assertIsNotNone(cubie.get('commands', None))
     self.assertIsNotNone(cubie.get('actions', None))
     self.assertIsNotNone(cubie['actions'].get('deploy', None))
     self.assertIsNotNone(cubie['actions']['deploy'].get('methods', None))
     self.assertIn('usb', cubie['actions']['deploy']['methods'])
     self.assertIsNotNone(cubie['actions'].get('boot', None))
     self.assertIsNotNone(cubie['actions']['boot'].get('methods', None))
     self.assertIn('u-boot', cubie['actions']['boot']['methods'])
     u_boot_params = cubie['actions']['boot']['methods']['u-boot']
     self.assertIn('usb', u_boot_params)
     self.assertIn('commands', u_boot_params['usb'])
     self.assertIn('parameters', u_boot_params)
     self.assertIn('boot_message', u_boot_params['parameters'])
     self.assertIn('bootloader_prompt', u_boot_params['parameters'])
Beispiel #32
0
 def test_device_constants(self):
     device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/bbb-01.yaml'))
     self.assertIn('constants', device)
     self.assertEqual(device.get_constant('kernel-start-message'), "Linux version [0-9]")
     self.assertRaises(ConfigurationError,
                       device.get_constant, ('non-existing-const'))
    def test_substitutions(self):
        """
        Test substitution of secondary media values into u-boot commands

        Unlike most u-boot calls, removable knows in advance all the values it needs to substitute
        into the boot commands for the secondary deployment as these are fixed by the device config
        and the image details from the job submission.
        """
        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')
        with open(sample_job_file) as sample_job_data:
            job = job_parser.parse(sample_job_data, cubie, 4212, None, "")
        job.logger = DummyLogger()
        job.validate()
        boot_params = [
            methods for methods in job.parameters['actions'] if 'boot' in methods.keys()][1]['boot']
        self.assertIn('ramdisk', boot_params)
        self.assertIn('kernel', boot_params)
        self.assertIn('dtb', boot_params)
        self.assertIn('root_uuid', boot_params)
        self.assertIn('boot_part', boot_params)
        self.assertNotIn('type', boot_params)
        self.assertGreater(len(job.pipeline.actions), 1)
        self.assertIsNotNone(job.pipeline.actions[1].internal_pipeline)
        u_boot_action = [action for action in job.pipeline.actions if action.name == 'uboot-action'][1]
        overlay = [action for action in u_boot_action.internal_pipeline.actions if action.name == 'bootloader-overlay'][0]
        self.assertIsNotNone(overlay.get_namespace_data(action='storage-deploy', label='u-boot', key='device'))

        methods = cubie['actions']['boot']['methods']
        self.assertIn('u-boot', methods)
        self.assertIn('usb', methods['u-boot'])
        self.assertIn('commands', methods['u-boot']['usb'])
        commands_list = methods['u-boot']['usb']['commands']
        device_id = u_boot_action.get_namespace_data(action='storage-deploy', label='u-boot', key='device')
        self.assertIsNotNone(device_id)
        kernel_type = u_boot_action.parameters['kernel_type']
        bootcommand = map_kernel_uboot(kernel_type, device_params=cubie.get('parameters', None))
        substitutions = {
            '{BOOTX}': "%s %s %s %s" % (
                bootcommand,
                cubie['parameters'][bootcommand]['kernel'],
                cubie['parameters'][bootcommand]['ramdisk'],
                cubie['parameters'][bootcommand]['dtb'],),
            '{RAMDISK}': boot_params['ramdisk'],
            '{KERNEL}': boot_params['kernel'],
            '{DTB}': boot_params['dtb'],
            '{ROOT}': boot_params['root_uuid'],
            '{ROOT_PART}': "%s:%s" % (
                cubie['parameters']['media']['usb'][device_id]['device_id'],
                u_boot_action.parameters['boot_part']
            )
        }
        self.assertEqual('bootz 0x42000000 0x43300000 0x43000000', substitutions['{BOOTX}'])
        self.assertEqual('/boot/initrd.img-3.16.0-4-armmp-lpae.u-boot', substitutions['{RAMDISK}'])
        commands = substitute(commands_list, substitutions)
        self.assertEqual(
            commands,
            [
                'usb start',
                'usb info',
                'setenv autoload no',
                "setenv initrd_high '0xffffffff'",
                "setenv fdt_high '0xffffffff'",
                'setenv initrd_addr_r ${ramdisk_addr_r}',
                "setenv loadkernel 'load usb 0:1 ${kernel_addr_r} /boot/vmlinuz-3.16.0-4-armmp-lpae'",
                "setenv loadinitrd 'load usb 0:1 ${initrd_addr_r} /boot/initrd.img-3.16.0-4-armmp-lpae.u-boot; setenv initrd_size ${filesize}'",
                "setenv loadfdt 'load usb 0:1 ${fdt_addr_r} /boot/dtb-3.16.0-4-armmp-lpae'",
                "setenv bootargs 'console=ttyS0,115200n8 root=UUID=159d17cc-697c-4125-95a0-a3775e1deabe ip=dhcp'",
                "setenv bootcmd 'run loadkernel; run loadinitrd; run loadfdt; bootz 0x42000000 0x43300000 0x43000000'", 'boot'
            ]
        )