[autotest] move tests in rpm_controller to a separate file
rpm_controller is getting big.
Move tests in rpm_controller to rpm_integration_test.py
The tests are commented out because most of the ports are in actual
use now.
CQ-DEPEND=CL:212357
BUG=chromium:392548
TEST=Lock some hosts, change rpm_integration_test to point to those
locked hosts and run the tests.
Change-Id: I131a0b343f95365f2e8c37a22f3b02690e6a5934
Reviewed-on: https://chromium-review.googlesource.com/212348
Tested-by: Fang Deng <fdeng@chromium.org>
Reviewed-by: Simran Basi <sbasi@chromium.org>
Commit-Queue: Fang Deng <fdeng@chromium.org>
diff --git a/site_utils/rpm_control_system/rpm_controller.py b/site_utils/rpm_control_system/rpm_controller.py
index 825d874..f323dad 100644
--- a/site_utils/rpm_control_system/rpm_controller.py
+++ b/site_utils/rpm_control_system/rpm_controller.py
@@ -20,10 +20,7 @@
import common
from autotest_lib.client.common_lib import error
from autotest_lib.client.common_lib.cros import retry
-from autotest_lib.site_utils.rpm_control_system import utils
-# Format Appears as: [Date] [Time] - [Msg Level] - [Message]
-LOGGING_FORMAT = '%(asctime)s - %(levelname)s - %(message)s'
RPM_CALL_TIMEOUT_MINS = rpm_config.getint('RPM_INFRASTRUCTURE',
'call_timeout_mins')
SET_POWER_STATE_TIMEOUT_SECONDS = rpm_config.getint(
@@ -978,69 +975,3 @@
logging.debug('Outlet for device: %s set to %s',
device_hostname, new_state)
return True
-
-
-def test_in_order_requests():
- """Simple integration testing."""
- rpm = WebPoweredRPMController('chromeos-rack8e-rpm1')
- rpm.queue_request('chromeos1-rack8e-hostbs1', 'OFF')
- rpm.queue_request('chromeos1-rack8e-hostbs2', 'OFF')
- rpm.queue_request('chromeos1-rack8e-hostbs3', 'CYCLE')
-
-
-def test_parrallel_webrequests():
- """Simple integration testing."""
- rpm = WebPoweredRPMController('chromeos-rack8e-rpm1')
- threading.Thread(target=rpm.queue_request,
- args=('chromeos1-rack8e-hostbs1', 'OFF')).start()
- threading.Thread(target=rpm.queue_request,
- args=('chromeos1-rack8e-hostbs2', 'ON')).start()
-
-
-def test_parrallel_sshrequests():
- """Simple integration testing."""
- rpm = SentryRPMController('chromeos-rack8-rpm1')
- threading.Thread(target=rpm.queue_request,
- args=('chromeos-rack8-hostbs1', 'OFF')).start()
- threading.Thread(target=rpm.queue_request,
- args=('chromeos-rack8-hostbs2', 'OFF')).start()
-
- # The following test are disabled as the
- # outlets on the rpm are in actual use.
- # rpm2 = SentryRPMController('chromeos2-row2-rack3-rpm1')
- # threading.Thread(target=rpm2.queue_request,
- # args=('chromeos2-row2-rack3-hostbs', 'ON')).start()
- # threading.Thread(target=rpm2.queue_request,
- # args=('chromeos2-row2-rack3-hostbs2', 'ON')).start()
- # threading.Thread(target=rpm2.queue_request,
- # args=('chromeos2-row1-rack7-hostbs1', 'ON')).start()
-
-
-def test_in_order_poerequests():
- """Simple integration testing for poe controller."""
- servo_interface = utils.load_servo_interface_mapping()
- poe_controller = CiscoPOEController(
- 'chromeos1-poe-switch1', servo_interface)
- poe_controller.queue_request('chromeos1-rack4-host1bs-servo', 'OFF')
- poe_controller.queue_request('chromeos1-rack4-host1bs-servo', 'ON')
- poe_controller.queue_request('chromeos1-rack4-host2bs-servo', 'CYCLE')
-
-
-def test_parrallel_poerequests():
- """Simple integration testing for poe controller."""
- servo_interface = utils.load_servo_interface_mapping()
- poe_controller = CiscoPOEController(
- 'chromeos1-poe-switch1', servo_interface)
- threading.Thread(target=poe_controller.queue_request,
- args=('chromeos1-rack4-host1bs-servo', 'CYCLE')).start()
- threading.Thread(target=poe_controller.queue_request,
- args=('chromeos1-rack4-host2bs-servo', 'CYCLE')).start()
-
-
-if __name__ == '__main__':
- logging.basicConfig(level=logging.DEBUG, format=LOGGING_FORMAT)
- test_in_order_requests()
- test_parrallel_webrequests()
- test_parrallel_sshrequests()
- test_in_order_poerequests()
- test_parrallel_poerequests()
diff --git a/site_utils/rpm_control_system/rpm_infrastructure_exception.py b/site_utils/rpm_control_system/rpm_infrastructure_exception.py
index d1b3d29..afce659 100644
--- a/site_utils/rpm_control_system/rpm_infrastructure_exception.py
+++ b/site_utils/rpm_control_system/rpm_infrastructure_exception.py
@@ -7,4 +7,9 @@
Exception used to indicate infrastructure failures in the RPM control
system.
"""
- pass
\ No newline at end of file
+ pass
+
+
+class RPMLoggingSetupError(RPMInfrastructureException):
+ """Rasied when setup logging fails."""
+ pass
diff --git a/site_utils/rpm_control_system/rpm_integration_test.py b/site_utils/rpm_control_system/rpm_integration_test.py
new file mode 100644
index 0000000..4431e14
--- /dev/null
+++ b/site_utils/rpm_control_system/rpm_integration_test.py
@@ -0,0 +1,146 @@
+import logging
+import threading
+
+import common
+
+from autotest_lib.site_utils.rpm_control_system import rpm_controller
+from autotest_lib.site_utils.rpm_control_system import utils
+
+
+# Format Appears as: [Date] [Time] - [Msg Level] - [Message]
+LOGGING_FORMAT = '%(asctime)s - %(levelname)s - %(message)s'
+
+
+def test_in_order_requests():
+ """Simple integration testing."""
+ rpm = rpm_controller.WebPoweredRPMController(
+ 'chromeos-rack8e-rpm1')
+ info_1 = utils.PowerUnitInfo(
+ device_hostname='chromeos1-rack8e-hostbs1',
+ powerunit_hostname='chromeos-rack8e-rpm1',
+ powerunit_type=utils.PowerUnitInfo.POWERUNIT_TYPES.RPM,
+ hydra_hostname=None,
+ outlet='')
+ info_2 = utils.PowerUnitInfo(
+ device_hostname='chromeos1-rack8e-hostbs2',
+ powerunit_hostname='chromeos-rack8e-rpm1',
+ powerunit_type=utils.PowerUnitInfo.POWERUNIT_TYPES.RPM,
+ hydra_hostname=None,
+ outlet='')
+ info_3 = utils.PowerUnitInfo(
+ device_hostname='chromeos1-rack8e-hostbs3',
+ powerunit_hostname='chromeos-rack8e-rpm1',
+ powerunit_type=utils.PowerUnitInfo.POWERUNIT_TYPES.RPM,
+ hydra_hostname=None,
+ outlet='')
+ rpm.queue_request(info_1, 'OFF')
+ rpm.queue_request(info_2, 'OFF')
+ rpm.queue_request(info_3, 'CYCLE')
+
+
+def test_parrallel_webrequests():
+ """Simple integration testing."""
+ rpm = rpm_controller.WebPoweredRPMController(
+ 'chromeos-rack8e-rpm1')
+ info_1 = utils.PowerUnitInfo(
+ device_hostname='chromeos1-rack8e-hostbs1',
+ powerunit_hostname='chromeos-rack8e-rpm1',
+ powerunit_type=utils.PowerUnitInfo.POWERUNIT_TYPES.RPM,
+ hydra_hostname=None,
+ outlet='')
+ info_2 = utils.PowerUnitInfo(
+ device_hostname='chromeos1-rack8e-hostbs2',
+ powerunit_hostname='chromeos-rack8e-rpm1',
+ powerunit_type=utils.PowerUnitInfo.POWERUNIT_TYPES.RPM,
+ hydra_hostname=None,
+ outlet='')
+ threading.Thread(target=rpm.queue_request,
+ args=(info_1, 'OFF')).start()
+ threading.Thread(target=rpm.queue_request,
+ args=(info_2, 'ON')).start()
+
+
+def test_parrallel_sshrequests():
+ """Simple integration testing."""
+ rpm = rpm_controller.SentryRPMController('chromeos-rack8-rpm1')
+ info_1 = utils.PowerUnitInfo(
+ device_hostname='chromeos-rack8-hostbs1',
+ powerunit_hostname='chromeos-rack8-rpm1',
+ powerunit_type=utils.PowerUnitInfo.POWERUNIT_TYPES.RPM,
+ hydra_hostname=None,
+ outlet='.A14')
+ info_2 = utils.PowerUnitInfo(
+ device_hostname='chromeos-rack8-hostbs2',
+ powerunit_hostname='chromeos-rack8-rpm1',
+ powerunit_type=utils.PowerUnitInfo.POWERUNIT_TYPES.RPM,
+ hydra_hostname=None,
+ outlet='.A11')
+ threading.Thread(target=rpm.queue_request,
+ args=(info_1, 'CYCLE')).start()
+ threading.Thread(target=rpm.queue_request,
+ args=(info_2, 'CYCLE')).start()
+
+ # The following test are disabled as the
+ # outlets on the rpm are in actual use.
+ # rpm2 = SentryRPMController('chromeos2-row2-rack3-rpm1')
+ # threading.Thread(target=rpm2.queue_request,
+ # args=('chromeos2-row2-rack3-hostbs', 'ON')).start()
+ # threading.Thread(target=rpm2.queue_request,
+ # args=('chromeos2-row2-rack3-hostbs2', 'ON')).start()
+ # threading.Thread(target=rpm2.queue_request,
+ # args=('chromeos2-row1-rack7-hostbs1', 'ON')).start()
+
+
+def test_in_order_poerequests():
+ """Simple integration testing for poe controller."""
+ poe_controller = rpm_controller.CiscoPOEController(
+ 'chromeos1-poe-switch1')
+ info_1 = utils.PowerUnitInfo(
+ device_hostname='chromeos1-rack4-host1bs-servo',
+ powerunit_hostname='chromeos1-poe-switch1',
+ powerunit_type=utils.PowerUnitInfo.POWERUNIT_TYPES.RPM,
+ hydra_hostname=None,
+ outlet='fa33')
+ info_2 = utils.PowerUnitInfo(
+ device_hostname='chromeos1-rack4-host2bs-servo',
+ powerunit_hostname='chromeos1-poe-switch1',
+ powerunit_type=utils.PowerUnitInfo.POWERUNIT_TYPES.RPM,
+ hydra_hostname=None,
+ outlet='fa34')
+ poe_controller.queue_request(info_1, 'OFF')
+ poe_controller.queue_request(info_1, 'ON')
+ poe_controller.queue_request(info_2, 'CYCLE')
+
+
+def test_parrallel_poerequests():
+ """Simple integration testing for poe controller."""
+ poe_controller = rpm_controller.CiscoPOEController(
+ 'chromeos1-poe-switch1')
+ info_1 = utils.PowerUnitInfo(
+ device_hostname='chromeos1-rack4-host1bs-servo',
+ powerunit_hostname='chromeos1-poe-switch1',
+ powerunit_type=utils.PowerUnitInfo.POWERUNIT_TYPES.RPM,
+ hydra_hostname=None,
+ outlet='fa33')
+ info_2 = utils.PowerUnitInfo(
+ device_hostname='chromeos1-rack4-host2bs-servo',
+ powerunit_hostname='chromeos1-poe-switch1',
+ powerunit_type=utils.PowerUnitInfo.POWERUNIT_TYPES.RPM,
+ hydra_hostname=None,
+ outlet='fa34')
+ threading.Thread(target=poe_controller.queue_request,
+ args=(info_1, 'CYCLE')).start()
+ threading.Thread(target=poe_controller.queue_request,
+ args=(info_2, 'CYCLE')).start()
+
+
+if __name__ == '__main__':
+ logging.basicConfig(level=logging.DEBUG, format=LOGGING_FORMAT)
+# The tests in this file are disabled since most of the ports are
+# in actual use now. If you are going to run them, make sure
+# to choose unused hosts/ports.
+# test_in_order_requests()
+# test_parrallel_webrequests()
+# test_parrallel_sshrequests()
+# test_in_order_poerequests()
+# test_parrallel_poerequests()
diff --git a/site_utils/rpm_control_system/rpm_logging_config.py b/site_utils/rpm_control_system/rpm_logging_config.py
index 152d438..b97401c 100644
--- a/site_utils/rpm_control_system/rpm_logging_config.py
+++ b/site_utils/rpm_control_system/rpm_logging_config.py
@@ -12,6 +12,7 @@
import common
from autotest_lib.site_utils import log_socket_server
+from autotest_lib.site_utils.rpm_control_system import rpm_infrastructure_exception
LOGGING_FORMAT = rpm_config.get('GENERAL', 'logging_format')
RECEIVERS = rpm_config.get('RPM_INFRASTRUCTURE',
@@ -84,6 +85,10 @@
@returns email_handler: Logging handler used to send out email alerts.
"""
+ if log_socket_server.LogSocketServer.port is None and use_log_server:
+ # Port is unknown, can't log to the server.
+ raise rpm_infrastructure_exception.RPMLoggingSetupError(
+ 'set_up_logging failed: Log server port is unknown.')
if use_log_server:
socketHandler = logging.handlers.SocketHandler(
'localhost', log_socket_server.LogSocketServer.port)