def try_flash_model(self, args): ''' Reserve and flash a machine. By default it tries to flash 2 times, Args: args: AFT arguments Returns: device, tester: Reserved machine and tester handles. ''' device = self.reserve() if args.testplan: device.test_plan = args.testplan tester = Tester(device) if args.record: device.record_serial() if not self.check_libcomposite_service_running(): self.stop_image_usb_emulation(device.leases_file_name) if args.emulateusb: self.start_image_usb_emulation(args, device.leases_file_name) inject_ssh_keys_to_image(args.file_name) return device, tester if args.noflash: return device, tester flash_attempt = 0 flash_retries = args.flash_retries while flash_attempt < flash_retries: flash_attempt += 1 try: print("Flashing " + str(device.name) + ", attempt " + str(flash_attempt) + " of " + str(flash_retries) + ".") device.write_image(args.file_name) print("Flashing successful.") return device, tester except KeyboardInterrupt: raise except: _err = sys.exc_info() _err = str(_err[0]).split("'")[1] + ": " + str(_err[1]) logger.error(_err) print(_err) if (flash_retries - flash_attempt) == 0: print("Flashing failed " + str(flash_attempt) + " times") self.release(device) raise elif (flash_retries - flash_attempt) == 1: print("Flashing failed, trying again one more time") elif (flash_retries - flash_attempt) > 1: print("Flashing failed, trying again " + str(flash_retries - flash_attempt) + " more times")
def worker(results): os.chdir(os.path.join(image_directory_path, "iottest")) # nuke test logs for f in os.listdir("."): if "ssh_target_log" in f: os.remove(f) os.chdir(image_directory_path) ## Remove all log and xml files from previous run to prevent clutter #for f in os.listdir("."): # if f.endswith(".log") or f.endswith(".xml"): # os.remove(f) device.write_image(image) tester = Tester(device) tester.execute() results.put((tester.get_results(), tester.get_results_str()))
def try_flash_specific(self, args): ''' Reserve and flash specific device. Args: args: AFT arguments Returns: device, tester: Reserved machine and tester handles. ''' device = self.reserve_specific(args.device, model=args.machine) tester = Tester(device) if args.record: device.record_serial() if not args.noflash: print("Flashing " + str(device.name) + ".") device.write_image(args.file_name) print("Flashing successful.") return device, tester
def main(argv=None): """ Entry point for library-like use. """ config.parse() logging.basicConfig(filename=config.AFT_LOG_NAME, level=logging.INFO, format='%(asctime)s - %(name)s - ' '%(levelname)s - %(message)s') if argv != None: backup_argv = sys.argv sys.argv = argv args = parse_args() if args.configure: builder = TopologyBuilder(args) builder.build_topology() return 0 if args.check: results = device_config.check(args) logging.info(results[1]) print results[1] if results[0] == True: return 0 else: return 1 elif args.checkall: results = device_config.check_all(args) logging.info(results[1]) print results[1] if results[0] == True: logging.info("All tests passed") return 0 else: logging.info("There were failures") return 1 device_manager = DevicesManager(args) if args.blacklist: if not args.device: print "Device must be specified for blacklisting" return 1 device_manager.blacklist_device(args.device, args.reason) return 0 if args.recover_edisons: recover_edisons(device_manager, args.verbose) return 0 if not args.machine or not args.file_name: print "Both machine and image must be specified" return 1 device = device_manager.reserve() tester = Tester(device) if args.record: device.record_serial() if not args.noflash: print "Flashing " + str(device.name) + "." device.write_image(args.file_name) if not args.notest: tester.execute() if not args.nopoweroff: device.detach() if "backup_argv" in locals(): sys.argv = backup_argv return 0
def test(self): """ Runs the tests associated with the specified image. """ return Tester.test(device=self)
def try_flash_model(args, device_manager): ''' Reserve and flash a machine. By default it tries to flash 2 times with 2 different machines. If flashing fails machine will be blacklisted. Args: args: AFT arguments device_manager: Device manager object Returns: device, tester: Reserved machine and tester handles. ''' machine_attempt = 0 machine_retries = args.machine_retries while machine_attempt < machine_retries: machine_attempt += 1 device = device_manager.reserve() tester = Tester(device) if args.record: device.record_serial() if args.noflash: return device, tester flash_attempt = 0 flash_retries = args.flash_retries while flash_attempt < flash_retries: flash_attempt += 1 try: print("Flashing " + str(device.name) + ", attempt " + str(flash_attempt) + " of " + str(flash_retries) + ".") device.write_image(args.file_name) print("Flashing successful.") return device, tester except KeyboardInterrupt: raise except: _err = sys.exc_info() _err = str(_err[0]).split("'")[1] + ": " + str(_err[1]) logger.error(_err) print(_err) if (flash_retries - flash_attempt) == 0: msg = "Flashing failed " + str(flash_attempt) + " times" print(msg + ", blacklisting " + str(device.name)) logger.info(msg + ", blacklisting " + str(device.name)) common.blacklist_device(device.dev_id, device.name, msg) device_manager.release(device) if machine_attempt < machine_retries: print("Attempting flashing another machine") else: raise elif (flash_retries - flash_attempt) == 1: print("Flashing failed, trying again one more time") elif (flash_retries - flash_attempt) > 1: print("Flashing failed, trying again " + str(flash_retries - flash_attempt) + " more times")