blob: 72471d876b3a5060c054d13d9cbd0bd16e1e605e [file] [log] [blame]
Holger Hans Peter Freythereb0acb62013-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 Erlbeck6cb2ccc2013-08-14 11:10:34 +020021import socket
Holger Hans Peter Freythereb0acb62013-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
Holger Hans Peter Freyther8d998a72014-07-04 20:23:56 +020059class TestVTYMGCP(TestVTYBase):
60 def vty_command(self):
61 return ["./src/osmo-bsc_mgcp/osmo-bsc_mgcp", "-c",
62 "doc/examples/osmo-bsc_mgcp/mgcp.cfg"]
63
64 def vty_app(self):
65 return (4243, "./src/osmo-bsc_mgcp/osmo-bsc_mgcp", "OpenBSC MGCP", "mgcp")
66
67 def testForcePtime(self):
68 self.vty.enable()
69 res = self.vty.command("show running-config")
70 self.assert_(res.find(' rtp force-ptime 20\r') > 0)
71 self.assertEquals(res.find(' no rtp force-ptime\r'), -1)
72
73 self.vty.command("configure terminal")
74 self.vty.command("mgcp")
75 self.vty.command("no rtp force-ptime")
76 res = self.vty.command("show running-config")
77 self.assertEquals(res.find(' rtp force-ptime 20\r'), -1)
78 self.assertEquals(res.find(' no rtp force-ptime\r'), -1)
79
Holger Hans Peter Freyther619b0142014-11-19 16:04:45 +010080 def testOmitAudio(self):
81 self.vty.enable()
82 res = self.vty.command("show running-config")
83 self.assert_(res.find(' sdp audio-payload send-name\r') > 0)
84 self.assertEquals(res.find(' no sdp audio-payload send-name\r'), -1)
85
86 self.vty.command("configure terminal")
87 self.vty.command("mgcp")
88 self.vty.command("no sdp audio-payload send-name")
89 res = self.vty.command("show running-config")
90 self.assertEquals(res.find(' rtp sdp audio-payload send-name\r'), -1)
91 self.assert_(res.find(' no sdp audio-payload send-name\r') > 0)
92
93 # TODO: test it for the trunk!
94
Jacob Erlbeck96903c42013-09-02 13:17:14 +020095
96class TestVTYGenericBSC(TestVTYBase):
97
98 def checkForEndAndExit(self):
99 res = self.vty.command("list")
100 #print ('looking for "exit"\n')
101 self.assert_(res.find(' exit\r') > 0)
102 #print 'found "exit"\nlooking for "end"\n'
103 self.assert_(res.find(' end\r') > 0)
104 #print 'found "end"\n'
105
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200106 def _testConfigNetworkTree(self):
107 self.vty.enable()
108 self.assertTrue(self.vty.verify("configure terminal",['']))
109 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100110 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200111 self.assertTrue(self.vty.verify("network",['']))
112 self.assertEquals(self.vty.node(), 'config-net')
113 self.checkForEndAndExit()
114 self.assertTrue(self.vty.verify("bts 0",['']))
115 self.assertEquals(self.vty.node(), 'config-net-bts')
116 self.checkForEndAndExit()
117 self.assertTrue(self.vty.verify("trx 0",['']))
118 self.assertEquals(self.vty.node(), 'config-net-bts-trx')
119 self.checkForEndAndExit()
Jacob Erlbeck733bec82013-09-11 10:46:56 +0200120 self.vty.command("write terminal")
121 self.assertTrue(self.vty.verify("exit",['']))
122 self.assertEquals(self.vty.node(), 'config-net-bts')
123 self.assertTrue(self.vty.verify("exit",['']))
124 self.assertTrue(self.vty.verify("bts 1",['']))
125 self.assertEquals(self.vty.node(), 'config-net-bts')
126 self.checkForEndAndExit()
127 self.assertTrue(self.vty.verify("trx 1",['']))
128 self.assertEquals(self.vty.node(), 'config-net-bts-trx')
129 self.checkForEndAndExit()
130 self.vty.command("write terminal")
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200131 self.assertTrue(self.vty.verify("exit",['']))
132 self.assertEquals(self.vty.node(), 'config-net-bts')
133 self.assertTrue(self.vty.verify("exit",['']))
134 self.assertEquals(self.vty.node(), 'config-net')
135 self.assertTrue(self.vty.verify("exit",['']))
136 self.assertEquals(self.vty.node(), 'config')
137 self.assertTrue(self.vty.verify("exit",['']))
138 self.assertTrue(self.vty.node() is None)
139
140class TestVTYNITB(TestVTYGenericBSC):
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200141
142 def vty_command(self):
143 return ["./src/osmo-nitb/osmo-nitb", "-c",
144 "doc/examples/osmo-nitb/nanobts/openbsc.cfg"]
145
146 def vty_app(self):
147 return (4242, "./src/osmo-nitb/osmo-nitb", "OpenBSC", "nitb")
148
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200149 def testConfigNetworkTree(self):
Jacob Erlbeck75877272013-10-23 11:24:14 +0200150 self._testConfigNetworkTree()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200151
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200152 def checkForSmpp(self):
153 """SMPP is not always enabled, check if it is"""
154 res = self.vty.command("list")
155 return "smpp" in res
156
Holger Hans Peter Freyther42cf2e02015-07-06 16:41:30 +0200157 def testSmppFirst(self):
Holger Hans Peter Freyther42cf2e02015-07-06 16:41:30 +0200158 # enable the configuration
159 self.vty.enable()
160 self.vty.command("configure terminal")
Holger Hans Peter Freythera2c41c42015-07-13 11:23:53 +0200161
162 if not self.checkForSmpp():
163 return
164
Holger Hans Peter Freyther42cf2e02015-07-06 16:41:30 +0200165 self.vty.command("smpp")
166
167 # check the default
168 res = self.vty.command("write terminal")
169 self.assert_(res.find(' no smpp-first') > 0)
170
171 self.vty.verify("smpp-first", [''])
172 res = self.vty.command("write terminal")
173 self.assert_(res.find(' smpp-first') > 0)
174 self.assertEquals(res.find('no smpp-first'), -1)
175
176 self.vty.verify("no smpp-first", [''])
177 res = self.vty.command("write terminal")
178 self.assert_(res.find('no smpp-first') > 0)
179
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200180 def testVtyTree(self):
181 self.vty.enable()
182 self.assertTrue(self.vty.verify("configure terminal", ['']))
183 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100184 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200185 self.assertTrue(self.vty.verify('mncc-int', ['']))
186 self.assertEquals(self.vty.node(), 'config-mncc-int')
187 self.checkForEndAndExit()
188 self.assertTrue(self.vty.verify('exit', ['']))
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200189
190 if self.checkForSmpp():
191 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck75877272013-10-23 11:24:14 +0200192 self.assertTrue(self.vty.verify('smpp', ['']))
193 self.assertEquals(self.vty.node(), 'config-smpp')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100194 self.checkForEndAndExit()
Jacob Erlbeck75877272013-10-23 11:24:14 +0200195 self.assertTrue(self.vty.verify("exit", ['']))
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200196
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200197 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200198 self.assertTrue(self.vty.verify("exit", ['']))
199 self.assertTrue(self.vty.node() is None)
200
201 # Check searching for outer node's commands
202 self.vty.command("configure terminal")
203 self.vty.command('mncc-int')
Holger Hans Peter Freyther0df1ab92013-09-02 20:58:38 +0200204
205 if self.checkForSmpp():
206 self.vty.command('smpp')
207 self.assertEquals(self.vty.node(), 'config-smpp')
208 self.vty.command('mncc-int')
209
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200210 self.assertEquals(self.vty.node(), 'config-mncc-int')
211
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200212 def testEnableDisablePeriodicLU(self):
213 self.vty.enable()
214 self.vty.command("configure terminal")
215 self.vty.command("network")
216 self.vty.command("bts 0")
217
218 # Test invalid input
219 self.vty.verify("periodic location update 0", ['% Unknown command.'])
220 self.vty.verify("periodic location update 5", ['% Unknown command.'])
221 self.vty.verify("periodic location update 1531", ['% Unknown command.'])
222
223 # Enable periodic lu..
224 self.vty.verify("periodic location update 60", [''])
225 res = self.vty.command("write terminal")
Holger Hans Peter Freytherc0438e32013-07-27 22:23:25 +0200226 self.assert_(res.find('periodic location update 60') > 0)
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +0200227 self.assertEquals(res.find('no periodic location update'), -1)
228
229 # Now disable it..
230 self.vty.verify("no periodic location update", [''])
231 res = self.vty.command("write terminal")
232 self.assertEquals(res.find('periodic location update 60'), -1)
Holger Hans Peter Freytherc0438e32013-07-27 22:23:25 +0200233 self.assert_(res.find('no periodic location update') > 0)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200234
Jacob Erlbeck65d114f2014-01-16 11:02:14 +0100235 def testEnableDisableSiHacks(self):
236 self.vty.enable()
237 self.vty.command("configure terminal")
238 self.vty.command("network")
239 self.vty.command("bts 0")
240
241 # Enable periodic lu..
242 self.vty.verify("force-combined-si", [''])
243 res = self.vty.command("write terminal")
244 self.assert_(res.find(' force-combined-si') > 0)
245 self.assertEquals(res.find('no force-combined-si'), -1)
246
247 # Now disable it..
248 self.vty.verify("no force-combined-si", [''])
249 res = self.vty.command("write terminal")
250 self.assertEquals(res.find(' force-combined-si'), -1)
251 self.assert_(res.find('no force-combined-si') > 0)
252
Ivan Kluchnikov67920592013-09-16 13:13:04 +0400253 def testRachAccessControlClass(self):
254 self.vty.enable()
255 self.vty.command("configure terminal")
256 self.vty.command("network")
257 self.vty.command("bts 0")
258
259 # Test invalid input
260 self.vty.verify("rach access-control-class", ['% Command incomplete.'])
261 self.vty.verify("rach access-control-class 1", ['% Command incomplete.'])
262 self.vty.verify("rach access-control-class -1", ['% Unknown command.'])
263 self.vty.verify("rach access-control-class 10", ['% Unknown command.'])
264 self.vty.verify("rach access-control-class 16", ['% Unknown command.'])
265
266 # Barred rach access control classes
267 for classNum in range(16):
268 if classNum != 10:
269 self.vty.verify("rach access-control-class " + str(classNum) + " barred", [''])
270
271 # Verify settings
272 res = self.vty.command("write terminal")
273 for classNum in range(16):
274 if classNum != 10:
275 self.assert_(res.find("rach access-control-class " + str(classNum) + " barred") > 0)
276
277 # Allowed rach access control classes
278 for classNum in range(16):
279 if classNum != 10:
280 self.vty.verify("rach access-control-class " + str(classNum) + " allowed", [''])
281
282 # Verify settings
283 res = self.vty.command("write terminal")
284 for classNum in range(16):
285 if classNum != 10:
286 self.assertEquals(res.find("rach access-control-class " + str(classNum) + " barred"), -1)
287
Ruben Pollaned04a0d2014-09-24 20:50:13 -0500288 def testSubscriberCreateDelete(self):
Alexander Chemerisbd6d40f2013-10-04 23:54:17 +0200289 self.vty.enable()
290
291 imsi = "204300854013739"
292
293 # Initially we don't have this subscriber
294 self.vty.verify('show subscriber imsi '+imsi, ['% No subscriber found for imsi '+imsi])
295
296 # Lets create one
297 res = self.vty.command('subscriber create imsi '+imsi)
298 self.assert_(res.find(" IMSI: "+imsi) > 0)
299
300 # Now we have it
301 res = self.vty.command('show subscriber imsi '+imsi)
302 self.assert_(res.find(" IMSI: "+imsi) > 0)
303
Ruben Pollaned04a0d2014-09-24 20:50:13 -0500304 # Delete it
305 res = self.vty.command('subscriber delete imsi '+imsi)
306 self.assert_(res != "")
307
308 # Now it should not be there anymore
309 res = self.vty.command('show subscriber imsi '+imsi)
310 self.assert_(res != '% No subscriber found for imsi '+imsi)
311
Jacob Erlbeck322b1492015-04-07 17:49:49 +0200312 def testSubscriberSettings(self):
313 self.vty.enable()
314
315 imsi = "204300854013739"
316 wrong_imsi = "204300999999999"
317
318 # Lets create one
319 res = self.vty.command('subscriber create imsi '+imsi)
320 self.assert_(res.find(" IMSI: "+imsi) > 0)
321
322 self.vty.verify('subscriber imsi '+wrong_imsi+' name wrong', ['% No subscriber found for imsi '+wrong_imsi])
323 res = self.vty.command('subscriber imsi '+imsi+' name '+('X' * 160))
324 self.assert_(res.find("NAME is too long") > 0)
325
326 self.vty.verify('subscriber imsi '+imsi+' name '+('G' * 159), [''])
327
328 self.vty.verify('subscriber imsi '+wrong_imsi+' extension 840', ['% No subscriber found for imsi '+wrong_imsi])
329 res = self.vty.command('subscriber imsi '+imsi+' extension '+('9' * 15))
330 self.assert_(res.find("EXTENSION is too long") > 0)
331
332 self.vty.verify('subscriber imsi '+imsi+' extension '+('1' * 14), [''])
333
334 # Delete it
335 res = self.vty.command('subscriber delete imsi '+imsi)
336 self.assert_(res != "")
337
Holger Hans Peter Freytherec37bb22013-02-05 09:39:09 +0100338 def testShowPagingGroup(self):
339 res = self.vty.command("show paging-group 255 1234567")
340 self.assertEqual(res, "% can't find BTS 255")
341 res = self.vty.command("show paging-group 0 1234567")
342 self.assertEquals(res, "%Paging group for IMSI 1234567 on BTS #0 is 7")
343
Ciabyec6e4f82014-03-06 17:20:55 +0100344 def testShowNetwork(self):
345 res = self.vty.command("show network")
346 self.assert_(res.startswith('BSC is on Country Code') >= 0)
347
Holger Hans Peter Freyther86573262015-01-31 09:47:37 +0100348 def testMeasurementFeed(self):
349 self.vty.enable()
350 self.vty.command("configure terminal")
351 self.vty.command("mncc-int")
352
353 res = self.vty.command("write terminal")
354 self.assertEquals(res.find('meas-feed scenario'), -1)
355
356 self.vty.command("meas-feed scenario bla")
357 res = self.vty.command("write terminal")
358 self.assert_(res.find('meas-feed scenario bla') > 0)
359
360 self.vty.command("meas-feed scenario abcdefghijklmnopqrstuvwxyz01234567890")
361 res = self.vty.command("write terminal")
362 self.assertEquals(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz01234567890'), -1)
363 self.assertEquals(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz012345'), -1)
364 self.assert_(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz01234') > 0)
365
366
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200367class TestVTYBSC(TestVTYGenericBSC):
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200368
369 def vty_command(self):
370 return ["./src/osmo-bsc/osmo-bsc", "-c",
371 "doc/examples/osmo-bsc/osmo-bsc.cfg"]
372
373 def vty_app(self):
374 return (4242, "./src/osmo-bsc/osmo-bsc", "OsmoBSC", "bsc")
375
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200376 def testConfigNetworkTree(self):
Jacob Erlbeck75877272013-10-23 11:24:14 +0200377 self._testConfigNetworkTree()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200378
379 def testVtyTree(self):
380 self.vty.enable()
381 self.assertTrue(self.vty.verify("configure terminal", ['']))
382 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100383 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200384 self.assertTrue(self.vty.verify("msc 0", ['']))
385 self.assertEquals(self.vty.node(), 'config-msc')
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200386 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200387 self.assertTrue(self.vty.verify("exit", ['']))
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200388 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200389 self.assertTrue(self.vty.verify("bsc", ['']))
390 self.assertEquals(self.vty.node(), 'config-bsc')
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200391 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200392 self.assertTrue(self.vty.verify("exit", ['']))
Jacob Erlbeck0ae92a92013-09-02 13:17:16 +0200393 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200394 self.assertTrue(self.vty.verify("exit", ['']))
395 self.assertTrue(self.vty.node() is None)
396
397 # Check searching for outer node's commands
398 self.vty.command("configure terminal")
399 self.vty.command('msc 0')
400 self.vty.command("bsc")
401 self.assertEquals(self.vty.node(), 'config-bsc')
402 self.vty.command("msc 0")
403 self.assertEquals(self.vty.node(), 'config-msc')
404
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200405 def testUssdNotificationsMsc(self):
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200406 self.vty.enable()
407 self.vty.command("configure terminal")
408 self.vty.command("msc")
409
410 # Test invalid input
411 self.vty.verify("bsc-msc-lost-text", ['% Command incomplete.'])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200412 self.vty.verify("bsc-welcome-text", ['% Command incomplete.'])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200413 self.vty.verify("bsc-grace-text", ['% Command incomplete.'])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200414
415 # Enable USSD notifications
416 self.vty.verify("bsc-msc-lost-text MSC disconnected", [''])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200417 self.vty.verify("bsc-welcome-text Hello MS", [''])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200418 self.vty.verify("bsc-grace-text In grace period", [''])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200419
420 # Verify settings
421 res = self.vty.command("write terminal")
422 self.assert_(res.find('bsc-msc-lost-text MSC disconnected') > 0)
423 self.assertEquals(res.find('no bsc-msc-lost-text'), -1)
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200424 self.assert_(res.find('bsc-welcome-text Hello MS') > 0)
425 self.assertEquals(res.find('no bsc-welcome-text'), -1)
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200426 self.assert_(res.find('bsc-grace-text In grace period') > 0)
427 self.assertEquals(res.find('no bsc-grace-text'), -1)
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200428
429 # Now disable it..
430 self.vty.verify("no bsc-msc-lost-text", [''])
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200431 self.vty.verify("no bsc-welcome-text", [''])
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200432 self.vty.verify("no bsc-grace-text", [''])
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200433
434 # Verify settings
435 res = self.vty.command("write terminal")
436 self.assertEquals(res.find('bsc-msc-lost-text MSC disconnected'), -1)
437 self.assert_(res.find('no bsc-msc-lost-text') > 0)
Jacob Erlbeck97e139f2013-08-28 10:16:55 +0200438 self.assertEquals(res.find('bsc-welcome-text Hello MS'), -1)
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200439 self.assert_(res.find('no bsc-welcome-text') > 0)
440 self.assertEquals(res.find('bsc-grace-text In grace period'), -1)
441 self.assert_(res.find('no bsc-grace-text') > 0)
442
443 def testUssdNotificationsBsc(self):
444 self.vty.enable()
445 self.vty.command("configure terminal")
446 self.vty.command("bsc")
447
448 # Test invalid input
449 self.vty.verify("missing-msc-text", ['% Command incomplete.'])
450
451 # Enable USSD notifications
452 self.vty.verify("missing-msc-text No MSC found", [''])
453
454 # Verify settings
455 res = self.vty.command("write terminal")
456 self.assert_(res.find('missing-msc-text No MSC found') > 0)
457 self.assertEquals(res.find('no missing-msc-text'), -1)
458
459 # Now disable it..
460 self.vty.verify("no missing-msc-text", [''])
461
462 # Verify settings
463 res = self.vty.command("write terminal")
464 self.assertEquals(res.find('missing-msc-text No MSC found'), -1)
465 self.assert_(res.find('no missing-msc-text') > 0)
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200466
Jacob Erlbeck946d1412013-09-17 13:59:29 +0200467 def testNetworkTimezone(self):
468 self.vty.enable()
469 self.vty.verify("configure terminal", [''])
470 self.vty.verify("network", [''])
471 self.vty.verify("bts 0", [''])
472
473 # Test invalid input
474 self.vty.verify("timezone", ['% Command incomplete.'])
475 self.vty.verify("timezone 20 0", ['% Unknown command.'])
476 self.vty.verify("timezone 0 11", ['% Unknown command.'])
477 self.vty.verify("timezone 0 0 99", ['% Unknown command.'])
478
479 # Set time zone without DST
480 self.vty.verify("timezone 2 30", [''])
481
482 # Verify settings
483 res = self.vty.command("write terminal")
484 self.assert_(res.find('timezone 2 30') > 0)
485 self.assertEquals(res.find('timezone 2 30 '), -1)
486
487 # Set time zone with DST
488 self.vty.verify("timezone 2 30 1", [''])
489
490 # Verify settings
491 res = self.vty.command("write terminal")
492 self.assert_(res.find('timezone 2 30 1') > 0)
493
494 # Now disable it..
495 self.vty.verify("no timezone", [''])
496
497 # Verify settings
498 res = self.vty.command("write terminal")
499 self.assertEquals(res.find(' timezone'), -1)
500
Ciabyec6e4f82014-03-06 17:20:55 +0100501 def testShowNetwork(self):
502 res = self.vty.command("show network")
503 self.assert_(res.startswith('BSC is on Country Code') >= 0)
504
Holger Hans Peter Freytherdb64f2e2014-10-29 10:06:15 +0100505 def testPingPongConfiguration(self):
506 self.vty.enable()
507 self.vty.verify("configure terminal", [''])
508 self.vty.verify("network", [''])
509 self.vty.verify("msc 0", [''])
510
511 self.vty.verify("timeout-ping 12", [''])
512 self.vty.verify("timeout-pong 14", [''])
513 res = self.vty.command("show running-config")
514 self.assert_(res.find(" timeout-ping 12") > 0)
515 self.assert_(res.find(" timeout-pong 14") > 0)
516 self.assert_(res.find(" no timeout-ping advanced") > 0)
517
518 self.vty.verify("timeout-ping advanced", [''])
519 res = self.vty.command("show running-config")
520 self.assert_(res.find(" timeout-ping 12") > 0)
521 self.assert_(res.find(" timeout-pong 14") > 0)
522 self.assert_(res.find(" timeout-ping advanced") > 0)
523
524 self.vty.verify("no timeout-ping advanced", [''])
525 res = self.vty.command("show running-config")
526 self.assert_(res.find(" timeout-ping 12") > 0)
527 self.assert_(res.find(" timeout-pong 14") > 0)
528 self.assert_(res.find(" no timeout-ping advanced") > 0)
529
530 self.vty.verify("no timeout-ping", [''])
531 res = self.vty.command("show running-config")
532 self.assertEquals(res.find(" timeout-ping 12"), -1)
533 self.assertEquals(res.find(" timeout-pong 14"), -1)
534 self.assertEquals(res.find(" no timeout-ping advanced"), -1)
535 self.assert_(res.find(" no timeout-ping") > 0)
536
537 self.vty.verify("timeout-ping advanced", ['%ping handling is disabled. Enable it first.'])
538
539 # And back to enabling it
540 self.vty.verify("timeout-ping 12", [''])
541 self.vty.verify("timeout-pong 14", [''])
542 res = self.vty.command("show running-config")
543 self.assert_(res.find(" timeout-ping 12") > 0)
544 self.assert_(res.find(" timeout-pong 14") > 0)
545 self.assert_(res.find(" timeout-ping advanced") > 0)
546
Holger Hans Peter Freyther32dd2f32015-04-01 18:15:48 +0200547 def testMscDataCoreLACCI(self):
548 self.vty.enable()
549 res = self.vty.command("show running-config")
550 self.assertEquals(res.find("core-location-area-code"), -1)
551 self.assertEquals(res.find("core-cell-identity"), -1)
552
553 self.vty.command("configure terminal")
554 self.vty.command("msc 0")
555 self.vty.command("core-location-area-code 666")
556 self.vty.command("core-cell-identity 333")
557
558 res = self.vty.command("show running-config")
559 self.assert_(res.find("core-location-area-code 666") > 0)
560 self.assert_(res.find("core-cell-identity 333") > 0)
561
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200562class TestVTYNAT(TestVTYGenericBSC):
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200563
564 def vty_command(self):
565 return ["./src/osmo-bsc_nat/osmo-bsc_nat", "-c",
566 "doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg"]
567
568 def vty_app(self):
569 return (4244, "src/osmo-bsc_nat/osmo-bsc_nat", "OsmoBSCNAT", "nat")
570
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200571 def testVtyTree(self):
572 self.vty.enable()
573 self.assertTrue(self.vty.verify('configure terminal', ['']))
574 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100575 self.checkForEndAndExit()
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200576 self.assertTrue(self.vty.verify('mgcp', ['']))
577 self.assertEquals(self.vty.node(), 'config-mgcp')
578 self.checkForEndAndExit()
579 self.assertTrue(self.vty.verify('exit', ['']))
580 self.assertEquals(self.vty.node(), 'config')
581 self.assertTrue(self.vty.verify('nat', ['']))
582 self.assertEquals(self.vty.node(), 'config-nat')
583 self.checkForEndAndExit()
584 self.assertTrue(self.vty.verify('bsc 0', ['']))
585 self.assertEquals(self.vty.node(), 'config-nat-bsc')
586 self.checkForEndAndExit()
587 self.assertTrue(self.vty.verify('exit', ['']))
588 self.assertEquals(self.vty.node(), 'config-nat')
589 self.assertTrue(self.vty.verify('exit', ['']))
590 self.assertEquals(self.vty.node(), 'config')
591 self.assertTrue(self.vty.verify('exit', ['']))
592 self.assertTrue(self.vty.node() is None)
593
594 # Check searching for outer node's commands
595 self.vty.command('configure terminal')
596 self.vty.command('mgcp')
597 self.vty.command('nat')
598 self.assertEquals(self.vty.node(), 'config-nat')
Jacob Erlbeck4c9dff52013-09-02 13:17:17 +0200599 self.vty.command('mgcp')
600 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200601 self.vty.command('nat')
602 self.assertEquals(self.vty.node(), 'config-nat')
603 self.vty.command('bsc 0')
Jacob Erlbeck4c9dff52013-09-02 13:17:17 +0200604 self.vty.command('mgcp')
605 self.assertEquals(self.vty.node(), 'config-mgcp')
Jacob Erlbeck96903c42013-09-02 13:17:14 +0200606
Holger Hans Peter Freytherb718ad32013-06-25 09:08:02 +0200607 def testRewriteNoRewrite(self):
608 self.vty.enable()
609 res = self.vty.command("configure terminal")
610 res = self.vty.command("nat")
611 res = self.vty.command("number-rewrite rewrite.cfg")
612 res = self.vty.command("no number-rewrite")
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200613
Holger Hans Peter Freyther7f100c92015-04-23 20:25:17 -0400614 def testEnsureNoEnsureModeSet(self):
615 self.vty.enable()
616 res = self.vty.command("configure terminal")
617 res = self.vty.command("nat")
618
619 # Ensure the default
620 res = self.vty.command("show running-config")
621 self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0)
622
623 self.vty.command("sdp-ensure-amr-mode-set")
624 res = self.vty.command("show running-config")
625 self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0)
626
627 self.vty.command("no sdp-ensure-amr-mode-set")
628 res = self.vty.command("show running-config")
629 self.assert_(res.find('\n no sdp-ensure-amr-mode-set') > 0)
630
Holger Hans Peter Freyther67e423c2013-06-25 15:38:31 +0200631 def testRewritePostNoRewrite(self):
632 self.vty.enable()
633 self.vty.command("configure terminal")
634 self.vty.command("nat")
635 self.vty.verify("number-rewrite-post rewrite.cfg", [''])
636 self.vty.verify("no number-rewrite-post", [''])
637
638
Holger Hans Peter Freytherddf191e2013-06-25 11:44:01 +0200639 def testPrefixTreeLoading(self):
640 cfg = os.path.join(confpath, "tests/bsc-nat-trie/prefixes.csv")
641
642 self.vty.enable()
643 self.vty.command("configure terminal")
644 self.vty.command("nat")
645 res = self.vty.command("prefix-tree %s" % cfg)
646 self.assertEqual(res, "% prefix-tree loaded 17 rules.")
647 self.vty.command("end")
648
649 res = self.vty.command("show prefix-tree")
650 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')
651
652 self.vty.command("configure terminal")
653 self.vty.command("nat")
654 self.vty.command("no prefix-tree")
655 self.vty.command("end")
656
657 res = self.vty.command("show prefix-tree")
658 self.assertEqual(res, "% there is now prefix tree loaded.")
659
Jacob Erlbeck6cb2ccc2013-08-14 11:10:34 +0200660 def testUssdSideChannelProvider(self):
661 self.vty.command("end")
662 self.vty.enable()
663 self.vty.command("configure terminal")
664 self.vty.command("nat")
665 self.vty.command("ussd-token key")
666 self.vty.command("end")
667
668 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
669 self.assertTrue(res)
670
671 ussdSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
672 ussdSocket.connect(('127.0.0.1', 5001))
673 ussdSocket.settimeout(2.0)
674 print "Connected to %s:%d" % ussdSocket.getpeername()
675
676 print "Expecting ID_GET request"
677 data = ussdSocket.recv(4)
678 self.assertEqual(data, "\x00\x01\xfe\x04")
679
680 print "Going to send ID_RESP response"
681 res = ussdSocket.send("\x00\x07\xfe\x05\x00\x04\x01\x6b\x65\x79")
682 self.assertEqual(res, 10)
683
684 # initiating PING/PONG cycle to know, that the ID_RESP message has been processed
685
686 print "Going to send PING request"
687 res = ussdSocket.send("\x00\x01\xfe\x00")
688 self.assertEqual(res, 4)
689
690 print "Expecting PONG response"
691 data = ussdSocket.recv(4)
692 self.assertEqual(data, "\x00\x01\xfe\x01")
693
694 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is connected and authorized.'])
695 self.assertTrue(res)
696
697 print "Going to shut down connection"
698 ussdSocket.shutdown(socket.SHUT_WR)
699
700 print "Expecting EOF"
701 data = ussdSocket.recv(4)
702 self.assertEqual(data, "")
703
704 ussdSocket.close()
705
706 res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.'])
707 self.assertTrue(res)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200708
Holger Hans Peter Freyther64190182014-01-20 10:14:05 +0100709 def testAccessList(self):
710 """
711 Verify that the imsi-deny can have a reject cause or no reject cause
712 """
713 self.vty.enable()
714 self.vty.command("configure terminal")
715 self.vty.command("nat")
716
717 # Old default
718 self.vty.command("access-list test-default imsi-deny ^123[0-9]*$")
719 res = self.vty.command("show running-config").split("\r\n")
720 asserted = False
721 for line in res:
Holger Hans Peter Freyther4ecc6872014-03-04 15:38:00 +0100722 if line.startswith(" access-list test-default"):
Holger Hans Peter Freyther64190182014-01-20 10:14:05 +0100723 self.assertEqual(line, " access-list test-default imsi-deny ^123[0-9]*$ 11 11")
724 asserted = True
725 self.assert_(asserted)
726
727 # Check the optional CM Service Reject Cause
728 self.vty.command("access-list test-cm-deny imsi-deny ^123[0-9]*$ 42").split("\r\n")
729 res = self.vty.command("show running-config").split("\r\n")
730 asserted = False
731 for line in res:
732 if line.startswith(" access-list test-cm"):
733 self.assertEqual(line, " access-list test-cm-deny imsi-deny ^123[0-9]*$ 42 11")
734 asserted = True
735 self.assert_(asserted)
736
737 # Check the optional LU Reject Cause
738 self.vty.command("access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42").split("\r\n")
739 res = self.vty.command("show running-config").split("\r\n")
740 asserted = False
741 for line in res:
742 if line.startswith(" access-list test-lu"):
743 self.assertEqual(line, " access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42")
744 asserted = True
745 self.assert_(asserted)
746
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200747class TestVTYGbproxy(TestVTYGenericBSC):
748
749 def vty_command(self):
750 return ["./src/gprs/osmo-gbproxy", "-c",
751 "doc/examples/osmo-gbproxy/osmo-gbproxy.cfg"]
752
753 def vty_app(self):
754 return (4246, "./src/gprs/osmo-gbproxy", "OsmoGbProxy", "bsc")
755
756 def testVtyTree(self):
757 self.vty.enable()
758 self.assertTrue(self.vty.verify('configure terminal', ['']))
759 self.assertEquals(self.vty.node(), 'config')
Jacob Erlbeck6e919db2013-10-29 09:30:31 +0100760 self.checkForEndAndExit()
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200761 self.assertTrue(self.vty.verify('ns', ['']))
762 self.assertEquals(self.vty.node(), 'config-ns')
763 self.checkForEndAndExit()
764 self.assertTrue(self.vty.verify('exit', ['']))
765 self.assertEquals(self.vty.node(), 'config')
766 self.assertTrue(self.vty.verify('gbproxy', ['']))
767 self.assertEquals(self.vty.node(), 'config-gbproxy')
768 self.checkForEndAndExit()
769 self.assertTrue(self.vty.verify('exit', ['']))
770 self.assertEquals(self.vty.node(), 'config')
771
772 def testVtyShow(self):
773 res = self.vty.command("show ns")
774 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
775
776 res = self.vty.command("show gbproxy stats")
777 self.assert_(res.find('GBProxy Global Statistics') >= 0)
778
Jacob Erlbeck4211d792013-10-24 12:48:23 +0200779 def testVtyDeletePeer(self):
780 self.vty.enable()
781 self.assertTrue(self.vty.verify('delete-gbproxy-peer 9999 bvci 7777', ['BVC not found']))
782 res = self.vty.command("delete-gbproxy-peer 9999 all dry-run")
783 self.assert_(res.find('Not Deleted 0 BVC') >= 0)
784 self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
785 res = self.vty.command("delete-gbproxy-peer 9999 only-bvc dry-run")
786 self.assert_(res.find('Not Deleted 0 BVC') >= 0)
787 self.assert_(res.find('Not Deleted 0 NS-VC') < 0)
788 res = self.vty.command("delete-gbproxy-peer 9999 only-nsvc dry-run")
789 self.assert_(res.find('Not Deleted 0 BVC') < 0)
790 self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
791 res = self.vty.command("delete-gbproxy-peer 9999 all")
792 self.assert_(res.find('Deleted 0 BVC') >= 0)
793 self.assert_(res.find('Deleted 0 NS-VC') >= 0)
794
Jacob Erlbeck144b8b12014-11-04 11:15:01 +0100795class TestVTYSGSN(TestVTYGenericBSC):
796
797 def vty_command(self):
798 return ["./src/gprs/osmo-sgsn", "-c",
799 "doc/examples/osmo-sgsn/osmo-sgsn.cfg"]
800
801 def vty_app(self):
802 return (4245, "./src/gprs/osmo-sgsn", "OsmoSGSN", "sgsn")
803
804 def testVtyTree(self):
805 self.vty.enable()
806 self.assertTrue(self.vty.verify('configure terminal', ['']))
807 self.assertEquals(self.vty.node(), 'config')
808 self.checkForEndAndExit()
809 self.assertTrue(self.vty.verify('ns', ['']))
810 self.assertEquals(self.vty.node(), 'config-ns')
811 self.checkForEndAndExit()
812 self.assertTrue(self.vty.verify('exit', ['']))
813 self.assertEquals(self.vty.node(), 'config')
814 self.assertTrue(self.vty.verify('sgsn', ['']))
815 self.assertEquals(self.vty.node(), 'config-sgsn')
816 self.checkForEndAndExit()
817 self.assertTrue(self.vty.verify('exit', ['']))
818 self.assertEquals(self.vty.node(), 'config')
819
820 def testVtyShow(self):
821 res = self.vty.command("show ns")
822 self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
823 self.assertTrue(self.vty.verify('show bssgp', ['']))
824 self.assertTrue(self.vty.verify('show bssgp stats', ['']))
825 # TODO: uncomment when the command does not segfault anymore
826 # self.assertTrue(self.vty.verify('show bssgp nsei 123', ['']))
827 # self.assertTrue(self.vty.verify('show bssgp nsei 123 stats', ['']))
828
829 self.assertTrue(self.vty.verify('show sgsn', ['']))
830 self.assertTrue(self.vty.verify('show mm-context all', ['']))
831 self.assertTrue(self.vty.verify('show mm-context imsi 000001234567', ['No MM context for IMSI 000001234567']))
832 self.assertTrue(self.vty.verify('show pdp-context all', ['']))
833
834 res = self.vty.command("show sndcp")
835 self.assert_(res.find('State of SNDCP Entities') >= 0)
836
837 res = self.vty.command("show llc")
838 self.assert_(res.find('State of LLC Entities') >= 0)
839
Jacob Erlbeck106f5472014-11-04 10:08:37 +0100840 def testVtyAuth(self):
841 self.vty.enable()
842 self.assertTrue(self.vty.verify('configure terminal', ['']))
843 self.assertEquals(self.vty.node(), 'config')
844 self.assertTrue(self.vty.verify('sgsn', ['']))
845 self.assertEquals(self.vty.node(), 'config-sgsn')
846 self.assertTrue(self.vty.verify('auth-policy accept-all', ['']))
847 res = self.vty.command("show running-config")
848 self.assert_(res.find('auth-policy accept-all') > 0)
849 self.assertTrue(self.vty.verify('auth-policy acl-only', ['']))
850 res = self.vty.command("show running-config")
851 self.assert_(res.find('auth-policy acl-only') > 0)
852 self.assertTrue(self.vty.verify('auth-policy closed', ['']))
853 res = self.vty.command("show running-config")
854 self.assert_(res.find('auth-policy closed') > 0)
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +0100855 self.assertTrue(self.vty.verify('auth-policy remote', ['']))
856 res = self.vty.command("show running-config")
857 self.assert_(res.find('auth-policy remote') > 0)
Jacob Erlbeck106f5472014-11-04 10:08:37 +0100858
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100859 def testVtySubscriber(self):
860 self.vty.enable()
861 res = self.vty.command('show subscriber cache')
862 self.assert_(res.find('1234567890') < 0)
Jacob Erlbeckd9193432015-01-19 14:11:46 +0100863 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 create', ['']))
864 res = self.vty.command('show subscriber cache')
865 self.assert_(res.find('1234567890') >= 0)
866 self.assert_(res.find('Authorized: 0') >= 0)
867 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 update-location-result ok', ['']))
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100868 res = self.vty.command('show subscriber cache')
869 self.assert_(res.find('1234567890') >= 0)
870 self.assert_(res.find('Authorized: 1') >= 0)
Jacob Erlbeck8000e0e2015-01-27 14:56:40 +0100871 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 cancel update-procedure', ['']))
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100872 res = self.vty.command('show subscriber cache')
Jacob Erlbecke988ae42015-01-27 12:41:19 +0100873 self.assert_(res.find('1234567890') >= 0)
874 self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 destroy', ['']))
875 res = self.vty.command('show subscriber cache')
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100876 self.assert_(res.find('1234567890') < 0)
877
Jacob Erlbeckcb1db8b2015-02-03 13:47:53 +0100878 def testVtyGgsn(self):
879 self.vty.enable()
880 self.assertTrue(self.vty.verify('configure terminal', ['']))
881 self.assertEquals(self.vty.node(), 'config')
882 self.assertTrue(self.vty.verify('sgsn', ['']))
883 self.assertEquals(self.vty.node(), 'config-sgsn')
884 self.assertTrue(self.vty.verify('ggsn 0 remote-ip 127.99.99.99', ['']))
885 self.assertTrue(self.vty.verify('ggsn 0 gtp-version 1', ['']))
886 self.assertTrue(self.vty.verify('apn * ggsn 0', ['']))
887 self.assertTrue(self.vty.verify('apn apn1.test ggsn 0', ['']))
888 self.assertTrue(self.vty.verify('apn apn1.test ggsn 1', ['% a GGSN with id 1 has not been defined']))
889 self.assertTrue(self.vty.verify('apn apn1.test imsi-prefix 123456 ggsn 0', ['']))
890 self.assertTrue(self.vty.verify('apn apn2.test imsi-prefix 123456 ggsn 0', ['']))
891 res = self.vty.command("show running-config")
892 self.assert_(res.find('ggsn 0 remote-ip 127.99.99.99') >= 0)
893 self.assert_(res.find('ggsn 0 gtp-version 1') >= 0)
894 self.assert_(res.find('apn * ggsn 0') >= 0)
895 self.assert_(res.find('apn apn1.test ggsn 0') >= 0)
896 self.assert_(res.find('apn apn1.test imsi-prefix 123456 ggsn 0') >= 0)
897 self.assert_(res.find('apn apn2.test imsi-prefix 123456 ggsn 0') >= 0)
898
Holger Hans Peter Freyther9c20a5f2015-02-06 16:23:29 +0100899 def testVtyEasyAPN(self):
900 self.vty.enable()
901 self.assertTrue(self.vty.verify('configure terminal', ['']))
902 self.assertEquals(self.vty.node(), 'config')
903 self.assertTrue(self.vty.verify('sgsn', ['']))
904 self.assertEquals(self.vty.node(), 'config-sgsn')
905
906 res = self.vty.command("show running-config")
907 self.assertEquals(res.find("apn internet"), -1)
908
909 self.assertTrue(self.vty.verify("access-point-name internet.apn", ['']))
910 res = self.vty.command("show running-config")
911 self.assert_(res.find("apn internet.apn ggsn 0") >= 0)
912
913 self.assertTrue(self.vty.verify("no access-point-name internet.apn", ['']))
914 res = self.vty.command("show running-config")
915 self.assertEquals(res.find("apn internet"), -1)
916
Holger Hans Peter Freytherc15c61c2015-05-06 17:46:08 +0200917 def testVtyCDR(self):
918 self.vty.enable()
919 self.assertTrue(self.vty.verify('configure terminal', ['']))
920 self.assertEquals(self.vty.node(), 'config')
921 self.assertTrue(self.vty.verify('sgsn', ['']))
922 self.assertEquals(self.vty.node(), 'config-sgsn')
923
924 res = self.vty.command("show running-config")
925 self.assert_(res.find("no cdr filename") > 0)
926
927 self.vty.command("cdr filename bla.cdr")
928 res = self.vty.command("show running-config")
929 self.assertEquals(res.find("no cdr filename"), -1)
930 self.assert_(res.find(" cdr filename bla.cdr") > 0)
931
932 self.vty.command("no cdr filename")
933 res = self.vty.command("show running-config")
934 self.assert_(res.find("no cdr filename") > 0)
935 self.assertEquals(res.find(" cdr filename bla.cdr"), -1)
936
937 res = self.vty.command("show running-config")
938 self.assert_(res.find(" cdr interval 600") > 0)
939
940 self.vty.command("cdr interval 900")
941 res = self.vty.command("show running-config")
942 self.assert_(res.find(" cdr interval 900") > 0)
943 self.assertEquals(res.find(" cdr interval 600"), -1)
944
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200945def add_nat_test(suite, workdir):
946 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")):
947 print("Skipping the NAT test")
948 return
949 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYNAT)
950 suite.addTest(test)
951
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200952def add_bsc_test(suite, workdir):
953 if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")):
954 print("Skipping the BSC test")
955 return
956 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYBSC)
957 suite.addTest(test)
958
Jacob Erlbeck6d233712013-10-23 11:24:15 +0200959def add_gbproxy_test(suite, workdir):
960 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-gbproxy")):
961 print("Skipping the Gb-Proxy test")
962 return
963 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYGbproxy)
964 suite.addTest(test)
965
Jacob Erlbeck144b8b12014-11-04 11:15:01 +0100966def add_sgsn_test(suite, workdir):
967 if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-sgsn")):
968 print("Skipping the SGSN test")
969 return
970 test = unittest.TestLoader().loadTestsFromTestCase(TestVTYSGSN)
971 suite.addTest(test)
972
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +0200973if __name__ == '__main__':
974 import argparse
975 import sys
976
977 workdir = '.'
978
979 parser = argparse.ArgumentParser()
980 parser.add_argument("-v", "--verbose", dest="verbose",
981 action="store_true", help="verbose mode")
982 parser.add_argument("-p", "--pythonconfpath", dest="p",
983 help="searchpath for config")
984 parser.add_argument("-w", "--workdir", dest="w",
985 help="Working directory")
986 args = parser.parse_args()
987
988 verbose_level = 1
989 if args.verbose:
990 verbose_level = 2
991
992 if args.w:
993 workdir = args.w
994
995 if args.p:
996 confpath = args.p
997
998 print "confpath %s, workdir %s" % (confpath, workdir)
999 os.chdir(workdir)
1000 print "Running tests for specific VTY commands"
1001 suite = unittest.TestSuite()
Holger Hans Peter Freyther8d998a72014-07-04 20:23:56 +02001002 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYMGCP))
Holger Hans Peter Freytherc63f6f12013-07-27 21:07:57 +02001003 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYNITB))
Jacob Erlbeck1b894022013-08-28 10:16:54 +02001004 add_bsc_test(suite, workdir)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001005 add_nat_test(suite, workdir)
Jacob Erlbeck6d233712013-10-23 11:24:15 +02001006 add_gbproxy_test(suite, workdir)
Jacob Erlbeck144b8b12014-11-04 11:15:01 +01001007 add_sgsn_test(suite, workdir)
Holger Hans Peter Freythereb0acb62013-06-24 15:47:34 +02001008 res = unittest.TextTestRunner(verbosity=verbose_level).run(suite)
1009 sys.exit(len(res.errors) + len(res.failures))