def sudo(cmd): '''sudo command automatically input password''' cmd = 'sudo ' + cmd msger.info(cmd) expecting = [('[p|P]assword', settings.SUDO_PASSWD)] return pcall(cmd, expecting=expecting, timeout=60, output=sys.stdout)
def _thread(): while 1: if to_die.wait(interval): break #FIXME: eliminate the message print out every interval make_report(local_path) if rsync(local_path, remote_path) != 0: msger.warning('sync thread exit, please sync manually') break msger.info('sync thread exit')
def _acquire_lock(self): if os.path.exists(self.lockname): return False # race condition here, but i simply ignore this path = self.workdir if os.path.exists(path): msger.info('removing old test space %s' % path) if sudo('rm -rf %s' % path) != 0: msger.error("can't clean old workspace, please fix manually") os.mkdir(path) open(self.lockname, 'w').close() self._locked = True return True
def run_test(args): env = TestEnv(settings) loader = TestLoader() suite = loader.load_args(args.cases, env) if suite.count < 1: print 'No case found' return space = TestSpace(settings.WORKSPACE) if not space.setup(suite, env): return to_upload = args.auto_sync or args.url if to_upload: url = transform_url(args.url) mkdir_in_remote(url) if args.auto_sync: msger.info('automatically upload report ot %s' % url) to_die = Event() thread = start_sync_worker(space.logdir, url, to_die, args.interval) def make_report_and_upload(): if args.auto_sync: to_die.set() thread.join() make_report(space.logdir) if to_upload: rsync(space.logdir, url) runner = TextTestRunner(args.verbose) try: runner.run(suite, space, env) except KeyboardInterrupt: print '\nAbort!' finally: make_report_and_upload()