Пример #1
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('boot-message'), "Booting Linux")
     self.assertRaises(ConfigurationError, device.get_constant,
                       ('non-existing-const'))
Пример #2
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, '')
     self.assertNotEqual(device.power_command, '')
     self.assertIn('on', device.power_command)
     device = NewDevice(
         os.path.join(os.path.dirname(__file__), '../devices/kvm01.yaml'))
     self.assertEqual(device.hard_reset_command, '')
     self.assertEqual(device.power_command, '')
 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)
 def test_device_power(self):
     device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/bbb-01.yaml'))
     self.assertEqual(device.power_state, 'off')
     self.assertNotEqual(device.hard_reset_command, '')
     self.assertNotEqual(device.power_command, '')
     self.assertIn('on', device.power_command)
     device.power_state = 'on'
     self.assertEqual(device.power_state, 'on')
     device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/kvm01.yaml'))
     self.assertEqual(device.power_state, '')
     self.assertEqual(device.hard_reset_command, '')
     self.assertEqual(device.power_command, '')
     with self.assertRaises(RuntimeError):
         device.power_state = ''
     self.assertEqual(device.power_command, '')
Пример #5
0
 def setUp(self):
     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)
Пример #6
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.assertEqual(device.power_state, 'off')
        self.assertTrue(hasattr(device, 'power_state'))
        self.assertFalse(hasattr(device, 'hostname'))
        self.assertIn('hostname', device)
        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, None,
                                   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, UBootInterrupt):
                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.assertTrue(
                    type(action.parameters['u-boot']['ramdisk']['commands']) ==
                    list)
                self.assertTrue(
                    len(action.parameters['u-boot']['ramdisk']['commands']) > 2
                )
Пример #7
0
    def test_job_parameters(self):
        """
        Test that the job parameters match expected structure
        """
        self.maxDiff = None  # pylint: disable=invalid-name
        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, "", output_dir='/tmp/')
        job.logger = DummyLogger()
        try:
            job.validate()
        except JobError:
            self.fail(job.pipeline.errors)
        sample_job_data.close()
        description_ref = pipeline_reference('cubietruck-removable.yaml')
        self.assertEqual(description_ref, job.pipeline.describe(False))

        mass_storage = None  # deploy
        for action in job.pipeline.actions:
            if isinstance(action, DeployAction):
                if isinstance(action, MassStorage):
                    self.assertTrue(action.valid)
                    agent = action.parameters['download']['tool']
                    self.assertTrue(agent.startswith('/'))  # needs to be a full path but on the device, so avoid os.path
                    self.assertIn(action.parameters['device'], job.device['parameters']['media']['usb'])
                    mass_storage = action
        self.assertIsNotNone(mass_storage)
        self.assertIn('device', mass_storage.parameters)
        self.assertIn(mass_storage.parameters['device'], cubie['parameters']['media']['usb'])
        self.assertIsNotNone(mass_storage.get_namespace_data(action='storage-deploy', label='u-boot', key='device'))
        u_boot_params = cubie['actions']['boot']['methods']['u-boot']
        self.assertEqual(mass_storage.get_namespace_data(action='uboot-retry', label='bootloader_prompt', key='prompt'), u_boot_params['parameters']['bootloader_prompt'])
Пример #8
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,
                            "",
                            output_dir='/tmp/')
     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)
