summaryrefslogtreecommitdiffstats
path: root/source/stf/smbcontrol.py
blob: 30c331819c76712e05a66f8ec4c17a7b6f6f6832 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#!/usr/bin/python
#
# Test for smbcontrol command line argument handling.
#

import comfychair

class NoArgs(comfychair.TestCase):
    """Test no arguments produces usage message."""
    def runtest(self):
        out = self.runcmd("smbcontrol", expectedResult = 1)
        self.assert_re_match("Usage: smbcontrol", out[1])
        
class OneArg(comfychair.TestCase):
    """Test single argument produces usage message."""
    def runtest(self):
        out = self.runcmd("smbcontrol foo", expectedResult = 1)
        self.assert_re_match("Usage: smbcontrol", out[1])
        
class SmbdDest(comfychair.TestCase):
    """Test the broadcast destination 'smbd'."""
    def runtest(self):
        out = self.runcmd("smbcontrol smbd noop")

class NmbdDest(comfychair.TestCase):
    """Test the destination 'nmbd'."""
    def runtest(self):
        # We need a way to start/stop/whatever nmbd
        raise comfychair.NotRunError, "not implemented"

class PidDest(comfychair.TestCase):
    """Test a pid number destination'."""
    def runtest(self):
        out = self.runcmd("smbcontrol 1234 noop")

class SelfDest(comfychair.TestCase):
    """Test the destination 'self'."""
    def runtest(self):
        out = self.runcmd("smbcontrol self noop")

class WinbinddDest(comfychair.TestCase):
    """Test the destination 'winbindd'."""
    def runtest(self):
        # We need a way to start/stop/whatever winbindd
        raise comfychair.NotRunError, "not implemented"

class BadDest(comfychair.TestCase):
    """Test a bad destination."""
    def runtest(self):
        out = self.runcmd("smbcontrol foo noop", expectedResult = 1)

class BadCmd(comfychair.TestCase):
    """Test a bad command."""
    def runtest(self):
        out = self.runcmd("smbcontrol self spottyfoot", expectedResult = 1)
        self.assert_re_match("smbcontrol: unknown command", out[1]);

class NoArgCmdTest(comfychair.TestCase):
    """A test class that tests a command with no argument."""
    def runtest(self):
        self.require_root()
        out = self.runcmd("smbcontrol self %s" % self.cmd)
        out = self.runcmd("smbcontrol self %s spottyfoot" % self.cmd,
                          expectedResult = 1)

class ForceElection(NoArgCmdTest):
    """Test a force-election message."""
    def setup(self):
        self.cmd = "force-election"

class SamSync(NoArgCmdTest):
    """Test a samsync message."""
    def setup(self):
        self.cmd = "samsync"

class SamRepl(NoArgCmdTest):
    """Test a samrepl message."""
    def setup(self):
        self.cmd = "samrepl"

class DmallocChanged(NoArgCmdTest):
    """Test a dmalloc-changed message."""
    def setup(self):
        self.cmd = "dmalloc-log-changed"

class DmallocMark(NoArgCmdTest):
    """Test a dmalloc-mark message."""
    def setup(self):
        self.cmd = "dmalloc-mark"

class Shutdown(NoArgCmdTest):
    """Test a shutdown message."""
    def setup(self):
        self.cmd = "shutdown"

class Ping(NoArgCmdTest):
    """Test a ping message."""
    def setup(self):
        self.cmd = "ping"

class Debuglevel(NoArgCmdTest):
    """Test a debuglevel message."""
    def setup(self):
        self.cmd = "debuglevel"

class OneArgCmdTest(comfychair.TestCase):
    """A test class that tests a command with one argument."""
    def runtest(self):
        self.require_root()
        out = self.runcmd("smbcontrol self %s spottyfoot" % self.cmd)
        out = self.runcmd("smbcontrol self %s" % self.cmd, expectedResult = 1)

class DrvUpgrade(OneArgCmdTest):
    """Test driver upgrade message."""
    def setup(self):
        self.cmd = "drvupgrade"
        
class CloseShare(OneArgCmdTest):
    """Test close share message."""
    def setup(self):
        self.cmd = "close-share"
        
