blob: 3bb7bd86b894390c1442b63f77b679110099fcc6 [file] [log] [blame]
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +02001#!/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
18import os
19import time
20import unittest
Jacob Erlbeck4684eb62013-08-14 11:10:34 +020021import socket
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +020022
23import osmopy.obscvty as obscvty
24import osmopy.osmoutil as osmoutil
25
26confpath = '.'
27
28class 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 Erlbeck768a7c32013-09-02 13:17:14 +020059
60class 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 Erlbeck768a7c32013-09-02 13:17:14 +020077 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()
Jacob Erlbeck5e229112013-09-11 10:46:56 +020091 self.vty.command("write terminal")
92 self.assertTrue(self.vty.verify("exit",['']))
93 self.assertEquals(self.vty.node(), 'config-net-bts')
94 self.assertTrue(self.vty.verify("exit",['']))
95 self.assertTrue(self.vty.verify("bts 1",['']))
96 self.assertEquals(self.vty.node(), 'config-net-bts')
97 self.checkForEndAndExit()
98 self.assertTrue(self.vty.verify("trx 1",['']))
99 self.assertEquals(self.vty.node(), 'config-net-bts-trx')
100 self.checkForEndAndExit()
101 self.vty.command("write terminal")
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200102 self.assertTrue(self.vty.verify("exit",['']))
103 self.assertEquals(self.vty.node(), 'config-net-bts')
104 self.assertTrue(self.vty.verify("exit",['']))
105 self.assertEquals(self.vty.node(), 'config-net')
106 self.assertTrue(self.vty.verify("exit",['']))
107 self.assertEquals(self.vty.node(), 'config')
108 self.assertTrue(self.vty.verify("exit",['']))
109 self.assertTrue(self.vty.node() is None)
110
111class TestVTYNITB(TestVTYGenericBSC):
Holger Hans Peter Freyther2fb8ebf2013-07-27 21:07:57 +0200112
113 def vty_command(self):
114 return ["./src/osmo-nitb/osmo-nitb", "-c",
115 "doc/examples/osmo-nitb/nanobts/openbsc.cfg"]
116
117 def vty_app(self):
118 return (4242, "./src/osmo-nitb/osmo-nitb", "OpenBSC", "nitb")
119
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200120 def testConfigNetworkTree(self):
121 self._testConfigNetworkTree()
122
Holger Hans Peter Freytherabb54ae2013-09-02 20:58:38 +0200123 def checkForSmpp(self):
124 """SMPP is not always enabled, check if it is"""
125 res = self.vty.command("list")
126 return "smpp" in res
127
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200128 def testVtyTree(self):
129 self.vty.enable()
130 self.assertTrue(self.vty.verify("configure terminal", ['']))
131 self.assertEquals(self.vty.node(), 'config')
132 self.ignoredCheckForEndAndExit()
133 self.assertTrue(self.vty.verify('mncc-int', ['']))
134 self.assertEquals(self.vty.node(), 'config-mncc-int')
135 self.checkForEndAndExit()
136 self.assertTrue(self.vty.verify('exit', ['']))
Holger Hans Peter Freytherabb54ae2013-09-02 20:58:38 +0200137
138 if self.checkForSmpp():
139 self.assertEquals(self.vty.node(), 'config')
140 self.assertTrue(self.vty.verify('smpp', ['']))
141 self.assertEquals(self.vty.node(), 'config-smpp')
142 self.ignoredCheckForEndAndExit()
143 self.assertTrue(self.vty.verify("exit", ['']))
144
Jacob Erlbeckbf8eec72013-09-02 13:17:16 +0200145 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200146 self.assertTrue(self.vty.verify("exit", ['']))
147 self.assertTrue(self.vty.node() is None)
148
149 # Check searching for outer node's commands
150 self.vty.command("configure terminal")
151 self.vty.command('mncc-int')
Holger Hans Peter Freytherabb54ae2013-09-02 20:58:38 +0200152
153 if self.checkForSmpp():
154 self.vty.command('smpp')
155 self.assertEquals(self.vty.node(), 'config-smpp')
156 self.vty.command('mncc-int')
157
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200158 self.assertEquals(self.vty.node(), 'config-mncc-int')
159
Holger Hans Peter Freyther2fb8ebf2013-07-27 21:07:57 +0200160 def testEnableDisablePeriodicLU(self):
161 self.vty.enable()
162 self.vty.command("configure terminal")
163 self.vty.command("network")
164 self.vty.command("bts 0")
165
166 # Test invalid input
167 self.vty.verify("periodic location update 0", ['% Unknown command.'])
168 self.vty.verify("periodic location update 5", ['% Unknown command.'])
169 self.vty.verify("periodic location update 1531", ['% Unknown command.'])
170
171 # Enable periodic lu..
172 self.vty.verify("periodic location update 60", [''])
173 res = self.vty.command("write terminal")
Holger Hans Peter Freythereda08672013-07-27 22:23:25 +0200174 self.assert_(res.find('periodic location update 60') > 0)
Holger Hans Peter Freyther2fb8ebf2013-07-27 21:07:57 +0200175 self.assertEquals(res.find('no periodic location update'), -1)
176
177 # Now disable it..
178 self.vty.verify("no periodic location update", [''])
179 res = self.vty.command("write terminal")
180 self.assertEquals(res.find('periodic location update 60'), -1)
Holger Hans Peter Freythereda08672013-07-27 22:23:25 +0200181 self.assert_(res.find('no periodic location update') > 0)
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +0200182
Ivan Kluchnikov80d58432013-09-16 13:13:04 +0400183 def testRachAccessControlClass(self):
184 self.vty.enable()
185 self.vty.command("configure terminal")
186 self.vty.command("network")
187 self.vty.command("bts 0")
188
189 # Test invalid input
190 self.vty.verify("rach access-control-class", ['% Command incomplete.'])
191 self.vty.verify("rach access-control-class 1", ['% Command incomplete.'])
192 self.vty.verify("rach access-control-class -1", ['% Unknown command.'])
193 self.vty.verify("rach access-control-class 10", ['% Unknown command.'])
194 self.vty.verify("rach access-control-class 16", ['% Unknown command.'])
195
196 # Barred rach access control classes
197 for classNum in range(16):
198 if classNum != 10:
199 self.vty.verify("rach access-control-class " + str(classNum) + " barred", [''])
200
201 # Verify settings
202 res = self.vty.command("write terminal")
203 for classNum in range(16):
204 if classNum != 10:
205 self.assert_(res.find("rach access-control-class " + str(classNum) + " barred") > 0)
206
207 # Allowed rach access control classes
208 for classNum in range(16):
209 if classNum != 10:
210 self.vty.verify("rach access-control-class " + str(classNum) + " allowed", [''])
211
212 # Verify settings
213 res = self.vty.command("write terminal")
214 for classNum in range(16):
215 if classNum != 10:
216 self.assertEquals(res.find("rach access-control-class " + str(classNum) + " barred"), -1)
217
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200218class TestVTYBSC(TestVTYGenericBSC):
Jacob Erlbeck058b1e52013-08-28 10:16:54 +0200219
220 def vty_command(self):
221 return ["./src/osmo-bsc/osmo-bsc", "-c",
222 "doc/examples/osmo-bsc/osmo-bsc.cfg"]
223
224 def vty_app(self):
225 return (4242, "./src/osmo-bsc/osmo-bsc", "OsmoBSC", "bsc")
226
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200227 def testConfigNetworkTree(self):
228 self._testConfigNetworkTree()
229
230 def testVtyTree(self):
231 self.vty.enable()
232 self.assertTrue(self.vty.verify("configure terminal", ['']))
233 self.assertEquals(self.vty.node(), 'config')
234 self.ignoredCheckForEndAndExit()
235 self.assertTrue(self.vty.verify("msc 0", ['']))
236 self.assertEquals(self.vty.node(), 'config-msc')
Jacob Erlbeckbf8eec72013-09-02 13:17:16 +0200237 self.checkForEndAndExit()
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200238 self.assertTrue(self.vty.verify("exit", ['']))
Jacob Erlbeckbf8eec72013-09-02 13:17:16 +0200239 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200240 self.assertTrue(self.vty.verify("bsc", ['']))
241 self.assertEquals(self.vty.node(), 'config-bsc')
Jacob Erlbeckbf8eec72013-09-02 13:17:16 +0200242 self.checkForEndAndExit()
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200243 self.assertTrue(self.vty.verify("exit", ['']))
Jacob Erlbeckbf8eec72013-09-02 13:17:16 +0200244 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200245 self.assertTrue(self.vty.verify("exit", ['']))
246 self.assertTrue(self.vty.node() is None)
247
248 # Check searching for outer node's commands
249 self.vty.command("configure terminal")
250 self.vty.command('msc 0')
251 self.vty.command("bsc")
252 self.assertEquals(self.vty.node(), 'config-bsc')
253 self.vty.command("msc 0")
254 self.assertEquals(self.vty.node(), 'config-msc')
255
Jacob Erlbeck3ccb86b2013-09-11 10:46:55 +0200256 def testUssdNotificationsMsc(self):
Jacob Erlbeck058b1e52013-08-28 10:16:54 +0200257 self.vty.enable()
258 self.vty.command("configure terminal")
259 self.vty.command("msc")
260
261 # Test invalid input
262 self.vty.verify("bsc-msc-lost-text", ['% Command incomplete.'])
Jacob Erlbeckb62092a2013-08-28 10:16:55 +0200263 self.vty.verify("bsc-welcome-text", ['% Command incomplete.'])
Jacob Erlbeck3ccb86b2013-09-11 10:46:55 +0200264 self.vty.verify("bsc-grace-text", ['% Command incomplete.'])
Jacob Erlbeck058b1e52013-08-28 10:16:54 +0200265
266 # Enable USSD notifications
267 self.vty.verify("bsc-msc-lost-text MSC disconnected", [''])
Jacob Erlbeckb62092a2013-08-28 10:16:55 +0200268 self.vty.verify("bsc-welcome-text Hello MS", [''])
Jacob Erlbeck3ccb86b2013-09-11 10:46:55 +0200269 self.vty.verify("bsc-grace-text In grace period", [''])
Jacob Erlbeck058b1e52013-08-28 10:16:54 +0200270
271 # Verify settings
272 res = self.vty.command("write terminal")
273 self.assert_(res.find('bsc-msc-lost-text MSC disconnected') > 0)
274 self.assertEquals(res.find('no bsc-msc-lost-text'), -1)
Jacob Erlbeckb62092a2013-08-28 10:16:55 +0200275 self.assert_(res.find('bsc-welcome-text Hello MS') > 0)
276 self.assertEquals(res.find('no bsc-welcome-text'), -1)
Jacob Erlbeck3ccb86b2013-09-11 10:46:55 +0200277 self.assert_(res.find('bsc-grace-text In grace period') > 0)
278 self.assertEquals(res.find('no bsc-grace-text'), -1)
Jacob Erlbeck058b1e52013-08-28 10:16:54 +0200279
280 # Now disable it..
281 self.vty.verify("no bsc-msc-lost-text", [''])
Jacob Erlbeckb62092a2013-08-28 10:16:55 +0200282 self.vty.verify("no bsc-welcome-text", [''])
Jacob Erlbeck3ccb86b2013-09-11 10:46:55 +0200283 self.vty.verify("no bsc-grace-text", [''])
Jacob Erlbeck058b1e52013-08-28 10:16:54 +0200284
285 # Verify settings
286 res = self.vty.command("write terminal")
287 self.assertEquals(res.find('bsc-msc-lost-text MSC disconnected'), -1)
288 self.assert_(res.find('no bsc-msc-lost-text') > 0)
Jacob Erlbeckb62092a2013-08-28 10:16:55 +0200289 self.assertEquals(res.find('bsc-welcome-text Hello MS'), -1)
Jacob Erlbeck3ccb86b2013-09-11 10:46:55 +0200290 self.assert_(res.find('no bsc-welcome-text') > 0)
291 self.assertEquals(res.find('bsc-grace-text In grace period'), -1)
292 self.assert_(res.find('no bsc-grace-text') > 0)
293
294 def testUssdNotificationsBsc(self):
295 self.vty.enable()
296 self.vty.command("configure terminal")
297 self.vty.command("bsc")
298
299 # Test invalid input
300 self.vty.verify("missing-msc-text", ['% Command incomplete.'])
301
302 # Enable USSD notifications
303 self.vty.verify("missing-msc-text No MSC found", [''])
304
305 # Verify settings
306 res = self.vty.command("write terminal")
307 self.assert_(res.find('missing-msc-text No MSC found') > 0)
308 self.assertEquals(res.find('no missing-msc-text'), -1)
309
310 # Now disable it..
311 self.vty.verify("no missing-msc-text", [''])
312
313 # Verify settings
314 res = self.vty.command("write terminal")
315 self.assertEquals(res.find('missing-msc-text No MSC found'), -1)
316 self.assert_(res.find('no missing-msc-text') > 0)
Jacob Erlbeck058b1e52013-08-28 10:16:54 +0200317
Jacob Erlbeckcc0d8842013-09-17 13:59:29 +0200318 def testNetworkTimezone(self):
319 self.vty.enable()
320 self.vty.verify("configure terminal", [''])
321 self.vty.verify("network", [''])
322 self.vty.verify("bts 0", [''])
323
324 # Test invalid input
325 self.vty.verify("timezone", ['% Command incomplete.'])
326 self.vty.verify("timezone 20 0", ['% Unknown command.'])
327 self.vty.verify("timezone 0 11", ['% Unknown command.'])
328 self.vty.verify("timezone 0 0 99", ['% Unknown command.'])
329
330 # Set time zone without DST
331 self.vty.verify("timezone 2 30", [''])
332
333 # Verify settings
334 res = self.vty.command("write terminal")
335 self.assert_(res.find('timezone 2 30') > 0)
336 self.assertEquals(res.find('timezone 2 30 '), -1)
337
338 # Set time zone with DST
339 self.vty.verify("timezone 2 30 1", [''])
340
341 # Verify settings
342 res = self.vty.command("write terminal")
343 self.assert_(res.find('timezone 2 30 1') > 0)
344
345 # Now disable it..
346 self.vty.verify("no timezone", [''])
347
348 # Verify settings
349 res = self.vty.command("write terminal")
350 self.assertEquals(res.find(' timezone'), -1)
351
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200352class TestVTYNAT(TestVTYGenericBSC):
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +0200353
354 def vty_command(self):
355 return ["./src/osmo-bsc_nat/osmo-bsc_nat", "-c",
356 "doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg"]
357
358 def vty_app(self):
359 return (4244, "src/osmo-bsc_nat/osmo-bsc_nat", "OsmoBSCNAT", "nat")
360
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200361 def testVtyTree(self):
362 self.vty.enable()
363 self.assertTrue(self.vty.verify('configure terminal', ['']))
364 self.assertEquals(self.vty.node(), 'config')
365 self.ignoredCheckForEndAndExit()
366 self.assertTrue(self.vty.verify('mgcp', ['']))
367 self.assertEquals(self.vty.node(), 'config-mgcp')
368 self.checkForEndAndExit()
369 self.assertTrue(self.vty.verify('exit', ['']))
370 self.assertEquals(self.vty.node(), 'config')
371 self.assertTrue(self.vty.verify('nat', ['']))
372 self.assertEquals(self.vty.node(), 'config-nat')
373 self.checkForEndAndExit()
374 self.assertTrue(self.vty.verify('bsc 0', ['']))
375 self.assertEquals(self.vty.node(), 'config-nat-bsc')
376 self.checkForEndAndExit()
377 self.assertTrue(self.vty.verify('exit', ['']))
378 self.assertEquals(self.vty.node(), 'config-nat')
379 self.assertTrue(self.vty.verify('exit', ['']))
380 self.assertEquals(self.vty.node(), 'config')
381 self.assertTrue(self.vty.verify('exit', ['']))
382 self.assertTrue(self.vty.node() is None)
383
384 # Check searching for outer node's commands
385 self.vty.command('configure terminal')
386 self.vty.command('mgcp')
387 self.vty.command('nat')
388 self.assertEquals(self.vty.node(), 'config-nat')
Jacob Erlbeckcdf18572013-09-02 13:17:17 +0200389 self.vty.command('mgcp')
390 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200391 self.vty.command('nat')
392 self.assertEquals(self.vty.node(), 'config-nat')
393 self.vty.command('bsc 0')
Jacob Erlbeckcdf18572013-09-02 13:17:17 +0200394 self.vty.command('mgcp')
395 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck768a7c32013-09-02 13:17:14 +0200396
Holger Hans Peter Freytherbf123a12013-06-25 09:08:02 +0200397 def testRewriteNoRewrite(self):
398 self.vty.enable()
399 res = self.vty.command("configure terminal")
400 res = self.vty.command("nat")
401 res = self.vty.command("number-rewrite rewrite.cfg")
402 res = self.vty.command("no number-rewrite")
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +0200403
Holger Hans Peter Freythere9c7e272013-06-25 15:38:31 +0200404 def testRewritePostNoRewrite(self):
405 self.vty.enable()
406 self.vty.command("configure terminal")
407 self.vty.command("nat")
408 self.vty.verify("number-rewrite-post rewrite.cfg", [''])
409 self.vty.verify("no number-rewrite-post", [''])
410
411
Holger Hans Peter Freyther367390b2013-06-25 11:44:01 +0200412 def testPrefixTreeLoading(self):
413 cfg = os.path.join(confpath, "tests/bsc-nat-trie/prefixes.csv")
414
415 self.vty.enable()
416 self.vty.command("configure terminal")
417 self.vty.command("nat")
418 res = self.vty.command("prefix-tree %s" % cfg)
419 self.assertEqual(res, "% prefix-tree loaded 17 rules.")
420 self.vty.command("end")
421
422 res = self.vty.command("show prefix-tree")
423 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')
424
425 self.vty.command("configure terminal")
426 self.vty.command("nat")
427 self.vty.command("no prefix-tree")
428 self.vty.command("end")
429
430 res = self.vty.command("show prefix-tree")
431 self.assertEqual(res, "% there is now prefix tree loaded.")
432
Jacob Erlbeck4684eb62013-08-14 11:10:34 +0200433 def testUssdSideChannelProvider(self):
434 self.vty.command("end")
435 self.vty.enable()
436 self.vty.command("configure terminal")
437 self.vty.command("nat")
438 self.vty.command("ussd-token key")
439 self.vty.command("end")
440
441 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
442 self.assertTrue(res)
443
444 ussdSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
445 ussdSocket.connect(('127.0.0.1', 5001))
446 ussdSocket.settimeout(2.0)
447 print "Connected to %s:%d" % ussdSocket.getpeername()
448
449 print "Expecting ID_GET request"
450 data = ussdSocket.recv(4)
451 self.assertEqual(data, "\x00\x01\xfe\x04")
452
453 print "Going to send ID_RESP response"
454 res = ussdSocket.send("\x00\x07\xfe\x05\x00\x04\x01\x6b\x65\x79")
455 self.assertEqual(res, 10)
456
457 # initiating PING/PONG cycle to know, that the ID_RESP message has been processed
458
459 print "Going to send PING request"
460 res = ussdSocket.send("\x00\x01\xfe\x00")
461 self.assertEqual(res, 4)
462
463 print "Expecting PONG response"
464 data = ussdSocket.recv(4)
465 self.assertEqual(data, "\x00\x01\xfe\x01")
466
467 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is connected and authorized.'])
468 self.assertTrue(res)
469
470 print "Going to shut down connection"
471 ussdSocket.shutdown(socket.SHUT_WR)
472
473 print "Expecting EOF"
474 data = ussdSocket.recv(4)
475 self.assertEqual(data, "")
476
477 ussdSocket.close()
478
479 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
480 self.assertTrue(res)
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +0200481
482def add_nat_test(suite, workdir):
483 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")):
484 print("Skipping the NAT test")
485 return
486 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYNAT)
487 suite.addTest(test)
488
Jacob Erlbeck058b1e52013-08-28 10:16:54 +0200489def add_bsc_test(suite, workdir):
490 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")):
491 print("Skipping the BSC test")
492 return
493 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYBSC)
494 suite.addTest(test)
495
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +0200496if __name__ == '__main__':
497 import argparse
498 import sys
499
500 workdir = '.'
501
502 parser = argparse.ArgumentParser()
503 parser.add_argument("-v", "--verbose", dest="verbose",
504 action="store_true", help="verbose mode")
505 parser.add_argument("-p", "--pythonconfpath", dest="p",
506 help="searchpath for config")
507 parser.add_argument("-w", "--workdir", dest="w",
508 help="Working directory")
509 args = parser.parse_args()
510
511 verbose_level = 1
512 if args.verbose:
513 verbose_level = 2
514
515 if args.w:
516 workdir = args.w
517
518 if args.p:
519 confpath = args.p
520
521 print "confpath %s, workdir %s" % (confpath, workdir)
522 os.chdir(workdir)
523 print "Running tests for specific VTY commands"
524 suite = unittest.TestSuite()
Holger Hans Peter Freyther2fb8ebf2013-07-27 21:07:57 +0200525 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYNITB))
Jacob Erlbeck058b1e52013-08-28 10:16:54 +0200526 add_bsc_test(suite, workdir)
Holger Hans Peter Freyther65397522013-06-24 15:47:34 +0200527 add_nat_test(suite, workdir)
528 res = unittest.TextTestRunner(verbosity=verbose_level).run(suite)
529 sys.exit(len(res.errors) + len(res.failures))