Пример #9
0
 def test_deployment(self):
     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, "", output_dir='/tmp/')
     job.logger = DummyLogger()
     job.validate()
     self.assertIn('usb', cubie['parameters']['media'].keys())
     deploy_params = [methods for methods in job.parameters['actions'] if 'deploy' in methods.keys()][1]['deploy']
     self.assertIn('device', deploy_params)
     self.assertIn(deploy_params['device'], cubie['parameters']['media']['usb'])
     self.assertIn('uuid', cubie['parameters']['media']['usb'][deploy_params['device']])
     self.assertIn('device_id', cubie['parameters']['media']['usb'][deploy_params['device']])
     self.assertNotIn('boot_part', cubie['parameters']['media']['usb'][deploy_params['device']])
     deploy_action = [action for action in job.pipeline.actions if action.name == 'storage-deploy'][0]
     tftp_deploy_action = [action for action in job.pipeline.actions if action.name == 'tftp-deploy'][0]
     self.assertIsNotNone(deploy_action)
     test_dir = deploy_action.get_namespace_data(action='test', label='results', key='lava_test_results_dir', parameters=tftp_deploy_action.parameters)
     self.assertIsNotNone(test_dir)
     self.assertIn('/lava-', test_dir)
     self.assertIsInstance(deploy_action, MassStorage)
     self.assertIn('image', deploy_action.parameters.keys())
     dd_action = [action for action in deploy_action.internal_pipeline.actions if action.name == 'dd-image'][0]
     self.assertEqual(
         dd_action.boot_params[dd_action.parameters['device']]['uuid'],
         'usb-SanDisk_Ultra_20060775320F43006019-0:0')
     self.assertIsNotNone(dd_action.get_namespace_data(action=dd_action.name, label='u-boot', key='boot_part'))
     self.assertIsNotNone(dd_action.get_namespace_data(action='uboot-from-media', label='uuid', key='boot_part'))
     self.assertEqual('0', '%s' % dd_action.get_namespace_data(action=dd_action.name, label='u-boot', key='boot_part'))
     self.assertIsInstance(dd_action.get_namespace_data(action='uboot-from-media', label='uuid', key='boot_part'), str)
     self.assertEqual('0:1', dd_action.get_namespace_data(action='uboot-from-media', label='uuid', key='boot_part'))
Пример #10
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,
                                   "",
                                   output_dir='/tmp',
                                   env_dut=data)
        job.logger = DummyLogger()
        self.assertEqual(job.parameters['env_dut'], data)
        with self.assertRaises(JobError):
            job.validate()
Пример #11
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))
        test_template = prepare_jinja_template('staging-panda-01',
                                               data,
                                               system_path=self.system)
        rendered = test_template.render()
        template_dict = yaml.load(rendered)
        fdesc, device_yaml = tempfile.mkstemp()
        os.write(fdesc, yaml.dump(template_dict))
        panda = NewDevice(device_yaml)
        lxc_yaml = os.path.join(os.path.dirname(__file__),
                                'panda-lxc-aep.yaml')
        with open(lxc_yaml) as sample_job_data:
            parser = JobParser()
            job = parser.parse(sample_job_data,
                               panda,
                               4577,
                               None,
                               "",
                               output_dir='/tmp')
        os.close(fdesc)
        job.validate()
Пример #12
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,
                               "",
                               output_dir='/tmp/')
        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'})
Пример #13
0
    def test_prompt_from_job(self):
        """
        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.
        """
        factory = Factory()
        job = 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]
        sample_job_string = yaml.dump(sample_job_data)
        job = parser.parse(sample_job_string, device, 4212, None, None, None,
                           output_dir='/tmp')
        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]
        self.assertNotEqual(check, expect.parameters)
Пример #14
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,
                            "",
                            output_dir='/tmp/')
     job.logger = DummyLogger()
     job.validate()
     sample_job_data.close()
     u_boot_media = [
         action for action in job.pipeline.actions
         if action.name == 'uboot-action'
     ][1].internal_pipeline.actions[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=u_boot_media.name,
                                         label='file',
                                         key='kernel'))
     self.assertEqual(
         u_boot_media.parameters['ramdisk'],
         u_boot_media.get_namespace_data(action=u_boot_media.name,
                                         label='file',
                                         key='ramdisk'))
     self.assertEqual(
         u_boot_media.parameters['dtb'],
         u_boot_media.get_namespace_data(action=u_boot_media.name,
                                         label='file',
                                         key='dtb'))
     self.assertEqual(
         u_boot_media.parameters['root_uuid'],
         u_boot_media.get_namespace_data(action=u_boot_media.name,
                                         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")
Пример #15
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,
                            output_dir='/tmp/')
     job.validate()
     u_boot_media = job.pipeline.actions[1].internal_pipeline.actions[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_common_data('file', 'kernel'))
     self.assertEqual(u_boot_media.parameters['ramdisk'],
                      u_boot_media.get_common_data('file', 'ramdisk'))
     self.assertEqual(u_boot_media.parameters['dtb'],
                      u_boot_media.get_common_data('file', 'dtb'))
     self.assertEqual(u_boot_media.parameters['root_uuid'],
                      u_boot_media.get_common_data('uuid', 'root'))
     part_reference = '%s:%s' % (job.device['parameters']['media']['usb'][
         u_boot_media.get_common_data('u-boot', 'device')]['device_id'],
                                 u_boot_media.parameters['boot_part'])
     self.assertEqual(part_reference,
                      u_boot_media.get_common_data('uuid', 'boot_part'))
     self.assertEqual(part_reference, "0:1")
Пример #16
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,
                           "",
                           output_dir='/tmp')
        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]
        if sys.version < '3':
            # skipping in 3 due to "RecursionError: maximum recursion depth exceeded in comparison"
            self.assertNotEqual(check, expect.parameters)
