mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-devtest
synced 2026-01-15 02:22:56 +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
|
# -- phase trigger methods
|
||||||
async def __trigger_boot(self, env, machine):
|
async def __trigger_boot(self, env, machine):
|
||||||
slog(INFO, "requesting power-on")
|
slog(INFO, "requesting power-on")
|
||||||
await machine.request_power_on(env)
|
await machine.request_power_on()
|
||||||
|
|
||||||
async def __trigger_up(self, env, machine):
|
async def __trigger_up(self, env, machine):
|
||||||
await machine.wait_up(env)
|
await machine.wait_up()
|
||||||
|
|
||||||
async def __trigger_shutdown(self, env, machine):
|
async def __trigger_shutdown(self, env, machine):
|
||||||
await machine.request_shutdown(env)
|
await machine.request_shutdown()
|
||||||
|
|
||||||
async def __trigger_post(self, env, machine):
|
async def __trigger_post(self, env, machine):
|
||||||
await machine.wait_poweroff(env)
|
await machine.wait_power_off()
|
||||||
|
|
||||||
# -- phase filtered batches
|
# -- phase filtered batches
|
||||||
async def __establish_connections(self, phase, env, machine):
|
async def __establish_connections(self, phase, env, machine):
|
||||||
|
|
@ -121,8 +121,8 @@ class CmdTestOs(MachineCmd): # export
|
||||||
finally:
|
finally:
|
||||||
if machine is not None:
|
if machine is not None:
|
||||||
if TestPhases.Phase.Shutdown in phases:
|
if TestPhases.Phase.Shutdown in phases:
|
||||||
await machine.request_shutdown(env)
|
await machine.request_shutdown()
|
||||||
await machine.wait_poweroff(env)
|
await machine.wait_power_off()
|
||||||
await machine.cleanup(env)
|
await machine.cleanup(env)
|
||||||
for conn in env.connections:
|
for conn in env.connections:
|
||||||
if conn.instance:
|
if conn.instance:
|
||||||
|
|
|
||||||
|
|
@ -125,5 +125,17 @@ class Machine(ABC): # export
|
||||||
async def request_shutdown(self):
|
async def request_shutdown(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def wait_poweroff(self, timeout):
|
@abstractmethod
|
||||||
|
async def request_power_off(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
async def wait_power_off(self, timeout):
|
||||||
return True
|
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):
|
async def unregister_connection(self, conn):
|
||||||
return await super().unregister_connection(conn)
|
return await super().unregister_connection(conn)
|
||||||
|
|
||||||
async def request_power_on(self, env):
|
async def request_power_on(self):
|
||||||
if self.__running:
|
if self.__running:
|
||||||
raise Exception("Tried to power on a running Qemu machine")
|
raise Exception("Tried to power on a running Qemu machine")
|
||||||
slog(NOTICE, "switching on DUT")
|
slog(NOTICE, "switching on DUT")
|
||||||
|
|
@ -367,17 +367,20 @@ class Machine(MachineBase): # export
|
||||||
slog(NOTICE, "switched on DUT")
|
slog(NOTICE, "switched on DUT")
|
||||||
self.__running = True
|
self.__running = True
|
||||||
|
|
||||||
async def wait_up(self, env):
|
async def wait_up(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def request_shutdown(self, env):
|
async def request_shutdown(self):
|
||||||
if not self.__shutdown_requested:
|
if not self.__shutdown_requested:
|
||||||
slog(NOTICE, "requesting shutdown")
|
slog(NOTICE, "requesting shutdown")
|
||||||
self.__shutdown_requested = True
|
self.__shutdown_requested = True
|
||||||
if self.monitor and self.__rc is None:
|
if self.monitor and self.__rc is None:
|
||||||
await self.monitor.write(b'quit\n')
|
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")
|
slog(NOTICE, "waiting on powerdown")
|
||||||
await self.__cleanup_qemu()
|
await self.__cleanup_qemu()
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,10 @@ class Machine(MachineBase): # export
|
||||||
self.__running = False
|
self.__running = False
|
||||||
self.__shutdown_requested = False
|
self.__shutdown_requested = False
|
||||||
self.__cmds = {
|
self.__cmds = {
|
||||||
'request-shutdown': "jw-switch-allesnix.sh off",
|
|
||||||
'wait-power-off' : "sleep 2",
|
|
||||||
'request-power-on' : "jw-switch-allesnix.sh on",
|
'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
|
'cleanup' : None
|
||||||
}
|
}
|
||||||
for key in self.__cmds.keys():
|
for key in self.__cmds.keys():
|
||||||
|
|
@ -30,7 +31,7 @@ class Machine(MachineBase): # export
|
||||||
if cmd is None:
|
if cmd is None:
|
||||||
slog(INFO, 'No command registered for phase "{}", not running'.format(phase))
|
slog(INFO, 'No command registered for phase "{}", not running'.format(phase))
|
||||||
return
|
return
|
||||||
if isinstance(cmd, str):
|
if isinstance(cmd, str) and cmd != 'none':
|
||||||
cmd = cmd.split(' ')
|
cmd = cmd.split(' ')
|
||||||
sc = ShellCmd(cmd)
|
sc = ShellCmd(cmd)
|
||||||
await sc.run()
|
await sc.run()
|
||||||
|
|
@ -54,7 +55,7 @@ class Machine(MachineBase): # export
|
||||||
async def unregister_connection(self, conn):
|
async def unregister_connection(self, conn):
|
||||||
return await super().unregister_connection(conn)
|
return await super().unregister_connection(conn)
|
||||||
|
|
||||||
async def request_power_on(self, env):
|
async def request_power_on(self):
|
||||||
if self.__running:
|
if self.__running:
|
||||||
raise Exception("Tried to power on a running shell command machine")
|
raise Exception("Tried to power on a running shell command machine")
|
||||||
slog(NOTICE, "switching on DUT")
|
slog(NOTICE, "switching on DUT")
|
||||||
|
|
@ -64,26 +65,33 @@ class Machine(MachineBase): # export
|
||||||
self.__running = True
|
self.__running = True
|
||||||
self.__clear_for_tests = True
|
self.__clear_for_tests = True
|
||||||
|
|
||||||
async def wait_up(self, env):
|
async def wait_up(self):
|
||||||
count = 5
|
count = 5
|
||||||
while not self.__running and count > 0:
|
while not self.__running and count > 0:
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
count -= 1
|
count -= 1
|
||||||
return self.__running
|
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:
|
if not self.__shutdown_requested:
|
||||||
slog(NOTICE, "requesting shutdown")
|
slog(NOTICE, "requesting shutdown")
|
||||||
await self.__run('request-shutdown')
|
|
||||||
self.__shutdown_requested = True
|
self.__shutdown_requested = True
|
||||||
|
self.__running = False
|
||||||
|
return await self.request_power_off()
|
||||||
|
|
||||||
|
async def request_power_off(self):
|
||||||
|
slog(NOTICE, "switching off DUT")
|
||||||
|
await self.__run('request-power-off')
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
self.__running = False
|
self.__running = False
|
||||||
#self.__clear_for_tests = False
|
#self.__clear_for_tests = False
|
||||||
|
|
||||||
async def wait_poweroff(self, env):
|
async def wait_power_off(self):
|
||||||
slog(NOTICE, "waiting on powerdown")
|
slog(NOTICE, "waiting on powerdown")
|
||||||
count = 5
|
count = 5
|
||||||
while self.__running and count > 0:
|
while self.__running and count > 0:
|
||||||
asyncio.sleep(1)
|
asyncio.sleep(1)
|
||||||
count -= 1
|
count -= 1
|
||||||
|
await self.__run('wait-power-off')
|
||||||
return self.__running
|
return self.__running
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue