How to use run_banner_output method in autotest

Best Python code snippet using autotest_python


Source:monitor_db_babysitter Github


Full Screen

...23 print " -r Run recovery mode. (Note: recovery is implicit after"24 print " any crash!)"25 print26 sys.exit(1)27def run_banner_output(cmd):28 """Returns ------ CMD ------\nCMD_OUTPUT in a string"""29 banner_output = '%s\n%%s\n\n' %, '-')30 command_output = ''31 try:32 cmd_out =, ignore_status=True, timeout=30)33 command_output = cmd_out.stdout + cmd_out.stderr34 except error.CmdError:35 command_output = 'Timed out'36 return banner_output % command_output37def kill_all_monitors():38"Killing all monitor_dbs")39 # try shutdown first40 status = os.system("killall -2")41 if status == 0: # were any killed?42 # give them some time to shutdown43 time.sleep(30)44 # kill any that are left45 os.system("killall")46def handle_sigterm(signum, frame):47'Caught SIGTERM')48 kill_all_monitors()49 sys.exit(1)50signal.signal(signal.SIGTERM, handle_sigterm)51class MonitorProc:52 def __init__(self, do_recovery=False):53 args = [monitor_db]54 if do_recovery:55 args.append("--recover-hosts")56 args.append(results_dir)57 kill_all_monitors()58 environ = os.environ59 scheduler_config = scheduler_logging_config.SchedulerLoggingConfig60 log_name = scheduler_config.get_log_name()61 os.environ['AUTOTEST_SCHEDULER_LOG_NAME'] = log_name62 scheduler_log_dir = scheduler_config.get_server_log_dir()63 self.log_path = os.path.join(scheduler_log_dir, log_name)64 self.log_size = 065 self.last_log_change = time.time()66"STARTING monitor_db with log file %s" % self.log_path)67 devnull = open(os.devnull, 'w')68 self.proc = subprocess.Popen(args, stdout=devnull)69 def is_running(self):70 if self.proc.poll() is not None:71"monitor_db DIED")72 return False73 old_size = self.log_size74 new_size = os.path.getsize(self.log_path)75 if old_size != new_size:76"Log was touched")77 self.log_size = new_size78 self.last_log_change = time.time()79 elif self.last_log_change + STALL_TIMEOUT < time.time():80"monitor_db STALLED")81 self.collect_stalled_info()82 return False83 return True84 def collect_stalled_info(self):85 INFO_TO_COLLECT = ['uptime',86 'ps auxwww',87 'iostat -k -x 2 4',88 ]89 db_cmd = '/usr/bin/mysqladmin --verbose processlist -u%s -p%s'90 config = global_config.global_config91 try:92 user = config.get_config_value("BACKUP", "user")93 password = config.get_config_value("BACKUP", "password")94 db_cmd %= (user, password)95 INFO_TO_COLLECT.append(db_cmd)96 except global_config.ConfigError:97 pass98 stall_log_path = self.log_path + '.stall_info'99 log = open(stall_log_path, "w")100 for cmd in INFO_TO_COLLECT:101 log.write(run_banner_output(cmd))102 log.close()"initializing")104if os.getuid() == 0:105 logging.critical("running as root, aborting!")106 sys.exit(1)107utils.write_pid("monitor_db_babysitter")108while True:109 proc = MonitorProc(do_recovery=recover)110 time.sleep(PAUSE_LENGTH)111 while proc.is_running():112"Tick")113 time.sleep(PAUSE_LENGTH)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:


You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?