Home | History | Annotate | Download | only in rpm_control_system
      1 import logging
      2 import threading
      3 
      4 import common
      5 
      6 from autotest_lib.site_utils.rpm_control_system import rpm_controller
      7 from autotest_lib.site_utils.rpm_control_system import utils
      8 
      9 
     10 # Format Appears as: [Date] [Time] - [Msg Level] - [Message]
     11 LOGGING_FORMAT = '%(asctime)s - %(levelname)s - %(message)s'
     12 
     13 
     14 def test_in_order_requests():
     15     """Simple integration testing."""
     16     rpm = rpm_controller.WebPoweredRPMController(
     17             'chromeos-rack8e-rpm1')
     18     info_1 = utils.PowerUnitInfo(
     19             device_hostname='chromeos1-rack8e-hostbs1',
     20             powerunit_hostname='chromeos-rack8e-rpm1',
     21             powerunit_type=utils.PowerUnitInfo.POWERUNIT_TYPES.RPM,
     22             hydra_hostname=None,
     23             outlet='')
     24     info_2 = utils.PowerUnitInfo(
     25             device_hostname='chromeos1-rack8e-hostbs2',
     26             powerunit_hostname='chromeos-rack8e-rpm1',
     27             powerunit_type=utils.PowerUnitInfo.POWERUNIT_TYPES.RPM,
     28             hydra_hostname=None,
     29             outlet='')
     30     info_3 = utils.PowerUnitInfo(
     31             device_hostname='chromeos1-rack8e-hostbs3',
     32             powerunit_hostname='chromeos-rack8e-rpm1',
     33             powerunit_type=utils.PowerUnitInfo.POWERUNIT_TYPES.RPM,
     34             hydra_hostname=None,
     35             outlet='')
     36     rpm.queue_request(info_1, 'OFF')
     37     rpm.queue_request(info_2, 'OFF')
     38     rpm.queue_request(info_3, 'CYCLE')
     39 
     40 
     41 def test_parrallel_webrequests():
     42     """Simple integration testing."""
     43     rpm = rpm_controller.WebPoweredRPMController(
     44             'chromeos-rack8e-rpm1')
     45     info_1 = utils.PowerUnitInfo(
     46             device_hostname='chromeos1-rack8e-hostbs1',
     47             powerunit_hostname='chromeos-rack8e-rpm1',
     48             powerunit_type=utils.PowerUnitInfo.POWERUNIT_TYPES.RPM,
     49             hydra_hostname=None,
     50             outlet='')
     51     info_2 = utils.PowerUnitInfo(
     52             device_hostname='chromeos1-rack8e-hostbs2',
     53             powerunit_hostname='chromeos-rack8e-rpm1',
     54             powerunit_type=utils.PowerUnitInfo.POWERUNIT_TYPES.RPM,
     55             hydra_hostname=None,
     56             outlet='')
     57     threading.Thread(target=rpm.queue_request,
     58                      args=(info_1, 'OFF')).start()
     59     threading.Thread(target=rpm.queue_request,
     60                      args=(info_2, 'ON')).start()
     61 
     62 
     63 def test_parrallel_sshrequests():
     64     """Simple integration testing."""
     65     rpm =   rpm_controller.SentryRPMController('chromeos-rack8-rpm1')
     66     info_1 = utils.PowerUnitInfo(
     67             device_hostname='chromeos-rack8-hostbs1',
     68             powerunit_hostname='chromeos-rack8-rpm1',
     69             powerunit_type=utils.PowerUnitInfo.POWERUNIT_TYPES.RPM,
     70             hydra_hostname=None,
     71             outlet='.A14')
     72     info_2 = utils.PowerUnitInfo(
     73             device_hostname='chromeos-rack8-hostbs2',
     74             powerunit_hostname='chromeos-rack8-rpm1',
     75             powerunit_type=utils.PowerUnitInfo.POWERUNIT_TYPES.RPM,
     76             hydra_hostname=None,
     77             outlet='.A11')
     78     threading.Thread(target=rpm.queue_request,
     79                      args=(info_1, 'CYCLE')).start()
     80     threading.Thread(target=rpm.queue_request,
     81                      args=(info_2, 'CYCLE')).start()
     82 
     83     # The following test are disabled as the
     84     # outlets on the rpm are in actual use.
     85     # rpm2 = SentryRPMController('chromeos2-row2-rack3-rpm1')
     86     # threading.Thread(target=rpm2.queue_request,
     87     #                  args=('chromeos2-row2-rack3-hostbs', 'ON')).start()
     88     # threading.Thread(target=rpm2.queue_request,
     89     #                  args=('chromeos2-row2-rack3-hostbs2', 'ON')).start()
     90     # threading.Thread(target=rpm2.queue_request,
     91     #                  args=('chromeos2-row1-rack7-hostbs1', 'ON')).start()
     92 
     93 
     94 def test_in_order_poerequests():
     95     """Simple integration testing for poe controller."""
     96     poe_controller = rpm_controller.CiscoPOEController(
     97             'chromeos1-poe-switch1')
     98     info_1 = utils.PowerUnitInfo(
     99             device_hostname='chromeos1-rack4-host1bs-servo',
    100             powerunit_hostname='chromeos1-poe-switch1',
    101             powerunit_type=utils.PowerUnitInfo.POWERUNIT_TYPES.RPM,
    102             hydra_hostname=None,
    103             outlet='fa33')
    104     info_2 = utils.PowerUnitInfo(
    105             device_hostname='chromeos1-rack4-host2bs-servo',
    106             powerunit_hostname='chromeos1-poe-switch1',
    107             powerunit_type=utils.PowerUnitInfo.POWERUNIT_TYPES.RPM,
    108             hydra_hostname=None,
    109             outlet='fa34')
    110     poe_controller.queue_request(info_1, 'OFF')
    111     poe_controller.queue_request(info_1, 'ON')
    112     poe_controller.queue_request(info_2, 'CYCLE')
    113 
    114 
    115 def test_parrallel_poerequests():
    116     """Simple integration testing for poe controller."""
    117     poe_controller = rpm_controller.CiscoPOEController(
    118             'chromeos1-poe-switch1')
    119     info_1 = utils.PowerUnitInfo(
    120             device_hostname='chromeos1-rack4-host1bs-servo',
    121             powerunit_hostname='chromeos1-poe-switch1',
    122             powerunit_type=utils.PowerUnitInfo.POWERUNIT_TYPES.RPM,
    123             hydra_hostname=None,
    124             outlet='fa33')
    125     info_2 = utils.PowerUnitInfo(
    126             device_hostname='chromeos1-rack4-host2bs-servo',
    127             powerunit_hostname='chromeos1-poe-switch1',
    128             powerunit_type=utils.PowerUnitInfo.POWERUNIT_TYPES.RPM,
    129             hydra_hostname=None,
    130             outlet='fa34')
    131     threading.Thread(target=poe_controller.queue_request,
    132                      args=(info_1, 'CYCLE')).start()
    133     threading.Thread(target=poe_controller.queue_request,
    134                      args=(info_2, 'CYCLE')).start()
    135 
    136 
    137 if __name__ == '__main__':
    138     logging.basicConfig(level=logging.DEBUG, format=LOGGING_FORMAT)
    139 #    The tests in this file are disabled since most of the ports are
    140 #    in actual use now. If you are going to run them, make sure
    141 #    to choose unused hosts/ports.
    142 #    test_in_order_requests()
    143 #    test_parrallel_webrequests()
    144 #    test_parrallel_sshrequests()
    145 #    test_in_order_poerequests()
    146 #    test_parrallel_poerequests()
    147