class Debug(OneArgCmdTest):
    """Test a debug message."""
    def setup(self):
        self.cmd = "debug"

class PrintNotify(comfychair.TestCase):
    """Test print notification commands."""
    def runtest(self):

        # No subcommand

        out = self.runcmd("smbcontrol self printnotify", expectedResult = 1)
        self.assert_re_match("Must specify subcommand", out[1]);

        # Invalid subcommand name

        out = self.runcmd("smbcontrol self printnotify spottyfoot",
                          expectedResult = 1)
        self.assert_re_match("Invalid subcommand", out[1]);

        # Queue commands

        for cmd in ["queuepause", "queueresume"]:

            out = self.runcmd("smbcontrol self printnotify %s" % cmd,
                              expectedResult = 1)
            self.assert_re_match("Usage:", out[1])
        
            out = self.runcmd("smbcontrol self printnotify %s spottyfoot"
                              % cmd)

        # Job commands

        for cmd in ["jobpause", "jobresume", "jobdelete"]:

            out = self.runcmd("smbcontrol self printnotify %s" % cmd,
                              expectedResult = 1)
            self.assert_re_match("Usage:", out[1])

            out = self.runcmd("smbcontrol self printnotify %s spottyfoot"
                              % cmd, expectedResult = 1)
            self.assert_re_match("Usage:", out[1])

            out = self.runcmd("smbcontrol self printnotify %s spottyfoot 123"
                              % cmd)

        # Printer properties

        out = self.runcmd("smbcontrol self printnotify printer",
                          expectedResult = 1)
        self.assert_re_match("Usage", out[1])

        out = self.runcmd("smbcontrol self printnotify printer spottyfoot",
                          expectedResult = 1)
        self.assert_re_match("Usage", out[1])

        for cmd in ["comment", "port", "driver"]:

            out = self.runcmd("smbcontrol self printnotify printer spottyfoot "
                              "%s" % cmd, expectedResult = 1)
            self.assert_re_match("Usage", out[1])

            out = self.runcmd("smbcontrol self printnotify printer spottyfoot "
                              "%s value" % cmd)

class Profile(comfychair.TestCase):
    """Test setting the profiling level."""
    def runtest(self):
        self.require_root()
        out = self.runcmd("smbcontrol self profile", expectedResult = 1)
        self.assert_re_match("Usage", out[1])
        
        out = self.runcmd("smbcontrol self profile spottyfoot",
                          expectedResult = 1)
        self.assert_re_match("Unknown", out[1])
        
        for cmd in ["off", "count", "on", "flush"]:
            out = self.runcmd("smbcontrol self profile %s" % cmd)

class ProfileLevel(comfychair.TestCase):
    """Test requesting the current profiling level."""
    def runtest(self):
        self.require_root()
        out = self.runcmd("smbcontrol self profilelevel spottyfoot",
                          expectedResult = 1)
        self.assert_re_match("Usage", out[1])
        
        out = self.runcmd("smbcontrol self profilelevel")
        
class TimeoutArg(comfychair.TestCase):
    """Test the --timeout argument."""
    def runtest(self):
        out = self.runcmd("smbcontrol --timeout 5 self noop")
        out = self.runcmd("smbcontrol --timeout spottyfoot self noop",
                          expectedResult = 1)

class ConfigFileArg(comfychair.TestCase):
    """Test the --configfile argument."""
    def runtest(self):
        out = self.runcmd("smbcontrol --configfile /dev/null self noop")

class BogusArg(comfychair.TestCase):
    """Test a bogus command line argument."""
    def runtest(self):
        out = self.runcmd("smbcontrol --bogus self noop", expectedResult = 1)

tests = [NoArgs, OneArg, SmbdDest, NmbdDest, WinbinddDest, PidDest,
         SelfDest, BadDest, BadCmd, Debug, ForceElection, SamSync,
         SamRepl, DmallocMark, DmallocChanged, Shutdown, DrvUpgrade,
         CloseShare, Ping, Debuglevel, PrintNotify, Profile, ProfileLevel,
         TimeoutArg, ConfigFileArg, BogusArg]

# Handle execution of this file as a main program

if __name__ == '__main__':
    comfychair.main(tests)