How to use program_is_alive method in autotest

Best Python code snippet using autotest_python

openvswitch.py

Source:openvswitch.py Github

copy

Full Screen

...286 def check_db_daemon(self):287 """288 Check if OVS daemon is started correctly.289 """290 working = utils_misc.program_is_alive(291 "ovsdb-server", self.pid_files_path)292 if not working:293 logging.error("OpenVSwitch database daemon with PID in file %s"294 " not working.", self.db_pidfile)295 return working296 def check_switch_daemon(self):297 """298 Check if OVS daemon is started correctly.299 """300 working = utils_misc.program_is_alive(301 "ovs-vswitchd", self.pid_files_path)302 if not working:303 logging.error("OpenVSwitch switch daemon with PID in file %s"304 " not working.", self.ovs_pidfile)305 return working306 def check_db_file(self):307 """308 Check if db_file exists.309 """310 exists = os.path.exists(self.db_path)311 if not exists:312 logging.error("OpenVSwitch database file %s not exists.",313 self.db_path)314 return exists315 def check_db_socket(self):316 """317 Check if db socket exists.318 """319 exists = os.path.exists(self.db_socket)320 if not exists:321 logging.error("OpenVSwitch database socket file %s not exists.",322 self.db_socket)323 return exists324 def check(self):325 return (self.check_db_daemon() and self.check_switch_daemon() and326 self.check_db_file() and self.check_db_socket())327 def init_system(self):328 """329 Create new dbfile without any configuration.330 """331 sm = factory(ServiceManager)()332 try:333 if linux_modules.load_module("openvswitch"):334 sm.restart("openvswitch")335 except process.CmdError:336 logging.error("Service OpenVSwitch is probably not"337 " installed in system.")338 raise339 self.pid_files_path = "/var/run/openvswitch/"340 def clean(self):341 """342 Empty cleanup function343 """344 pass345class OpenVSwitch(OpenVSwitchSystem):346 """347 OpenVSwtich class.348 """349 def __init__(self, tmpdir, db_path=None, db_socket=None, db_pidfile=None,350 ovs_pidfile=None, dbschema=None, install_prefix=None):351 """352 Makes initialization of OpenVSwitch.353 :param tmpdir: Tmp directory for save openvswitch test files.354 :param db_path: Path of OVS database.355 :param db_socket: Path of OVS db socket.356 :param db_pidfile: Path of OVS db ovsdb-server pid.357 :param ovs_pidfile: Path of OVS ovs-vswitchd pid.358 :param install_prefix: Path where is openvswitch installed.359 """360 super(man[self, OpenVSwitch], self).__init__(db_path, db_socket,361 db_pidfile, ovs_pidfile,362 dbschema, install_prefix)363 self.tmpdir = "/%s/openvswitch" % (tmpdir)364 try:365 os.mkdir(self.tmpdir)366 except OSError, e:367 if e.errno != 17:368 raise369 def init_db(self):370 process.run('%s %s %s %s' %371 (path.find_command("ovsdb-tool"), "create",372 self.db_path, self.dbschema))373 process.run('%s %s %s %s %s' %374 (path.find_command("ovsdb-server"),375 "--remote=punix:%s" % (self.db_socket),376 "--remote=db:Open_vSwitch,manager_options",377 "--pidfile=%s" % (self.db_pidfile),378 "--detach"))379 self.ovs_vsctl(["--no-wait", "init"])380 def start_ovs_vswitchd(self):381 process.run('%s %s %s %s' %382 (path.find_command("ovs-vswitchd"),383 "--detach",384 "--pidfile=%s" % self.ovs_pidfile,385 "unix:%s" % self.db_socket))386 def init_new(self):387 """388 Create new dbfile without any configuration.389 """390 self.db_path = os.path.join(self.tmpdir, "conf.db")391 self.db_socket = os.path.join(self.tmpdir, "db.sock")392 self.db_pidfile = utils_misc.get_pid_path("ovsdb-server")393 self.ovs_pidfile = utils_misc.get_pid_path("ovs-vswitchd")394 self.dbschema = "/usr/share/openvswitch/vswitch.ovsschema"395 self.cleanup = True396 sm = ServiceManager()397 # Stop system openvswitch398 try:399 sm.stop("openvswitch")400 except process.CmdError:401 pass402 linux_modules.load_module("openvswitch")403 self.clean()404 if os.path.exists(self.db_path):405 os.remove(self.db_path)406 self.init_db()407 self.start_ovs_vswitchd()408 def clean(self):409 logging.debug("Killall ovsdb-server")410 utils_misc.signal_program("ovsdb-server")411 if utils_misc.program_is_alive("ovsdb-server"):412 utils_misc.signal_program("ovsdb-server", signal.SIGKILL)413 logging.debug("Killall ovs-vswitchd")414 utils_misc.signal_program("ovs-vswitchd")415 if utils_misc.program_is_alive("ovs-vswitchd"):...

