def run(self, connection, args=None): if 'download_action' not in self.data: raise RuntimeError("Missing download action") if 'offset' in self.data['download_action']: # idempotency return connection image = self.data['download_action']['file'] if not os.path.exists(image): raise RuntimeError("Not able to mount %s: file does not exist" % image) part_data = self._run_command([ '/sbin/parted', image, '-m', '-s', 'unit', 'b', 'print' ]) if not part_data: raise JobError("Unable to identify offset") # FIXME: identify the partitions from the image, not from the device configuration partno = self.job.device.parameters[self.parameters['deployment_data']['lava_test_results_part_attr']] pattern = re.compile('%d:([0-9]+)B:' % partno) for line in part_data.splitlines(): found = re.match(pattern, line) if found: self.data['download_action']['offset'] = found.group(1) if 'offset' not in self.data['download_action']: # more reliable than checking if offset exists as offset can be zero raise JobError( # FIXME: JobError needs a unit test "Unable to determine offset for %s" % image ) return connection
def run(self, connection, args=None): connection = super(ApplyNexellOverlay, self).run(connection, args) overlay_file = self.data['compress-overlay'].get('output') adb_serial_number = self.job.device['adb_serial_number'] self.logger.debug("SUKER: deploy/apply_overlay.py: " + str(adb_serial_number)) if overlay_file is None: self.logger.debug("skipped %s", self.name) self.logger.debug("[SEOJI] skipped %s", self.name) #return connection nexell_path = os.path.join(NEXELL_PATH) if not os.path.exists(nexell_path): raise JobError("Nexell path not found") tar_cmd = [ 'tar', '--warning', 'no-timestamp', '-C', nexell_path, '-xaf', overlay_file ] command_output = self.run_command(tar_cmd) if command_output and command_output is not '': raise JobError("Unable to untar overlay: %s" % command_output) # FIXME: JobError needs a unit test # FIXME: Avoid copying this special 'lava-test-runner' which does not # have 'sync' in cleanup. This should be handled during the # creation of the overlay instead. Make a special case to copy # lxc specific scripts, with distro specific versions. fname = os.path.join(self.lava_test_dir, 'lava-test-runner') output_file = '%s/bin/%s' % (nexell_path, os.path.basename(fname)) self.logger.debug("SUKER: deploy/apply_overlay.py output_file: " + str(output_file)) self.logger.debug("SUKER: deploy/apply_overlay.py nexell_path: " + str(nexell_path)) lava_test_results_dir = self.data['lava_test_results_dir'] self.logger.debug( "SUKER: deploy/apply_overlay.py var/lib/nexell path: " + str(lava_test_results_dir)) # adb push nexell_real_path = nexell_path + lava_test_results_dir adb_cmd = [ '/opt/android-sdk-linux/platform-tools/adb', '-s', adb_serial_number, 'push', nexell_real_path, '/' ] self.logger.debug("SUKER: apply_overlay.py: " + str(adb_cmd)) command_output = self.run_command(adb_cmd) adb_cmd = [ '/opt/android-sdk-linux/platform-tools/adb', '-s', adb_serial_number, 'push', fname, lava_test_results_dir + '/bin/' ] self.logger.debug("SUKER: apply_overlay.py: " + str(adb_cmd)) command_output = self.run_command(adb_cmd) return connection
def reader(self): res = None try: res = requests.get(self.url.geturl(), allow_redirects=True, stream=True, timeout=HTTP_DOWNLOAD_TIMEOUT) if res.status_code != requests.codes.OK: # pylint: disable=no-member raise JobError("Unable to download '%s'" % (self.url.geturl())) for buff in res.iter_content(HTTP_DOWNLOAD_CHUNK_SIZE): yield buff except requests.RequestException as exc: # TODO: improve error reporting raise JobError(exc) finally: if res is not None: res.close()
def run(self, connection, args=None): if connection: self.logger.debug("Already connected") return connection signal.alarm(0) # clear the timeouts used without connections. # ShellCommand executes the connection command params = self._check_params() command = self.command[:] # local copy for idempotency overrides = self.get_common_data("prepare-scp-overlay", self.key) host_address = None if overrides: host_address = str( self.get_common_data("prepare-scp-overlay", overrides[0])) if host_address: self.logger.info( "Using common data to retrieve host_address for secondary connection." ) command_str = " ".join(str(item) for item in command) self.logger.info("%s Connecting to device %s using '%s'", self.name, host_address, command_str) command.append("%s@%s" % (self.ssh_user, host_address)) elif self.host and self.primary: self.logger.info( "Using device data host_address for primary connection.") command_str = " ".join(str(item) for item in command) self.logger.info("%s Connecting to device %s using '%s'", self.name, self.host, command_str) command.append("%s@%s" % (self.ssh_user, self.host)) else: raise JobError("Unable to identify host address. Primary? %s", self.primary) command_str = " ".join(str(item) for item in command) shell = ShellCommand("%s\n" % command_str, self.timeout, logger=self.logger) if shell.exitstatus: raise JobError("%s command exited %d: %s" % (self.command, shell.exitstatus, shell.readlines())) # SshSession monitors the pexpect connection = SShSession(self.job, shell) connection = super(ConnectSsh, self).run(connection, args) connection.sendline('export PS1="%s"' % DEFAULT_SHELL_PROMPT) connection.prompt_str = [DEFAULT_SHELL_PROMPT] connection.connected = True self.wait(connection) self.data["boot-result"] = 'failed' if self.errors else 'success' return connection