Ejemplo n.º 1
0
 def run(self, connection, max_end_time, args=None):
     connection = super(WaitUSBDeviceAction,
                        self).run(connection, max_end_time, args)
     self.logger.info("Waiting for USB device(s) with actions %s ...",
                      self.device_actions)
     usb_device_wait(self.job, device_actions=self.device_actions)
     return connection
Ejemplo n.º 2
0
    def check_patterns(self, event, test_connection, check_char):  # pylint: disable=unused-argument
        """
        Defines the base set of pattern responses.
        Stores the results of testcases inside the TestAction
        Call from subclasses before checking subclass-specific events.
        """
        ret_val = False
        if event == "exit":
            self.logger.info("ok: lava_test_shell seems to have completed")
            self.testset_name = None

        elif event == "error":
            # Parsing is not finished
            ret_val = self.pattern_error(test_connection)

        elif event == "eof":
            self.logger.warning("err: lava_test_shell connection dropped")
            self.errors = "lava_test_shell connection dropped"
            self.testset_name = None

        elif event == "timeout":
            self.logger.warning("err: lava_test_shell has timed out")
            self.errors = "lava_test_shell has timed out"
            self.testset_name = None

        elif event == "signal":
            name, params = test_connection.match.groups()
            self.logger.debug("Received signal: <%s> %s" % (name, params))
            params = params.split()
            if name == "STARTRUN":
                self.signal_start_run(params)
            elif name == "ENDRUN":
                self.signal_end_run(params)
            elif name == "TESTCASE":
                self.signal_test_case(params)
            elif name == "TESTREFERENCE":
                self.signal_test_reference(params)
            elif name == "TESTSET":
                ret = self.signal_test_set(params)
                if ret:
                    name = ret
            elif name == "LXCDEVICEADD":
                self.signal_lxc_add()
            elif name == "LXCDEVICEWAITADD":
                self.logger.info("Waiting for USB device(s) ...")
                usb_device_wait(self.job, device_actions=['add'])

            self.signal_director.signal(name, params)
            ret_val = True

        elif event == "test_case":
            ret_val = self.pattern_test_case(test_connection)
        elif event == 'test_case_result':
            ret_val = self.pattern_test_case_result(test_connection)
        return ret_val
Ejemplo n.º 3
0
    def run(self, connection, max_end_time, args=None):  # pylint: disable=too-many-locals
        connection = super(FastbootFlashAction, self).run(connection, max_end_time, args)
        # this is the device namespace - the lxc namespace is not accessible
        lxc_name = None
        protocol = [protocol for protocol in self.job.protocols if protocol.name == LxcProtocol.name][0]
        if protocol:
            lxc_name = protocol.lxc_name
        if not lxc_name:
            raise JobError("Unable to use fastboot")

        # Order flash commands so that some commands take priority over others
        flash_cmds_order = self.job.device['flash_cmds_order']
        namespace = self.parameters['namespace']
        flash_cmds = set(self.data[namespace]['download-action'].keys()).difference(
            set(flash_cmds_order))
        flash_cmds = flash_cmds_order + list(flash_cmds)

        for flash_cmd in flash_cmds:
            src = self.get_namespace_data(action='download-action', label=flash_cmd, key='file')
            if not src:
                continue
            dst = copy_to_lxc(lxc_name, src, self.job.parameters['dispatcher'])
            sequence = self.job.device['actions']['boot']['methods'].get(
                'fastboot', [])
            if 'no-flash-boot' in sequence and flash_cmd in ['boot']:
                continue
            serial_number = self.job.device['fastboot_serial_number']
            fastboot_opts = self.job.device['fastboot_options']
            fastboot_cmd = ['lxc-attach', '-n', lxc_name, '--', 'fastboot',
                            '-s', serial_number, 'flash', flash_cmd,
                            dst] + fastboot_opts
            command_output = self.run_command(fastboot_cmd)
            if command_output and 'error' in command_output:
                raise InfrastructureError("Unable to flash %s using fastboot: %s" %
                                          (flash_cmd, command_output))
            reboot = self.parameters['images'][flash_cmd].get('reboot', False)
            if reboot == 'fastboot-reboot':
                self.logger.info("fastboot rebooting device.")
                fastboot_cmd = ['lxc-attach', '-n', lxc_name, '--',
                                'fastboot', '-s', serial_number,
                                'reboot'] + fastboot_opts
                command_output = self.run_command(fastboot_cmd)
                if command_output and 'error' in command_output:
                    raise InfrastructureError("Unable to reboot: %s"
                                              % (command_output))
            if reboot == 'fastboot-reboot-bootloader':
                self.logger.info("fastboot reboot device to bootloader.")
                fastboot_cmd = ['lxc-attach', '-n', lxc_name, '--',
                                'fastboot', '-s', serial_number,
                                'reboot-bootloader'] + fastboot_opts
                command_output = self.run_command(fastboot_cmd)
                if command_output and 'error' in command_output:
                    raise InfrastructureError(
                        "Unable to reboot to bootloader: %s"
                        % (command_output))
            if reboot == 'hard-reset':
                if self.job.device.hard_reset_command:
                    self.logger.info("Hard resetting device.")
                    command = self.job.device.hard_reset_command
                    if not isinstance(command, list):
                        command = [command]
                    for cmd in command:
                        if not self.run_command(cmd.split(' '),
                                                allow_silent=True):
                            raise InfrastructureError("%s failed" % cmd)
                else:
                    self.logger.info("Device does not have hard reset command")
            if reboot:
                self.logger.info("Waiting for USB device addition ...")
                usb_device_wait(self.job, device_actions=['add'])
                self.logger.info("Get USB device(s) ...")
                device_paths = []
                while True:
                    device_paths = get_udev_devices(self.job,
                                                    logger=self.logger)
                    if device_paths:
                        break
                for device in device_paths:
                    lxc_cmd = ['lxc-device', '-n', lxc_name, 'add', device]
                    log = self.run_command(lxc_cmd)
                    self.logger.debug(log)
                    self.logger.debug("%s: device %s added", lxc_name, device)
        return connection