mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-devtest
synced 2026-01-15 10:23:32 +01:00
os.Machine: Rename virtual power functions
Rename for consistency:
wait_poweroff -> wait_power_off()
Now, here's what we have:
request_power_on(self)
wait_up(self, timeout)
request_shutdown(self)
request_power_off(self)
wait_power_off(self, timeout)
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
2dcf5a2cf4
commit
6c06abffe9
4 changed files with 46 additions and 23 deletions
|
|
@ -56,16 +56,16 @@ class CmdTestOs(MachineCmd): # export
|
|||
# -- phase trigger methods
|
||||
async def __trigger_boot(self, env, machine):
|
||||
slog(INFO, "requesting power-on")
|
||||
await machine.request_power_on(env)
|
||||
await machine.request_power_on()
|
||||
|
||||
async def __trigger_up(self, env, machine):
|
||||
await machine.wait_up(env)
|
||||
await machine.wait_up()
|
||||
|
||||
async def __trigger_shutdown(self, env, machine):
|
||||
await machine.request_shutdown(env)
|
||||
await machine.request_shutdown()
|
||||
|
||||
async def __trigger_post(self, env, machine):
|
||||
await machine.wait_poweroff(env)
|
||||
await machine.wait_power_off()
|
||||
|
||||
# -- phase filtered batches
|
||||
async def __establish_connections(self, phase, env, machine):
|
||||
|
|
@ -121,8 +121,8 @@ class CmdTestOs(MachineCmd): # export
|
|||
finally:
|
||||
if machine is not None:
|
||||
if TestPhases.Phase.Shutdown in phases:
|
||||
await machine.request_shutdown(env)
|
||||
await machine.wait_poweroff(env)
|
||||
await machine.request_shutdown()
|
||||
await machine.wait_power_off()
|
||||
await machine.cleanup(env)
|
||||
for conn in env.connections:
|
||||
if conn.instance:
|
||||
|
|
|
|||
|
|
@ -125,5 +125,17 @@ class Machine(ABC): # export
|
|||
async def request_shutdown(self):
|
||||
pass
|
||||
|
||||
async def wait_poweroff(self, timeout):
|
||||
@abstractmethod
|
||||
async def request_power_off(self):
|
||||
pass
|
||||
|
||||
async def wait_power_off(self, timeout):
|
||||
return True
|
||||
|
||||
async def power_cycle(self, wait_time=None):
|
||||
await self.request_power_off()
|
||||
await self.wait_power_off()
|
||||
if wait_time is not None:
|
||||
await asyncio.sleep(wait_time)
|
||||
await self.request_power_on()
|
||||
await self.wait_up()
|
||||
|
|
|
|||
|
|
@ -358,7 +358,7 @@ class Machine(MachineBase): # export
|
|||
async def unregister_connection(self, conn):
|
||||
return await super().unregister_connection(conn)
|
||||
|
||||
async def request_power_on(self, env):
|
||||
async def request_power_on(self):
|
||||
if self.__running:
|
||||
raise Exception("Tried to power on a running Qemu machine")
|
||||
slog(NOTICE, "switching on DUT")
|
||||
|
|
@ -367,17 +367,20 @@ class Machine(MachineBase): # export
|
|||
slog(NOTICE, "switched on DUT")
|
||||
self.__running = True
|
||||
|
||||
async def wait_up(self, env):
|
||||
async def wait_up(self):
|
||||
return True
|
||||
|
||||
async def request_shutdown(self, env):
|
||||
async def request_shutdown(self):
|
||||
if not self.__shutdown_requested:
|
||||
slog(NOTICE, "requesting shutdown")
|
||||
self.__shutdown_requested = True
|
||||
if self.monitor and self.__rc is None:
|
||||
await self.monitor.write(b'quit\n')
|
||||
|
||||
async def wait_poweroff(self, env):
|
||||
async def request_power_off(self):
|
||||
raise Exception("Power off is not implemented")
|
||||
|
||||
async def wait_power_off(self):
|
||||
slog(NOTICE, "waiting on powerdown")
|
||||
await self.__cleanup_qemu()
|
||||
return True
|
||||
|
|
|
|||
|
|
@ -14,10 +14,11 @@ class Machine(MachineBase): # export
|
|||
self.__running = False
|
||||
self.__shutdown_requested = False
|
||||
self.__cmds = {
|
||||
'request-shutdown': "jw-switch-allesnix.sh off",
|
||||
'wait-power-off' : "sleep 2",
|
||||
'request-power-on': "jw-switch-allesnix.sh on",
|
||||
'cleanup' : None
|
||||
'request-power-on' : "jw-switch-allesnix.sh on",
|
||||
'request-shutdown' : "jw-switch-allesnix.sh off",
|
||||
'request-power-off': "jw-switch-allesnix.sh off",
|
||||
'wait-power-off' : "sleep 2",
|
||||
'cleanup' : None
|
||||
}
|
||||
for key in self.__cmds.keys():
|
||||
if 'cmd.' + key in env.be_opts.keys():
|
||||
|
|
@ -30,7 +31,7 @@ class Machine(MachineBase): # export
|
|||
if cmd is None:
|
||||
slog(INFO, 'No command registered for phase "{}", not running'.format(phase))
|
||||
return
|
||||
if isinstance(cmd, str):
|
||||
if isinstance(cmd, str) and cmd != 'none':
|
||||
cmd = cmd.split(' ')
|
||||
sc = ShellCmd(cmd)
|
||||
await sc.run()
|
||||
|
|
@ -54,7 +55,7 @@ class Machine(MachineBase): # export
|
|||
async def unregister_connection(self, conn):
|
||||
return await super().unregister_connection(conn)
|
||||
|
||||
async def request_power_on(self, env):
|
||||
async def request_power_on(self):
|
||||
if self.__running:
|
||||
raise Exception("Tried to power on a running shell command machine")
|
||||
slog(NOTICE, "switching on DUT")
|
||||
|
|
@ -64,26 +65,33 @@ class Machine(MachineBase): # export
|
|||
self.__running = True
|
||||
self.__clear_for_tests = True
|
||||
|
||||
async def wait_up(self, env):
|
||||
async def wait_up(self):
|
||||
count = 5
|
||||
while not self.__running and count > 0:
|
||||
await asyncio.sleep(1)
|
||||
count -= 1
|
||||
return self.__running
|
||||
|
||||
async def request_shutdown(self, env):
|
||||
# default for request_shutdown is to power off
|
||||
async def request_shutdown(self):
|
||||
if not self.__shutdown_requested:
|
||||
slog(NOTICE, "requesting shutdown")
|
||||
await self.__run('request-shutdown')
|
||||
self.__shutdown_requested = True
|
||||
await asyncio.sleep(1)
|
||||
self.__running = False
|
||||
#self.__clear_for_tests = False
|
||||
return await self.request_power_off()
|
||||
|
||||
async def wait_poweroff(self, env):
|
||||
async def request_power_off(self):
|
||||
slog(NOTICE, "switching off DUT")
|
||||
await self.__run('request-power-off')
|
||||
await asyncio.sleep(1)
|
||||
self.__running = False
|
||||
#self.__clear_for_tests = False
|
||||
|
||||
async def wait_power_off(self):
|
||||
slog(NOTICE, "waiting on powerdown")
|
||||
count = 5
|
||||
while self.__running and count > 0:
|
||||
asyncio.sleep(1)
|
||||
count -= 1
|
||||
await self.__run('wait-power-off')
|
||||
return self.__running
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue