def deploy(self): # base class just sets the ssh log file for us super(MasterImageHardwareTarget, self).deploy() self.master = sshcontrol.SSHControl(ip=self.ip, logfile=self.sshlog, timeout=600, port=self.port) status, output = self.master.run("cat /etc/masterimage") if status != 0: # We're not booted into the master image, so try rebooting bb.plain("%s - booting into the master image" % self.pn) self.power_ctl("cycle") self._wait_until_booted() bb.plain("%s - deploying image on target" % self.pn) status, output = self.master.run("cat /etc/masterimage") if status != 0: bb.fatal( "No ssh connectivity or target isn't running a master image.\n%s" % output) if self.user_cmds: self.deploy_cmds = self.user_cmds.split("\n") try: self._deploy() except Exception as e: bb.fatal("Failed deploying test image: %s" % e)
def readfifo(data): lines = data.split(b"\0") for line in lines: splitval = line.split(b" ", 1) cmd = splitval[0] if len(splitval) > 1: value = splitval[1].decode("utf-8") else: value = "" if cmd == "bbplain": bb.plain(value) elif cmd == "bbnote": bb.note(value) elif cmd == "bbwarn": bb.warn(value) elif cmd == "bberror": bb.error(value) elif cmd == "bbfatal": # The caller will call exit themselves, so bb.error() is # what we want here rather than bb.fatal() bb.error(value) elif cmd == "bbfatal_log": bb.error(value, forcelog=True) elif cmd == "bbdebug": splitval = value.split(" ", 1) level = int(splitval[0]) value = splitval[1] bb.debug(level, value)
def readfifo(data): lines = data.split('\0') for line in lines: splitval = line.split(' ', 1) cmd = splitval[0] if len(splitval) > 1: value = splitval[1] else: value = '' if cmd == 'bbplain': bb.plain(value) elif cmd == 'bbnote': bb.note(value) elif cmd == 'bbwarn': bb.warn(value) elif cmd == 'bberror': bb.error(value) elif cmd == 'bbfatal': # The caller will call exit themselves, so bb.error() is # what we want here rather than bb.fatal() bb.error(value) elif cmd == 'bbfatal_log': bb.error(value, forcelog=True) elif cmd == 'bbdebug': splitval = value.split(' ', 1) level = int(splitval[0]) value = splitval[1] bb.debug(level, value)
def readfifo(data): lines = data.split(b'\0') for line in lines: # Just skip empty commands if not line: continue splitval = line.split(b' ', 1) cmd = splitval[0].decode("utf-8") if len(splitval) > 1: value = splitval[1].decode("utf-8") else: value = '' if cmd == 'bbplain': bb.plain(value) elif cmd == 'bbnote': bb.note(value) elif cmd == 'bbwarn': bb.warn(value) elif cmd == 'bberror': bb.error(value) elif cmd == 'bbfatal': # The caller will call exit themselves, so bb.error() is # what we want here rather than bb.fatal() bb.error(value) elif cmd == 'bbfatal_log': bb.error(value, forcelog=True) elif cmd == 'bbdebug': splitval = value.split(' ', 1) level = int(splitval[0]) value = splitval[1] bb.debug(level, value) else: bb.warn("Unrecognised command '%s' on FIFO" % cmd)
def start(self, params=None): bb.plain("%s - boot test image on target" % self.pn) self.power_cycle(self.master) # there are better ways than a timeout but this should work for now time.sleep(120) # set the ssh object for the target/test image self.connection = sshcontrol.SSHControl(self.ip, logfile=self.sshlog, port=self.port) bb.plain("%s - start running tests" % self.pn)
def start(self, params=None): bb.plain("%s - boot test image on target" % self.pn) self._start() # set the ssh object for the target/test image self.connection = sshcontrol.SSHControl(self.ip, logfile=self.sshlog, port=self.port) bb.plain("%s - start running tests" % self.pn)
def deploy(self): bb.plain("%s - deploying image on target" % self.pn) # base class just sets the ssh log file for us super(GummibootTarget, self).deploy() self.master = sshcontrol.SSHControl(ip=self.ip, logfile=self.sshlog, timeout=600, port=self.port) try: self._deploy() except Exception as e: bb.fatal("Failed deploying test image: %s" % e)
def custom_verbose(msg, *args, **kwargs): global _buffer_logger if msg[-1] != "\n": _buffer_logger += msg else: _buffer_logger += msg try: bb.plain(_buffer_logger.rstrip("\n"), *args, **kwargs) except NameError: logger.info(_buffer_logger.rstrip("\n"), *args, **kwargs) _buffer_logger = ""
def deploy(self): # base class just sets the ssh log file for us super(MasterImageHardwareTarget, self).deploy() self.master = sshcontrol.SSHControl(ip=self.ip, logfile=self.sshlog, timeout=600, port=self.port) status, output = self.master.run("cat /etc/masterimage") if status != 0: # We're not booted into the master image, so try rebooting bb.plain("%s - booting into the master image" % self.pn) self.power_ctl("cycle") self._wait_until_booted() bb.plain("%s - deploying image on target" % self.pn) status, output = self.master.run("cat /etc/masterimage") if status != 0: bb.fatal("No ssh connectivity or target isn't running a master image.\n%s" % output) if self.user_cmds: self.deploy_cmds = self.user_cmds.split("\n") try: self._deploy() except Exception as e: bb.fatal("Failed deploying test image: %s" % e)
def readfifo(data): nonlocal fifobuffer fifobuffer.extend(data) while fifobuffer: message, token, nextmsg = fifobuffer.partition(b"\00") if token: splitval = message.split(b' ', 1) cmd = splitval[0].decode("utf-8") if len(splitval) > 1: value = splitval[1].decode("utf-8") else: value = '' if cmd == 'bbplain': bb.plain(value) elif cmd == 'bbnote': bb.note(value) elif cmd == 'bbverbnote': bb.verbnote(value) elif cmd == 'bbwarn': bb.warn(value) elif cmd == 'bberror': bb.error(value) elif cmd == 'bbfatal': # The caller will call exit themselves, so bb.error() is # what we want here rather than bb.fatal() bb.error(value) elif cmd == 'bbfatal_log': bb.error(value, forcelog=True) elif cmd == 'bbdebug': splitval = value.split(' ', 1) level = int(splitval[0]) value = splitval[1] bb.debug(level, value) else: bb.warn("Unrecognised command '%s' on FIFO" % cmd) fifobuffer = nextmsg else: break
def process_binaries(d, params): param_list = params export_env = d.getVar("TEST_EXPORT_ONLY") def extract_binary(pth_to_pkg, dest_pth=None): cpio_command = runCmd("which cpio") rpm2cpio_command = runCmd("ls /usr/bin/rpm2cpio") if (cpio_command.status != 0) and (rpm2cpio_command.status != 0): bb.fatal("Either \"rpm2cpio\" or \"cpio\" tools are not available on your system." "All binaries extraction processes will not be available, crashing all related tests." "Please install them according to your OS recommendations") # will exit here if dest_pth: os.chdir(dest_pth) else: os.chdir("%s" % os.sep)# this is for native package extract_bin_command = runCmd("%s %s | %s -idm" % (rpm2cpio_command.output, pth_to_pkg, cpio_command.output)) # semi-hardcoded because of a bug on poky's rpm2cpio return extract_bin_command if determine_if_poky_env(): # machine with poky environment exportpath = d.getVar("TEST_EXPORT_DIR") if export_env else d.getVar("DEPLOY_DIR") rpm_deploy_dir = d.getVar("DEPLOY_DIR_RPM") arch = get_dest_folder(d.getVar("TUNE_FEATURES"), os.listdir(rpm_deploy_dir)) arch_rpm_dir = os.path.join(rpm_deploy_dir, arch) extracted_bin_dir = os.path.join(exportpath,"binaries", arch, "extracted_binaries") packaged_bin_dir = os.path.join(exportpath,"binaries", arch, "packaged_binaries") # creating necessary directory structure in case testing is done in poky env. if export_env == "0": if not os.path.exists(extracted_bin_dir): bb.utils.mkdirhier(extracted_bin_dir) if not os.path.exists(packaged_bin_dir): bb.utils.mkdirhier(packaged_bin_dir) if param_list[3] == "native": if export_env == "1": #this is a native package and we only need to copy it. no need for extraction native_rpm_dir = os.path.join(rpm_deploy_dir, get_dest_folder("{} nativesdk".format(d.getVar("BUILD_SYS")), os.listdir(rpm_deploy_dir))) native_rpm_file_list = [item for item in os.listdir(native_rpm_dir) if re.search("nativesdk-" + param_list[0] + "-([0-9]+\.*)", item)] if not native_rpm_file_list: bb.warn("Couldn't find any version of {} native package. Related tests will most probably fail.".format(param_list[0])) return "" for item in native_rpm_file_list:# will copy all versions of package. Used version will be selected on remote machine bb.plain("Copying native package file: %s" % item) sh.copy(os.path.join(rpm_deploy_dir, native_rpm_dir, item), os.path.join(d.getVar("TEST_EXPORT_DIR"), "binaries", "native")) else: # nothing to do here; running tests under bitbake, so we asume native binaries are in sysroots dir. if param_list[1] or param_list[4]: bb.warn("Native binary %s %s%s. Running tests under bitbake environment. Version can't be checked except when the test itself does it" " and binary can't be removed."%(param_list[0],"has assigned ver. " + param_list[1] if param_list[1] else "", ", is marked for removal" if param_list[4] else "")) else:# the package is target aka DUT intended and it is either required to be delivered in an extracted form or in a packaged version target_rpm_file_list = [item for item in os.listdir(arch_rpm_dir) if re.search(param_list[0] + "-([0-9]+\.*)", item)] if not target_rpm_file_list: bb.warn("Couldn't find any version of target package %s. Please ensure it was built. " "Related tests will probably fail." % param_list[0]) return "" if param_list[2] == "rpm": # binary should be deployed as rpm; (other, .deb, .ipk? ; in the near future) for item in target_rpm_file_list: # copying all related rpm packages. "Intuition" reasons, someone may need other versions too. Deciding later on version bb.plain("Copying target specific packaged file: %s" % item) sh.copy(os.path.join(arch_rpm_dir, item), packaged_bin_dir) return "copied" else: # it is required to extract the binary if param_list[1]: # the package is versioned for item in target_rpm_file_list: if re.match(".*-{}-.*\.rpm".format(param_list[1]), item): destination = os.path.join(extracted_bin_dir,param_list[0], param_list[1]) bb.utils.mkdirhier(destination) extract_binary(os.path.join(arch_rpm_dir, item), destination) break else: bb.warn("Couldn't find the desired version %s for target binary %s. Related test cases will probably fail." % (param_list[1], param_list[0])) return "" return "extracted" else: # no version provided, just extract one binary destination = os.path.join(extracted_bin_dir,param_list[0], re.search(".*-([0-9]+\.[0-9]+)-.*rpm", target_rpm_file_list[0]).group(1)) bb.utils.mkdirhier(destination) extract_binary(os.path.join(arch_rpm_dir, target_rpm_file_list[0]), destination) return "extracted" else: # remote machine binaries_path = os.getenv("bin_dir")# in order to know where the binaries are, bin_dir is set as env. variable if param_list[3] == "native": #need to extract the native pkg here native_rpm_dir = os.path.join(binaries_path, "native") native_rpm_file_list = os.listdir(native_rpm_dir) for item in native_rpm_file_list: if param_list[1] and re.match("nativesdk-{}-{}-.*\.rpm".format(param_list[0], param_list[1]), item): # native package has version extract_binary(os.path.join(native_rpm_dir, item)) break else:# just copy any related native binary found_version = re.match("nativesdk-{}-([0-9]+\.[0-9]+)-".format(param_list[0]), item).group(1) if found_version: extract_binary(os.path.join(native_rpm_dir, item)) else: bb.warn("Couldn't find native package %s%s. Related test cases will be influenced." % (param_list[0], " with version " + param_list[1] if param_list[1] else "")) return else: # this is for target device if param_list[2] == "rpm": return "No need to extract, this is an .rpm file" arch = get_dest_folder(d.getVar("TUNE_FEATURES"), os.listdir(binaries_path)) extracted_bin_path = os.path.join(binaries_path, arch, "extracted_binaries") extracted_bin_list = [item for item in os.listdir(extracted_bin_path)] packaged_bin_path = os.path.join(binaries_path, arch, "packaged_binaries") packaged_bin_file_list = os.listdir(packaged_bin_path) # see if the package is already in the extracted ones; maybe it was deployed when exported the env. if os.path.exists(os.path.join(extracted_bin_path, param_list[0], param_list[1] if param_list[1] else "")): return "binary %s is already extracted" % param_list[0] else: # we need to search for it in the packaged binaries directory. It may have been shipped after export for item in packaged_bin_file_list: if param_list[1]: if re.match("%s-%s.*rpm" % (param_list[0], param_list[1]), item): # package with version if not os.path.exists(os.path.join(extracted_bin_path, param_list[0],param_list[1])): os.makedirs(os.path.join(extracted_bin_path, param_list[0], param_list[1])) extract_binary(os.path.join(packaged_bin_path, item), os.path.join(extracted_bin_path, param_list[0],param_list[1])) bb.plain("Using {} for {}".format(os.path.join(packaged_bin_path, item), param_list[0])) break else: if re.match("%s-.*rpm" % param_list[0], item): found_version = re.match(".*-([0-9]+\.[0-9]+)-", item).group(1) if not os.path.exists(os.path.join(extracted_bin_path, param_list[0], found_version)): os.makedirs(os.path.join(extracted_bin_path, param_list[0], found_version)) bb.plain("Used ver. %s for %s" % (found_version, param_list[0])) extract_binary(os.path.join(packaged_bin_path, item), os.path.join(extracted_bin_path, param_list[0], found_version)) break else: bb.warn("Couldn't find target package %s%s. Please ensure it is available " "in either of these directories: extracted_binaries or packaged_binaries. " "Related tests will probably fail." % (param_list[0], " with version " + param_list[1] if param_list[1] else "")) return return "Binary %s extracted successfully." % param_list[0]
def start(self, extra_bootparams=None): bb.plain("%s - boot test image on target" % self.pn) self._start() # set the ssh object for the target/test image self.connection = sshcontrol.SSHControl(self.ip, logfile=self.sshlog, port=self.port) bb.plain("%s - start running tests" % self.pn)
def stop(self): bb.plain("%s - reboot/powercycle target" % self.pn) self.power_cycle(self.master)
def stop(self): bb.plain("%s - reboot/powercycle target" % self.pn) self.power_cycle(self.connection)
def process_binaries(d, params): param_list = params export_env = d.getVar("TEST_EXPORT_ONLY") def extract_binary(pth_to_pkg, dest_pth=None): cpio_command = runCmd("which cpio") rpm2cpio_command = runCmd("ls /usr/bin/rpm2cpio") if (cpio_command.status != 0) and (rpm2cpio_command.status != 0): bb.fatal( "Either \"rpm2cpio\" or \"cpio\" tools are not available on your system." "All binaries extraction processes will not be available, crashing all related tests." "Please install them according to your OS recommendations" ) # will exit here if dest_pth: os.chdir(dest_pth) else: os.chdir("%s" % os.sep) # this is for native package extract_bin_command = runCmd( "%s %s | %s -idm" % (rpm2cpio_command.output, pth_to_pkg, cpio_command.output) ) # semi-hardcoded because of a bug on poky's rpm2cpio return extract_bin_command if determine_if_poky_env(): # machine with poky environment exportpath = d.getVar("TEST_EXPORT_DIR", True) if export_env else d.getVar( "DEPLOY_DIR", True) rpm_deploy_dir = d.getVar("DEPLOY_DIR_RPM", True) arch = get_dest_folder(d.getVar("TUNE_FEATURES", True), os.listdir(rpm_deploy_dir)) arch_rpm_dir = os.path.join(rpm_deploy_dir, arch) extracted_bin_dir = os.path.join(exportpath, "binaries", arch, "extracted_binaries") packaged_bin_dir = os.path.join(exportpath, "binaries", arch, "packaged_binaries") # creating necessary directory structure in case testing is done in poky env. if export_env == "0": if not os.path.exists(extracted_bin_dir): bb.utils.mkdirhier(extracted_bin_dir) if not os.path.exists(packaged_bin_dir): bb.utils.mkdirhier(packaged_bin_dir) if param_list[3] == "native": if export_env == "1": #this is a native package and we only need to copy it. no need for extraction native_rpm_dir = os.path.join( rpm_deploy_dir, get_dest_folder( "{} nativesdk".format(d.getVar("BUILD_SYS")), os.listdir(rpm_deploy_dir))) native_rpm_file_list = [ item for item in os.listdir(native_rpm_dir) if re.search("nativesdk-" + param_list[0] + "-([0-9]+\.*)", item) ] if not native_rpm_file_list: bb.warn( "Couldn't find any version of {} native package. Related tests will most probably fail." .format(param_list[0])) return "" for item in native_rpm_file_list: # will copy all versions of package. Used version will be selected on remote machine bb.plain("Copying native package file: %s" % item) sh.copy( os.path.join(rpm_deploy_dir, native_rpm_dir, item), os.path.join(d.getVar("TEST_EXPORT_DIR", True), "binaries", "native")) else: # nothing to do here; running tests under bitbake, so we asume native binaries are in sysroots dir. if param_list[1] or param_list[4]: bb.warn( "Native binary %s %s%s. Running tests under bitbake environment. Version can't be checked except when the test itself does it" " and binary can't be removed." % (param_list[0], "has assigned ver. " + param_list[1] if param_list[1] else "", ", is marked for removal" if param_list[4] else "")) else: # the package is target aka DUT intended and it is either required to be delivered in an extracted form or in a packaged version target_rpm_file_list = [ item for item in os.listdir(arch_rpm_dir) if re.search(param_list[0] + "-([0-9]+\.*)", item) ] if not target_rpm_file_list: bb.warn( "Couldn't find any version of target package %s. Please ensure it was built. " "Related tests will probably fail." % param_list[0]) return "" if param_list[ 2] == "rpm": # binary should be deployed as rpm; (other, .deb, .ipk? ; in the near future) for item in target_rpm_file_list: # copying all related rpm packages. "Intuition" reasons, someone may need other versions too. Deciding later on version bb.plain("Copying target specific packaged file: %s" % item) sh.copy(os.path.join(arch_rpm_dir, item), packaged_bin_dir) return "copied" else: # it is required to extract the binary if param_list[1]: # the package is versioned for item in target_rpm_file_list: if re.match(".*-{}-.*\.rpm".format(param_list[1]), item): destination = os.path.join(extracted_bin_dir, param_list[0], param_list[1]) bb.utils.mkdirhier(destination) extract_binary(os.path.join(arch_rpm_dir, item), destination) break else: bb.warn( "Couldn't find the desired version %s for target binary %s. Related test cases will probably fail." % (param_list[1], param_list[0])) return "" return "extracted" else: # no version provided, just extract one binary destination = os.path.join( extracted_bin_dir, param_list[0], re.search(".*-([0-9]+\.[0-9]+)-.*rpm", target_rpm_file_list[0]).group(1)) bb.utils.mkdirhier(destination) extract_binary( os.path.join(arch_rpm_dir, target_rpm_file_list[0]), destination) return "extracted" else: # remote machine binaries_path = os.getenv( "bin_dir" ) # in order to know where the binaries are, bin_dir is set as env. variable if param_list[3] == "native": #need to extract the native pkg here native_rpm_dir = os.path.join(binaries_path, "native") native_rpm_file_list = os.listdir(native_rpm_dir) for item in native_rpm_file_list: if param_list[1] and re.match( "nativesdk-{}-{}-.*\.rpm".format( param_list[0], param_list[1]), item): # native package has version extract_binary(os.path.join(native_rpm_dir, item)) break else: # just copy any related native binary found_version = re.match( "nativesdk-{}-([0-9]+\.[0-9]+)-".format(param_list[0]), item).group(1) if found_version: extract_binary(os.path.join(native_rpm_dir, item)) else: bb.warn( "Couldn't find native package %s%s. Related test cases will be influenced." % (param_list[0], " with version " + param_list[1] if param_list[1] else "")) return else: # this is for target device if param_list[2] == "rpm": return "No need to extract, this is an .rpm file" arch = get_dest_folder(d.getVar("TUNE_FEATURES", True), os.listdir(binaries_path)) extracted_bin_path = os.path.join(binaries_path, arch, "extracted_binaries") extracted_bin_list = [ item for item in os.listdir(extracted_bin_path) ] packaged_bin_path = os.path.join(binaries_path, arch, "packaged_binaries") packaged_bin_file_list = os.listdir(packaged_bin_path) # see if the package is already in the extracted ones; maybe it was deployed when exported the env. if os.path.exists( os.path.join(extracted_bin_path, param_list[0], param_list[1] if param_list[1] else "")): return "binary %s is already extracted" % param_list[0] else: # we need to search for it in the packaged binaries directory. It may have been shipped after export for item in packaged_bin_file_list: if param_list[1]: if re.match( "%s-%s.*rpm" % (param_list[0], param_list[1]), item): # package with version if not os.path.exists( os.path.join(extracted_bin_path, param_list[0], param_list[1])): os.makedirs( os.path.join(extracted_bin_path, param_list[0], param_list[1])) extract_binary( os.path.join(packaged_bin_path, item), os.path.join(extracted_bin_path, param_list[0], param_list[1])) bb.plain("Using {} for {}".format( os.path.join(packaged_bin_path, item), param_list[0])) break else: if re.match("%s-.*rpm" % param_list[0], item): found_version = re.match(".*-([0-9]+\.[0-9]+)-", item).group(1) if not os.path.exists( os.path.join(extracted_bin_path, param_list[0], found_version)): os.makedirs( os.path.join(extracted_bin_path, param_list[0], found_version)) bb.plain("Used ver. %s for %s" % (found_version, param_list[0])) extract_binary( os.path.join(packaged_bin_path, item), os.path.join(extracted_bin_path, param_list[0], found_version)) break else: bb.warn( "Couldn't find target package %s%s. Please ensure it is available " "in either of these directories: extracted_binaries or packaged_binaries. " "Related tests will probably fail." % (param_list[0], " with version " + param_list[1] if param_list[1] else "")) return return "Binary %s extracted successfully." % param_list[0]
def stop(self): bb.plain("stop target") self.power_cycle()