You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
3.3 KiB
103 lines
3.3 KiB
#!/usr/bin/python2
|
|
# pylint: disable=missing-docstring
|
|
|
|
import unittest
|
|
import common
|
|
|
|
from autotest_lib.client.common_lib import global_config
|
|
from autotest_lib.client.common_lib.test_utils import mock
|
|
from autotest_lib.server import utils
|
|
from autotest_lib.server.hosts import base_classes
|
|
|
|
|
|
class test_host_class(unittest.TestCase):
|
|
def setUp(self):
|
|
self.god = mock.mock_god()
|
|
# stub out get_server_dir, global_config.get_config_value
|
|
self.god.stub_with(utils, "get_server_dir",
|
|
lambda: "/unittest/server")
|
|
self.god.stub_function(global_config.global_config,
|
|
"get_config_value")
|
|
|
|
|
|
def tearDown(self):
|
|
self.god.unstub_all()
|
|
|
|
|
|
def test_init(self):
|
|
self.god.stub_function(utils, "get_server_dir")
|
|
host = base_classes.Host.__new__(base_classes.Host)
|
|
# set up the recording
|
|
utils.get_server_dir.expect_call().and_return("/unittest/server")
|
|
# run the actual test
|
|
host.__init__()
|
|
self.god.check_playback()
|
|
|
|
|
|
def test_install(self):
|
|
host = base_classes.Host()
|
|
# create a dummy installable class
|
|
class installable(object):
|
|
def install(self, host):
|
|
pass
|
|
installableObj = self.god.create_mock_class(installable,
|
|
"installableObj")
|
|
installableObj.install.expect_call(host)
|
|
# run the actual test
|
|
host.install(installableObj)
|
|
self.god.check_playback()
|
|
|
|
|
|
def test_get_wait_up_empty(self):
|
|
global_config.global_config.get_config_value.expect_call(
|
|
"HOSTS", "wait_up_processes", default="").and_return("")
|
|
|
|
host = base_classes.Host()
|
|
self.assertEquals(host.get_wait_up_processes(), set())
|
|
self.god.check_playback()
|
|
|
|
|
|
def test_get_wait_up_ignores_whitespace(self):
|
|
global_config.global_config.get_config_value.expect_call(
|
|
"HOSTS", "wait_up_processes", default="").and_return(" ")
|
|
|
|
host = base_classes.Host()
|
|
self.assertEquals(host.get_wait_up_processes(), set())
|
|
self.god.check_playback()
|
|
|
|
|
|
def test_get_wait_up_single_process(self):
|
|
global_config.global_config.get_config_value.expect_call(
|
|
"HOSTS", "wait_up_processes", default="").and_return("proc1")
|
|
|
|
host = base_classes.Host()
|
|
self.assertEquals(host.get_wait_up_processes(),
|
|
set(["proc1"]))
|
|
self.god.check_playback()
|
|
|
|
|
|
def test_get_wait_up_multiple_process(self):
|
|
global_config.global_config.get_config_value.expect_call(
|
|
"HOSTS", "wait_up_processes", default="").and_return(
|
|
"proc1,proc2,proc3")
|
|
|
|
host = base_classes.Host()
|
|
self.assertEquals(host.get_wait_up_processes(),
|
|
set(["proc1", "proc2", "proc3"]))
|
|
self.god.check_playback()
|
|
|
|
|
|
def test_get_wait_up_drops_duplicates(self):
|
|
global_config.global_config.get_config_value.expect_call(
|
|
"HOSTS", "wait_up_processes", default="").and_return(
|
|
"proc1,proc2,proc1")
|
|
|
|
host = base_classes.Host()
|
|
self.assertEquals(host.get_wait_up_processes(),
|
|
set(["proc1", "proc2"]))
|
|
self.god.check_playback()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|