Пример #17
0
 def create_job(self, sample_job, device_file, output_dir='/tmp/'):  # 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, "",
                            output_dir=output_dir)
     return job
Пример #18
0
 def create_x15_job(self, filename, output_dir='/tmp/'):  # pylint: disable=no-self-use
     device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/x15-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, "",
                            output_dir=output_dir)
     return job
Пример #19
0
    def parse_job_file(self, filename, oob_file):
        """
        Uses the parsed device_config instead of the old Device class
        so it can fail before the Pipeline is made.
        Avoids loading all configuration for all supported devices for every job.
        """
        if is_pipeline_job(filename):
            # Prepare the pipeline from the file using the parser.
            device = None  # secondary connections do not need a device
            if self.args.target:
                device = NewDevice(self.args.target)  # DeviceParser
            parser = JobParser()
            job = None

            # Load the configuration files (this should *not* fail)
            env_dut = None
            if self.args.env_dut_path is not None:
                with open(self.args.env_dut_path, 'r') as f_in:
                    env_dut = f_in.read()
            dispatcher_config = None
            if self.args.dispatcher_config is not None:
                with open(self.args.dispatcher_config, "r") as f_in:
                    dispatcher_config = f_in.read()

            try:
                # Create the ZMQ config
                zmq_config = None
                if self.args.socket_addr is not None:
                    zmq_config = ZMQConfig(self.args.socket_addr,
                                           self.args.master_cert,
                                           self.args.slave_cert,
                                           self.args.ipv6)
                # Generate the pipeline
                with open(filename) as f_in:
                    job = parser.parse(f_in, device, self.args.job_id,
                                       zmq_config=zmq_config,
                                       dispatcher_config=dispatcher_config,
                                       output_dir=self.args.output_dir,
                                       env_dut=env_dut)
                # Generate the description
                description = job.describe()
                description_file = os.path.join(self.args.output_dir,
                                                'description.yaml')
                if not os.path.exists(self.args.output_dir):
                    os.makedirs(self.args.output_dir, 0o755)
                with open(description_file, 'w') as f_describe:
                    f_describe.write(yaml.dump(description))

            except JobError as exc:
                logging.error("Invalid job submission: %s" % exc)
                exit(1)
            # FIXME: NewDevice schema needs a validation parser
            # device.check_config(job)
            return get_pipeline_runner(job), job.parameters

        # everything else is assumed to be JSON
        return run_legacy_job, json.load(open(filename))
Пример #20
0
 def create_mustang_job(self, filename, output_dir='/tmp/'):  # 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, "",
                            output_dir=output_dir)
     job.logger = DummyLogger()
     return job
Пример #21
0
 def setUp(self):
     super(TestVland, self).setUp()
     self.filename = os.path.join(os.path.dirname(__file__),
                                  'sample_jobs/bbb-group-vland-alpha.yaml')
     self.beta_filename = os.path.join(
         os.path.dirname(__file__), 'sample_jobs/bbb-group-vland-beta.yaml')
     self.device = NewDevice(
         os.path.join(os.path.dirname(__file__), '../devices/bbb-01.yaml'))
     self.job_id = "100"
Пример #22
0
 def create_uefi_job(self, filename, output_dir=None):  # pylint: disable=no-self-use
     device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/mustang-uefi.yaml'))
     mustang_yaml = os.path.join(os.path.dirname(__file__), filename)
     with open(mustang_yaml) as sample_job_data:
         parser = JobParser()
         job = parser.parse(sample_job_data, device, 0, None, dispatcher_config="",
                            output_dir=output_dir)
         job.logger = DummyLogger()
     return job
