• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python
2
3import unittest
4import common
5
6from autotest_lib.client.common_lib import global_config
7from autotest_lib.client.common_lib.test_utils import mock
8from autotest_lib.server import utils
9from autotest_lib.server.hosts import base_classes, bootloader
10
11
12class test_host_class(unittest.TestCase):
13    def setUp(self):
14        self.god = mock.mock_god()
15        # stub out get_server_dir, global_config.get_config_value
16        self.god.stub_with(utils, "get_server_dir",
17                           lambda: "/unittest/server")
18        self.god.stub_function(global_config.global_config,
19                               "get_config_value")
20        # stub out the bootloader
21        self.real_bootloader = bootloader.Bootloader
22        bootloader.Bootloader = lambda arg: object()
23
24
25    def tearDown(self):
26        self.god.unstub_all()
27        bootloader.Bootloader = self.real_bootloader
28
29
30    def test_init(self):
31        self.god.stub_function(utils, "get_server_dir")
32        host = base_classes.Host.__new__(base_classes.Host)
33        bootloader.Bootloader = \
34                self.god.create_mock_class_obj(self.real_bootloader,
35                                               "Bootloader")
36        # overwrite this attribute as it's irrelevant for these tests
37        # and may cause problems with construction of the mock
38        bootloader.Bootloader.boottool_path = None
39        # set up the recording
40        utils.get_server_dir.expect_call().and_return("/unittest/server")
41        bootloader.Bootloader.expect_new(host)
42        # run the actual test
43        host.__init__()
44        self.god.check_playback()
45
46
47    def test_install(self):
48        host = base_classes.Host()
49        # create a dummy installable class
50        class installable(object):
51            def install(self, host):
52                pass
53        installableObj = self.god.create_mock_class(installable,
54                                                    "installableObj")
55        installableObj.install.expect_call(host)
56        # run the actual test
57        host.install(installableObj)
58        self.god.check_playback()
59
60
61    def test_get_wait_up_empty(self):
62        global_config.global_config.get_config_value.expect_call(
63            "HOSTS", "wait_up_processes", default="").and_return("")
64
65        host = base_classes.Host()
66        self.assertEquals(host.get_wait_up_processes(), set())
67        self.god.check_playback()
68
69
70    def test_get_wait_up_ignores_whitespace(self):
71        global_config.global_config.get_config_value.expect_call(
72            "HOSTS", "wait_up_processes", default="").and_return("  ")
73
74        host = base_classes.Host()
75        self.assertEquals(host.get_wait_up_processes(), set())
76        self.god.check_playback()
77
78
79    def test_get_wait_up_single_process(self):
80        global_config.global_config.get_config_value.expect_call(
81            "HOSTS", "wait_up_processes", default="").and_return("proc1")
82
83        host = base_classes.Host()
84        self.assertEquals(host.get_wait_up_processes(),
85                          set(["proc1"]))
86        self.god.check_playback()
87
88
89    def test_get_wait_up_multiple_process(self):
90        global_config.global_config.get_config_value.expect_call(
91            "HOSTS", "wait_up_processes", default="").and_return(
92            "proc1,proc2,proc3")
93
94        host = base_classes.Host()
95        self.assertEquals(host.get_wait_up_processes(),
96                          set(["proc1", "proc2", "proc3"]))
97        self.god.check_playback()
98
99
100    def test_get_wait_up_drops_duplicates(self):
101        global_config.global_config.get_config_value.expect_call(
102            "HOSTS", "wait_up_processes", default="").and_return(
103            "proc1,proc2,proc1")
104
105        host = base_classes.Host()
106        self.assertEquals(host.get_wait_up_processes(),
107                          set(["proc1", "proc2"]))
108        self.god.check_playback()
109
110
111if __name__ == "__main__":
112    unittest.main()
113