1#!/usr/bin/python2 2# pylint: disable=missing-docstring 3 4import unittest 5import common 6 7from autotest_lib.client.common_lib import global_config 8from autotest_lib.client.common_lib.test_utils import mock 9from autotest_lib.server import utils 10from autotest_lib.server.hosts import base_classes 11 12 13class test_host_class(unittest.TestCase): 14 def setUp(self): 15 self.god = mock.mock_god() 16 # stub out get_server_dir, global_config.get_config_value 17 self.god.stub_with(utils, "get_server_dir", 18 lambda: "/unittest/server") 19 self.god.stub_function(global_config.global_config, 20 "get_config_value") 21 22 23 def tearDown(self): 24 self.god.unstub_all() 25 26 27 def test_init(self): 28 self.god.stub_function(utils, "get_server_dir") 29 host = base_classes.Host.__new__(base_classes.Host) 30 # set up the recording 31 utils.get_server_dir.expect_call().and_return("/unittest/server") 32 # run the actual test 33 host.__init__() 34 self.god.check_playback() 35 36 37 def test_install(self): 38 host = base_classes.Host() 39 # create a dummy installable class 40 class installable(object): 41 def install(self, host): 42 pass 43 installableObj = self.god.create_mock_class(installable, 44 "installableObj") 45 installableObj.install.expect_call(host) 46 # run the actual test 47 host.install(installableObj) 48 self.god.check_playback() 49 50 51 def test_get_wait_up_empty(self): 52 global_config.global_config.get_config_value.expect_call( 53 "HOSTS", "wait_up_processes", default="").and_return("") 54 55 host = base_classes.Host() 56 self.assertEquals(host.get_wait_up_processes(), set()) 57 self.god.check_playback() 58 59 60 def test_get_wait_up_ignores_whitespace(self): 61 global_config.global_config.get_config_value.expect_call( 62 "HOSTS", "wait_up_processes", default="").and_return(" ") 63 64 host = base_classes.Host() 65 self.assertEquals(host.get_wait_up_processes(), set()) 66 self.god.check_playback() 67 68 69 def test_get_wait_up_single_process(self): 70 global_config.global_config.get_config_value.expect_call( 71 "HOSTS", "wait_up_processes", default="").and_return("proc1") 72 73 host = base_classes.Host() 74 self.assertEquals(host.get_wait_up_processes(), 75 set(["proc1"])) 76 self.god.check_playback() 77 78 79 def test_get_wait_up_multiple_process(self): 80 global_config.global_config.get_config_value.expect_call( 81 "HOSTS", "wait_up_processes", default="").and_return( 82 "proc1,proc2,proc3") 83 84 host = base_classes.Host() 85 self.assertEquals(host.get_wait_up_processes(), 86 set(["proc1", "proc2", "proc3"])) 87 self.god.check_playback() 88 89 90 def test_get_wait_up_drops_duplicates(self): 91 global_config.global_config.get_config_value.expect_call( 92 "HOSTS", "wait_up_processes", default="").and_return( 93 "proc1,proc2,proc1") 94 95 host = base_classes.Host() 96 self.assertEquals(host.get_wait_up_processes(), 97 set(["proc1", "proc2"])) 98 self.god.check_playback() 99 100 101if __name__ == "__main__": 102 unittest.main() 103