Пример #23
0
    def test_overlay_action(self):  # pylint: disable=too-many-locals
        parameters = {
            'device_type': 'd02',
            'job_name': 'grub-standard-ramdisk',
            'job_timeout': '15m',
            'action_timeout': '5m',
            'priority': 'medium',
            'output_dir': mkdtemp(),
            'actions': {
                'boot': {
                    'method': 'grub',
                    'commands': 'ramdisk',
                    'prompts': ['linaro-test', 'root@debian:~#']
                },
                'deploy': {
                    'ramdisk': 'initrd.gz',
                    'kernel': 'zImage',
                    'dtb': 'broken.dtb'
                }
            }
        }
        device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/d02-01.yaml'))
        job = Job(4212, parameters, None)
        job.device = device
        pipeline = Pipeline(job=job, parameters=parameters['actions']['boot'])
        job.pipeline = pipeline
        overlay = BootloaderCommandOverlay()
        pipeline.add_action(overlay)
        ip_addr = dispatcher_ip(None)
        parsed = []
        kernel = parameters['actions']['deploy']['kernel']
        ramdisk = parameters['actions']['deploy']['ramdisk']
        dtb = parameters['actions']['deploy']['dtb']

        substitution_dictionary = {
            '{SERVER_IP}': ip_addr,
            # the addresses need to be hexadecimal
            '{RAMDISK}': ramdisk,
            '{KERNEL}': kernel,
            '{DTB}': dtb
        }
        params = device['actions']['boot']['methods']
        commands = params['grub']['ramdisk']['commands']
        self.assertIn('net_bootp', commands)
        self.assertIn("linux (tftp,{SERVER_IP})/{KERNEL} console=ttyS0,115200 earlycon=uart8250,mmio32,0x80300000 root=/dev/ram0 ip=dhcp", commands)
        self.assertIn('initrd (tftp,{SERVER_IP})/{RAMDISK}', commands)
        self.assertIn('devicetree (tftp,{SERVER_IP})/{DTB}', commands)

        params['grub']['ramdisk']['commands'] = substitute(params['grub']['ramdisk']['commands'], substitution_dictionary)
        substituted_commands = params['grub']['ramdisk']['commands']
        self.assertIs(type(substituted_commands), list)
        self.assertIn('net_bootp', substituted_commands)
        self.assertNotIn("linux (tftp,{SERVER_IP})/{KERNEL} console=ttyS0,115200 earlycon=uart8250,mmio32,0x80300000 root=/dev/ram0 ip=dhcp", substituted_commands)
        self.assertIn("linux (tftp,%s)/%s console=ttyS0,115200 earlycon=uart8250,mmio32,0x80300000 root=/dev/ram0 ip=dhcp" % (ip_addr, kernel), substituted_commands)
        self.assertNotIn('initrd (tftp,{SERVER_IP})/{RAMDISK}', parsed)
        self.assertNotIn('devicetree (tftp,{SERVER_IP})/{DTB}', parsed)
Пример #24
0
 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'])
Пример #25
0
    def test_overlay_action(self):  # pylint: disable=too-many-locals
        parameters = {
            'device_type': 'x86',
            'job_name': 'ipxe-pipeline',
            'job_timeout': '15m',
            'action_timeout': '5m',
            'priority': 'medium',
            'output_dir': mkdtemp(),
            'actions': {
                'boot': {
                    'method': 'ipxe',
                    'commands': 'ramdisk',
                    'prompts': ['linaro-test', 'root@debian:~#']
                },
                'deploy': {
                    'ramdisk': 'initrd.gz',
                    'kernel': 'zImage',
                }
            }
        }
        device = NewDevice(
            os.path.join(os.path.dirname(__file__), '../devices/x86-01.yaml'))
        job = Job(4212, parameters, None)
        job.device = device
        pipeline = Pipeline(job=job, parameters=parameters['actions']['boot'])
        job.pipeline = pipeline
        overlay = BootloaderCommandOverlay()
        pipeline.add_action(overlay)
        ip_addr = dispatcher_ip(None)
        kernel = parameters['actions']['deploy']['kernel']
        ramdisk = parameters['actions']['deploy']['ramdisk']

        substitution_dictionary = {
            '{SERVER_IP}': ip_addr,
            '{RAMDISK}': ramdisk,
            '{KERNEL}': kernel,
            '{LAVA_MAC}': "00:00:00:00:00:00"
        }
        params = device['actions']['boot']['methods']
        params['ipxe']['ramdisk']['commands'] = substitute(
            params['ipxe']['ramdisk']['commands'], substitution_dictionary)

        commands = params['ipxe']['ramdisk']['commands']
        self.assertIs(type(commands), list)
        self.assertIn("dhcp net0", commands)
        self.assertIn(
            "set console console=ttyS0,115200n8 lava_mac=00:00:00:00:00:00",
            commands)
        self.assertIn("set extraargs init=/sbin/init ip=dhcp", commands)
        self.assertNotIn(
            "kernel tftp://{SERVER_IP}/{KERNEL} ${extraargs} ${console}",
            commands)
        self.assertNotIn("initrd tftp://{SERVER_IP}/{RAMDISK}", commands)
        self.assertIn("boot", commands)
