Move the contents of power_state_controller.py to servo.py.
After recent refactoring, the content of the power_state_controller
module is compact enough to be private to the servo module. This
makes it so.
BUG=chromium:326738
TEST=FAFTSetup, platform_ServoPowerStateController
Change-Id: I5215a9709ed4e64251ca5b980112720bfe63a964
Reviewed-on: https://chromium-review.googlesource.com/203496
Tested-by: Richard Barnette <jrbarnette@chromium.org>
Reviewed-by: Dan Shi <dshi@chromium.org>
Commit-Queue: Richard Barnette <jrbarnette@chromium.org>
diff --git a/server/cros/servo/servo.py b/server/cros/servo/servo.py
index 454606a..f59a88e 100644
--- a/server/cros/servo/servo.py
+++ b/server/cros/servo/servo.py
@@ -10,10 +10,109 @@
import logging, re, time, xmlrpclib
from autotest_lib.client.common_lib import error
-from autotest_lib.server.cros.servo import power_state_controller
from autotest_lib.server.cros.servo import firmware_programmer
+class _PowerStateController(object):
+
+ """Class to provide board-specific power operations.
+
+ This class is responsible for "power on" and "power off"
+ operations that can operate without making assumptions in
+ advance about board state. It offers an interface that
+ abstracts out the different sequences required for different
+ board types.
+
+ """
+
+ # Constants acceptable to be passed for the `rec_mode` parameter
+ # to power_on().
+ #
+ # REC_ON: Boot the DUT in recovery mode, i.e. boot from USB or
+ # SD card.
+ # REC_OFF: Boot in normal mode, i.e. boot from internal storage.
+
+ REC_ON = 'rec'
+ REC_OFF = 'on'
+
+ # Delay in seconds needed between asserting and de-asserting
+ # warm reset.
+ _RESET_HOLD_TIME = 0.5
+
+ def __init__(self, servo):
+ """Initialize the power state control.
+
+ @param servo Servo object providing the underlying `set` and `get`
+ methods for the target controls.
+
+ """
+ self._servo = servo
+
+ def reset(self):
+ """Force the DUT to reset.
+
+ The DUT is guaranteed to be on at the end of this call,
+ regardless of its previous state, provided that there is
+ working OS software. This also guarantees that the EC has
+ been restarted.
+
+ """
+ self._servo.set_nocheck('power_state', 'reset')
+
+ def warm_reset(self):
+ """Apply warm reset to the DUT.
+
+ This asserts, then de-asserts the 'warm_reset' signal.
+ Generally, this causes the board to restart.
+
+ """
+ self._servo.set_get_all(['warm_reset:on',
+ 'sleep:%.4f' % self._RESET_HOLD_TIME,
+ 'warm_reset:off'])
+
+ def recovery_supported(self):
+ """Return whether the power on/off methods are supported.
+
+ @return True means the power_on() and power_off() methods will
+ not raise a NotImplementedError. False means they will.
+
+ """
+ return True
+
+ def power_off(self):
+ """Force the DUT to power off.
+
+ The DUT is guaranteed to be off at the end of this call,
+ regardless of its previous state, provided that there is
+ working EC and boot firmware. There is no requirement for
+ working OS software.
+
+ """
+ self._servo.set_nocheck('power_state', 'off')
+
+ def power_on(self, rec_mode=REC_OFF):
+ """Force the DUT to power on.
+
+ Prior to calling this function, the DUT must be powered off,
+ e.g. with a call to `power_off()`.
+
+ At power on, recovery mode is set as specified by the
+ corresponding argument. When booting with recovery mode on, it
+ is the caller's responsibility to unplug/plug in a bootable
+ external storage device.
+
+ If the DUT requires a delay after powering on but before
+ processing inputs such as USB stick insertion, the delay is
+ handled by this method; the caller is not responsible for such
+ delays.
+
+ @param rec_mode Setting of recovery mode to be applied at
+ power on. default: REC_OFF aka 'off'
+
+ """
+ self._servo.set_nocheck('power_state', rec_mode)
+
+
class Servo(object):
"""Manages control of a Servo board.
@@ -74,8 +173,7 @@
self._servo_host = servo_host
self._servo_serial = servo_serial
self._server = servo_host.get_servod_server_proxy()
- self._power_state = (
- power_state_controller.create_controller(self))
+ self._power_state = _PowerStateController(self)
# a string, showing what interface (host or dut) the USB device is
# connected to.