~ahasenack/landscape-client/landscape-client-1.5.5-0ubuntu0.9.04.0

« back to all changes in this revision

Viewing changes to landscape/tests/test_sysvconfig.py

  • Committer: Bazaar Package Importer
  • Author(s): Rick Clark
  • Date: 2008-09-08 16:35:57 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080908163557-l3ixzj5dxz37wnw2
Tags: 1.0.18-0ubuntu1
New upstream release 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import time
 
2
import os
 
3
 
 
4
from landscape.tests.helpers import LandscapeTest
 
5
 
 
6
from landscape.sysvconfig import SysVConfig, ProcessError
 
7
 
 
8
 
 
9
class SysVConfigTest(LandscapeTest):
 
10
 
 
11
    def test_set_to_run_on_boot(self):
 
12
        filename = self.makeFile("RUN=0\n")
 
13
        sysvconfig = SysVConfig(filename)
 
14
        sysvconfig.set_start_on_boot(True)
 
15
        self.assertEquals(file(filename, "r").read(), "RUN=1\n")
 
16
 
 
17
    def test_set_to_not_run_on_boot(self):
 
18
        filename = self.makeFile("RUN=1\n")
 
19
        sysvconfig = SysVConfig(filename)
 
20
        sysvconfig.set_start_on_boot(False)
 
21
        self.assertEquals(file(filename, "r").read(), "RUN=0\n")
 
22
 
 
23
    def test_is_landscape_configured_to_run(self):
 
24
        filename = self.makeFile("RUN=1\n")
 
25
        sysvconfig = SysVConfig(filename)
 
26
        self.assertTrue(sysvconfig.is_configured_to_run(), True)
 
27
 
 
28
    def test_is_landscape_configured_to_run(self):
 
29
        filename = self.makeFile("RUN=0\n")
 
30
        sysvconfig = SysVConfig(filename)
 
31
        self.assertTrue(sysvconfig.is_configured_to_run(), False)
 
32
 
 
33
    def test_run_landscape(self):
 
34
        system = self.mocker.replace("os.system")
 
35
        system("/etc/init.d/landscape-client restart")
 
36
        self.mocker.replay()
 
37
        filename = self.makeFile("RUN=1\n")
 
38
        sysvconfig = SysVConfig(filename)
 
39
        sysvconfig.restart_landscape()
 
40
 
 
41
    def test_run_landscape_with_error(self):
 
42
        system = self.mocker.replace("os.system")
 
43
        system("/etc/init.d/landscape-client restart")
 
44
        self.mocker.result(-1)
 
45
        self.mocker.replay()
 
46
        filename = self.makeFile("RUN=1\n")
 
47
        sysvconfig = SysVConfig(filename)
 
48
        self.assertRaises(ProcessError, sysvconfig.restart_landscape)
 
49
 
 
50
    def test_stop_landscape(self):
 
51
        system = self.mocker.replace("os.system")
 
52
        system("/etc/init.d/landscape-client stop")
 
53
        self.mocker.replay()
 
54
        filename = self.makeFile("RUN=1\n")
 
55
        sysvconfig = SysVConfig(filename)
 
56
        sysvconfig.stop_landscape()
 
57
 
 
58
    def test_stop_landscape(self):
 
59
        system = self.mocker.replace("os.system")
 
60
        system("/etc/init.d/landscape-client stop")
 
61
        self.mocker.result(-1)
 
62
        self.mocker.replay()
 
63
        filename = self.makeFile("RUN=1\n")
 
64
        sysvconfig = SysVConfig(filename)
 
65
        self.assertRaises(ProcessError, sysvconfig.stop_landscape)