def run(self, commands=None, command_file=None, parser=None, timeout=-1, repeat_count=0): """ :param commands: a list of commands :param command_file: a file containing commands :param parser: The parser to use for the test :param timeout: The timeout to apply. """ # Make sure in test image now self.check_lava_android_test_installed() if commands or command_file: with self.client.android_tester_session() as session: bundle_name = generate_bundle_file_name('custom') cmds = ["lava-android-test", 'run-custom'] if commands: for command in commands: cmds.extend(['-c', command]) elif command_file: cmds.extend(['-f', command_file]) else: raise OperationFailed( "Only one of the -c and -f option can be specified" " for lava_android_test_run_custom action") cmds.extend([ '-s', session.dev_name, '-o', '%s/%s.bundle' % (self.context.host_result_dir, bundle_name) ]) if parser is not None: cmds.extend(['-p', parser]) if timeout != -1: cmds.insert(0, 'timeout') cmds.insert(1, '%ss' % timeout) logging.info("Execute command on host: %s" % (' '.join(cmds))) rc = self.context.run_command(cmds) if rc == 124: raise TimeoutError( "The test (%s) on device(%s) timed out." % (' '.join(cmds), session.dev_name)) elif rc != 0: raise OperationFailed( "Failed to run test custom case[%s] on device(%s)" " with return value: %s" % (' '.join(cmds), session.dev_name, rc))
def _enter_mcc(self): match_id = self.proc.expect([ self.config.wg_stop_autoboot_prompt, pexpect.EOF, pexpect.TIMEOUT ], timeout=120) if match_id != 0: msg = 'Unable to intercept MCC boot prompt' logging.error(msg) raise OperationFailed(msg) self.proc.sendline("") match_id = self.proc.expect(['Cmd>', pexpect.EOF, pexpect.TIMEOUT], timeout=120) if match_id != 0: msg = 'MCC boot prompt not found' logging.error(msg) raise OperationFailed(msg)
def run(self, test_name, option=None, timeout=-1, repeat_count=0): # Make sure in test image now self.check_lava_android_test_installed() with self.client.android_tester_session() as session: bundle_name = generate_bundle_file_name(test_name) cmds = [ "lava-android-test", 'run', test_name, '-s', session.dev_name, '-o', '%s/%s.bundle' % (self.context.host_result_dir, bundle_name) ] if option is not None: cmds.extend(['-O', option]) if timeout != -1: cmds.insert(0, 'timeout') cmds.insert(1, '%ss' % timeout) t = DrainConsoleOutput(proc=session._connection, timeout=timeout) t.start() logging.info("Execute command on host: %s" % (' '.join(cmds))) rc = self.context.run_command(cmds) t.join() if rc == 124: raise TimeoutError( "The test case(%s) on device(%s) timed out" % (test_name, session.dev_name)) elif rc != 0: raise OperationFailed( "Failed to run test case(%s) on device(%s) with return " "value: %s" % (test_name, session.dev_name, rc))
def _mount_usbmsd(self, mount_point): self.proc.sendline("USB_ON") self.proc.expect(['Cmd>']) # wait a few seconds so that the kernel on the host detects the USB # mass storage interface exposed by the Vexpress sleep(5) usb_device = self.config.vexpress_usb_mass_storage_device # Try to mount the MMC device. If we detect a failure when mounting. Toggle # the USB MSD interface, and try again. If we fail again, raise an OperationFailed # except to retry to the boot process. if self.context.run_command('mount %s %s' % (usb_device, mount_point)) != 0: self.proc.sendline("USB_OFF") self.proc.expect(['Cmd>']) self.proc.sendline("USB_ON") self.proc.expect(['Cmd>']) sleep(5) if self.context.run_command('mount %s %s' % (usb_device, mount_point)) != 0: msg = "Failed to mount MMC on host" logging.exception(msg) raise OperationFailed(msg)
def submit_group_list(self, bundle, server, stream, token, group_name): """ Called from the dispatcher job when a MultiNode job has been allowed by the coordinator to aggregate the group bundles as all jobs in the group have registered bundle checksums with the coordinator. :param bundle: The single bundle from this job to be added to the pending list. :param server: Where the aggregated bundle will be submitted :param stream: The bundle stream to use :param token: The token to allow access :param group_name: MultiNode group unique ID :raise: OperationFailed if the xmlrpclib call fails """ dashboard = _get_dashboard(server, token) json_bundle = simplejson.dumps(bundle) job_name = self.context.job_data.get("job_name", "LAVA Results") try: # make the put_group xmlrpc call to aggregate the bundles for the entire group & submit. result = dashboard.put_group(json_bundle, job_name, stream, group_name) print >> self.context.oob_file, "dashboard-group:", result, job_name self.context.output.write_named_data('result-bundle', result) logging.info("Dashboard: bundle %s is to be aggregated into %s" % (result, group_name)) except xmlrpclib.Fault, err: logging.warning("xmlrpclib.Fault occurred") logging.warning("Fault code: %d" % err.faultCode) logging.warning("Fault string: %s" % err.faultString) raise OperationFailed("could not push group bundle to dashboard")
def power_on(self): try: if self._booted and self._target_type != 'android': self._setup_prompt() return self.proc self._enter_fastboot() if self._use_boot_cmds: boot_cmds = self._load_boot_cmds( default=self.driver.get_default_boot_cmds(), boot_tags=self.driver.get_boot_tags()) self.driver.boot(boot_cmds) else: self.driver.boot() if self.proc is None: self.proc = self.driver.connect() if self.config.run_boot_cmds: self._enter_bootloader(self.proc) boot_cmds = self._load_boot_cmds( default=self.driver.get_default_boot_cmds(), boot_tags=self.driver.get_boot_tags()) self._customize_bootloader(self.proc, boot_cmds) self._monitor_boot(self.proc, self.tester_ps1, self.tester_ps1_pattern) if self.config.start_fastboot_command and not \ self.config.android_adb_over_tcp: self.driver.wait_for_adb() self._booted = True return self.proc except subprocess.CalledProcessError: logging.info("Infrastructure Error: fastboot exception caught.") msg = 'Fastboot boot failed' raise OperationFailed(msg)
def _soft_reboot(self, connection): logging.info("Perform soft reboot the system") # Try to C-c the running process, if any. connection.sendcontrol('c') connection.sendline(self.config.soft_boot_cmd) # Looking for reboot messages or if they are missing, the U-Boot # message will also indicate the reboot is done. match_id = connection.expect( [pexpect.TIMEOUT, 'Restarting system.', 'The system is going down for reboot NOW', 'Will now restart', 'U-Boot'], timeout=120) if match_id == 0: raise OperationFailed("Soft reboot failed")
def power_on(self): sdmux.host_disconnect(self.config.sdmux_id) sdmux.dut_usda(self.config.sdmux_id) logging.info('powering on') try: self.context.run_command(self.config.hard_reset_command) self._run_boot() except KeyboardInterrupt: raise KeyboardInterrupt except: raise OperationFailed("_run_boot failed") return self.proc
def run(self, tests, option=None, timeout=2400): self.check_lava_android_test_installed() with self.client.android_tester_session() as session: for test in tests: cmds = [ "lava-android-test", 'install', test, '-s', session.dev_name ] if option is not None: cmds.extend(['-o', option]) if timeout != -1: cmds.insert(0, 'timeout') cmds.insert(1, '%ss' % timeout) logging.info("Execute command on host: %s" % (' '.join(cmds))) rc = self.context.run_command(cmds) if rc == 124: raise OperationFailed("The installation of test case(%s)" " on device(%s) timed out" % (test, session.dev_name)) elif rc != 0: raise OperationFailed( "Failed to install test case(%s) on device(%s) with " "return value: %s" % (test, session.dev_name, rc))
def _get_dashboard(server, token): if not server.endswith("/"): server = ''.join([server, "/"]) # add backward compatible for 'dashboard/'-end URL # Fix it: it's going to be deleted after transition if server.endswith("dashboard/"): server = ''.join([server, "xml-rpc/"]) logging.warning( "Please use whole endpoint URL not just end with 'dashboard/', " "'xml-rpc/' is added automatically now!!!") parsed_server = urlparse.urlparse(server) auth_backend = MemoryAuthBackend([]) if parsed_server.username: if token: userless_server = '%s://%s' % (parsed_server.scheme, parsed_server.hostname) if parsed_server.port: userless_server += ':' + str(parsed_server.port) userless_server += parsed_server.path auth_backend = MemoryAuthBackend([(parsed_server.username, userless_server, token)]) else: logging.warning( "specifying a user without a token is unlikely to work") else: if token: logging.warning( "specifying a token without a user is probably useless") srv = AuthenticatingServerProxy(server, allow_none=True, use_datetime=True, auth_backend=auth_backend) if server.endswith("xml-rpc/"): logging.error( "Please use RPC2 endpoint instead, xml-rpc is no longer supported") raise OperationFailed("xml-rpc endpoint is not supported.") elif server.endswith("RPC2/"): # include lava-server/RPC2/ dashboard = srv.dashboard else: logging.warning( "The url seems not RPC2 or xml-rpc endpoints, please make sure it's a valid one!!!" ) dashboard = srv.dashboard logging.debug("server RPC endpoint URL: %s" % server) return dashboard
def submit_bundle(self, main_bundle, server, stream, token): dashboard = _get_dashboard(server, token) json_bundle = DocumentIO.dumps(main_bundle) job_name = self.context.job_data.get('job_name', "LAVA Results") job_name = urllib2.quote(job_name.encode('utf-8')) try: result = dashboard.put_ex(json_bundle, job_name, stream) self.context.output.write_named_data('result-bundle', result) logging.info("Dashboard : %s" % result) except xmlrpclib.Fault, err: logging.warning("xmlrpclib.Fault occurred") logging.warning("Fault code: %d" % err.faultCode) logging.warning("Fault string: %s" % err.faultString) raise OperationFailed("could not push to dashboard")
def run(self, test_name, test_options="", timeout=-1): self.context.any_device_bundles = True logging.info("Executing lava_test_run %s command" % test_name) with self.client.tester_session() as session: session.run('mkdir -p %s' % self.context.config.lava_result_dir) session.export_display() bundle_name = generate_bundle_file_name(test_name) if test_options != "": test_options = "-t '%s'" % test_options cmd = ('lava-test run %s %s -o %s/%s.bundle' % (test_name, test_options, self.context.config.lava_result_dir, bundle_name)) try: rc = session.run(cmd, timeout=timeout) except KeyboardInterrupt: raise KeyboardInterrupt except: logging.exception("session.run failed") self.client.proc.sendcontrol('c') try: session.run('true', timeout=20) except KeyboardInterrupt: raise KeyboardInterrupt except: logging.exception("killing test failed, rebooting") self.client.boot_linaro_image() raise finally: # try to make sure the test bundle is safely written to disk session.run('sync', timeout=60) if rc is None: raise OperationFailed("test case getting return value failed") elif rc != 0: raise OperationFailed( "test case failed with return value: %s" % rc)
def _setup_adb_over_tcp(self): logging.info("adb connect over default network interface") self.dev_ip = self.get_default_nic_ip() if self.dev_ip is None: raise OperationFailed("failed to get board ip address") try: # just disconnect the adb connection in case is remained # by last action or last job # that connection should be expired already self.android_adb_over_tcp_disconnect() except KeyboardInterrupt: raise KeyboardInterrupt except: # ignore all exception # this just in case of exception pass self.android_adb_over_tcp_connect() self.wait_until_attached()
def run_command_with_retries(self, command): retries = 0 successful = False error = None num_retries = self.config.host_command_retries while (retries < num_retries) and (not successful): try: self.run_command(command, failok=False) except CalledProcessError as e: error = e retries += 1 sleep(1) continue successful = True if not successful: msg = "Failed to execute command '%s' on host (%s)" % (command, error) logging.exception(msg) raise OperationFailed(msg)
def submit_pending(self, bundle, server, stream, token, group_name): """ Called from the dispatcher job when a MultiNode job requests to submit results but the job does not have sub_id zero. The bundle is cached in the dashboard until the coordinator allows sub_id zero to call submit_group_list. :param bundle: A single bundle which is part of the group :param server: Where the bundle will be cached :param token: token to allow access :param group_name: MultiNode group unique ID :raise: OperationFailed if the xmlrpclib call fails """ dashboard = _get_dashboard(server, token) json_bundle = simplejson.dumps(bundle) try: # make the put_pending xmlrpc call to store the bundle in the dashboard until the group is complete. result = dashboard.put_pending(json_bundle, stream, group_name) print >> self.context.oob_file, "dashboard-put-pending:", result logging.info("Dashboard: bundle %s is pending in %s" % (result, group_name)) except xmlrpclib.Fault, err: logging.warning("xmlrpclib.Fault occurred") logging.warning("Fault code: %d" % err.faultCode) logging.warning("Fault string: %s" % err.faultString) raise OperationFailed("could not push pending bundle to dashboard")
def run(self, url=None, timeout=-1, repeat_count=0): # Make sure in test image now self.check_lava_android_test_installed() with self.client.android_tester_session() as session: bundle_name = generate_bundle_file_name('monkeyrunner') cmds = ["lava-android-test", 'run-monkeyrunner', url] cmds.extend([ '-s', session.dev_name, '-o', '%s/%s.bundle' % (self.context.host_result_dir, bundle_name) ]) if timeout != -1: cmds.insert(0, 'timeout') cmds.insert(1, '%ss' % timeout) logging.info("Execute command on host: %s" % (' '.join(cmds))) rc = self.context.run_command(cmds) if rc == 124: raise TimeoutError( "Failed to run monkeyrunner test url[%s] on device(%s)" % (url, session.dev_name)) elif rc != 0: raise OperationFailed( "Failed to run monkeyrunner test url[%s] on device(%s)" " with return value: %s" % (url, session.dev_name, rc))
def power_on(self): try: if self._booted and self._target_type != 'android': self._setup_prompt() return self.proc self._enter_fastboot() if self._use_boot_cmds: boot_cmds = ''.join( self._load_boot_cmds( default=self.driver.get_default_boot_cmds())) self.driver.boot(boot_cmds) else: self.driver.boot() if self.proc is None: self.proc = self.driver.connect() self._auto_login(self.proc) self._wait_for_prompt(self.proc, self.config.test_image_prompts, self.config.boot_linaro_timeout) self._setup_prompt() self._booted = True return self.proc except subprocess.CalledProcessError: msg = 'Fastboot boot failed' raise OperationFailed(msg)
def check_lava_android_test_installed(self): rc = os.system('which lava-android-test') if rc != 0: raise OperationFailed('lava-android-test has not been installed')