1# Copyright (c) 2020 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import unittest 6import common 7from autotest_lib.server.hosts import labstation_host 8 9 10LabstationHost = labstation_host.LabstationHost 11 12 13class MockRPMClient(object): 14 """Mocking out the rpm_client to avoid actual API calls""" 15 def __init__(self, expected_state=None): 16 self._expected_state = expected_state 17 18 def set_power(self, host, new_state): 19 assert new_state == self._expected_state 20 21 22class MockMainSsh(object): 23 def __init__(self): 24 self.ssh_option = "" 25 26 def maybe_start(self, *args, **kwargs): 27 pass 28 29 def close(self, *args, **kwargs): 30 pass 31 32 33class LabstationHostSkipInit(LabstationHost): 34 """LabstationHostSkipInit is like a labstation host, but 35 skips initialization. 36 37 This gives us the ability to inject our own mocks during host 38 setup. 39 """ 40 def __init__(self): 41 self._is_localhost = False 42 self._main_ssh = MockMainSsh() 43 self.env = {} 44 self.user = "a" 45 self.port = 7 46 self.known_hosts_file = None 47 self.hostname = "a" 48 49 def run(self, *args, **kwargs): 50 class FakeResult(object): 51 def __init__(self): 52 self.stdout = "" 53 return FakeResult() 54 55 def wait_down(self, *args, **kwargs): 56 return True 57 58 def wait_up(self, *args, **kwargs): 59 return True 60 61 62class LabstationHostUnittest(unittest.TestCase): 63 def test_rpm_power_on_and_wait(self): 64 m = MockRPMClient(expected_state='ON') 65 labstation = LabstationHostSkipInit() 66 labstation.rpm_power_on_and_wait(_rpm_client=m) 67 68 def test_rpm_power_off_and_wait(self): 69 m = MockRPMClient(expected_state='OFF') 70 labstation = LabstationHostSkipInit() 71 labstation.rpm_power_off_and_wait(_rpm_client=m) 72 73 74if __name__ == "__main__": 75 unittest.main() 76