def signal_lxc_add(self): # the lxc namespace may not be accessible here depending on the # lava-test-shell action namespace. lxc_name = None protocols = [ protocol for protocol in self.job.protocols if protocol.name == LxcProtocol.name ] protocol = protocols[0] if protocols else None if protocol: lxc_name = protocol.lxc_name if not lxc_name: self.logger.debug("No LXC device requested") return False self.logger.info( "Get USB device(s) using: %s", yaml.dump(self.job.device.get('device_info', [])).strip()) device_paths = get_udev_devices(self.job, self.logger) if not device_paths: self.logger.warning("No USB devices added to the LXC.") return False 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 True
def run(self, connection, max_end_time, args=None): lxc_name = self.get_namespace_data(action='lxc-create-action', label='lxc', key='name') if not lxc_name: self.logger.debug("No LXC device requested") return connection self.logger.info("Get USB device(s) ...") device_paths = get_udev_devices(self.job, logger=self.logger) 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) connection = self.get_namespace_data(action='shared', label='shared', key='connection', deepcopy=False) if connection: return connection cmd = "lxc-attach -n {0}".format(lxc_name) self.logger.info("%s Connecting to device using '%s'", self.name, cmd) # ShellCommand executes the connection command shell = self.shell_class("%s\n" % cmd, self.timeout, logger=self.logger) if shell.exitstatus: raise JobError("%s command exited %d: %s" % (cmd, shell.exitstatus, shell.readlines())) # ShellSession monitors the pexpect connection = self.session_class(self.job, shell) connection.connected = True connection = super(ConnectLxc, self).run(connection, max_end_time, args) connection.prompt_str = self.parameters['prompts'] res = 'failed' if self.errors else 'success' self.set_namespace_data(action='boot', label='shared', key='boot-result', value=res) self.set_namespace_data(action='shared', label='shared', key='connection', value=connection) return connection
def run(self, connection, max_end_time, args=None): connection = super(LxcAddDeviceAction, self).run(connection, max_end_time, args) # this is the device namespace - the lxc namespace is not accessible lxc_name = None protocols = [protocol for protocol in self.job.protocols if protocol.name == LxcProtocol.name] if protocols: lxc_name = protocols[0].lxc_name if not lxc_name: self.logger.debug("No LXC device requested") return connection self.logger.info("Get USB device(s) ...") device_paths = get_udev_devices(self.job, logger=self.logger) 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
# it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # LAVA Coordinator is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, see <http://www.gnu.org/licenses>. # # Reads content of device-info-file and adds the given devices to lxc # identified by lxc-name # # Usage: lava_lxc_device_add.py <lxc-name> <device-info-file> import sys import ast import subprocess from lava_dispatcher.pipeline.utils.udev import get_udev_devices lxc_name = sys.argv[1] device_info = ast.literal_eval(open(sys.argv[2], 'r').read()) device_paths = get_udev_devices(device_info=device_info) for device in device_paths: lxc_cmd = ['lxc-device', '-n', lxc_name, 'add', device] output = subprocess.check_output(lxc_cmd, stderr=subprocess.STDOUT) print(output) print("%s: device %s added" % (lxc_name, device))
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
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