Best Python code snippet using autotest_python
externalstandby.py
Source:externalstandby.py
1# -*- coding: utf-8 -*- 2#3# Description:4#5# Definiton6#7#8#9# Changes:10#11# 2012-01-1012# Initial Commit13#14#15# Copyright 2010-2012, WyDev Team.16# Author: Polo35 (polo35580@hotmail.fr)17#18# Licenced under Academic Free License version 3.019# Review WyGui README & LICENSE files for further details.20nname: 021n 0(None)[self.wdb = wydb22self.scheduler = scheduler23self.ref_wystandby = self.wdb.reference(config.standby_dbus_bus_name, config.standby_dbus_path_name)24self._AddStandbyModule = self.ref_wystandby.method('AddStandbyModule', 's', 's')25self._RemoveStandbyModule = self.ref_wystandby.method('RemoveStandbyModule', 's', 'i')26self.SetMaxPowerState = self.ref_wystandby.method('NotifyNewMaxPowerState', 'si', '')27self.SetPowerState = self.ref_wystandby.method('NotifyPowerStateChanged', 'si', '')28self.SetAlarm = self.ref_wystandby.method('SetAlarm', 'x', '')29]:30 i: 31 o: 32self.nodes: {0: <unpyclib.structure.node instance at 0xb76ab98c>}33nname: 6034n 60(None)[return id35]:36 i: 3(), 30(), 58(AE)37 o: 38nname: 5839n 58(None)[]:40 i: 20(f)41 o: 60(AE)42nname: 3043n 30(None)[#, e44log.debug(str(e))45]:46 i: 20(t)47 o: 60()48nname: 2049n 20(<dummy_ex3> EXC_MATCH BaseException)[]:50 i: 0(except)51 o: 30(t), 58(f)52nname: 353n 3(None)[return self._AddStandbyModule(id)54]:55 i: 0(try)56 o: 60()57nname: 058n 0(None)[]:59 i: 60 o: 3(try), 20(except)61nname: 2062n 20(None)[except BaseException, e:63 log.debug(str(e))64return id65]:66 i: 0()67 o: 68nname: 069n 0(None)[try:70 return self._AddStandbyModule(id)71]:72 i: 73 o: 20()74nname: 075n 0(None)[try:76 return self._AddStandbyModule(id)77except BaseException, e:78 log.debug(str(e))79return id80]:81 i: 82 o: 83self.nodes: {0: <unpyclib.structure.node instance at 0xb76a6fac>}84nname: 6085n 60(None)[return 086]:87 i: 3(), 30(), 58(AE)88 o: 89nname: 5890n 58(None)[]:91 i: 20(f)92 o: 60(AE)93nname: 3094n 30(None)[#, e95log.debug(str(e))96]:97 i: 20(t)98 o: 60()99nname: 20100n 20(<dummy_ex3> EXC_MATCH BaseException)[]:101 i: 0(except)102 o: 30(t), 58(f)103nname: 3104n 3(None)[return self._RemoveStandbyModule(id)105]:106 i: 0(try)107 o: 60()108nname: 0109n 0(None)[]:110 i: 111 o: 3(try), 20(except)112nname: 20113n 20(None)[except BaseException, e:114 log.debug(str(e))115return 0116]:117 i: 0()118 o: 119nname: 0120n 0(None)[try:121 return self._RemoveStandbyModule(id)122]:123 i: 124 o: 20()125nname: 0126n 0(None)[try:127 return self._RemoveStandbyModule(id)128except BaseException, e:129 log.debug(str(e))130return 0131]:132 i: 133 o: 134self.nodes: {0: <unpyclib.structure.node instance at 0xb76a6fcc>}135nname: 0136n 0(None)[log.debug('StateReadySignal')137self.scheduler.AsynchronousCheckSchedule()138self.SetPowerState(config.wystandby_id, APM_STATE_READY)139]:140 i: 141 o: 142self.nodes: {0: <unpyclib.structure.node instance at 0xb76a6fcc>}143nname: 0144n 0(None)[log.debug('StateStandbySignal')145self.SetPowerState(config.wystandby_id, APM_STATE_STANDBY)146]:147 i: 148 o: 149self.nodes: {0: <unpyclib.structure.node instance at 0xb76a6e4c>}150nname: 68151n 68(None)[]:152 i: 25(), 48()153 o: 154nname: 48155n 48(None)[self.SetPowerState(config.wystandby_id, APM_STATE_STANDBY)156]:157 i: 0(f)158 o: 68()159nname: 25160n 25(None)[self.SetPowerState(config.wystandby_id, APM_STATE_SUSPEND)161]:162 i: 0(t)163 o: 68()164nname: 0165n 0(self._ExternalStandby__is_standby_ready())[log.debug('StateSuspendSignal')166]:167 i: 168 o: 25(t), 48(f)169nname: 0170n 0(None)[log.debug('StateSuspendSignal')171if self._ExternalStandby__is_standby_ready():172 self.SetPowerState(config.wystandby_id, APM_STATE_SUSPEND)173else:174 self.SetPowerState(config.wystandby_id, APM_STATE_STANDBY)175]:176 i: 177 o: 178self.nodes: {0: <unpyclib.structure.node instance at 0xb76a6f2c>}179nname: 68180n 68(None)[]:181 i: 25(), 48()182 o: 183nname: 48184n 48(None)[self.SetPowerState(config.wystandby_id, APM_STATE_STANDBY)185]:186 i: 0(f)187 o: 68()188nname: 25189n 25(None)[self.SetPowerState(config.wystandby_id, APM_STATE_OFF)190]:191 i: 0(t)192 o: 68()193nname: 0194n 0(self._ExternalStandby__is_standby_ready())[log.debug('StateOffSignal')195]:196 i: 197 o: 25(t), 48(f)198nname: 0199n 0(None)[log.debug('StateOffSignal')200if self._ExternalStandby__is_standby_ready():201 self.SetPowerState(config.wystandby_id, APM_STATE_OFF)202else:203 self.SetPowerState(config.wystandby_id, APM_STATE_STANDBY)204]:205 i: 206 o: 207self.nodes: {0: <unpyclib.structure.node instance at 0xb76a6fac>}208nname: 111209n 111(None)[return True210]:211 i: 94(), 110()212 o: 213nname: 110214n 110(None)[]:215 i: 24(f)216 o: 111()217nname: 94218n 94(None)[self.SetAlarm(time)219]:220 i: 55(), 75()221 o: 111()222nname: 75223n 75(None)[time = int(time.time())224]:225 i: 45(f)226 o: 94()227nname: 55228n 55(None)[time = rec.start_time - rec.start_padding229]:230 i: 45(t)231 o: 94()232nname: 45233n 45(rec.start_time)[]:234 i: 24(t)235 o: 55(t), 75(f)236nname: 24237n 24(rec)[rec = self.scheduler.GetFirstRecordingToStart()238]:239 i: 15(), 23()240 o: 45(t), 110(f)241nname: 23242n 23(None)[]:243 i: 0(f)244 o: 24()245nname: 15246n 15(None)[return False247]:248 i: 0(t)249 o: 24()250nname: 0251n 0(self.scheduler.IsSomeRecordingRunning())[]:252 i: 253 o: 15(t), 23(f)254nname: 111255n 111(None)[return True256]:257 i: 45(), 0(f)258 o: 259nname: 45260n 45(None)[if rec.start_time:261 time = rec.start_time - rec.start_padding262else:263 time = int(time.time())264self.SetAlarm(time)265]:266 i: 0(t)267 o: 111()268nname: 0269n 0(rec)[if self.scheduler.IsSomeRecordingRunning():270 return False271rec = self.scheduler.GetFirstRecordingToStart()272]:273 i: 274 o: 45(t), 111(f)275nname: 0276n 0(None)[if self.scheduler.IsSomeRecordingRunning():277 return False278rec = self.scheduler.GetFirstRecordingToStart()279if rec:280 if rec.start_time:281 time = rec.start_time - rec.start_padding282 else:283 time = int(time.time())284 self.SetAlarm(time)285return True286]:287 i: 288 o: 289self.nodes: {0: <unpyclib.structure.node instance at 0xb76ab96c>}290nname: 6291n 6(None)[def __init__(self, wydb, scheduler=None):292 self.wdb = wydb293 self.scheduler = scheduler294 self.ref_wystandby = self.wdb.reference(config.standby_dbus_bus_name, config.standby_dbus_path_name)295 self._AddStandbyModule = self.ref_wystandby.method('AddStandbyModule', 's', 's')296 self._RemoveStandbyModule = self.ref_wystandby.method('RemoveStandbyModule', 's', 'i')297 self.SetMaxPowerState = self.ref_wystandby.method('NotifyNewMaxPowerState', 'si', '')298 self.SetPowerState = self.ref_wystandby.method('NotifyPowerStateChanged', 'si', '')299 self.SetAlarm = self.ref_wystandby.method('SetAlarm', 'x', '')300def AddStandbyModule(self, id):301 try:302 return self._AddStandbyModule(id)303 except BaseException, e:304 log.debug(str(e))305 return id306def RemoveStandbyModule(self, id):307 try:308 return self._RemoveStandbyModule(id)309 except BaseException, e:310 log.debug(str(e))311 return 0312def treat_StateReadySignal(self):313 log.debug('StateReadySignal')314 self.scheduler.AsynchronousCheckSchedule()315 self.SetPowerState(config.wystandby_id, APM_STATE_READY)316def treat_StateStandbySignal(self):317 log.debug('StateStandbySignal')318 self.SetPowerState(config.wystandby_id, APM_STATE_STANDBY)319def treat_StateSuspendSignal(self):320 log.debug('StateSuspendSignal')321 if self._ExternalStandby__is_standby_ready():322 self.SetPowerState(config.wystandby_id, APM_STATE_SUSPEND)323 else:324 self.SetPowerState(config.wystandby_id, APM_STATE_STANDBY)325def treat_StateOffSignal(self):326 log.debug('StateOffSignal')327 if self._ExternalStandby__is_standby_ready():328 self.SetPowerState(config.wystandby_id, APM_STATE_OFF)329 else:330 self.SetPowerState(config.wystandby_id, APM_STATE_STANDBY)331def _ExternalStandby__is_standby_ready(self):332 if self.scheduler.IsSomeRecordingRunning():333 return False334 rec = self.scheduler.GetFirstRecordingToStart()335 if rec:336 if rec.start_time:337 time = rec.start_time - rec.start_padding338 else:339 time = int(time.time())340 self.SetAlarm(time)341 return True342]:343 i: 344 o: 345self.nodes: {6: <unpyclib.structure.node instance at 0xb76a69ec>}346nname: 0347n 0(None)[from logger import log348from config import *349from peewee.analyse import Chrono350from peewee.analyse import timestep351class ExternalStandby(object):352 def __init__(self, wydb, scheduler=None):353 self.wdb = wydb354 self.scheduler = scheduler355 self.ref_wystandby = self.wdb.reference(config.standby_dbus_bus_name, config.standby_dbus_path_name)356 self._AddStandbyModule = self.ref_wystandby.method('AddStandbyModule', 's', 's')357 self._RemoveStandbyModule = self.ref_wystandby.method('RemoveStandbyModule', 's', 'i')358 self.SetMaxPowerState = self.ref_wystandby.method('NotifyNewMaxPowerState', 'si', '')359 self.SetPowerState = self.ref_wystandby.method('NotifyPowerStateChanged', 'si', '')360 self.SetAlarm = self.ref_wystandby.method('SetAlarm', 'x', '')361 def AddStandbyModule(self, id):362 try:363 return self._AddStandbyModule(id)364 except BaseException, e:365 log.debug(str(e))366 return id367 def RemoveStandbyModule(self, id):368 try:369 return self._RemoveStandbyModule(id)370 except BaseException, e:371 log.debug(str(e))372 return 0373 def treat_StateReadySignal(self):374 log.debug('StateReadySignal')375 self.scheduler.AsynchronousCheckSchedule()376 self.SetPowerState(config.wystandby_id, APM_STATE_READY)377 def treat_StateStandbySignal(self):378 log.debug('StateStandbySignal')379 self.SetPowerState(config.wystandby_id, APM_STATE_STANDBY)380 def treat_StateSuspendSignal(self):381 log.debug('StateSuspendSignal')382 if self._ExternalStandby__is_standby_ready():383 self.SetPowerState(config.wystandby_id, APM_STATE_SUSPEND)384 else:385 self.SetPowerState(config.wystandby_id, APM_STATE_STANDBY)386 def treat_StateOffSignal(self):387 log.debug('StateOffSignal')388 if self._ExternalStandby__is_standby_ready():389 self.SetPowerState(config.wystandby_id, APM_STATE_OFF)390 else:391 self.SetPowerState(config.wystandby_id, APM_STATE_STANDBY)392 def _ExternalStandby__is_standby_ready(self):393 if self.scheduler.IsSomeRecordingRunning():394 return False395 rec = self.scheduler.GetFirstRecordingToStart()396 if rec:397 if rec.start_time:398 time = rec.start_time - rec.start_padding399 else:400 time = int(time.time())401 self.SetAlarm(time)402 return True403]:404 i: 405 o: 406self.nodes: {0: <unpyclib.structure.node instance at 0xb769fe8c>}407from logger import log408from config import *409from peewee.analyse import Chrono410from peewee.analyse import timestep411class ExternalStandby(object):412 def __init__(self, wydb, scheduler=None):413 self.wdb = wydb414 self.scheduler = scheduler415 self.ref_wystandby = self.wdb.reference(config.standby_dbus_bus_name, config.standby_dbus_path_name)416 self._AddStandbyModule = self.ref_wystandby.method('AddStandbyModule', 's', 's')417 self._RemoveStandbyModule = self.ref_wystandby.method('RemoveStandbyModule', 's', 'i')418 self.SetMaxPowerState = self.ref_wystandby.method('NotifyNewMaxPowerState', 'si', '')419 self.SetPowerState = self.ref_wystandby.method('NotifyPowerStateChanged', 'si', '')420 self.SetAlarm = self.ref_wystandby.method('SetAlarm', 'x', '')421 def AddStandbyModule(self, id):422 try:423 return self._AddStandbyModule(id)424 except BaseException, e:425 log.debug(str(e))426 return id427 def RemoveStandbyModule(self, id):428 try:429 return self._RemoveStandbyModule(id)430 except BaseException, e:431 log.debug(str(e))432 return 0433 def treat_StateReadySignal(self):434 log.debug('StateReadySignal')435 self.scheduler.AsynchronousCheckSchedule()436 self.SetPowerState(config.wystandby_id, APM_STATE_READY)437 def treat_StateStandbySignal(self):438 log.debug('StateStandbySignal')439 self.SetPowerState(config.wystandby_id, APM_STATE_STANDBY)440 def treat_StateSuspendSignal(self):441 log.debug('StateSuspendSignal')442 if self._ExternalStandby__is_standby_ready():443 self.SetPowerState(config.wystandby_id, APM_STATE_SUSPEND)444 else:445 self.SetPowerState(config.wystandby_id, APM_STATE_STANDBY)446 def treat_StateOffSignal(self):447 log.debug('StateOffSignal')448 if self._ExternalStandby__is_standby_ready():449 self.SetPowerState(config.wystandby_id, APM_STATE_OFF)450 else:451 self.SetPowerState(config.wystandby_id, APM_STATE_STANDBY)452 def _ExternalStandby__is_standby_ready(self):453 if self.scheduler.IsSomeRecordingRunning():454 return False455 rec = self.scheduler.GetFirstRecordingToStart()456 if rec:457 if rec.start_time:458 time = rec.start_time - rec.start_padding459 else:460 time = int(time.time())461 self.SetAlarm(time)...
utilities.py
Source:utilities.py
...69 query = helena.take_command().lower()70 print("The query in standby false: ", query)71 print("The type of query in standby false: ", type(query))72 task_controller(helena, query, standbyEvent, patterns)73def standby(standbyEvent):74 """75 This function put the program in standby after a certain amount of time76 :param standbyEvent: Threading event: Event that sets up the stand by process77 """78 counter = 079 while True:80 if not standbyEvent.is_set():81 break82 time.sleep(1)83 counter += 184 print("The timeout: ", counter)85 if counter == 45:86 standbyEvent.clear()87 break...
test_reject_swacts.py
Source:test_reject_swacts.py
1import time2from pytest import fixture, skip, mark3from utils.tis_log import LOG4from keywords import host_helper, system_helper5from consts.reasons import SkipSysType6from testfixtures.recover_hosts import HostsToRecover7@fixture(scope='module', autouse=True)8def skip_simplex():9 if len(system_helper.get_controllers()) < 2:10 skip(SkipSysType.LESS_THAN_TWO_CONTROLLERS)11def test_swact_standby_controller_negative():12 """13 TC610_214 Verify that trying to swact a standby controller is rejected15 Test Steps:16 - Get the standby controller17 - Attempt to swact the controller18 - Verify that the swact doesn't happen19 """20 standby = system_helper.get_standby_controller_name()21 active = system_helper.get_active_controller_name()22 LOG.tc_step("Attempting to swact from standby controller {}".format(standby))23 code, out = host_helper.swact_host(standby, fail_ok=True)24 LOG.tc_step("Verifying that the swact didn't occur.")25 assert 0 != code, "FAIL: The swact wasn't rejected"26 curr_active = system_helper.get_active_controller_name()27 assert curr_active == active, "FAIL: The active controller was changed. " \28 "Previous: {} Current: {}".format(active, curr_active)29@fixture(scope='function')30def fail_controller(request):31 standby = system_helper.get_standby_controller_name()32 HostsToRecover.add(standby, scope='function')33 host_helper.reboot_hosts(standby, wait_for_reboot_finish=False)34 return True35def test_swact_failed_controller_negative(fail_controller):36 """37 TC610_338 Verify that swacting to a failed controller is rejected39 Test Setup:40 - Reset the standby controller41 Test Steps:42 - Attempt to swact from the active controller43 - Verify that the swact was rejected and the active controller is the same44 Teardown:45 - Wait until the controller is online again46 Returns:47 """48 if not fail_controller:49 skip("Couldn't put controller into failed state.")50 active = system_helper.get_active_controller_name()51 LOG.tc_step("Attempting to swact to failed controller.")52 code, out = host_helper.swact_host(fail_ok=True)53 LOG.tc_step("Verifying that the swact didn't occur.")54 assert 1 == code, "FAIL: The swact wasn't rejected"55 curr_active = system_helper.get_active_controller_name()56 assert curr_active == active, "FAIL: The active controller was changed. " \57 "Previous: {} Current: {}".format(active, curr_active)58@fixture(scope='function')59def lock_controller():60 LOG.fixture_step("Ensure system has no standby controller available for swact")61 standby = system_helper.get_standby_controller_name()62 if standby:63 HostsToRecover.add(standby)64 host_helper.lock_host(standby, swact=False)65@mark.domain_sanity66def test_swact_no_standby_negative(lock_controller):67 """68 TC610_469 Verify swact without standby controller is rejected70 Test Setup:71 - Lock the standby controller72 Test Steps:73 - Attempt to swact when no standby controller available74 Teardown:75 - Unlock the controller76 """77 LOG.tc_step("Attempting to swact when no standby controller available")78 active = system_helper.get_active_controller_name()79 code, out = host_helper.swact_host(hostname=active, fail_ok=True)80 LOG.tc_step("Verifying that the swact didn't occur.")81 assert 1 == code, "FAIL: The swact wasn't rejected"82 curr_active = system_helper.get_active_controller_name()83 assert curr_active == active, "FAIL: The active controller was changed. " \84 "Previous: {} Current: {}".format(active, curr_active)85def test_swact_compute_negative():86 """87 TC610_588 Verify that trying to swact a compute node is rejected89 Test Steps:90 - Attempt to swact from a compute91 """92 computes = system_helper.get_hosts(personality='compute')93 if not computes:94 skip("No compute host in system")95 for compute in computes:96 LOG.tc_step("Attempting to swact from {}".format(compute))97 code, out = host_helper.swact_host(compute, fail_ok=True)98 LOG.tc_step("Verifying that the swact didn't occur.")...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!