1
from landscape.tests.helpers import LandscapeTest
3
from landscape.sysvconfig import SysVConfig, ProcessError
6
class SysVConfigTest(LandscapeTest):
8
def test_set_to_run_on_boot(self):
9
filename = self.makeFile("RUN=0\n")
10
sysvconfig = SysVConfig(filename)
11
sysvconfig.set_start_on_boot(True)
12
self.assertEquals(file(filename, "r").read(), "RUN=1\n")
14
def test_set_to_not_run_on_boot(self):
15
filename = self.makeFile("RUN=1\n")
16
sysvconfig = SysVConfig(filename)
17
sysvconfig.set_start_on_boot(False)
18
self.assertEquals(file(filename, "r").read(), "RUN=0\n")
20
def test_configured_to_run(self):
21
filename = self.makeFile("RUN=1\n")
22
sysvconfig = SysVConfig(filename)
23
self.assertTrue(sysvconfig.is_configured_to_run())
25
def test_not_configured_to_run(self):
26
filename = self.makeFile("RUN=0\n")
27
sysvconfig = SysVConfig(filename)
28
self.assertFalse(sysvconfig.is_configured_to_run())
30
def test_blank_line(self):
31
filename = self.makeFile("RUN=1\n\n")
32
sysvconfig = SysVConfig(filename)
33
self.assertTrue(sysvconfig.is_configured_to_run())
35
def test_spaces(self):
36
filename = self.makeFile(" RUN = 1 \n")
37
sysvconfig = SysVConfig(filename)
38
self.assertFalse(sysvconfig.is_configured_to_run())
40
def test_leading_and_trailing_spaces(self):
41
filename = self.makeFile(" RUN=1 \n")
42
sysvconfig = SysVConfig(filename)
43
self.assertTrue(sysvconfig.is_configured_to_run())
45
def test_spaces_in_value(self):
46
filename = self.makeFile(" RUN= 1 \n")
47
sysvconfig = SysVConfig(filename)
48
self.assertFalse(sysvconfig.is_configured_to_run())
50
def test_non_integer_run(self):
51
filename = self.makeFile("RUN=yesplease")
52
sysvconfig = SysVConfig(filename)
53
self.assertTrue(sysvconfig.is_configured_to_run())
55
def test_run_landscape(self):
56
system = self.mocker.replace("os.system")
57
system("/etc/init.d/landscape-client restart")
59
filename = self.makeFile("RUN=1\n")
60
sysvconfig = SysVConfig(filename)
61
sysvconfig.restart_landscape()
63
def test_run_landscape_with_error(self):
64
system = self.mocker.replace("os.system")
65
system("/etc/init.d/landscape-client restart")
66
self.mocker.result(-1)
68
filename = self.makeFile("RUN=1\n")
69
sysvconfig = SysVConfig(filename)
70
self.assertRaises(ProcessError, sysvconfig.restart_landscape)
72
def test_stop_landscape(self):
73
system = self.mocker.replace("os.system")
74
system("/etc/init.d/landscape-client stop")
76
filename = self.makeFile("RUN=1\n")
77
sysvconfig = SysVConfig(filename)
78
sysvconfig.stop_landscape()
80
def test_stop_landscape_with_error(self):
81
system = self.mocker.replace("os.system")
82
system("/etc/init.d/landscape-client stop")
83
self.mocker.result(-1)
85
filename = self.makeFile("RUN=1\n")
86
sysvconfig = SysVConfig(filename)
87
self.assertRaises(ProcessError, sysvconfig.stop_landscape)