| 1 | #!/usr/bin/python | 
|---|
| 2 | # | 
|---|
| 3 | # Test for smbcontrol command line argument handling. | 
|---|
| 4 | # | 
|---|
| 5 |  | 
|---|
| 6 | import comfychair | 
|---|
| 7 |  | 
|---|
| 8 | class NoArgs(comfychair.TestCase): | 
|---|
| 9 | """Test no arguments produces usage message.""" | 
|---|
| 10 | def runtest(self): | 
|---|
| 11 | out = self.runcmd("smbcontrol", expectedResult = 1) | 
|---|
| 12 | self.assert_re_match("Usage: smbcontrol", out[1]) | 
|---|
| 13 |  | 
|---|
| 14 | class OneArg(comfychair.TestCase): | 
|---|
| 15 | """Test single argument produces usage message.""" | 
|---|
| 16 | def runtest(self): | 
|---|
| 17 | out = self.runcmd("smbcontrol foo", expectedResult = 1) | 
|---|
| 18 | self.assert_re_match("Usage: smbcontrol", out[1]) | 
|---|
| 19 |  | 
|---|
| 20 | class SmbdDest(comfychair.TestCase): | 
|---|
| 21 | """Test the broadcast destination 'smbd'.""" | 
|---|
| 22 | def runtest(self): | 
|---|
| 23 | out = self.runcmd("smbcontrol smbd noop") | 
|---|
| 24 |  | 
|---|
| 25 | class NmbdDest(comfychair.TestCase): | 
|---|
| 26 | """Test the destination 'nmbd'.""" | 
|---|
| 27 | def runtest(self): | 
|---|
| 28 | # We need a way to start/stop/whatever nmbd | 
|---|
| 29 | raise comfychair.NotRunError, "not implemented" | 
|---|
| 30 |  | 
|---|
| 31 | class PidDest(comfychair.TestCase): | 
|---|
| 32 | """Test a pid number destination'.""" | 
|---|
| 33 | def runtest(self): | 
|---|
| 34 | out = self.runcmd("smbcontrol 1234 noop") | 
|---|
| 35 |  | 
|---|
| 36 | class SelfDest(comfychair.TestCase): | 
|---|
| 37 | """Test the destination 'self'.""" | 
|---|
| 38 | def runtest(self): | 
|---|
| 39 | out = self.runcmd("smbcontrol self noop") | 
|---|
| 40 |  | 
|---|
| 41 | class WinbinddDest(comfychair.TestCase): | 
|---|
| 42 | """Test the destination 'winbindd'.""" | 
|---|
| 43 | def runtest(self): | 
|---|
| 44 | # We need a way to start/stop/whatever winbindd | 
|---|
| 45 | raise comfychair.NotRunError, "not implemented" | 
|---|
| 46 |  | 
|---|
| 47 | class BadDest(comfychair.TestCase): | 
|---|
| 48 | """Test a bad destination.""" | 
|---|
| 49 | def runtest(self): | 
|---|
| 50 | out = self.runcmd("smbcontrol foo noop", expectedResult = 1) | 
|---|
| 51 |  | 
|---|
| 52 | class BadCmd(comfychair.TestCase): | 
|---|
| 53 | """Test a bad command.""" | 
|---|
| 54 | def runtest(self): | 
|---|
| 55 | out = self.runcmd("smbcontrol self spottyfoot", expectedResult = 1) | 
|---|
| 56 | self.assert_re_match("smbcontrol: unknown command", out[1]); | 
|---|
| 57 |  | 
|---|
| 58 | class NoArgCmdTest(comfychair.TestCase): | 
|---|
| 59 | """A test class that tests a command with no argument.""" | 
|---|
| 60 | def runtest(self): | 
|---|
| 61 | self.require_root() | 
|---|
| 62 | out = self.runcmd("smbcontrol self %s" % self.cmd) | 
|---|
| 63 | out = self.runcmd("smbcontrol self %s spottyfoot" % self.cmd, | 
|---|
| 64 | expectedResult = 1) | 
|---|
| 65 |  | 
|---|
| 66 | class ForceElection(NoArgCmdTest): | 
|---|
| 67 | """Test a force-election message.""" | 
|---|
| 68 | def setup(self): | 
|---|
| 69 | self.cmd = "force-election" | 
|---|
| 70 |  | 
|---|
| 71 | class SamSync(NoArgCmdTest): | 
|---|
| 72 | """Test a samsync message.""" | 
|---|
| 73 | def setup(self): | 
|---|
| 74 | self.cmd = "samsync" | 
|---|
| 75 |  | 
|---|
| 76 | class SamRepl(NoArgCmdTest): | 
|---|
| 77 | """Test a samrepl message.""" | 
|---|
| 78 | def setup(self): | 
|---|
| 79 | self.cmd = "samrepl" | 
|---|
| 80 |  | 
|---|
| 81 | class DmallocChanged(NoArgCmdTest): | 
|---|
| 82 | """Test a dmalloc-changed message.""" | 
|---|
| 83 | def setup(self): | 
|---|
| 84 | self.cmd = "dmalloc-log-changed" | 
|---|
| 85 |  | 
|---|
| 86 | class DmallocMark(NoArgCmdTest): | 
|---|
| 87 | """Test a dmalloc-mark message.""" | 
|---|
| 88 | def setup(self): | 
|---|
| 89 | self.cmd = "dmalloc-mark" | 
|---|
| 90 |  | 
|---|
| 91 | class Shutdown(NoArgCmdTest): | 
|---|
| 92 | """Test a shutdown message.""" | 
|---|
| 93 | def setup(self): | 
|---|
| 94 | self.cmd = "shutdown" | 
|---|
| 95 |  | 
|---|
| 96 | class Ping(NoArgCmdTest): | 
|---|
| 97 | """Test a ping message.""" | 
|---|
| 98 | def setup(self): | 
|---|
| 99 | self.cmd = "ping" | 
|---|
| 100 |  | 
|---|
| 101 | class Debuglevel(NoArgCmdTest): | 
|---|
| 102 | """Test a debuglevel message.""" | 
|---|
| 103 | def setup(self): | 
|---|
| 104 | self.cmd = "debuglevel" | 
|---|
| 105 |  | 
|---|
| 106 | class OneArgCmdTest(comfychair.TestCase): | 
|---|
| 107 | """A test class that tests a command with one argument.""" | 
|---|
| 108 | def runtest(self): | 
|---|
| 109 | self.require_root() | 
|---|
| 110 | out = self.runcmd("smbcontrol self %s spottyfoot" % self.cmd) | 
|---|
| 111 | out = self.runcmd("smbcontrol self %s" % self.cmd, expectedResult = 1) | 
|---|
| 112 |  | 
|---|
| 113 | class DrvUpgrade(OneArgCmdTest): | 
|---|
| 114 | """Test driver upgrade message.""" | 
|---|
| 115 | def setup(self): | 
|---|
| 116 | self.cmd = "drvupgrade" | 
|---|
| 117 |  | 
|---|
| 118 | class CloseShare(OneArgCmdTest): | 
|---|
| 119 | """Test close share message.""" | 
|---|
| 120 | def setup(self): | 
|---|
| 121 | self.cmd = "close-share" | 
|---|
| 122 |  | 
|---|
| 123 | class Debug(OneArgCmdTest): | 
|---|
| 124 | """Test a debug message.""" | 
|---|
| 125 | def setup(self): | 
|---|
| 126 | self.cmd = "debug" | 
|---|
| 127 |  | 
|---|
| 128 | class PrintNotify(comfychair.TestCase): | 
|---|
| 129 | """Test print notification commands.""" | 
|---|
| 130 | def runtest(self): | 
|---|
| 131 |  | 
|---|
| 132 | # No subcommand | 
|---|
| 133 |  | 
|---|
| 134 | out = self.runcmd("smbcontrol self printnotify", expectedResult = 1) | 
|---|
| 135 | self.assert_re_match("Must specify subcommand", out[1]); | 
|---|
| 136 |  | 
|---|
| 137 | # Invalid subcommand name | 
|---|
| 138 |  | 
|---|
| 139 | out = self.runcmd("smbcontrol self printnotify spottyfoot", | 
|---|
| 140 | expectedResult = 1) | 
|---|
| 141 | self.assert_re_match("Invalid subcommand", out[1]); | 
|---|
| 142 |  | 
|---|
| 143 | # Queue commands | 
|---|
| 144 |  | 
|---|
| 145 | for cmd in ["queuepause", "queueresume"]: | 
|---|
| 146 |  | 
|---|
| 147 | out = self.runcmd("smbcontrol self printnotify %s" % cmd, | 
|---|
| 148 | expectedResult = 1) | 
|---|
| 149 | self.assert_re_match("Usage:", out[1]) | 
|---|
| 150 |  | 
|---|
| 151 | out = self.runcmd("smbcontrol self printnotify %s spottyfoot" | 
|---|
| 152 | % cmd) | 
|---|
| 153 |  | 
|---|
| 154 | # Job commands | 
|---|
| 155 |  | 
|---|
| 156 | for cmd in ["jobpause", "jobresume", "jobdelete"]: | 
|---|
| 157 |  | 
|---|
| 158 | out = self.runcmd("smbcontrol self printnotify %s" % cmd, | 
|---|
| 159 | expectedResult = 1) | 
|---|
| 160 | self.assert_re_match("Usage:", out[1]) | 
|---|
| 161 |  | 
|---|
| 162 | out = self.runcmd("smbcontrol self printnotify %s spottyfoot" | 
|---|
| 163 | % cmd, expectedResult = 1) | 
|---|
| 164 | self.assert_re_match("Usage:", out[1]) | 
|---|
| 165 |  | 
|---|
| 166 | out = self.runcmd("smbcontrol self printnotify %s spottyfoot 123" | 
|---|
| 167 | % cmd) | 
|---|
| 168 |  | 
|---|
| 169 | # Printer properties | 
|---|
| 170 |  | 
|---|
| 171 | out = self.runcmd("smbcontrol self printnotify printer", | 
|---|
| 172 | expectedResult = 1) | 
|---|
| 173 | self.assert_re_match("Usage", out[1]) | 
|---|
| 174 |  | 
|---|
| 175 | out = self.runcmd("smbcontrol self printnotify printer spottyfoot", | 
|---|
| 176 | expectedResult = 1) | 
|---|
| 177 | self.assert_re_match("Usage", out[1]) | 
|---|
| 178 |  | 
|---|
| 179 | for cmd in ["comment", "port", "driver"]: | 
|---|
| 180 |  | 
|---|
| 181 | out = self.runcmd("smbcontrol self printnotify printer spottyfoot " | 
|---|
| 182 | "%s" % cmd, expectedResult = 1) | 
|---|
| 183 | self.assert_re_match("Usage", out[1]) | 
|---|
| 184 |  | 
|---|
| 185 | out = self.runcmd("smbcontrol self printnotify printer spottyfoot " | 
|---|
| 186 | "%s value" % cmd) | 
|---|
| 187 |  | 
|---|
| 188 | class Profile(comfychair.TestCase): | 
|---|
| 189 | """Test setting the profiling level.""" | 
|---|
| 190 | def runtest(self): | 
|---|
| 191 | self.require_root() | 
|---|
| 192 | out = self.runcmd("smbcontrol self profile", expectedResult = 1) | 
|---|
| 193 | self.assert_re_match("Usage", out[1]) | 
|---|
| 194 |  | 
|---|
| 195 | out = self.runcmd("smbcontrol self profile spottyfoot", | 
|---|
| 196 | expectedResult = 1) | 
|---|
| 197 | self.assert_re_match("Unknown", out[1]) | 
|---|
| 198 |  | 
|---|
| 199 | for cmd in ["off", "count", "on", "flush"]: | 
|---|
| 200 | out = self.runcmd("smbcontrol self profile %s" % cmd) | 
|---|
| 201 |  | 
|---|
| 202 | class ProfileLevel(comfychair.TestCase): | 
|---|
| 203 | """Test requesting the current profiling level.""" | 
|---|
| 204 | def runtest(self): | 
|---|
| 205 | self.require_root() | 
|---|
| 206 | out = self.runcmd("smbcontrol self profilelevel spottyfoot", | 
|---|
| 207 | expectedResult = 1) | 
|---|
| 208 | self.assert_re_match("Usage", out[1]) | 
|---|
| 209 |  | 
|---|
| 210 | out = self.runcmd("smbcontrol self profilelevel") | 
|---|
| 211 |  | 
|---|
| 212 | class TimeoutArg(comfychair.TestCase): | 
|---|
| 213 | """Test the --timeout argument.""" | 
|---|
| 214 | def runtest(self): | 
|---|
| 215 | out = self.runcmd("smbcontrol --timeout 5 self noop") | 
|---|
| 216 | out = self.runcmd("smbcontrol --timeout spottyfoot self noop", | 
|---|
| 217 | expectedResult = 1) | 
|---|
| 218 |  | 
|---|
| 219 | class ConfigFileArg(comfychair.TestCase): | 
|---|
| 220 | """Test the --configfile argument.""" | 
|---|
| 221 | def runtest(self): | 
|---|
| 222 | out = self.runcmd("smbcontrol --configfile /dev/null self noop") | 
|---|
| 223 |  | 
|---|
| 224 | class BogusArg(comfychair.TestCase): | 
|---|
| 225 | """Test a bogus command line argument.""" | 
|---|
| 226 | def runtest(self): | 
|---|
| 227 | out = self.runcmd("smbcontrol --bogus self noop", expectedResult = 1) | 
|---|
| 228 |  | 
|---|
| 229 | tests = [NoArgs, OneArg, SmbdDest, NmbdDest, WinbinddDest, PidDest, | 
|---|
| 230 | SelfDest, BadDest, BadCmd, Debug, ForceElection, SamSync, | 
|---|
| 231 | SamRepl, DmallocMark, DmallocChanged, Shutdown, DrvUpgrade, | 
|---|
| 232 | CloseShare, Ping, Debuglevel, PrintNotify, Profile, ProfileLevel, | 
|---|
| 233 | TimeoutArg, ConfigFileArg, BogusArg] | 
|---|
| 234 |  | 
|---|
| 235 | # Handle execution of this file as a main program | 
|---|
| 236 |  | 
|---|
| 237 | if __name__ == '__main__': | 
|---|
| 238 | comfychair.main(tests) | 
|---|