Holger Hans Peter Freyther | 6539752 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # (C) 2013 by Katerina Barone-Adesi <kat.obsc@gmail.com> |
| 4 | # (C) 2013 by Holger Hans Peter Freyther |
| 5 | # This program is free software: you can redistribute it and/or modify |
| 6 | # it under the terms of the GNU General Public License as published by |
| 7 | # the Free Software Foundation, either version 3 of the License, or |
| 8 | # (at your option) any later version. |
| 9 | |
| 10 | # This program is distributed in the hope that it will be useful, |
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | # GNU General Public License for more details. |
| 14 | |
| 15 | # You should have received a copy of the GNU General Public License |
| 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | import os |
| 19 | import time |
| 20 | import unittest |
Jacob Erlbeck | 4684eb6 | 2013-08-14 11:10:34 +0200 | [diff] [blame] | 21 | import socket |
Holger Hans Peter Freyther | 6539752 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 22 | |
| 23 | import osmopy.obscvty as obscvty |
| 24 | import osmopy.osmoutil as osmoutil |
| 25 | |
| 26 | confpath = '.' |
| 27 | |
| 28 | class TestVTYBase(unittest.TestCase): |
| 29 | |
| 30 | def vty_command(self): |
| 31 | raise Exception("Needs to be implemented by a subclass") |
| 32 | |
| 33 | def vty_app(self): |
| 34 | raise Exception("Needs to be implemented by a subclass") |
| 35 | |
| 36 | def setUp(self): |
| 37 | osmo_vty_cmd = self.vty_command()[:] |
| 38 | config_index = osmo_vty_cmd.index('-c') |
| 39 | if config_index: |
| 40 | cfi = config_index + 1 |
| 41 | osmo_vty_cmd[cfi] = os.path.join(confpath, osmo_vty_cmd[cfi]) |
| 42 | |
| 43 | try: |
| 44 | print "Launch: %s from %s" % (' '.join(osmo_vty_cmd), os.getcwd()) |
| 45 | self.proc = osmoutil.popen_devnull(osmo_vty_cmd) |
| 46 | except OSError: |
| 47 | print >> sys.stderr, "Current directory: %s" % os.getcwd() |
| 48 | print >> sys.stderr, "Consider setting -b" |
| 49 | time.sleep(1) |
| 50 | |
| 51 | appstring = self.vty_app()[2] |
| 52 | appport = self.vty_app()[0] |
| 53 | self.vty = obscvty.VTYInteract(appstring, "127.0.0.1", appport) |
| 54 | |
| 55 | def tearDown(self): |
| 56 | self.vty = None |
| 57 | osmoutil.end_proc(self.proc) |
| 58 | |
Jacob Erlbeck | 768a7c3 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 59 | |
| 60 | class TestVTYGenericBSC(TestVTYBase): |
| 61 | |
| 62 | def checkForEndAndExit(self): |
| 63 | res = self.vty.command("list") |
| 64 | #print ('looking for "exit"\n') |
| 65 | self.assert_(res.find(' exit\r') > 0) |
| 66 | #print 'found "exit"\nlooking for "end"\n' |
| 67 | self.assert_(res.find(' end\r') > 0) |
| 68 | #print 'found "end"\n' |
| 69 | |
| 70 | def ignoredCheckForEndAndExit(self): |
| 71 | sys.stderr.write('Going to ignore the next assertion(s) due to known bugs\n') |
| 72 | try: |
| 73 | self.checkForEndAndExit() |
| 74 | except BaseException as e: |
| 75 | sys.stderr.write('Expected and ignored failure: %s\n' % (str(e))) |
| 76 | |
Jacob Erlbeck | 768a7c3 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 77 | def _testConfigNetworkTree(self): |
| 78 | self.vty.enable() |
| 79 | self.assertTrue(self.vty.verify("configure terminal",[''])) |
| 80 | self.assertEquals(self.vty.node(), 'config') |
| 81 | self.ignoredCheckForEndAndExit() |
| 82 | self.assertTrue(self.vty.verify("network",[''])) |
| 83 | self.assertEquals(self.vty.node(), 'config-net') |
| 84 | self.checkForEndAndExit() |
| 85 | self.assertTrue(self.vty.verify("bts 0",[''])) |
| 86 | self.assertEquals(self.vty.node(), 'config-net-bts') |
| 87 | self.checkForEndAndExit() |
| 88 | self.assertTrue(self.vty.verify("trx 0",[''])) |
| 89 | self.assertEquals(self.vty.node(), 'config-net-bts-trx') |
| 90 | self.checkForEndAndExit() |
| 91 | self.assertTrue(self.vty.verify("exit",[''])) |
| 92 | self.assertEquals(self.vty.node(), 'config-net-bts') |
| 93 | self.assertTrue(self.vty.verify("exit",[''])) |
| 94 | self.assertEquals(self.vty.node(), 'config-net') |
| 95 | self.assertTrue(self.vty.verify("exit",[''])) |
| 96 | self.assertEquals(self.vty.node(), 'config') |
| 97 | self.assertTrue(self.vty.verify("exit",[''])) |
| 98 | self.assertTrue(self.vty.node() is None) |
| 99 | |
| 100 | class TestVTYNITB(TestVTYGenericBSC): |
Holger Hans Peter Freyther | 2fb8ebf | 2013-07-27 21:07:57 +0200 | [diff] [blame] | 101 | |
| 102 | def vty_command(self): |
| 103 | return ["./src/osmo-nitb/osmo-nitb", "-c", |
| 104 | "doc/examples/osmo-nitb/nanobts/openbsc.cfg"] |
| 105 | |
| 106 | def vty_app(self): |
| 107 | return (4242, "./src/osmo-nitb/osmo-nitb", "OpenBSC", "nitb") |
| 108 | |
Jacob Erlbeck | 768a7c3 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 109 | def testConfigNetworkTree(self): |
| 110 | self._testConfigNetworkTree() |
| 111 | |
| 112 | def testVtyTree(self): |
| 113 | self.vty.enable() |
| 114 | self.assertTrue(self.vty.verify("configure terminal", [''])) |
| 115 | self.assertEquals(self.vty.node(), 'config') |
| 116 | self.ignoredCheckForEndAndExit() |
| 117 | self.assertTrue(self.vty.verify('mncc-int', [''])) |
| 118 | self.assertEquals(self.vty.node(), 'config-mncc-int') |
| 119 | self.checkForEndAndExit() |
| 120 | self.assertTrue(self.vty.verify('exit', [''])) |
| 121 | self.assertEquals(self.vty.node(), 'config') |
| 122 | self.assertTrue(self.vty.verify('smpp', [''])) |
| 123 | self.assertEquals(self.vty.node(), 'config-smpp') |
| 124 | self.ignoredCheckForEndAndExit() |
| 125 | self.assertTrue(self.vty.verify("exit", [''])) |
Jacob Erlbeck | bf8eec7 | 2013-09-02 13:17:16 +0200 | [diff] [blame] | 126 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 768a7c3 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 127 | self.assertTrue(self.vty.verify("exit", [''])) |
| 128 | self.assertTrue(self.vty.node() is None) |
| 129 | |
| 130 | # Check searching for outer node's commands |
| 131 | self.vty.command("configure terminal") |
| 132 | self.vty.command('mncc-int') |
| 133 | self.vty.command('smpp') |
| 134 | self.assertEquals(self.vty.node(), 'config-smpp') |
| 135 | self.vty.command('mncc-int') |
| 136 | self.assertEquals(self.vty.node(), 'config-mncc-int') |
| 137 | |
Holger Hans Peter Freyther | 2fb8ebf | 2013-07-27 21:07:57 +0200 | [diff] [blame] | 138 | def testEnableDisablePeriodicLU(self): |
| 139 | self.vty.enable() |
| 140 | self.vty.command("configure terminal") |
| 141 | self.vty.command("network") |
| 142 | self.vty.command("bts 0") |
| 143 | |
| 144 | # Test invalid input |
| 145 | self.vty.verify("periodic location update 0", ['% Unknown command.']) |
| 146 | self.vty.verify("periodic location update 5", ['% Unknown command.']) |
| 147 | self.vty.verify("periodic location update 1531", ['% Unknown command.']) |
| 148 | |
| 149 | # Enable periodic lu.. |
| 150 | self.vty.verify("periodic location update 60", ['']) |
| 151 | res = self.vty.command("write terminal") |
Holger Hans Peter Freyther | eda0867 | 2013-07-27 22:23:25 +0200 | [diff] [blame] | 152 | self.assert_(res.find('periodic location update 60') > 0) |
Holger Hans Peter Freyther | 2fb8ebf | 2013-07-27 21:07:57 +0200 | [diff] [blame] | 153 | self.assertEquals(res.find('no periodic location update'), -1) |
| 154 | |
| 155 | # Now disable it.. |
| 156 | self.vty.verify("no periodic location update", ['']) |
| 157 | res = self.vty.command("write terminal") |
| 158 | self.assertEquals(res.find('periodic location update 60'), -1) |
Holger Hans Peter Freyther | eda0867 | 2013-07-27 22:23:25 +0200 | [diff] [blame] | 159 | self.assert_(res.find('no periodic location update') > 0) |
Holger Hans Peter Freyther | 6539752 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 160 | |
Jacob Erlbeck | 768a7c3 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 161 | class TestVTYBSC(TestVTYGenericBSC): |
Jacob Erlbeck | 058b1e5 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 162 | |
| 163 | def vty_command(self): |
| 164 | return ["./src/osmo-bsc/osmo-bsc", "-c", |
| 165 | "doc/examples/osmo-bsc/osmo-bsc.cfg"] |
| 166 | |
| 167 | def vty_app(self): |
| 168 | return (4242, "./src/osmo-bsc/osmo-bsc", "OsmoBSC", "bsc") |
| 169 | |
Jacob Erlbeck | 768a7c3 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 170 | def testConfigNetworkTree(self): |
| 171 | self._testConfigNetworkTree() |
| 172 | |
| 173 | def testVtyTree(self): |
| 174 | self.vty.enable() |
| 175 | self.assertTrue(self.vty.verify("configure terminal", [''])) |
| 176 | self.assertEquals(self.vty.node(), 'config') |
| 177 | self.ignoredCheckForEndAndExit() |
| 178 | self.assertTrue(self.vty.verify("msc 0", [''])) |
| 179 | self.assertEquals(self.vty.node(), 'config-msc') |
Jacob Erlbeck | bf8eec7 | 2013-09-02 13:17:16 +0200 | [diff] [blame] | 180 | self.checkForEndAndExit() |
Jacob Erlbeck | 768a7c3 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 181 | self.assertTrue(self.vty.verify("exit", [''])) |
Jacob Erlbeck | bf8eec7 | 2013-09-02 13:17:16 +0200 | [diff] [blame] | 182 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 768a7c3 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 183 | self.assertTrue(self.vty.verify("bsc", [''])) |
| 184 | self.assertEquals(self.vty.node(), 'config-bsc') |
Jacob Erlbeck | bf8eec7 | 2013-09-02 13:17:16 +0200 | [diff] [blame] | 185 | self.checkForEndAndExit() |
Jacob Erlbeck | 768a7c3 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 186 | self.assertTrue(self.vty.verify("exit", [''])) |
Jacob Erlbeck | bf8eec7 | 2013-09-02 13:17:16 +0200 | [diff] [blame] | 187 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 768a7c3 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 188 | self.assertTrue(self.vty.verify("exit", [''])) |
| 189 | self.assertTrue(self.vty.node() is None) |
| 190 | |
| 191 | # Check searching for outer node's commands |
| 192 | self.vty.command("configure terminal") |
| 193 | self.vty.command('msc 0') |
| 194 | self.vty.command("bsc") |
| 195 | self.assertEquals(self.vty.node(), 'config-bsc') |
| 196 | self.vty.command("msc 0") |
| 197 | self.assertEquals(self.vty.node(), 'config-msc') |
| 198 | |
Jacob Erlbeck | 058b1e5 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 199 | def testUssdNotifications(self): |
| 200 | self.vty.enable() |
| 201 | self.vty.command("configure terminal") |
| 202 | self.vty.command("msc") |
| 203 | |
| 204 | # Test invalid input |
| 205 | self.vty.verify("bsc-msc-lost-text", ['% Command incomplete.']) |
Jacob Erlbeck | b62092a | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 206 | self.vty.verify("bsc-welcome-text", ['% Command incomplete.']) |
Jacob Erlbeck | 058b1e5 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 207 | |
| 208 | # Enable USSD notifications |
| 209 | self.vty.verify("bsc-msc-lost-text MSC disconnected", ['']) |
Jacob Erlbeck | b62092a | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 210 | self.vty.verify("bsc-welcome-text Hello MS", ['']) |
Jacob Erlbeck | 058b1e5 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 211 | |
| 212 | # Verify settings |
| 213 | res = self.vty.command("write terminal") |
| 214 | self.assert_(res.find('bsc-msc-lost-text MSC disconnected') > 0) |
| 215 | self.assertEquals(res.find('no bsc-msc-lost-text'), -1) |
Jacob Erlbeck | b62092a | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 216 | self.assert_(res.find('bsc-welcome-text Hello MS') > 0) |
| 217 | self.assertEquals(res.find('no bsc-welcome-text'), -1) |
Jacob Erlbeck | 058b1e5 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 218 | |
| 219 | # Now disable it.. |
| 220 | self.vty.verify("no bsc-msc-lost-text", ['']) |
Jacob Erlbeck | b62092a | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 221 | self.vty.verify("no bsc-welcome-text", ['']) |
Jacob Erlbeck | 058b1e5 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 222 | |
| 223 | # Verify settings |
| 224 | res = self.vty.command("write terminal") |
| 225 | self.assertEquals(res.find('bsc-msc-lost-text MSC disconnected'), -1) |
| 226 | self.assert_(res.find('no bsc-msc-lost-text') > 0) |
Jacob Erlbeck | b62092a | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 227 | self.assert_(res.find('no bsc-welcome-text') > 0) |
| 228 | self.assertEquals(res.find('bsc-welcome-text Hello MS'), -1) |
Jacob Erlbeck | 058b1e5 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 229 | |
Jacob Erlbeck | 768a7c3 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 230 | class TestVTYNAT(TestVTYGenericBSC): |
Holger Hans Peter Freyther | 6539752 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 231 | |
| 232 | def vty_command(self): |
| 233 | return ["./src/osmo-bsc_nat/osmo-bsc_nat", "-c", |
| 234 | "doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg"] |
| 235 | |
| 236 | def vty_app(self): |
| 237 | return (4244, "src/osmo-bsc_nat/osmo-bsc_nat", "OsmoBSCNAT", "nat") |
| 238 | |
Jacob Erlbeck | 768a7c3 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 239 | def testVtyTree(self): |
| 240 | self.vty.enable() |
| 241 | self.assertTrue(self.vty.verify('configure terminal', [''])) |
| 242 | self.assertEquals(self.vty.node(), 'config') |
| 243 | self.ignoredCheckForEndAndExit() |
| 244 | self.assertTrue(self.vty.verify('mgcp', [''])) |
| 245 | self.assertEquals(self.vty.node(), 'config-mgcp') |
| 246 | self.checkForEndAndExit() |
| 247 | self.assertTrue(self.vty.verify('exit', [''])) |
| 248 | self.assertEquals(self.vty.node(), 'config') |
| 249 | self.assertTrue(self.vty.verify('nat', [''])) |
| 250 | self.assertEquals(self.vty.node(), 'config-nat') |
| 251 | self.checkForEndAndExit() |
| 252 | self.assertTrue(self.vty.verify('bsc 0', [''])) |
| 253 | self.assertEquals(self.vty.node(), 'config-nat-bsc') |
| 254 | self.checkForEndAndExit() |
| 255 | self.assertTrue(self.vty.verify('exit', [''])) |
| 256 | self.assertEquals(self.vty.node(), 'config-nat') |
| 257 | self.assertTrue(self.vty.verify('exit', [''])) |
| 258 | self.assertEquals(self.vty.node(), 'config') |
| 259 | self.assertTrue(self.vty.verify('exit', [''])) |
| 260 | self.assertTrue(self.vty.node() is None) |
| 261 | |
| 262 | # Check searching for outer node's commands |
| 263 | self.vty.command('configure terminal') |
| 264 | self.vty.command('mgcp') |
| 265 | self.vty.command('nat') |
| 266 | self.assertEquals(self.vty.node(), 'config-nat') |
Jacob Erlbeck | cdf1857 | 2013-09-02 13:17:17 +0200 | [diff] [blame^] | 267 | self.vty.command('mgcp') |
| 268 | self.assertEquals(self.vty.node(), 'config-mgcp') |
Jacob Erlbeck | 768a7c3 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 269 | self.vty.command('nat') |
| 270 | self.assertEquals(self.vty.node(), 'config-nat') |
| 271 | self.vty.command('bsc 0') |
Jacob Erlbeck | cdf1857 | 2013-09-02 13:17:17 +0200 | [diff] [blame^] | 272 | self.vty.command('mgcp') |
| 273 | self.assertEquals(self.vty.node(), 'config-mgcp') |
Jacob Erlbeck | 768a7c3 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 274 | |
Holger Hans Peter Freyther | bf123a1 | 2013-06-25 09:08:02 +0200 | [diff] [blame] | 275 | def testRewriteNoRewrite(self): |
| 276 | self.vty.enable() |
| 277 | res = self.vty.command("configure terminal") |
| 278 | res = self.vty.command("nat") |
| 279 | res = self.vty.command("number-rewrite rewrite.cfg") |
| 280 | res = self.vty.command("no number-rewrite") |
Holger Hans Peter Freyther | 6539752 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 281 | |
Holger Hans Peter Freyther | e9c7e27 | 2013-06-25 15:38:31 +0200 | [diff] [blame] | 282 | def testRewritePostNoRewrite(self): |
| 283 | self.vty.enable() |
| 284 | self.vty.command("configure terminal") |
| 285 | self.vty.command("nat") |
| 286 | self.vty.verify("number-rewrite-post rewrite.cfg", ['']) |
| 287 | self.vty.verify("no number-rewrite-post", ['']) |
| 288 | |
| 289 | |
Holger Hans Peter Freyther | 367390b | 2013-06-25 11:44:01 +0200 | [diff] [blame] | 290 | def testPrefixTreeLoading(self): |
| 291 | cfg = os.path.join(confpath, "tests/bsc-nat-trie/prefixes.csv") |
| 292 | |
| 293 | self.vty.enable() |
| 294 | self.vty.command("configure terminal") |
| 295 | self.vty.command("nat") |
| 296 | res = self.vty.command("prefix-tree %s" % cfg) |
| 297 | self.assertEqual(res, "% prefix-tree loaded 17 rules.") |
| 298 | self.vty.command("end") |
| 299 | |
| 300 | res = self.vty.command("show prefix-tree") |
| 301 | self.assertEqual(res, '1,1\r\n12,2\r\n123,3\r\n1234,4\r\n12345,5\r\n123456,6\r\n1234567,7\r\n12345678,8\r\n123456789,9\r\n1234567890,10\r\n13,11\r\n14,12\r\n15,13\r\n16,14\r\n82,16\r\n823455,15\r\n+49123,17') |
| 302 | |
| 303 | self.vty.command("configure terminal") |
| 304 | self.vty.command("nat") |
| 305 | self.vty.command("no prefix-tree") |
| 306 | self.vty.command("end") |
| 307 | |
| 308 | res = self.vty.command("show prefix-tree") |
| 309 | self.assertEqual(res, "% there is now prefix tree loaded.") |
| 310 | |
Jacob Erlbeck | 4684eb6 | 2013-08-14 11:10:34 +0200 | [diff] [blame] | 311 | def testUssdSideChannelProvider(self): |
| 312 | self.vty.command("end") |
| 313 | self.vty.enable() |
| 314 | self.vty.command("configure terminal") |
| 315 | self.vty.command("nat") |
| 316 | self.vty.command("ussd-token key") |
| 317 | self.vty.command("end") |
| 318 | |
| 319 | res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.']) |
| 320 | self.assertTrue(res) |
| 321 | |
| 322 | ussdSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 323 | ussdSocket.connect(('127.0.0.1', 5001)) |
| 324 | ussdSocket.settimeout(2.0) |
| 325 | print "Connected to %s:%d" % ussdSocket.getpeername() |
| 326 | |
| 327 | print "Expecting ID_GET request" |
| 328 | data = ussdSocket.recv(4) |
| 329 | self.assertEqual(data, "\x00\x01\xfe\x04") |
| 330 | |
| 331 | print "Going to send ID_RESP response" |
| 332 | res = ussdSocket.send("\x00\x07\xfe\x05\x00\x04\x01\x6b\x65\x79") |
| 333 | self.assertEqual(res, 10) |
| 334 | |
| 335 | # initiating PING/PONG cycle to know, that the ID_RESP message has been processed |
| 336 | |
| 337 | print "Going to send PING request" |
| 338 | res = ussdSocket.send("\x00\x01\xfe\x00") |
| 339 | self.assertEqual(res, 4) |
| 340 | |
| 341 | print "Expecting PONG response" |
| 342 | data = ussdSocket.recv(4) |
| 343 | self.assertEqual(data, "\x00\x01\xfe\x01") |
| 344 | |
| 345 | res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is connected and authorized.']) |
| 346 | self.assertTrue(res) |
| 347 | |
| 348 | print "Going to shut down connection" |
| 349 | ussdSocket.shutdown(socket.SHUT_WR) |
| 350 | |
| 351 | print "Expecting EOF" |
| 352 | data = ussdSocket.recv(4) |
| 353 | self.assertEqual(data, "") |
| 354 | |
| 355 | ussdSocket.close() |
| 356 | |
| 357 | res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.']) |
| 358 | self.assertTrue(res) |
Holger Hans Peter Freyther | 6539752 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 359 | |
| 360 | def add_nat_test(suite, workdir): |
| 361 | if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")): |
| 362 | print("Skipping the NAT test") |
| 363 | return |
| 364 | test = unittest.TestLoader().loadTestsFromTestCase(TestVTYNAT) |
| 365 | suite.addTest(test) |
| 366 | |
Jacob Erlbeck | 058b1e5 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 367 | def add_bsc_test(suite, workdir): |
| 368 | if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")): |
| 369 | print("Skipping the BSC test") |
| 370 | return |
| 371 | test = unittest.TestLoader().loadTestsFromTestCase(TestVTYBSC) |
| 372 | suite.addTest(test) |
| 373 | |
Holger Hans Peter Freyther | 6539752 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 374 | if __name__ == '__main__': |
| 375 | import argparse |
| 376 | import sys |
| 377 | |
| 378 | workdir = '.' |
| 379 | |
| 380 | parser = argparse.ArgumentParser() |
| 381 | parser.add_argument("-v", "--verbose", dest="verbose", |
| 382 | action="store_true", help="verbose mode") |
| 383 | parser.add_argument("-p", "--pythonconfpath", dest="p", |
| 384 | help="searchpath for config") |
| 385 | parser.add_argument("-w", "--workdir", dest="w", |
| 386 | help="Working directory") |
| 387 | args = parser.parse_args() |
| 388 | |
| 389 | verbose_level = 1 |
| 390 | if args.verbose: |
| 391 | verbose_level = 2 |
| 392 | |
| 393 | if args.w: |
| 394 | workdir = args.w |
| 395 | |
| 396 | if args.p: |
| 397 | confpath = args.p |
| 398 | |
| 399 | print "confpath %s, workdir %s" % (confpath, workdir) |
| 400 | os.chdir(workdir) |
| 401 | print "Running tests for specific VTY commands" |
| 402 | suite = unittest.TestSuite() |
Holger Hans Peter Freyther | 2fb8ebf | 2013-07-27 21:07:57 +0200 | [diff] [blame] | 403 | suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYNITB)) |
Jacob Erlbeck | 058b1e5 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 404 | add_bsc_test(suite, workdir) |
Holger Hans Peter Freyther | 6539752 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 405 | add_nat_test(suite, workdir) |
| 406 | res = unittest.TextTestRunner(verbosity=verbose_level).run(suite) |
| 407 | sys.exit(len(res.errors) + len(res.failures)) |