def run(self, connection, max_end_time, args=None): # pylint: disable=too-many-locals connection = super(CopyToLxcAction, 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 else: return connection # Copy each file to LXC. namespace = self.parameters['namespace'] images = self.data[namespace]['download-action'].keys() for image in images: src = self.get_namespace_data(action='download-action', label=image, key='file') # The archive extraction logic and some deploy logic in # DownloadHandler will set a label 'file' in the namespace but # that file would have been dealt with and the actual path may not # exist, though the key exists as part of the namespace, which we # can ignore safely, hence we continue on invalid src. if not src: continue copy_to_lxc(lxc_name, src, self.job.parameters['dispatcher']) overlay_file = self.get_namespace_data(action='compress-overlay', label='output', key='file') if overlay_file is None: self.logger.debug("skipped %s", self.name) else: copy_overlay_to_lxc(lxc_name, overlay_file, self.job.parameters['dispatcher'], namespace) return connection
def run(self, connection, max_end_time): connection = super().run(connection, max_end_time) # 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 else: return connection # Copy each file to LXC. for image in self.get_namespace_keys("download-action"): src = self.get_namespace_data( action="download-action", label=image, key="file" ) # The archive extraction logic and some deploy logic in # DownloadHandler will set a label 'file' in the namespace but # that file would have been dealt with and the actual path may not # exist, though the key exists as part of the namespace, which we # can ignore safely, hence we continue on invalid src. if not src: continue copy_to_lxc(lxc_name, src, self.job.parameters["dispatcher"]) overlay_file = self.get_namespace_data( action="compress-overlay", label="output", key="file" ) if overlay_file is None: self.logger.debug("skipped %s", self.name) else: copy_overlay_to_lxc( lxc_name, overlay_file, self.job.parameters["dispatcher"], self.parameters["namespace"], ) return connection
def run(self, connection, max_end_time, args=None): # pylint: disable=too-many-locals connection = super(CopyToLxcAction, 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 else: return connection # Copy each file to LXC. namespace = self.parameters['namespace'] images = self.data[namespace]['download-action'].keys() for image in images: src = self.get_namespace_data(action='download-action', label=image, key='file') # The archive extraction logic and some deploy logic in # DownloadHandler will set a label 'file' in the namespace but # that file would have been dealt with and the actual path may not # exist, though the key exists as part of the namespace, which we # can ignore safely, hence we continue on invalid src. if not src: continue copy_to_lxc(lxc_name, src, self.job.parameters['dispatcher']) overlay_file = self.get_namespace_data(action='compress-overlay', label='output', key='file') if overlay_file is None: self.logger.debug("skipped %s", self.name) else: copy_overlay_to_lxc(lxc_name, overlay_file, self.job.parameters['dispatcher'], namespace) 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: raise JobError("Unable to use fastboot") src = self.get_namespace_data(action='download-action', label=self.command, key='file') if not src: return connection 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 self.command in ['boot']: return connection # if a reboot is requested, will need to wait for the prompt # if not, continue in the existing mode. reboot = self.get_namespace_data(action=self.name, label='interrupt', key='reboot') if self.interrupt_prompt and reboot: 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', self.command, dst ] + fastboot_opts self.logger.info("Handling %s", self.command) command_output = self.run_command(fastboot_cmd) if command_output and 'error' in command_output: raise InfrastructureError("Unable to flash %s using fastboot: %s" % (self.command, command_output)) self.results = {'label': self.command} return connection
def run(self, connection, max_end_time): # pylint: disable=too-many-locals connection = super().run(connection, max_end_time) src = self.get_namespace_data( action="download-action", label=self.command, key="file" ) if not src: return connection self.logger.debug("%s bytes", os.stat(src)[6]) lxc_name = is_lxc_requested(self.job) if lxc_name: src = 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 self.command in ["boot"]: return connection # if a reboot is requested, will need to wait for the prompt # if not, continue in the existing mode. reboot = self.get_namespace_data( action=self.name, label="interrupt", key="reboot" ) if self.interrupt_prompt and reboot: 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_cmd_prefix(self.job) + ["fastboot", "-s", serial_number, "flash", self.command, src] + fastboot_opts ) self.logger.info("Handling %s", self.command) # needs to move to self.run_cmd with support for raising InfrastructureError command_output = self.run_command(fastboot_cmd) if not command_output: raise InfrastructureError( "Unable to flash %s using fastboot" % self.command ) self.results = {"label": self.command} return connection
def run(self, connection, max_end_time): # pylint: disable=too-many-locals connection = super().run(connection, max_end_time) src = self.get_namespace_data(action='download-action', label=self.command, key='file') if not src: return connection self.logger.debug("%s bytes", os.stat(src)[6]) lxc_name = is_lxc_requested(self.job) if lxc_name: src = 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 self.command in ['boot']: return connection # if a reboot is requested, will need to wait for the prompt # if not, continue in the existing mode. reboot = self.get_namespace_data(action=self.name, label='interrupt', key='reboot') if self.interrupt_prompt and reboot: 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_cmd_prefix(self.job) + [ 'fastboot', '-s', serial_number, 'flash', self.command, src ] + fastboot_opts self.logger.info("Handling %s", self.command) # needs to move to self.run_cmd with support for raising InfrastructureError command_output = self.run_command(fastboot_cmd) if not command_output: raise InfrastructureError("Unable to flash %s using fastboot" % self.command) self.results = {'label': self.command} 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: raise JobError("Unable to use fastboot") src = self.get_namespace_data(action='download-action', label=self.command, key='file') if not src: return connection 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 self.command in ['boot']: return connection # if a reboot is requested, will need to wait for the prompt # if not, continue in the existing mode. reboot = self.get_namespace_data( action=self.name, label='interrupt', key='reboot') if self.interrupt_prompt and reboot: 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', self.command, dst] + fastboot_opts self.logger.info("Handling %s", self.command) command_output = self.run_command(fastboot_cmd) if not command_output: raise InfrastructureError("Unable to flash %s using fastboot" % self.command) self.results = {'label': self.command} return connection
def maybe_copy_to_container(self, src): src = copy_to_lxc(self.lxc_name, src, self.action.job.parameters["dispatcher"]) return src