Пример #26
0
 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'])
Пример #27
0
 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"])
Пример #28
0
 def create_fake_qemu_job(self, output_dir=None):  # pylint: disable=no-self-use
     device = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/kvm01.yaml'))
     sample_job_file = os.path.join(os.path.dirname(__file__), 'sample_jobs/basics.yaml')
     parser = JobParser()
     try:
         with open(sample_job_file) as sample_job_data:
             job = parser.parse(sample_job_data, device, 4212, None, "",
                                output_dir=output_dir)
     except LAVAError:
         # some deployments listed in basics.yaml are not implemented yet
         return None
     return job
Пример #29
0
 def create_custom_job(self, data, output_dir='/tmp/'):  # pylint: disable=no-self-use
     device = NewDevice(
         os.path.join(os.path.dirname(__file__), '../devices/bbb-01.yaml'))
     parser = JobParser()
     job = parser.parse(data,
                        device,
                        4212,
                        None,
                        None,
                        None,
                        output_dir=output_dir)
     return job
Пример #30
0
 def test_name(self):
     deploy = [
         action for action in self.job.pipeline.actions
         if action.name == 'deployimages'
     ][0]
     overlay = [
         action for action in deploy.internal_pipeline.actions
         if action.name == 'lava-overlay'
     ][0]
     testdef = [
         action for action in overlay.internal_pipeline.actions
         if action.name == 'test-definition'
     ][0]
     testdef.validate()
     self.assertEqual([], testdef.errors)
     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, 'r') as sample_job_data:
         content = yaml.load(sample_job_data)
     data = [
         block['test'] for block in content['actions'] if 'test' in block
     ][0]
     definitions = [
         block for block in data['definitions'] if 'path' in block
     ][0]
     definitions['name'] = 'smoke tests'
     job = parser.parse(yaml.dump(content),
                        device,
                        4212,
                        None,
                        "",
                        output_dir='/tmp/')
     deploy = [
         action for action in job.pipeline.actions
         if action.name == 'deployimages'
     ][0]
     overlay = [
         action for action in deploy.internal_pipeline.actions
         if action.name == 'lava-overlay'
     ][0]
     testdef = [
         action for action in overlay.internal_pipeline.actions
         if action.name == 'test-definition'
     ][0]
     testdef.validate()
     self.assertNotEqual([], testdef.errors)
     self.assertIn(
         'Invalid characters found in test definition name: smoke tests',
         job.pipeline.errors)
Пример #31
0
 def create_ssh_job(self, filename, output_dir=None):  # 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,
                            socket_addr=None,
                            output_dir=output_dir)
     return job
Пример #32
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, "", output_dir='/tmp/')
     job.logger = DummyLogger()
     job.validate()
     self.assertEqual(job.pipeline.errors, [])
     self.assertIn('usb', bbb['parameters']['media'].keys())
Пример #33
0
 def create_bbb_lxc_job(self, filename, output_dir='/tmp/'):  # pylint: disable=no-self-use
     device = NewDevice(
         os.path.join(os.path.dirname(__file__), '../devices/bbb-01.yaml'))
     lxc_yaml = os.path.join(os.path.dirname(__file__), filename)
     with open(lxc_yaml) as sample_job_data:
         parser = JobParser()
         job = parser.parse(sample_job_data,
                            device,
                            4577,
                            None,
                            "",
                            output_dir=output_dir)
     job.logger = DummyLogger()
     return job