Full Screen

Full Screen

monitor_db_babysitter

Source:monitor_db_babysitter Github

copy

Full Screen

...38def kill_monitor():39 logging.info("Killing monitor_db")40 # try shutdown first41 utils.signal_program(monitor_db.PID_FILE_PREFIX, sig=signal.SIGINT)42 if utils.program_is_alive(monitor_db.PID_FILE_PREFIX): # was it killed?43 # give it some time to shutdown44 time.sleep(30)45 # kill it46 utils.signal_process(monitor_db.PID_FILE_PREFIX)47def handle_sigterm(signum, frame):48 logging.info('Caught SIGTERM')49 kill_monitor()50 utils.delete_pid_file_if_exists(monitor_db.BABYSITTER_PID_FILE_PREFIX)51 sys.exit(1)52signal.signal(signal.SIGTERM, handle_sigterm)53SiteMonitorProc = utils.import_site_class(54 __file__, 'autotest_lib.scheduler.site_monitor_db_babysitter',55 'SiteMonitorProc', object)56class MonitorProc(SiteMonitorProc):57 def __init__(self, do_recovery=False):58 args = [monitor_db_path]59 if do_recovery:60 args.append("--recover-hosts")61 args.append(results_dir)62 kill_monitor()63 environ = os.environ64 scheduler_config = scheduler_logging_config.SchedulerLoggingConfig65 log_name = scheduler_config.get_log_name()66 os.environ['AUTOTEST_SCHEDULER_LOG_NAME'] = log_name67 scheduler_log_dir = scheduler_config.get_server_log_dir()68 self.log_path = os.path.join(scheduler_log_dir, log_name)69 self.log_size = 070 self.last_log_change = time.time()71 logging.info("STARTING monitor_db with log file %s" % self.log_path)72 self.args = args73 # Allow site specific code to run, set environment variables and74 # modify self.args if desired.75 super(MonitorProc, self).__init__()76 def start(self):77 devnull = open(os.devnull, 'w')78 self.proc = subprocess.Popen(self.args, stdout=devnull)79 def is_running(self):80 if self.proc.poll() is not None:81 logging.info("monitor_db DIED")82 return False83 old_size = self.log_size84 new_size = os.path.getsize(self.log_path)85 if old_size != new_size:86 logging.info("Log was touched")87 self.log_size = new_size88 self.last_log_change = time.time()89 elif self.last_log_change + STALL_TIMEOUT < time.time():90 logging.info("monitor_db STALLED")91 self.collect_stalled_info()92 return False93 return True94 def collect_stalled_info(self):95 INFO_TO_COLLECT = ['uptime',96 'ps auxwww',97 'iostat -k -x 2 4',98 ]99 db_cmd = '/usr/bin/mysqladmin --verbose processlist -u%s -p%s'100 config = global_config.global_config101 try:102 user = config.get_config_value("BACKUP", "user")103 password = config.get_config_value("BACKUP", "password")104 db_cmd %= (user, password)105 INFO_TO_COLLECT.append(db_cmd)106 except global_config.ConfigError:107 pass108 stall_log_path = self.log_path + '.stall_info'109 log = open(stall_log_path, "w")110 for cmd in INFO_TO_COLLECT:111 log.write(run_banner_output(cmd))112 log.close()113logging.info("initializing")114if os.getuid() == 0:115 logging.critical("running as root, aborting!")116 sys.exit(1)117if utils.program_is_alive(monitor_db.BABYSITTER_PID_FILE_PREFIX):118 logging.critical("monitor_db_babysitter already running, aborting!")119 sys.exit(1)120utils.write_pid(monitor_db.BABYSITTER_PID_FILE_PREFIX)121while True:122 proc = MonitorProc(do_recovery=recover)123 proc.start()124 time.sleep(PAUSE_LENGTH)125 while proc.is_running():126 logging.info("Tick")127 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:

YouTube

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?

Helpful

NotHelpful