示例#1
0
 def run(self, connection, args=None):
     connection = super(ApplyVendorAction, self).run(connection, args)
     lxc_name = self.get_common_data('lxc', 'name')
     src = self.data['download_action']['vendor']['file']
     dst = copy_to_lxc(lxc_name, src)
     serial_number = self.job.device['fastboot_serial_number']
     fastboot_cmd = ['lxc-attach', '-n', lxc_name, '--', 'fastboot',
                     '-s', serial_number, 'flash', 'vendor', dst]
     command_output = self.run_command(fastboot_cmd)
     if command_output and 'error' in command_output:
         raise JobError("Unable to apply vendor image using fastboot: %s" %
                        command_output)  # FIXME: JobError needs a unit test
     return connection
示例#2
0
 def run(self, connection, args=None):
     connection = super(ApplyVendorAction, self).run(connection, args)
     lxc_name = self.get_common_data('lxc', 'name')
     src = self.data['download_action']['vendor']['file']
     dst = copy_to_lxc(lxc_name, src)
     serial_number = self.job.device['fastboot_serial_number']
     fastboot_cmd = ['lxc-attach', '-n', lxc_name, '--', 'fastboot',
                     '-s', serial_number, 'flash', 'vendor', dst]
     command_output = self.run_command(fastboot_cmd)
     if command_output and 'error' in command_output:
         raise JobError("Unable to apply vendor image using fastboot: %s" %
                        command_output)  # FIXME: JobError needs a unit test
     return connection
示例#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
示例#4
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

            # each time, read anything from the previous buffer before doing the reset.
            # cannot happen after the reset or it would be a race condition with the addition
            # of the device to the LXC.
            if self.interrupt_prompt:
                connection.prompt_str = self.interrupt_prompt
                self.logger.debug("Changing prompt to '%s'",
                                  connection.prompt_str)
                self.wait(connection)

            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")
        return connection
示例#5
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:
            self.errors = "Unable to use fastboot"
            return connection
        # Order flash commands so that some commands take priority over others
        flash_cmds_order = self.job.device['flash_cmds_order']
        namespace = self.parameters.get('namespace', 'common')
        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))
            # See: https://projects.linaro.org/browse/LAVA-920
            # NOTE: Though the following appears as a workaround for HiKey
            #       firmware, it is always safe to reboot to bootloader after
            #       flashing the ptable (partition table) for any device,
            #       provided the device enters fastboot mode after a
            #       'fastboot reboot-bootloader' command
            if flash_cmd in ['ptable']:
                self.logger.info("Rebooting device to refresh ptable.")
                if self.job.device.hard_reset_command:
                    # It is more reliable in some devices (like HiKey) to hard
                    # reset, than to issue 'fastboot reboot-bootloader' which
                    # sometimes hungs the device in UEFI startup.
                    command = self.job.device.hard_reset_command
                    # FIXME: run_command should handle commands that are string
                    #        or list properly.
                    if isinstance(command, list):
                        for cmd in command:
                            if not self.run_command(cmd.split(' '),
                                                    allow_silent=True):
                                raise InfrastructureError("%s failed" % cmd)
                    else:
                        if not self.run_command(command.split(' '),
                                                allow_silent=True):
                            raise InfrastructureError("%s failed" % command)
                else:
                    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-bootloader: %s" %
                            (command_output))
                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',
                        os.path.realpath(device)
                    ]
                    log = self.run_command(lxc_cmd)
                    self.logger.debug(log)
                    self.logger.debug("%s: device %s added", lxc_name, device)
        return connection