Holger Hans Peter Freyther | eb0acb6 | 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 | |
Max | 3e67689 | 2016-11-16 14:55:21 +0100 | [diff] [blame] | 18 | import os, sys |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 19 | import time |
| 20 | import unittest |
Jacob Erlbeck | 6cb2ccc | 2013-08-14 11:10:34 +0200 | [diff] [blame] | 21 | import socket |
Neels Hofmeyr | bcfee2a | 2017-02-03 16:09:17 +0100 | [diff] [blame] | 22 | import subprocess |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 23 | |
| 24 | import osmopy.obscvty as obscvty |
| 25 | import osmopy.osmoutil as osmoutil |
| 26 | |
Max | 3e67689 | 2016-11-16 14:55:21 +0100 | [diff] [blame] | 27 | sys.path.append("../contrib") |
| 28 | from ipa import IPA |
| 29 | |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 30 | confpath = '.' |
| 31 | |
| 32 | class TestVTYBase(unittest.TestCase): |
| 33 | |
| 34 | def vty_command(self): |
| 35 | raise Exception("Needs to be implemented by a subclass") |
| 36 | |
| 37 | def vty_app(self): |
| 38 | raise Exception("Needs to be implemented by a subclass") |
| 39 | |
| 40 | def setUp(self): |
| 41 | osmo_vty_cmd = self.vty_command()[:] |
| 42 | config_index = osmo_vty_cmd.index('-c') |
| 43 | if config_index: |
| 44 | cfi = config_index + 1 |
| 45 | osmo_vty_cmd[cfi] = os.path.join(confpath, osmo_vty_cmd[cfi]) |
| 46 | |
| 47 | try: |
| 48 | print "Launch: %s from %s" % (' '.join(osmo_vty_cmd), os.getcwd()) |
| 49 | self.proc = osmoutil.popen_devnull(osmo_vty_cmd) |
| 50 | except OSError: |
| 51 | print >> sys.stderr, "Current directory: %s" % os.getcwd() |
| 52 | print >> sys.stderr, "Consider setting -b" |
| 53 | time.sleep(1) |
| 54 | |
| 55 | appstring = self.vty_app()[2] |
| 56 | appport = self.vty_app()[0] |
| 57 | self.vty = obscvty.VTYInteract(appstring, "127.0.0.1", appport) |
| 58 | |
| 59 | def tearDown(self): |
| 60 | self.vty = None |
| 61 | osmoutil.end_proc(self.proc) |
| 62 | |
Holger Hans Peter Freyther | 8d998a7 | 2014-07-04 20:23:56 +0200 | [diff] [blame] | 63 | class TestVTYMGCP(TestVTYBase): |
| 64 | def vty_command(self): |
| 65 | return ["./src/osmo-bsc_mgcp/osmo-bsc_mgcp", "-c", |
| 66 | "doc/examples/osmo-bsc_mgcp/mgcp.cfg"] |
| 67 | |
| 68 | def vty_app(self): |
| 69 | return (4243, "./src/osmo-bsc_mgcp/osmo-bsc_mgcp", "OpenBSC MGCP", "mgcp") |
| 70 | |
| 71 | def testForcePtime(self): |
Neels Hofmeyr | 0867b72 | 2016-09-28 23:28:06 +0200 | [diff] [blame] | 72 | self.vty.enable() |
| 73 | res = self.vty.command("show running-config") |
| 74 | self.assert_(res.find(' rtp force-ptime 20\r') > 0) |
| 75 | self.assertEquals(res.find(' no rtp force-ptime\r'), -1) |
Holger Hans Peter Freyther | 8d998a7 | 2014-07-04 20:23:56 +0200 | [diff] [blame] | 76 | |
Neels Hofmeyr | 0867b72 | 2016-09-28 23:28:06 +0200 | [diff] [blame] | 77 | self.vty.command("configure terminal") |
| 78 | self.vty.command("mgcp") |
| 79 | self.vty.command("no rtp force-ptime") |
| 80 | res = self.vty.command("show running-config") |
| 81 | self.assertEquals(res.find(' rtp force-ptime 20\r'), -1) |
| 82 | self.assertEquals(res.find(' no rtp force-ptime\r'), -1) |
Holger Hans Peter Freyther | 8d998a7 | 2014-07-04 20:23:56 +0200 | [diff] [blame] | 83 | |
Holger Hans Peter Freyther | 619b014 | 2014-11-19 16:04:45 +0100 | [diff] [blame] | 84 | def testOmitAudio(self): |
| 85 | self.vty.enable() |
Neels Hofmeyr | 0867b72 | 2016-09-28 23:28:06 +0200 | [diff] [blame] | 86 | res = self.vty.command("show running-config") |
| 87 | self.assert_(res.find(' sdp audio-payload send-name\r') > 0) |
| 88 | self.assertEquals(res.find(' no sdp audio-payload send-name\r'), -1) |
Holger Hans Peter Freyther | 619b014 | 2014-11-19 16:04:45 +0100 | [diff] [blame] | 89 | |
Neels Hofmeyr | 0867b72 | 2016-09-28 23:28:06 +0200 | [diff] [blame] | 90 | self.vty.command("configure terminal") |
| 91 | self.vty.command("mgcp") |
| 92 | self.vty.command("no sdp audio-payload send-name") |
| 93 | res = self.vty.command("show running-config") |
| 94 | self.assertEquals(res.find(' rtp sdp audio-payload send-name\r'), -1) |
| 95 | self.assert_(res.find(' no sdp audio-payload send-name\r') > 0) |
Holger Hans Peter Freyther | 619b014 | 2014-11-19 16:04:45 +0100 | [diff] [blame] | 96 | |
| 97 | # TODO: test it for the trunk! |
| 98 | |
Holger Hans Peter Freyther | c390ae8 | 2015-08-20 15:15:50 +0200 | [diff] [blame] | 99 | def testBindAddr(self): |
| 100 | self.vty.enable() |
| 101 | |
Neels Hofmeyr | 0867b72 | 2016-09-28 23:28:06 +0200 | [diff] [blame] | 102 | self.vty.command("configure terminal") |
| 103 | self.vty.command("mgcp") |
Holger Hans Peter Freyther | c390ae8 | 2015-08-20 15:15:50 +0200 | [diff] [blame] | 104 | |
| 105 | # enable.. disable bts-bind-ip |
| 106 | self.vty.command("rtp bts-bind-ip 254.253.252.250") |
| 107 | res = self.vty.command("show running-config") |
| 108 | self.assert_(res.find('rtp bts-bind-ip 254.253.252.250') > 0) |
| 109 | self.vty.command("no rtp bts-bind-ip") |
| 110 | res = self.vty.command("show running-config") |
| 111 | self.assertEquals(res.find(' rtp bts-bind-ip'), -1) |
| 112 | |
| 113 | # enable.. disable net-bind-ip |
| 114 | self.vty.command("rtp net-bind-ip 254.253.252.250") |
| 115 | res = self.vty.command("show running-config") |
| 116 | self.assert_(res.find('rtp net-bind-ip 254.253.252.250') > 0) |
| 117 | self.vty.command("no rtp net-bind-ip") |
| 118 | res = self.vty.command("show running-config") |
| 119 | self.assertEquals(res.find(' rtp net-bind-ip'), -1) |
| 120 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 121 | |
| 122 | class TestVTYGenericBSC(TestVTYBase): |
| 123 | |
| 124 | def checkForEndAndExit(self): |
| 125 | res = self.vty.command("list") |
| 126 | #print ('looking for "exit"\n') |
| 127 | self.assert_(res.find(' exit\r') > 0) |
| 128 | #print 'found "exit"\nlooking for "end"\n' |
| 129 | self.assert_(res.find(' end\r') > 0) |
| 130 | #print 'found "end"\n' |
| 131 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 132 | def _testConfigNetworkTree(self): |
| 133 | self.vty.enable() |
| 134 | self.assertTrue(self.vty.verify("configure terminal",[''])) |
| 135 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 6e919db | 2013-10-29 09:30:31 +0100 | [diff] [blame] | 136 | self.checkForEndAndExit() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 137 | self.assertTrue(self.vty.verify("network",[''])) |
| 138 | self.assertEquals(self.vty.node(), 'config-net') |
| 139 | self.checkForEndAndExit() |
| 140 | self.assertTrue(self.vty.verify("bts 0",[''])) |
| 141 | self.assertEquals(self.vty.node(), 'config-net-bts') |
| 142 | self.checkForEndAndExit() |
| 143 | self.assertTrue(self.vty.verify("trx 0",[''])) |
| 144 | self.assertEquals(self.vty.node(), 'config-net-bts-trx') |
| 145 | self.checkForEndAndExit() |
Jacob Erlbeck | 733bec8 | 2013-09-11 10:46:56 +0200 | [diff] [blame] | 146 | self.vty.command("write terminal") |
| 147 | self.assertTrue(self.vty.verify("exit",[''])) |
| 148 | self.assertEquals(self.vty.node(), 'config-net-bts') |
| 149 | self.assertTrue(self.vty.verify("exit",[''])) |
| 150 | self.assertTrue(self.vty.verify("bts 1",[''])) |
| 151 | self.assertEquals(self.vty.node(), 'config-net-bts') |
| 152 | self.checkForEndAndExit() |
| 153 | self.assertTrue(self.vty.verify("trx 1",[''])) |
| 154 | self.assertEquals(self.vty.node(), 'config-net-bts-trx') |
| 155 | self.checkForEndAndExit() |
| 156 | self.vty.command("write terminal") |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 157 | self.assertTrue(self.vty.verify("exit",[''])) |
| 158 | self.assertEquals(self.vty.node(), 'config-net-bts') |
| 159 | self.assertTrue(self.vty.verify("exit",[''])) |
| 160 | self.assertEquals(self.vty.node(), 'config-net') |
| 161 | self.assertTrue(self.vty.verify("exit",[''])) |
| 162 | self.assertEquals(self.vty.node(), 'config') |
| 163 | self.assertTrue(self.vty.verify("exit",[''])) |
| 164 | self.assertTrue(self.vty.node() is None) |
| 165 | |
| 166 | class TestVTYNITB(TestVTYGenericBSC): |
Holger Hans Peter Freyther | c63f6f1 | 2013-07-27 21:07:57 +0200 | [diff] [blame] | 167 | |
| 168 | def vty_command(self): |
| 169 | return ["./src/osmo-nitb/osmo-nitb", "-c", |
| 170 | "doc/examples/osmo-nitb/nanobts/openbsc.cfg"] |
| 171 | |
| 172 | def vty_app(self): |
| 173 | return (4242, "./src/osmo-nitb/osmo-nitb", "OpenBSC", "nitb") |
| 174 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 175 | def testConfigNetworkTree(self): |
Jacob Erlbeck | 7587727 | 2013-10-23 11:24:14 +0200 | [diff] [blame] | 176 | self._testConfigNetworkTree() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 177 | |
Holger Hans Peter Freyther | 0df1ab9 | 2013-09-02 20:58:38 +0200 | [diff] [blame] | 178 | def checkForSmpp(self): |
| 179 | """SMPP is not always enabled, check if it is""" |
| 180 | res = self.vty.command("list") |
| 181 | return "smpp" in res |
| 182 | |
Holger Hans Peter Freyther | 42cf2e0 | 2015-07-06 16:41:30 +0200 | [diff] [blame] | 183 | def testSmppFirst(self): |
Holger Hans Peter Freyther | 42cf2e0 | 2015-07-06 16:41:30 +0200 | [diff] [blame] | 184 | # enable the configuration |
| 185 | self.vty.enable() |
| 186 | self.vty.command("configure terminal") |
Holger Hans Peter Freyther | a2c41c4 | 2015-07-13 11:23:53 +0200 | [diff] [blame] | 187 | |
| 188 | if not self.checkForSmpp(): |
| 189 | return |
| 190 | |
Holger Hans Peter Freyther | 42cf2e0 | 2015-07-06 16:41:30 +0200 | [diff] [blame] | 191 | self.vty.command("smpp") |
| 192 | |
| 193 | # check the default |
| 194 | res = self.vty.command("write terminal") |
| 195 | self.assert_(res.find(' no smpp-first') > 0) |
| 196 | |
| 197 | self.vty.verify("smpp-first", ['']) |
| 198 | res = self.vty.command("write terminal") |
| 199 | self.assert_(res.find(' smpp-first') > 0) |
| 200 | self.assertEquals(res.find('no smpp-first'), -1) |
| 201 | |
| 202 | self.vty.verify("no smpp-first", ['']) |
| 203 | res = self.vty.command("write terminal") |
| 204 | self.assert_(res.find('no smpp-first') > 0) |
| 205 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 206 | def testVtyTree(self): |
| 207 | self.vty.enable() |
| 208 | self.assertTrue(self.vty.verify("configure terminal", [''])) |
| 209 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 6e919db | 2013-10-29 09:30:31 +0100 | [diff] [blame] | 210 | self.checkForEndAndExit() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 211 | self.assertTrue(self.vty.verify('mncc-int', [''])) |
| 212 | self.assertEquals(self.vty.node(), 'config-mncc-int') |
| 213 | self.checkForEndAndExit() |
| 214 | self.assertTrue(self.vty.verify('exit', [''])) |
Holger Hans Peter Freyther | 0df1ab9 | 2013-09-02 20:58:38 +0200 | [diff] [blame] | 215 | |
| 216 | if self.checkForSmpp(): |
| 217 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 7587727 | 2013-10-23 11:24:14 +0200 | [diff] [blame] | 218 | self.assertTrue(self.vty.verify('smpp', [''])) |
| 219 | self.assertEquals(self.vty.node(), 'config-smpp') |
Jacob Erlbeck | 6e919db | 2013-10-29 09:30:31 +0100 | [diff] [blame] | 220 | self.checkForEndAndExit() |
Jacob Erlbeck | 7587727 | 2013-10-23 11:24:14 +0200 | [diff] [blame] | 221 | self.assertTrue(self.vty.verify("exit", [''])) |
Holger Hans Peter Freyther | 0df1ab9 | 2013-09-02 20:58:38 +0200 | [diff] [blame] | 222 | |
Jacob Erlbeck | 0ae92a9 | 2013-09-02 13:17:16 +0200 | [diff] [blame] | 223 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 224 | self.assertTrue(self.vty.verify("exit", [''])) |
| 225 | self.assertTrue(self.vty.node() is None) |
| 226 | |
| 227 | # Check searching for outer node's commands |
| 228 | self.vty.command("configure terminal") |
| 229 | self.vty.command('mncc-int') |
Holger Hans Peter Freyther | 0df1ab9 | 2013-09-02 20:58:38 +0200 | [diff] [blame] | 230 | |
| 231 | if self.checkForSmpp(): |
| 232 | self.vty.command('smpp') |
| 233 | self.assertEquals(self.vty.node(), 'config-smpp') |
| 234 | self.vty.command('mncc-int') |
| 235 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 236 | self.assertEquals(self.vty.node(), 'config-mncc-int') |
| 237 | |
Max | ddee01f | 2016-05-24 14:23:27 +0200 | [diff] [blame] | 238 | def testVtyAuthorization(self): |
| 239 | self.vty.enable() |
| 240 | self.vty.command("configure terminal") |
| 241 | self.vty.command("network") |
| 242 | self.assertTrue(self.vty.verify("auth policy closed", [''])) |
| 243 | self.assertTrue(self.vty.verify("auth policy regexp", [''])) |
| 244 | self.assertTrue(self.vty.verify("authorized-regexp ^001", [''])) |
| 245 | self.assertTrue(self.vty.verify("authorized-regexp 02$", [''])) |
| 246 | self.assertTrue(self.vty.verify("authorized-regexp *123.*", [''])) |
| 247 | self.vty.command("end") |
| 248 | self.vty.command("configure terminal") |
| 249 | self.vty.command("nitb") |
| 250 | self.assertTrue(self.vty.verify("subscriber-create-on-demand", [''])) |
Max | e6052c4 | 2016-06-30 10:25:49 +0200 | [diff] [blame] | 251 | self.assertTrue(self.vty.verify("subscriber-create-on-demand no-extension", [''])) |
Max | ddee01f | 2016-05-24 14:23:27 +0200 | [diff] [blame] | 252 | self.vty.command("end") |
| 253 | |
Max | 0c1bc26 | 2016-04-20 12:06:06 +0200 | [diff] [blame] | 254 | def testSi2Q(self): |
| 255 | self.vty.enable() |
| 256 | self.vty.command("configure terminal") |
| 257 | self.vty.command("network") |
| 258 | self.vty.command("bts 0") |
| 259 | before = self.vty.command("show running-config") |
| 260 | self.vty.command("si2quater neighbor-list add earfcn 1911 threshold 11 2") |
| 261 | self.vty.command("si2quater neighbor-list add earfcn 1924 threshold 11 3") |
| 262 | self.vty.command("si2quater neighbor-list add earfcn 2111 threshold 11") |
| 263 | self.vty.command("si2quater neighbor-list del earfcn 1911") |
| 264 | self.vty.command("si2quater neighbor-list del earfcn 1924") |
| 265 | self.vty.command("si2quater neighbor-list del earfcn 2111") |
| 266 | self.assertEquals(before, self.vty.command("show running-config")) |
Max | 26679e0 | 2016-04-20 15:57:13 +0200 | [diff] [blame] | 267 | self.vty.command("si2quater neighbor-list add uarfcn 1976 13 1") |
| 268 | self.vty.command("si2quater neighbor-list add uarfcn 1976 38 1") |
| 269 | self.vty.command("si2quater neighbor-list add uarfcn 1976 44 1") |
| 270 | self.vty.command("si2quater neighbor-list add uarfcn 1976 120 1") |
| 271 | self.vty.command("si2quater neighbor-list add uarfcn 1976 140 1") |
| 272 | self.vty.command("si2quater neighbor-list add uarfcn 1976 163 1") |
| 273 | self.vty.command("si2quater neighbor-list add uarfcn 1976 166 1") |
| 274 | self.vty.command("si2quater neighbor-list add uarfcn 1976 217 1") |
| 275 | self.vty.command("si2quater neighbor-list add uarfcn 1976 224 1") |
| 276 | self.vty.command("si2quater neighbor-list add uarfcn 1976 225 1") |
| 277 | self.vty.command("si2quater neighbor-list add uarfcn 1976 226 1") |
| 278 | self.vty.command("si2quater neighbor-list del uarfcn 1976 13") |
| 279 | self.vty.command("si2quater neighbor-list del uarfcn 1976 38") |
| 280 | self.vty.command("si2quater neighbor-list del uarfcn 1976 44") |
| 281 | self.vty.command("si2quater neighbor-list del uarfcn 1976 120") |
| 282 | self.vty.command("si2quater neighbor-list del uarfcn 1976 140") |
| 283 | self.vty.command("si2quater neighbor-list del uarfcn 1976 163") |
| 284 | self.vty.command("si2quater neighbor-list del uarfcn 1976 166") |
| 285 | self.vty.command("si2quater neighbor-list del uarfcn 1976 217") |
| 286 | self.vty.command("si2quater neighbor-list del uarfcn 1976 224") |
| 287 | self.vty.command("si2quater neighbor-list del uarfcn 1976 225") |
| 288 | self.vty.command("si2quater neighbor-list del uarfcn 1976 226") |
| 289 | self.assertEquals(before, self.vty.command("show running-config")) |
Max | 0c1bc26 | 2016-04-20 12:06:06 +0200 | [diff] [blame] | 290 | |
Holger Hans Peter Freyther | c63f6f1 | 2013-07-27 21:07:57 +0200 | [diff] [blame] | 291 | def testEnableDisablePeriodicLU(self): |
| 292 | self.vty.enable() |
| 293 | self.vty.command("configure terminal") |
| 294 | self.vty.command("network") |
| 295 | self.vty.command("bts 0") |
| 296 | |
| 297 | # Test invalid input |
| 298 | self.vty.verify("periodic location update 0", ['% Unknown command.']) |
| 299 | self.vty.verify("periodic location update 5", ['% Unknown command.']) |
| 300 | self.vty.verify("periodic location update 1531", ['% Unknown command.']) |
| 301 | |
| 302 | # Enable periodic lu.. |
| 303 | self.vty.verify("periodic location update 60", ['']) |
| 304 | res = self.vty.command("write terminal") |
Holger Hans Peter Freyther | c0438e3 | 2013-07-27 22:23:25 +0200 | [diff] [blame] | 305 | self.assert_(res.find('periodic location update 60') > 0) |
Holger Hans Peter Freyther | c63f6f1 | 2013-07-27 21:07:57 +0200 | [diff] [blame] | 306 | self.assertEquals(res.find('no periodic location update'), -1) |
| 307 | |
| 308 | # Now disable it.. |
| 309 | self.vty.verify("no periodic location update", ['']) |
| 310 | res = self.vty.command("write terminal") |
| 311 | self.assertEquals(res.find('periodic location update 60'), -1) |
Holger Hans Peter Freyther | c0438e3 | 2013-07-27 22:23:25 +0200 | [diff] [blame] | 312 | self.assert_(res.find('no periodic location update') > 0) |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 313 | |
Jacob Erlbeck | 65d114f | 2014-01-16 11:02:14 +0100 | [diff] [blame] | 314 | def testEnableDisableSiHacks(self): |
| 315 | self.vty.enable() |
| 316 | self.vty.command("configure terminal") |
| 317 | self.vty.command("network") |
| 318 | self.vty.command("bts 0") |
| 319 | |
| 320 | # Enable periodic lu.. |
| 321 | self.vty.verify("force-combined-si", ['']) |
| 322 | res = self.vty.command("write terminal") |
| 323 | self.assert_(res.find(' force-combined-si') > 0) |
| 324 | self.assertEquals(res.find('no force-combined-si'), -1) |
| 325 | |
| 326 | # Now disable it.. |
| 327 | self.vty.verify("no force-combined-si", ['']) |
| 328 | res = self.vty.command("write terminal") |
| 329 | self.assertEquals(res.find(' force-combined-si'), -1) |
| 330 | self.assert_(res.find('no force-combined-si') > 0) |
| 331 | |
Ivan Kluchnikov | 6792059 | 2013-09-16 13:13:04 +0400 | [diff] [blame] | 332 | def testRachAccessControlClass(self): |
| 333 | self.vty.enable() |
| 334 | self.vty.command("configure terminal") |
| 335 | self.vty.command("network") |
| 336 | self.vty.command("bts 0") |
| 337 | |
| 338 | # Test invalid input |
| 339 | self.vty.verify("rach access-control-class", ['% Command incomplete.']) |
| 340 | self.vty.verify("rach access-control-class 1", ['% Command incomplete.']) |
| 341 | self.vty.verify("rach access-control-class -1", ['% Unknown command.']) |
| 342 | self.vty.verify("rach access-control-class 10", ['% Unknown command.']) |
| 343 | self.vty.verify("rach access-control-class 16", ['% Unknown command.']) |
| 344 | |
| 345 | # Barred rach access control classes |
| 346 | for classNum in range(16): |
| 347 | if classNum != 10: |
| 348 | self.vty.verify("rach access-control-class " + str(classNum) + " barred", ['']) |
| 349 | |
| 350 | # Verify settings |
| 351 | res = self.vty.command("write terminal") |
| 352 | for classNum in range(16): |
| 353 | if classNum != 10: |
| 354 | self.assert_(res.find("rach access-control-class " + str(classNum) + " barred") > 0) |
| 355 | |
| 356 | # Allowed rach access control classes |
| 357 | for classNum in range(16): |
| 358 | if classNum != 10: |
| 359 | self.vty.verify("rach access-control-class " + str(classNum) + " allowed", ['']) |
| 360 | |
| 361 | # Verify settings |
| 362 | res = self.vty.command("write terminal") |
| 363 | for classNum in range(16): |
| 364 | if classNum != 10: |
| 365 | self.assertEquals(res.find("rach access-control-class " + str(classNum) + " barred"), -1) |
| 366 | |
Holger Hans Peter Freyther | de39225 | 2016-04-01 19:44:00 +0200 | [diff] [blame] | 367 | def testSubscriberCreateDeleteTwice(self): |
| 368 | """ |
| 369 | OS#1657 indicates that there might be an issue creating the |
| 370 | same subscriber twice. This test will use the VTY command to |
| 371 | create a subscriber and then issue a second create command |
| 372 | with the same IMSI. The test passes if the VTY continues to |
| 373 | respond to VTY commands. |
| 374 | """ |
| 375 | self.vty.enable() |
| 376 | |
| 377 | imsi = "204300854013739" |
| 378 | |
| 379 | # Initially we don't have this subscriber |
| 380 | self.vty.verify('show subscriber imsi '+imsi, ['% No subscriber found for imsi '+imsi]) |
| 381 | |
| 382 | # Lets create one |
| 383 | res = self.vty.command('subscriber create imsi '+imsi) |
| 384 | self.assert_(res.find(" IMSI: "+imsi) > 0) |
| 385 | # And now create one again. |
| 386 | res2 = self.vty.command('subscriber create imsi '+imsi) |
| 387 | self.assert_(res2.find(" IMSI: "+imsi) > 0) |
| 388 | self.assertEqual(res, res2) |
| 389 | |
| 390 | # Verify it has been created |
| 391 | res = self.vty.command('show subscriber imsi '+imsi) |
| 392 | self.assert_(res.find(" IMSI: "+imsi) > 0) |
| 393 | |
| 394 | # Delete it |
Max | 488902d | 2016-06-22 14:02:39 +0200 | [diff] [blame] | 395 | res = self.vty.command('subscriber imsi ' + imsi + ' delete') |
| 396 | self.assert_("" == res) |
Holger Hans Peter Freyther | de39225 | 2016-04-01 19:44:00 +0200 | [diff] [blame] | 397 | |
| 398 | # Now it should not be there anymore |
| 399 | res = self.vty.command('show subscriber imsi '+imsi) |
Max | 488902d | 2016-06-22 14:02:39 +0200 | [diff] [blame] | 400 | self.assert_(('% No subscriber found for imsi ' + imsi) == res) |
Holger Hans Peter Freyther | de39225 | 2016-04-01 19:44:00 +0200 | [diff] [blame] | 401 | |
| 402 | |
Ruben Pollan | ed04a0d | 2014-09-24 20:50:13 -0500 | [diff] [blame] | 403 | def testSubscriberCreateDelete(self): |
Alexander Chemeris | bd6d40f | 2013-10-04 23:54:17 +0200 | [diff] [blame] | 404 | self.vty.enable() |
| 405 | |
| 406 | imsi = "204300854013739" |
Max | e6052c4 | 2016-06-30 10:25:49 +0200 | [diff] [blame] | 407 | imsi2 = "222301824913762" |
| 408 | imsi3 = "333500854113763" |
| 409 | imsi4 = "444583744053764" |
Alexander Chemeris | bd6d40f | 2013-10-04 23:54:17 +0200 | [diff] [blame] | 410 | |
| 411 | # Initially we don't have this subscriber |
| 412 | self.vty.verify('show subscriber imsi '+imsi, ['% No subscriber found for imsi '+imsi]) |
| 413 | |
| 414 | # Lets create one |
| 415 | res = self.vty.command('subscriber create imsi '+imsi) |
| 416 | self.assert_(res.find(" IMSI: "+imsi) > 0) |
Max | e6052c4 | 2016-06-30 10:25:49 +0200 | [diff] [blame] | 417 | self.assert_(res.find("Extension") > 0) |
Alexander Chemeris | bd6d40f | 2013-10-04 23:54:17 +0200 | [diff] [blame] | 418 | |
| 419 | # Now we have it |
| 420 | res = self.vty.command('show subscriber imsi '+imsi) |
| 421 | self.assert_(res.find(" IMSI: "+imsi) > 0) |
| 422 | |
Max | e6052c4 | 2016-06-30 10:25:49 +0200 | [diff] [blame] | 423 | # With narrow random interval |
| 424 | self.vty.command("configure terminal") |
| 425 | self.vty.command("nitb") |
| 426 | self.assertTrue(self.vty.verify("subscriber-create-on-demand", [''])) |
| 427 | # wrong interval |
| 428 | res = self.vty.command("subscriber-create-on-demand random 221 122") |
| 429 | # error string will contain arguments |
| 430 | self.assert_(res.find("122") > 0) |
| 431 | self.assert_(res.find("221") > 0) |
| 432 | # correct interval - silent ok |
| 433 | self.assertTrue(self.vty.verify("subscriber-create-on-demand random 221 222", [''])) |
| 434 | self.vty.command("end") |
| 435 | |
| 436 | res = self.vty.command('subscriber create imsi ' + imsi2) |
| 437 | self.assert_(res.find(" IMSI: " + imsi2) > 0) |
| 438 | self.assert_(res.find("221") > 0 or res.find("222") > 0) |
| 439 | self.assert_(res.find(" Extension: ") > 0) |
| 440 | |
| 441 | # Without extension |
| 442 | self.vty.command("configure terminal") |
| 443 | self.vty.command("nitb") |
| 444 | self.assertTrue(self.vty.verify("subscriber-create-on-demand no-extension", [''])) |
| 445 | self.vty.command("end") |
| 446 | res = self.vty.command('subscriber create imsi ' + imsi3) |
| 447 | self.assert_(res.find(" IMSI: " + imsi3) > 0) |
| 448 | self.assertEquals(res.find("Extension"), -1) |
| 449 | |
| 450 | # With extension again |
| 451 | self.vty.command("configure terminal") |
| 452 | self.vty.command("nitb") |
| 453 | self.assertTrue(self.vty.verify("no subscriber-create-on-demand", [''])) |
| 454 | self.assertTrue(self.vty.verify("subscriber-create-on-demand", [''])) |
| 455 | self.assertTrue(self.vty.verify("subscriber-create-on-demand random 221 666", [''])) |
| 456 | self.vty.command("end") |
| 457 | |
| 458 | res = self.vty.command('subscriber create imsi ' + imsi4) |
| 459 | self.assert_(res.find(" IMSI: " + imsi4) > 0) |
| 460 | self.assert_(res.find(" Extension: ") > 0) |
| 461 | |
Ruben Pollan | ed04a0d | 2014-09-24 20:50:13 -0500 | [diff] [blame] | 462 | # Delete it |
Max | 488902d | 2016-06-22 14:02:39 +0200 | [diff] [blame] | 463 | res = self.vty.command('subscriber imsi ' + imsi + ' delete') |
| 464 | self.assert_("" == res) |
Max | e6052c4 | 2016-06-30 10:25:49 +0200 | [diff] [blame] | 465 | res = self.vty.command('subscriber imsi ' + imsi2 + ' delete') |
| 466 | self.assert_("" == res) |
| 467 | res = self.vty.command('subscriber imsi ' + imsi3 + ' delete') |
| 468 | self.assert_("" == res) |
| 469 | res = self.vty.command('subscriber imsi ' + imsi4 + ' delete') |
| 470 | self.assert_("" == res) |
Ruben Pollan | ed04a0d | 2014-09-24 20:50:13 -0500 | [diff] [blame] | 471 | |
| 472 | # Now it should not be there anymore |
| 473 | res = self.vty.command('show subscriber imsi '+imsi) |
Max | 488902d | 2016-06-22 14:02:39 +0200 | [diff] [blame] | 474 | self.assert_(('% No subscriber found for imsi ' + imsi) == res) |
Ruben Pollan | ed04a0d | 2014-09-24 20:50:13 -0500 | [diff] [blame] | 475 | |
Jacob Erlbeck | 322b149 | 2015-04-07 17:49:49 +0200 | [diff] [blame] | 476 | def testSubscriberSettings(self): |
| 477 | self.vty.enable() |
| 478 | |
| 479 | imsi = "204300854013739" |
Max | 0fcd2e2 | 2016-06-07 15:32:16 +0200 | [diff] [blame] | 480 | imsi2 = "204301824913769" |
Jacob Erlbeck | 322b149 | 2015-04-07 17:49:49 +0200 | [diff] [blame] | 481 | wrong_imsi = "204300999999999" |
| 482 | |
| 483 | # Lets create one |
| 484 | res = self.vty.command('subscriber create imsi '+imsi) |
| 485 | self.assert_(res.find(" IMSI: "+imsi) > 0) |
Max | 0fcd2e2 | 2016-06-07 15:32:16 +0200 | [diff] [blame] | 486 | self.assert_(res.find("Extension") > 0) |
Jacob Erlbeck | 322b149 | 2015-04-07 17:49:49 +0200 | [diff] [blame] | 487 | |
| 488 | self.vty.verify('subscriber imsi '+wrong_imsi+' name wrong', ['% No subscriber found for imsi '+wrong_imsi]) |
| 489 | res = self.vty.command('subscriber imsi '+imsi+' name '+('X' * 160)) |
| 490 | self.assert_(res.find("NAME is too long") > 0) |
| 491 | |
| 492 | self.vty.verify('subscriber imsi '+imsi+' name '+('G' * 159), ['']) |
| 493 | |
| 494 | self.vty.verify('subscriber imsi '+wrong_imsi+' extension 840', ['% No subscriber found for imsi '+wrong_imsi]) |
| 495 | res = self.vty.command('subscriber imsi '+imsi+' extension '+('9' * 15)) |
| 496 | self.assert_(res.find("EXTENSION is too long") > 0) |
| 497 | |
| 498 | self.vty.verify('subscriber imsi '+imsi+' extension '+('1' * 14), ['']) |
| 499 | |
Max | 0fcd2e2 | 2016-06-07 15:32:16 +0200 | [diff] [blame] | 500 | # With narrow random interval |
| 501 | self.vty.command("configure terminal") |
| 502 | self.vty.command("nitb") |
| 503 | self.assertTrue(self.vty.verify("subscriber-create-on-demand", [''])) |
| 504 | # wrong interval |
| 505 | res = self.vty.command("subscriber-create-on-demand random 221 122") |
| 506 | self.assert_(res.find("122") > 0) |
| 507 | self.assert_(res.find("221") > 0) |
| 508 | # correct interval |
| 509 | self.assertTrue(self.vty.verify("subscriber-create-on-demand random 221 222", [''])) |
| 510 | self.vty.command("end") |
| 511 | |
Max | 488902d | 2016-06-22 14:02:39 +0200 | [diff] [blame] | 512 | # create subscriber with extension in a configured interval |
Max | 0fcd2e2 | 2016-06-07 15:32:16 +0200 | [diff] [blame] | 513 | res = self.vty.command('subscriber create imsi ' + imsi2) |
| 514 | self.assert_(res.find(" IMSI: " + imsi2) > 0) |
| 515 | self.assert_(res.find("221") > 0 or res.find("222") > 0) |
| 516 | self.assert_(res.find(" Extension: ") > 0) |
| 517 | |
Jacob Erlbeck | 322b149 | 2015-04-07 17:49:49 +0200 | [diff] [blame] | 518 | # Delete it |
Max | 488902d | 2016-06-22 14:02:39 +0200 | [diff] [blame] | 519 | res = self.vty.command('subscriber imsi ' + imsi + ' delete') |
Jacob Erlbeck | 322b149 | 2015-04-07 17:49:49 +0200 | [diff] [blame] | 520 | self.assert_(res != "") |
Max | 488902d | 2016-06-22 14:02:39 +0200 | [diff] [blame] | 521 | # imsi2 is inactive so deletion should succeed |
| 522 | res = self.vty.command('subscriber imsi ' + imsi2 + ' delete') |
| 523 | self.assert_("" == res) |
Jacob Erlbeck | 322b149 | 2015-04-07 17:49:49 +0200 | [diff] [blame] | 524 | |
Holger Hans Peter Freyther | ec37bb2 | 2013-02-05 09:39:09 +0100 | [diff] [blame] | 525 | def testShowPagingGroup(self): |
| 526 | res = self.vty.command("show paging-group 255 1234567") |
| 527 | self.assertEqual(res, "% can't find BTS 255") |
| 528 | res = self.vty.command("show paging-group 0 1234567") |
| 529 | self.assertEquals(res, "%Paging group for IMSI 1234567 on BTS #0 is 7") |
| 530 | |
Ciaby | ec6e4f8 | 2014-03-06 17:20:55 +0100 | [diff] [blame] | 531 | def testShowNetwork(self): |
| 532 | res = self.vty.command("show network") |
| 533 | self.assert_(res.startswith('BSC is on Country Code') >= 0) |
| 534 | |
Holger Hans Peter Freyther | 8657326 | 2015-01-31 09:47:37 +0100 | [diff] [blame] | 535 | def testMeasurementFeed(self): |
| 536 | self.vty.enable() |
| 537 | self.vty.command("configure terminal") |
| 538 | self.vty.command("mncc-int") |
| 539 | |
| 540 | res = self.vty.command("write terminal") |
| 541 | self.assertEquals(res.find('meas-feed scenario'), -1) |
| 542 | |
| 543 | self.vty.command("meas-feed scenario bla") |
| 544 | res = self.vty.command("write terminal") |
| 545 | self.assert_(res.find('meas-feed scenario bla') > 0) |
| 546 | |
Neels Hofmeyr | 0867b72 | 2016-09-28 23:28:06 +0200 | [diff] [blame] | 547 | self.vty.command("meas-feed scenario abcdefghijklmnopqrstuvwxyz01234567890") |
Holger Hans Peter Freyther | 8657326 | 2015-01-31 09:47:37 +0100 | [diff] [blame] | 548 | res = self.vty.command("write terminal") |
| 549 | self.assertEquals(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz01234567890'), -1) |
| 550 | self.assertEquals(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz012345'), -1) |
| 551 | self.assert_(res.find('meas-feed scenario abcdefghijklmnopqrstuvwxyz01234') > 0) |
| 552 | |
| 553 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 554 | class TestVTYBSC(TestVTYGenericBSC): |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 555 | |
| 556 | def vty_command(self): |
| 557 | return ["./src/osmo-bsc/osmo-bsc", "-c", |
| 558 | "doc/examples/osmo-bsc/osmo-bsc.cfg"] |
| 559 | |
| 560 | def vty_app(self): |
| 561 | return (4242, "./src/osmo-bsc/osmo-bsc", "OsmoBSC", "bsc") |
| 562 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 563 | def testConfigNetworkTree(self): |
Jacob Erlbeck | 7587727 | 2013-10-23 11:24:14 +0200 | [diff] [blame] | 564 | self._testConfigNetworkTree() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 565 | |
| 566 | def testVtyTree(self): |
| 567 | self.vty.enable() |
| 568 | self.assertTrue(self.vty.verify("configure terminal", [''])) |
| 569 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 6e919db | 2013-10-29 09:30:31 +0100 | [diff] [blame] | 570 | self.checkForEndAndExit() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 571 | self.assertTrue(self.vty.verify("msc 0", [''])) |
| 572 | self.assertEquals(self.vty.node(), 'config-msc') |
Jacob Erlbeck | 0ae92a9 | 2013-09-02 13:17:16 +0200 | [diff] [blame] | 573 | self.checkForEndAndExit() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 574 | self.assertTrue(self.vty.verify("exit", [''])) |
Jacob Erlbeck | 0ae92a9 | 2013-09-02 13:17:16 +0200 | [diff] [blame] | 575 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 576 | self.assertTrue(self.vty.verify("bsc", [''])) |
| 577 | self.assertEquals(self.vty.node(), 'config-bsc') |
Jacob Erlbeck | 0ae92a9 | 2013-09-02 13:17:16 +0200 | [diff] [blame] | 578 | self.checkForEndAndExit() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 579 | self.assertTrue(self.vty.verify("exit", [''])) |
Jacob Erlbeck | 0ae92a9 | 2013-09-02 13:17:16 +0200 | [diff] [blame] | 580 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 581 | self.assertTrue(self.vty.verify("exit", [''])) |
| 582 | self.assertTrue(self.vty.node() is None) |
| 583 | |
| 584 | # Check searching for outer node's commands |
| 585 | self.vty.command("configure terminal") |
| 586 | self.vty.command('msc 0') |
| 587 | self.vty.command("bsc") |
| 588 | self.assertEquals(self.vty.node(), 'config-bsc') |
| 589 | self.vty.command("msc 0") |
| 590 | self.assertEquals(self.vty.node(), 'config-msc') |
| 591 | |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 592 | def testUssdNotificationsMsc(self): |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 593 | self.vty.enable() |
| 594 | self.vty.command("configure terminal") |
| 595 | self.vty.command("msc") |
| 596 | |
| 597 | # Test invalid input |
| 598 | self.vty.verify("bsc-msc-lost-text", ['% Command incomplete.']) |
Jacob Erlbeck | 97e139f | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 599 | self.vty.verify("bsc-welcome-text", ['% Command incomplete.']) |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 600 | self.vty.verify("bsc-grace-text", ['% Command incomplete.']) |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 601 | |
| 602 | # Enable USSD notifications |
| 603 | self.vty.verify("bsc-msc-lost-text MSC disconnected", ['']) |
Jacob Erlbeck | 97e139f | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 604 | self.vty.verify("bsc-welcome-text Hello MS", ['']) |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 605 | self.vty.verify("bsc-grace-text In grace period", ['']) |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 606 | |
| 607 | # Verify settings |
| 608 | res = self.vty.command("write terminal") |
| 609 | self.assert_(res.find('bsc-msc-lost-text MSC disconnected') > 0) |
| 610 | self.assertEquals(res.find('no bsc-msc-lost-text'), -1) |
Jacob Erlbeck | 97e139f | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 611 | self.assert_(res.find('bsc-welcome-text Hello MS') > 0) |
| 612 | self.assertEquals(res.find('no bsc-welcome-text'), -1) |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 613 | self.assert_(res.find('bsc-grace-text In grace period') > 0) |
| 614 | self.assertEquals(res.find('no bsc-grace-text'), -1) |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 615 | |
| 616 | # Now disable it.. |
| 617 | self.vty.verify("no bsc-msc-lost-text", ['']) |
Jacob Erlbeck | 97e139f | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 618 | self.vty.verify("no bsc-welcome-text", ['']) |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 619 | self.vty.verify("no bsc-grace-text", ['']) |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 620 | |
| 621 | # Verify settings |
| 622 | res = self.vty.command("write terminal") |
| 623 | self.assertEquals(res.find('bsc-msc-lost-text MSC disconnected'), -1) |
| 624 | self.assert_(res.find('no bsc-msc-lost-text') > 0) |
Jacob Erlbeck | 97e139f | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 625 | self.assertEquals(res.find('bsc-welcome-text Hello MS'), -1) |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 626 | self.assert_(res.find('no bsc-welcome-text') > 0) |
| 627 | self.assertEquals(res.find('bsc-grace-text In grace period'), -1) |
| 628 | self.assert_(res.find('no bsc-grace-text') > 0) |
| 629 | |
| 630 | def testUssdNotificationsBsc(self): |
| 631 | self.vty.enable() |
| 632 | self.vty.command("configure terminal") |
| 633 | self.vty.command("bsc") |
| 634 | |
| 635 | # Test invalid input |
| 636 | self.vty.verify("missing-msc-text", ['% Command incomplete.']) |
| 637 | |
| 638 | # Enable USSD notifications |
| 639 | self.vty.verify("missing-msc-text No MSC found", ['']) |
| 640 | |
| 641 | # Verify settings |
| 642 | res = self.vty.command("write terminal") |
| 643 | self.assert_(res.find('missing-msc-text No MSC found') > 0) |
| 644 | self.assertEquals(res.find('no missing-msc-text'), -1) |
| 645 | |
| 646 | # Now disable it.. |
| 647 | self.vty.verify("no missing-msc-text", ['']) |
| 648 | |
| 649 | # Verify settings |
| 650 | res = self.vty.command("write terminal") |
| 651 | self.assertEquals(res.find('missing-msc-text No MSC found'), -1) |
| 652 | self.assert_(res.find('no missing-msc-text') > 0) |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 653 | |
Jacob Erlbeck | 946d141 | 2013-09-17 13:59:29 +0200 | [diff] [blame] | 654 | def testNetworkTimezone(self): |
| 655 | self.vty.enable() |
| 656 | self.vty.verify("configure terminal", ['']) |
| 657 | self.vty.verify("network", ['']) |
Jacob Erlbeck | 946d141 | 2013-09-17 13:59:29 +0200 | [diff] [blame] | 658 | |
| 659 | # Test invalid input |
| 660 | self.vty.verify("timezone", ['% Command incomplete.']) |
| 661 | self.vty.verify("timezone 20 0", ['% Unknown command.']) |
| 662 | self.vty.verify("timezone 0 11", ['% Unknown command.']) |
| 663 | self.vty.verify("timezone 0 0 99", ['% Unknown command.']) |
| 664 | |
| 665 | # Set time zone without DST |
| 666 | self.vty.verify("timezone 2 30", ['']) |
| 667 | |
| 668 | # Verify settings |
| 669 | res = self.vty.command("write terminal") |
| 670 | self.assert_(res.find('timezone 2 30') > 0) |
| 671 | self.assertEquals(res.find('timezone 2 30 '), -1) |
| 672 | |
| 673 | # Set time zone with DST |
| 674 | self.vty.verify("timezone 2 30 1", ['']) |
| 675 | |
| 676 | # Verify settings |
| 677 | res = self.vty.command("write terminal") |
| 678 | self.assert_(res.find('timezone 2 30 1') > 0) |
| 679 | |
| 680 | # Now disable it.. |
| 681 | self.vty.verify("no timezone", ['']) |
| 682 | |
| 683 | # Verify settings |
| 684 | res = self.vty.command("write terminal") |
| 685 | self.assertEquals(res.find(' timezone'), -1) |
| 686 | |
Ciaby | ec6e4f8 | 2014-03-06 17:20:55 +0100 | [diff] [blame] | 687 | def testShowNetwork(self): |
| 688 | res = self.vty.command("show network") |
| 689 | self.assert_(res.startswith('BSC is on Country Code') >= 0) |
| 690 | |
Holger Hans Peter Freyther | db64f2e | 2014-10-29 10:06:15 +0100 | [diff] [blame] | 691 | def testPingPongConfiguration(self): |
| 692 | self.vty.enable() |
| 693 | self.vty.verify("configure terminal", ['']) |
| 694 | self.vty.verify("network", ['']) |
| 695 | self.vty.verify("msc 0", ['']) |
| 696 | |
| 697 | self.vty.verify("timeout-ping 12", ['']) |
| 698 | self.vty.verify("timeout-pong 14", ['']) |
| 699 | res = self.vty.command("show running-config") |
| 700 | self.assert_(res.find(" timeout-ping 12") > 0) |
| 701 | self.assert_(res.find(" timeout-pong 14") > 0) |
| 702 | self.assert_(res.find(" no timeout-ping advanced") > 0) |
| 703 | |
| 704 | self.vty.verify("timeout-ping advanced", ['']) |
| 705 | res = self.vty.command("show running-config") |
| 706 | self.assert_(res.find(" timeout-ping 12") > 0) |
| 707 | self.assert_(res.find(" timeout-pong 14") > 0) |
| 708 | self.assert_(res.find(" timeout-ping advanced") > 0) |
| 709 | |
| 710 | self.vty.verify("no timeout-ping advanced", ['']) |
| 711 | res = self.vty.command("show running-config") |
| 712 | self.assert_(res.find(" timeout-ping 12") > 0) |
| 713 | self.assert_(res.find(" timeout-pong 14") > 0) |
| 714 | self.assert_(res.find(" no timeout-ping advanced") > 0) |
| 715 | |
| 716 | self.vty.verify("no timeout-ping", ['']) |
| 717 | res = self.vty.command("show running-config") |
| 718 | self.assertEquals(res.find(" timeout-ping 12"), -1) |
| 719 | self.assertEquals(res.find(" timeout-pong 14"), -1) |
| 720 | self.assertEquals(res.find(" no timeout-ping advanced"), -1) |
| 721 | self.assert_(res.find(" no timeout-ping") > 0) |
| 722 | |
| 723 | self.vty.verify("timeout-ping advanced", ['%ping handling is disabled. Enable it first.']) |
| 724 | |
| 725 | # And back to enabling it |
| 726 | self.vty.verify("timeout-ping 12", ['']) |
| 727 | self.vty.verify("timeout-pong 14", ['']) |
| 728 | res = self.vty.command("show running-config") |
| 729 | self.assert_(res.find(" timeout-ping 12") > 0) |
| 730 | self.assert_(res.find(" timeout-pong 14") > 0) |
| 731 | self.assert_(res.find(" timeout-ping advanced") > 0) |
| 732 | |
Holger Hans Peter Freyther | 32dd2f3 | 2015-04-01 18:15:48 +0200 | [diff] [blame] | 733 | def testMscDataCoreLACCI(self): |
| 734 | self.vty.enable() |
| 735 | res = self.vty.command("show running-config") |
| 736 | self.assertEquals(res.find("core-location-area-code"), -1) |
| 737 | self.assertEquals(res.find("core-cell-identity"), -1) |
| 738 | |
Neels Hofmeyr | 0867b72 | 2016-09-28 23:28:06 +0200 | [diff] [blame] | 739 | self.vty.command("configure terminal") |
Holger Hans Peter Freyther | 32dd2f3 | 2015-04-01 18:15:48 +0200 | [diff] [blame] | 740 | self.vty.command("msc 0") |
| 741 | self.vty.command("core-location-area-code 666") |
| 742 | self.vty.command("core-cell-identity 333") |
| 743 | |
| 744 | res = self.vty.command("show running-config") |
| 745 | self.assert_(res.find("core-location-area-code 666") > 0) |
| 746 | self.assert_(res.find("core-cell-identity 333") > 0) |
| 747 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 748 | class TestVTYNAT(TestVTYGenericBSC): |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 749 | |
| 750 | def vty_command(self): |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 751 | return ["./src/osmo-bsc_nat/osmo-bsc_nat", "-l", "127.0.0.1", "-c", |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 752 | "doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg"] |
| 753 | |
| 754 | def vty_app(self): |
| 755 | return (4244, "src/osmo-bsc_nat/osmo-bsc_nat", "OsmoBSCNAT", "nat") |
| 756 | |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 757 | def testBSCreload(self): |
Holger Hans Peter Freyther | 44ed497 | 2016-04-14 10:05:13 -0400 | [diff] [blame] | 758 | # Use different port for the mock msc to avoid clashing with |
| 759 | # the osmo-bsc_nat itself |
Holger Hans Peter Freyther | f1a61bb | 2016-04-14 08:50:25 -0400 | [diff] [blame] | 760 | ip = "127.0.0.1" |
Holger Hans Peter Freyther | e98c9c7 | 2016-04-14 10:58:58 -0400 | [diff] [blame] | 761 | port = 5522 |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 762 | self.vty.enable() |
| 763 | bscs1 = self.vty.command("show bscs-config") |
| 764 | nat_bsc_reload(self) |
| 765 | bscs2 = self.vty.command("show bscs-config") |
| 766 | # check that multiple calls to bscs-config-file give the same result |
| 767 | self.assertEquals(bscs1, bscs2) |
| 768 | |
| 769 | # add new bsc |
| 770 | self.vty.command("configure terminal") |
| 771 | self.vty.command("nat") |
| 772 | self.vty.command("bsc 5") |
| 773 | self.vty.command("token key") |
| 774 | self.vty.command("location_area_code 666") |
| 775 | self.vty.command("end") |
| 776 | |
| 777 | # update bsc token |
| 778 | self.vty.command("configure terminal") |
| 779 | self.vty.command("nat") |
| 780 | self.vty.command("bsc 1") |
| 781 | self.vty.command("token xyu") |
| 782 | self.vty.command("end") |
| 783 | |
Holger Hans Peter Freyther | 44ed497 | 2016-04-14 10:05:13 -0400 | [diff] [blame] | 784 | nat_msc_ip(self, ip, port) |
Neels Hofmeyr | bcfee2a | 2017-02-03 16:09:17 +0100 | [diff] [blame] | 785 | msc = nat_msc_test(self, ip, port, verbose=True) |
| 786 | b0 = nat_bsc_sock_test(0, "lol", verbose=True, proc=self.proc) |
| 787 | b1 = nat_bsc_sock_test(1, "xyu", verbose=True, proc=self.proc) |
| 788 | b2 = nat_bsc_sock_test(5, "key", verbose=True, proc=self.proc) |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 789 | |
| 790 | self.assertEquals("3 BSCs configured", self.vty.command("show nat num-bscs-configured")) |
| 791 | self.assertTrue(3 == nat_bsc_num_con(self)) |
| 792 | self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection")) |
| 793 | |
| 794 | nat_bsc_reload(self) |
| 795 | bscs2 = self.vty.command("show bscs-config") |
| 796 | # check that the reset to initial config succeeded |
| 797 | self.assertEquals(bscs1, bscs2) |
| 798 | |
| 799 | self.assertEquals("2 BSCs configured", self.vty.command("show nat num-bscs-configured")) |
| 800 | self.assertTrue(1 == nat_bsc_num_con(self)) |
| 801 | rem = self.vty.command("show bsc connections").split(' ') |
| 802 | # remaining connection is for BSC0 |
| 803 | self.assertEquals('0', rem[2]) |
| 804 | # remaining connection is authorized |
| 805 | self.assertEquals('1', rem[4]) |
| 806 | self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection")) |
| 807 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 808 | def testVtyTree(self): |
| 809 | self.vty.enable() |
| 810 | self.assertTrue(self.vty.verify('configure terminal', [''])) |
| 811 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 6e919db | 2013-10-29 09:30:31 +0100 | [diff] [blame] | 812 | self.checkForEndAndExit() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 813 | self.assertTrue(self.vty.verify('mgcp', [''])) |
| 814 | self.assertEquals(self.vty.node(), 'config-mgcp') |
| 815 | self.checkForEndAndExit() |
| 816 | self.assertTrue(self.vty.verify('exit', [''])) |
| 817 | self.assertEquals(self.vty.node(), 'config') |
| 818 | self.assertTrue(self.vty.verify('nat', [''])) |
| 819 | self.assertEquals(self.vty.node(), 'config-nat') |
| 820 | self.checkForEndAndExit() |
| 821 | self.assertTrue(self.vty.verify('bsc 0', [''])) |
| 822 | self.assertEquals(self.vty.node(), 'config-nat-bsc') |
| 823 | self.checkForEndAndExit() |
| 824 | self.assertTrue(self.vty.verify('exit', [''])) |
| 825 | self.assertEquals(self.vty.node(), 'config-nat') |
| 826 | self.assertTrue(self.vty.verify('exit', [''])) |
| 827 | self.assertEquals(self.vty.node(), 'config') |
| 828 | self.assertTrue(self.vty.verify('exit', [''])) |
| 829 | self.assertTrue(self.vty.node() is None) |
| 830 | |
| 831 | # Check searching for outer node's commands |
| 832 | self.vty.command('configure terminal') |
| 833 | self.vty.command('mgcp') |
| 834 | self.vty.command('nat') |
| 835 | self.assertEquals(self.vty.node(), 'config-nat') |
Jacob Erlbeck | 4c9dff5 | 2013-09-02 13:17:17 +0200 | [diff] [blame] | 836 | self.vty.command('mgcp') |
| 837 | self.assertEquals(self.vty.node(), 'config-mgcp') |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 838 | self.vty.command('nat') |
| 839 | self.assertEquals(self.vty.node(), 'config-nat') |
| 840 | self.vty.command('bsc 0') |
Jacob Erlbeck | 4c9dff5 | 2013-09-02 13:17:17 +0200 | [diff] [blame] | 841 | self.vty.command('mgcp') |
| 842 | self.assertEquals(self.vty.node(), 'config-mgcp') |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 843 | |
Holger Hans Peter Freyther | b718ad3 | 2013-06-25 09:08:02 +0200 | [diff] [blame] | 844 | def testRewriteNoRewrite(self): |
| 845 | self.vty.enable() |
| 846 | res = self.vty.command("configure terminal") |
| 847 | res = self.vty.command("nat") |
| 848 | res = self.vty.command("number-rewrite rewrite.cfg") |
| 849 | res = self.vty.command("no number-rewrite") |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 850 | |
Holger Hans Peter Freyther | 7f100c9 | 2015-04-23 20:25:17 -0400 | [diff] [blame] | 851 | def testEnsureNoEnsureModeSet(self): |
| 852 | self.vty.enable() |
| 853 | res = self.vty.command("configure terminal") |
| 854 | res = self.vty.command("nat") |
| 855 | |
| 856 | # Ensure the default |
| 857 | res = self.vty.command("show running-config") |
| 858 | self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0) |
| 859 | |
| 860 | self.vty.command("sdp-ensure-amr-mode-set") |
| 861 | res = self.vty.command("show running-config") |
| 862 | self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0) |
| 863 | |
| 864 | self.vty.command("no sdp-ensure-amr-mode-set") |
| 865 | res = self.vty.command("show running-config") |
| 866 | self.assert_(res.find('\n no sdp-ensure-amr-mode-set') > 0) |
| 867 | |
Holger Hans Peter Freyther | 67e423c | 2013-06-25 15:38:31 +0200 | [diff] [blame] | 868 | def testRewritePostNoRewrite(self): |
| 869 | self.vty.enable() |
| 870 | self.vty.command("configure terminal") |
| 871 | self.vty.command("nat") |
| 872 | self.vty.verify("number-rewrite-post rewrite.cfg", ['']) |
| 873 | self.vty.verify("no number-rewrite-post", ['']) |
| 874 | |
| 875 | |
Holger Hans Peter Freyther | ddf191e | 2013-06-25 11:44:01 +0200 | [diff] [blame] | 876 | def testPrefixTreeLoading(self): |
| 877 | cfg = os.path.join(confpath, "tests/bsc-nat-trie/prefixes.csv") |
| 878 | |
| 879 | self.vty.enable() |
| 880 | self.vty.command("configure terminal") |
| 881 | self.vty.command("nat") |
| 882 | res = self.vty.command("prefix-tree %s" % cfg) |
| 883 | self.assertEqual(res, "% prefix-tree loaded 17 rules.") |
| 884 | self.vty.command("end") |
| 885 | |
| 886 | res = self.vty.command("show prefix-tree") |
| 887 | 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') |
| 888 | |
| 889 | self.vty.command("configure terminal") |
| 890 | self.vty.command("nat") |
| 891 | self.vty.command("no prefix-tree") |
| 892 | self.vty.command("end") |
| 893 | |
| 894 | res = self.vty.command("show prefix-tree") |
| 895 | self.assertEqual(res, "% there is now prefix tree loaded.") |
| 896 | |
Jacob Erlbeck | 6cb2ccc | 2013-08-14 11:10:34 +0200 | [diff] [blame] | 897 | def testUssdSideChannelProvider(self): |
| 898 | self.vty.command("end") |
| 899 | self.vty.enable() |
| 900 | self.vty.command("configure terminal") |
| 901 | self.vty.command("nat") |
| 902 | self.vty.command("ussd-token key") |
| 903 | self.vty.command("end") |
| 904 | |
| 905 | res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.']) |
| 906 | self.assertTrue(res) |
| 907 | |
| 908 | ussdSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 909 | ussdSocket.connect(('127.0.0.1', 5001)) |
| 910 | ussdSocket.settimeout(2.0) |
| 911 | print "Connected to %s:%d" % ussdSocket.getpeername() |
| 912 | |
| 913 | print "Expecting ID_GET request" |
| 914 | data = ussdSocket.recv(4) |
| 915 | self.assertEqual(data, "\x00\x01\xfe\x04") |
| 916 | |
| 917 | print "Going to send ID_RESP response" |
Max | 3e67689 | 2016-11-16 14:55:21 +0100 | [diff] [blame] | 918 | res = ussdSocket.send(IPA().id_resp(IPA().tag_name('key'))) |
Jacob Erlbeck | 6cb2ccc | 2013-08-14 11:10:34 +0200 | [diff] [blame] | 919 | self.assertEqual(res, 10) |
| 920 | |
| 921 | # initiating PING/PONG cycle to know, that the ID_RESP message has been processed |
| 922 | |
| 923 | print "Going to send PING request" |
Max | 3e67689 | 2016-11-16 14:55:21 +0100 | [diff] [blame] | 924 | res = ussdSocket.send(IPA().ping()) |
Jacob Erlbeck | 6cb2ccc | 2013-08-14 11:10:34 +0200 | [diff] [blame] | 925 | self.assertEqual(res, 4) |
| 926 | |
| 927 | print "Expecting PONG response" |
| 928 | data = ussdSocket.recv(4) |
| 929 | self.assertEqual(data, "\x00\x01\xfe\x01") |
| 930 | |
| 931 | res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is connected and authorized.']) |
| 932 | self.assertTrue(res) |
| 933 | |
| 934 | print "Going to shut down connection" |
| 935 | ussdSocket.shutdown(socket.SHUT_WR) |
| 936 | |
| 937 | print "Expecting EOF" |
| 938 | data = ussdSocket.recv(4) |
| 939 | self.assertEqual(data, "") |
| 940 | |
| 941 | ussdSocket.close() |
| 942 | |
| 943 | res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.']) |
| 944 | self.assertTrue(res) |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 945 | |
Holger Hans Peter Freyther | 6419018 | 2014-01-20 10:14:05 +0100 | [diff] [blame] | 946 | def testAccessList(self): |
| 947 | """ |
| 948 | Verify that the imsi-deny can have a reject cause or no reject cause |
| 949 | """ |
| 950 | self.vty.enable() |
| 951 | self.vty.command("configure terminal") |
| 952 | self.vty.command("nat") |
| 953 | |
| 954 | # Old default |
| 955 | self.vty.command("access-list test-default imsi-deny ^123[0-9]*$") |
| 956 | res = self.vty.command("show running-config").split("\r\n") |
| 957 | asserted = False |
| 958 | for line in res: |
Holger Hans Peter Freyther | 4ecc687 | 2014-03-04 15:38:00 +0100 | [diff] [blame] | 959 | if line.startswith(" access-list test-default"): |
Holger Hans Peter Freyther | 6419018 | 2014-01-20 10:14:05 +0100 | [diff] [blame] | 960 | self.assertEqual(line, " access-list test-default imsi-deny ^123[0-9]*$ 11 11") |
| 961 | asserted = True |
| 962 | self.assert_(asserted) |
| 963 | |
| 964 | # Check the optional CM Service Reject Cause |
| 965 | self.vty.command("access-list test-cm-deny imsi-deny ^123[0-9]*$ 42").split("\r\n") |
| 966 | res = self.vty.command("show running-config").split("\r\n") |
| 967 | asserted = False |
| 968 | for line in res: |
| 969 | if line.startswith(" access-list test-cm"): |
| 970 | self.assertEqual(line, " access-list test-cm-deny imsi-deny ^123[0-9]*$ 42 11") |
| 971 | asserted = True |
| 972 | self.assert_(asserted) |
| 973 | |
| 974 | # Check the optional LU Reject Cause |
| 975 | self.vty.command("access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42").split("\r\n") |
| 976 | res = self.vty.command("show running-config").split("\r\n") |
| 977 | asserted = False |
| 978 | for line in res: |
| 979 | if line.startswith(" access-list test-lu"): |
| 980 | self.assertEqual(line, " access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42") |
| 981 | asserted = True |
| 982 | self.assert_(asserted) |
| 983 | |
Jacob Erlbeck | 6d23371 | 2013-10-23 11:24:15 +0200 | [diff] [blame] | 984 | class TestVTYGbproxy(TestVTYGenericBSC): |
| 985 | |
| 986 | def vty_command(self): |
| 987 | return ["./src/gprs/osmo-gbproxy", "-c", |
| 988 | "doc/examples/osmo-gbproxy/osmo-gbproxy.cfg"] |
| 989 | |
| 990 | def vty_app(self): |
| 991 | return (4246, "./src/gprs/osmo-gbproxy", "OsmoGbProxy", "bsc") |
| 992 | |
| 993 | def testVtyTree(self): |
| 994 | self.vty.enable() |
| 995 | self.assertTrue(self.vty.verify('configure terminal', [''])) |
| 996 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 6e919db | 2013-10-29 09:30:31 +0100 | [diff] [blame] | 997 | self.checkForEndAndExit() |
Jacob Erlbeck | 6d23371 | 2013-10-23 11:24:15 +0200 | [diff] [blame] | 998 | self.assertTrue(self.vty.verify('ns', [''])) |
| 999 | self.assertEquals(self.vty.node(), 'config-ns') |
| 1000 | self.checkForEndAndExit() |
| 1001 | self.assertTrue(self.vty.verify('exit', [''])) |
| 1002 | self.assertEquals(self.vty.node(), 'config') |
| 1003 | self.assertTrue(self.vty.verify('gbproxy', [''])) |
| 1004 | self.assertEquals(self.vty.node(), 'config-gbproxy') |
| 1005 | self.checkForEndAndExit() |
| 1006 | self.assertTrue(self.vty.verify('exit', [''])) |
| 1007 | self.assertEquals(self.vty.node(), 'config') |
| 1008 | |
| 1009 | def testVtyShow(self): |
| 1010 | res = self.vty.command("show ns") |
| 1011 | self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0) |
| 1012 | |
| 1013 | res = self.vty.command("show gbproxy stats") |
| 1014 | self.assert_(res.find('GBProxy Global Statistics') >= 0) |
| 1015 | |
Jacob Erlbeck | 4211d79 | 2013-10-24 12:48:23 +0200 | [diff] [blame] | 1016 | def testVtyDeletePeer(self): |
| 1017 | self.vty.enable() |
| 1018 | self.assertTrue(self.vty.verify('delete-gbproxy-peer 9999 bvci 7777', ['BVC not found'])) |
| 1019 | res = self.vty.command("delete-gbproxy-peer 9999 all dry-run") |
| 1020 | self.assert_(res.find('Not Deleted 0 BVC') >= 0) |
| 1021 | self.assert_(res.find('Not Deleted 0 NS-VC') >= 0) |
| 1022 | res = self.vty.command("delete-gbproxy-peer 9999 only-bvc dry-run") |
| 1023 | self.assert_(res.find('Not Deleted 0 BVC') >= 0) |
| 1024 | self.assert_(res.find('Not Deleted 0 NS-VC') < 0) |
| 1025 | res = self.vty.command("delete-gbproxy-peer 9999 only-nsvc dry-run") |
| 1026 | self.assert_(res.find('Not Deleted 0 BVC') < 0) |
| 1027 | self.assert_(res.find('Not Deleted 0 NS-VC') >= 0) |
| 1028 | res = self.vty.command("delete-gbproxy-peer 9999 all") |
| 1029 | self.assert_(res.find('Deleted 0 BVC') >= 0) |
| 1030 | self.assert_(res.find('Deleted 0 NS-VC') >= 0) |
| 1031 | |
Jacob Erlbeck | 144b8b1 | 2014-11-04 11:15:01 +0100 | [diff] [blame] | 1032 | class TestVTYSGSN(TestVTYGenericBSC): |
| 1033 | |
| 1034 | def vty_command(self): |
| 1035 | return ["./src/gprs/osmo-sgsn", "-c", |
| 1036 | "doc/examples/osmo-sgsn/osmo-sgsn.cfg"] |
| 1037 | |
| 1038 | def vty_app(self): |
| 1039 | return (4245, "./src/gprs/osmo-sgsn", "OsmoSGSN", "sgsn") |
| 1040 | |
| 1041 | def testVtyTree(self): |
| 1042 | self.vty.enable() |
| 1043 | self.assertTrue(self.vty.verify('configure terminal', [''])) |
| 1044 | self.assertEquals(self.vty.node(), 'config') |
| 1045 | self.checkForEndAndExit() |
| 1046 | self.assertTrue(self.vty.verify('ns', [''])) |
| 1047 | self.assertEquals(self.vty.node(), 'config-ns') |
| 1048 | self.checkForEndAndExit() |
| 1049 | self.assertTrue(self.vty.verify('exit', [''])) |
| 1050 | self.assertEquals(self.vty.node(), 'config') |
| 1051 | self.assertTrue(self.vty.verify('sgsn', [''])) |
| 1052 | self.assertEquals(self.vty.node(), 'config-sgsn') |
| 1053 | self.checkForEndAndExit() |
| 1054 | self.assertTrue(self.vty.verify('exit', [''])) |
| 1055 | self.assertEquals(self.vty.node(), 'config') |
| 1056 | |
| 1057 | def testVtyShow(self): |
| 1058 | res = self.vty.command("show ns") |
| 1059 | self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0) |
| 1060 | self.assertTrue(self.vty.verify('show bssgp', [''])) |
| 1061 | self.assertTrue(self.vty.verify('show bssgp stats', [''])) |
| 1062 | # TODO: uncomment when the command does not segfault anymore |
| 1063 | # self.assertTrue(self.vty.verify('show bssgp nsei 123', [''])) |
| 1064 | # self.assertTrue(self.vty.verify('show bssgp nsei 123 stats', [''])) |
| 1065 | |
| 1066 | self.assertTrue(self.vty.verify('show sgsn', [''])) |
| 1067 | self.assertTrue(self.vty.verify('show mm-context all', [''])) |
| 1068 | self.assertTrue(self.vty.verify('show mm-context imsi 000001234567', ['No MM context for IMSI 000001234567'])) |
| 1069 | self.assertTrue(self.vty.verify('show pdp-context all', [''])) |
| 1070 | |
| 1071 | res = self.vty.command("show sndcp") |
| 1072 | self.assert_(res.find('State of SNDCP Entities') >= 0) |
| 1073 | |
| 1074 | res = self.vty.command("show llc") |
| 1075 | self.assert_(res.find('State of LLC Entities') >= 0) |
| 1076 | |
Jacob Erlbeck | 106f547 | 2014-11-04 10:08:37 +0100 | [diff] [blame] | 1077 | def testVtyAuth(self): |
| 1078 | self.vty.enable() |
| 1079 | self.assertTrue(self.vty.verify('configure terminal', [''])) |
| 1080 | self.assertEquals(self.vty.node(), 'config') |
| 1081 | self.assertTrue(self.vty.verify('sgsn', [''])) |
| 1082 | self.assertEquals(self.vty.node(), 'config-sgsn') |
| 1083 | self.assertTrue(self.vty.verify('auth-policy accept-all', [''])) |
| 1084 | res = self.vty.command("show running-config") |
| 1085 | self.assert_(res.find('auth-policy accept-all') > 0) |
| 1086 | self.assertTrue(self.vty.verify('auth-policy acl-only', [''])) |
| 1087 | res = self.vty.command("show running-config") |
| 1088 | self.assert_(res.find('auth-policy acl-only') > 0) |
| 1089 | self.assertTrue(self.vty.verify('auth-policy closed', [''])) |
| 1090 | res = self.vty.command("show running-config") |
| 1091 | self.assert_(res.find('auth-policy closed') > 0) |
Max | 176b62a | 2016-07-04 11:09:07 +0200 | [diff] [blame] | 1092 | self.assertTrue(self.vty.verify('gsup remote-ip 127.0.0.4', [''])) |
| 1093 | self.assertTrue(self.vty.verify('gsup remote-port 2222', [''])) |
Jacob Erlbeck | be2c8d9 | 2014-11-12 10:18:09 +0100 | [diff] [blame] | 1094 | self.assertTrue(self.vty.verify('auth-policy remote', [''])) |
| 1095 | res = self.vty.command("show running-config") |
| 1096 | self.assert_(res.find('auth-policy remote') > 0) |
Jacob Erlbeck | 106f547 | 2014-11-04 10:08:37 +0100 | [diff] [blame] | 1097 | |
Jacob Erlbeck | 207f4a5 | 2014-11-11 14:01:48 +0100 | [diff] [blame] | 1098 | def testVtySubscriber(self): |
| 1099 | self.vty.enable() |
| 1100 | res = self.vty.command('show subscriber cache') |
| 1101 | self.assert_(res.find('1234567890') < 0) |
Jacob Erlbeck | d919343 | 2015-01-19 14:11:46 +0100 | [diff] [blame] | 1102 | self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 create', [''])) |
| 1103 | res = self.vty.command('show subscriber cache') |
| 1104 | self.assert_(res.find('1234567890') >= 0) |
| 1105 | self.assert_(res.find('Authorized: 0') >= 0) |
| 1106 | self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 update-location-result ok', [''])) |
Jacob Erlbeck | 207f4a5 | 2014-11-11 14:01:48 +0100 | [diff] [blame] | 1107 | res = self.vty.command('show subscriber cache') |
| 1108 | self.assert_(res.find('1234567890') >= 0) |
| 1109 | self.assert_(res.find('Authorized: 1') >= 0) |
Jacob Erlbeck | 8000e0e | 2015-01-27 14:56:40 +0100 | [diff] [blame] | 1110 | self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 cancel update-procedure', [''])) |
Jacob Erlbeck | 207f4a5 | 2014-11-11 14:01:48 +0100 | [diff] [blame] | 1111 | res = self.vty.command('show subscriber cache') |
Jacob Erlbeck | e988ae4 | 2015-01-27 12:41:19 +0100 | [diff] [blame] | 1112 | self.assert_(res.find('1234567890') >= 0) |
| 1113 | self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 destroy', [''])) |
| 1114 | res = self.vty.command('show subscriber cache') |
Jacob Erlbeck | 207f4a5 | 2014-11-11 14:01:48 +0100 | [diff] [blame] | 1115 | self.assert_(res.find('1234567890') < 0) |
| 1116 | |
Jacob Erlbeck | cb1db8b | 2015-02-03 13:47:53 +0100 | [diff] [blame] | 1117 | def testVtyGgsn(self): |
| 1118 | self.vty.enable() |
| 1119 | self.assertTrue(self.vty.verify('configure terminal', [''])) |
| 1120 | self.assertEquals(self.vty.node(), 'config') |
| 1121 | self.assertTrue(self.vty.verify('sgsn', [''])) |
| 1122 | self.assertEquals(self.vty.node(), 'config-sgsn') |
| 1123 | self.assertTrue(self.vty.verify('ggsn 0 remote-ip 127.99.99.99', [''])) |
| 1124 | self.assertTrue(self.vty.verify('ggsn 0 gtp-version 1', [''])) |
| 1125 | self.assertTrue(self.vty.verify('apn * ggsn 0', [''])) |
| 1126 | self.assertTrue(self.vty.verify('apn apn1.test ggsn 0', [''])) |
| 1127 | self.assertTrue(self.vty.verify('apn apn1.test ggsn 1', ['% a GGSN with id 1 has not been defined'])) |
| 1128 | self.assertTrue(self.vty.verify('apn apn1.test imsi-prefix 123456 ggsn 0', [''])) |
| 1129 | self.assertTrue(self.vty.verify('apn apn2.test imsi-prefix 123456 ggsn 0', [''])) |
| 1130 | res = self.vty.command("show running-config") |
| 1131 | self.assert_(res.find('ggsn 0 remote-ip 127.99.99.99') >= 0) |
| 1132 | self.assert_(res.find('ggsn 0 gtp-version 1') >= 0) |
| 1133 | self.assert_(res.find('apn * ggsn 0') >= 0) |
| 1134 | self.assert_(res.find('apn apn1.test ggsn 0') >= 0) |
| 1135 | self.assert_(res.find('apn apn1.test imsi-prefix 123456 ggsn 0') >= 0) |
| 1136 | self.assert_(res.find('apn apn2.test imsi-prefix 123456 ggsn 0') >= 0) |
| 1137 | |
Holger Hans Peter Freyther | 9c20a5f | 2015-02-06 16:23:29 +0100 | [diff] [blame] | 1138 | def testVtyEasyAPN(self): |
| 1139 | self.vty.enable() |
| 1140 | self.assertTrue(self.vty.verify('configure terminal', [''])) |
| 1141 | self.assertEquals(self.vty.node(), 'config') |
| 1142 | self.assertTrue(self.vty.verify('sgsn', [''])) |
| 1143 | self.assertEquals(self.vty.node(), 'config-sgsn') |
| 1144 | |
| 1145 | res = self.vty.command("show running-config") |
| 1146 | self.assertEquals(res.find("apn internet"), -1) |
| 1147 | |
| 1148 | self.assertTrue(self.vty.verify("access-point-name internet.apn", [''])) |
| 1149 | res = self.vty.command("show running-config") |
| 1150 | self.assert_(res.find("apn internet.apn ggsn 0") >= 0) |
| 1151 | |
| 1152 | self.assertTrue(self.vty.verify("no access-point-name internet.apn", [''])) |
| 1153 | res = self.vty.command("show running-config") |
| 1154 | self.assertEquals(res.find("apn internet"), -1) |
| 1155 | |
Holger Hans Peter Freyther | c15c61c | 2015-05-06 17:46:08 +0200 | [diff] [blame] | 1156 | def testVtyCDR(self): |
| 1157 | self.vty.enable() |
| 1158 | self.assertTrue(self.vty.verify('configure terminal', [''])) |
| 1159 | self.assertEquals(self.vty.node(), 'config') |
| 1160 | self.assertTrue(self.vty.verify('sgsn', [''])) |
| 1161 | self.assertEquals(self.vty.node(), 'config-sgsn') |
| 1162 | |
| 1163 | res = self.vty.command("show running-config") |
| 1164 | self.assert_(res.find("no cdr filename") > 0) |
| 1165 | |
| 1166 | self.vty.command("cdr filename bla.cdr") |
| 1167 | res = self.vty.command("show running-config") |
| 1168 | self.assertEquals(res.find("no cdr filename"), -1) |
| 1169 | self.assert_(res.find(" cdr filename bla.cdr") > 0) |
| 1170 | |
| 1171 | self.vty.command("no cdr filename") |
| 1172 | res = self.vty.command("show running-config") |
| 1173 | self.assert_(res.find("no cdr filename") > 0) |
| 1174 | self.assertEquals(res.find(" cdr filename bla.cdr"), -1) |
| 1175 | |
| 1176 | res = self.vty.command("show running-config") |
| 1177 | self.assert_(res.find(" cdr interval 600") > 0) |
| 1178 | |
| 1179 | self.vty.command("cdr interval 900") |
| 1180 | res = self.vty.command("show running-config") |
| 1181 | self.assert_(res.find(" cdr interval 900") > 0) |
| 1182 | self.assertEquals(res.find(" cdr interval 600"), -1) |
| 1183 | |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 1184 | def add_nat_test(suite, workdir): |
| 1185 | if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")): |
| 1186 | print("Skipping the NAT test") |
| 1187 | return |
| 1188 | test = unittest.TestLoader().loadTestsFromTestCase(TestVTYNAT) |
| 1189 | suite.addTest(test) |
| 1190 | |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 1191 | def nat_bsc_reload(x): |
| 1192 | x.vty.command("configure terminal") |
| 1193 | x.vty.command("nat") |
| 1194 | x.vty.command("bscs-config-file bscs.config") |
| 1195 | x.vty.command("end") |
| 1196 | |
Holger Hans Peter Freyther | 44ed497 | 2016-04-14 10:05:13 -0400 | [diff] [blame] | 1197 | def nat_msc_ip(x, ip, port): |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 1198 | x.vty.command("configure terminal") |
| 1199 | x.vty.command("nat") |
| 1200 | x.vty.command("msc ip " + ip) |
Holger Hans Peter Freyther | 84ae27e | 2016-04-14 10:40:06 -0400 | [diff] [blame] | 1201 | x.vty.command("msc port " + str(port)) |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 1202 | x.vty.command("end") |
| 1203 | |
| 1204 | def data2str(d): |
Holger Hans Peter Freyther | 8bb6204 | 2016-04-14 21:40:04 -0400 | [diff] [blame] | 1205 | return d.encode('hex').lower() |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 1206 | |
Holger Hans Peter Freyther | 44ed497 | 2016-04-14 10:05:13 -0400 | [diff] [blame] | 1207 | def nat_msc_test(x, ip, port, verbose = False): |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 1208 | msc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
Neels Hofmeyr | caeb62d | 2016-09-28 23:38:45 +0200 | [diff] [blame] | 1209 | msc.settimeout(5) |
Holger Hans Peter Freyther | 44ed497 | 2016-04-14 10:05:13 -0400 | [diff] [blame] | 1210 | msc.bind((ip, port)) |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 1211 | msc.listen(5) |
| 1212 | if (verbose): |
| 1213 | print "MSC is ready at " + ip |
Neels Hofmeyr | 89d20b6 | 2016-09-26 12:59:36 +0200 | [diff] [blame] | 1214 | conn = None |
Neels Hofmeyr | caeb62d | 2016-09-28 23:38:45 +0200 | [diff] [blame] | 1215 | while True: |
| 1216 | vty_response = x.vty.command("show msc connection") |
| 1217 | print "'show msc connection' says: %r" % vty_response |
| 1218 | if vty_response == "MSC is connected: 1": |
| 1219 | # success |
| 1220 | break; |
| 1221 | if vty_response != "MSC is connected: 0": |
| 1222 | raise Exception("Unexpected response to 'show msc connection'" |
| 1223 | " vty command: %r" % vty_response) |
| 1224 | |
| 1225 | timeout_retries = 6 |
| 1226 | while timeout_retries > 0: |
| 1227 | try: |
| 1228 | conn, addr = msc.accept() |
| 1229 | print "MSC got connection from ", addr |
| 1230 | break |
| 1231 | except socket.timeout: |
| 1232 | print "socket timed out." |
| 1233 | timeout_retries -= 1 |
| 1234 | continue |
| 1235 | |
Neels Hofmeyr | 89d20b6 | 2016-09-26 12:59:36 +0200 | [diff] [blame] | 1236 | if not conn: |
Neels Hofmeyr | 0867b72 | 2016-09-28 23:28:06 +0200 | [diff] [blame] | 1237 | raise Exception("VTY reports MSC is connected, but I haven't" |
| 1238 | " connected yet: %r %r" % (ip, port)) |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 1239 | return conn |
| 1240 | |
Neels Hofmeyr | bcfee2a | 2017-02-03 16:09:17 +0100 | [diff] [blame] | 1241 | def cmd(what): |
| 1242 | print '\n> %s' % what |
| 1243 | sys.stdout.flush() |
| 1244 | subprocess.call(what, shell=True) |
| 1245 | sys.stdout.flush() |
| 1246 | sys.stderr.flush() |
| 1247 | print '' |
| 1248 | sys.stdout.flush() |
| 1249 | |
| 1250 | def checkxxx(): |
| 1251 | cmd('cat /proc/net/tcp'); |
| 1252 | cmd('ps xua | grep osmo'); |
| 1253 | |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 1254 | def ipa_handle_small(x, verbose = False): |
| 1255 | s = data2str(x.recv(4)) |
Neels Hofmeyr | ba1468e | 2017-02-03 04:23:46 +0100 | [diff] [blame] | 1256 | if len(s) != 4*2: |
| 1257 | raise Exception("expected to receive 4 bytes, but got %d (%r)" % (len(s)/2, s)) |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 1258 | if "0001fe00" == s: |
| 1259 | if (verbose): |
| 1260 | print "\tBSC <- NAT: PING?" |
Max | 3e67689 | 2016-11-16 14:55:21 +0100 | [diff] [blame] | 1261 | x.send(IPA().pong()) |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 1262 | elif "0001fe06" == s: |
| 1263 | if (verbose): |
| 1264 | print "\tBSC <- NAT: IPA ID ACK" |
Max | 3e67689 | 2016-11-16 14:55:21 +0100 | [diff] [blame] | 1265 | x.send(IPA().id_ack()) |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 1266 | elif "0001fe00" == s: |
| 1267 | if (verbose): |
| 1268 | print "\tBSC <- NAT: PONG!" |
| 1269 | else: |
| 1270 | if (verbose): |
| 1271 | print "\tBSC <- NAT: ", s |
| 1272 | |
Neels Hofmeyr | bcfee2a | 2017-02-03 16:09:17 +0100 | [diff] [blame] | 1273 | def ipa_handle_resp(x, tk, verbose = False, proc=None): |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 1274 | s = data2str(x.recv(38)) |
| 1275 | if "0023fe040108010701020103010401050101010011" in s: |
Neels Hofmeyr | 7d17c3e | 2017-01-26 23:04:28 +0100 | [diff] [blame] | 1276 | retries = 3 |
| 1277 | while True: |
Neels Hofmeyr | bcfee2a | 2017-02-03 16:09:17 +0100 | [diff] [blame] | 1278 | if proc: |
| 1279 | print "\tproc.poll() = %r" % proc.poll() |
| 1280 | print "\tproc.pid = %r" % proc.pid |
| 1281 | checkxxx() |
Neels Hofmeyr | 7d17c3e | 2017-01-26 23:04:28 +0100 | [diff] [blame] | 1282 | print "\tsending IPA identity(%s) at %s" % (tk, time.strftime("%T")) |
| 1283 | try: |
| 1284 | x.send(IPA().id_resp(IPA().identity(name = tk.encode('utf-8')))) |
| 1285 | print "\tdone sending IPA identity(%s) at %s" % (tk, |
| 1286 | time.strftime("%T")) |
| 1287 | break |
| 1288 | except: |
| 1289 | print "\tfailed sending IPA identity at", time.strftime("%T") |
Neels Hofmeyr | bcfee2a | 2017-02-03 16:09:17 +0100 | [diff] [blame] | 1290 | if proc: |
| 1291 | print "\tproc.poll() = %r" % proc.poll() |
Neels Hofmeyr | 7d17c3e | 2017-01-26 23:04:28 +0100 | [diff] [blame] | 1292 | if retries < 1: |
| 1293 | print "\tgiving up" |
| 1294 | raise |
Neels Hofmeyr | e02e1e7 | 2017-02-03 05:55:26 +0100 | [diff] [blame] | 1295 | print "\tretrying (%d attempts left)" % retries |
Neels Hofmeyr | 7d17c3e | 2017-01-26 23:04:28 +0100 | [diff] [blame] | 1296 | retries -= 1 |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 1297 | else: |
| 1298 | if (verbose): |
| 1299 | print "\tBSC <- NAT: ", s |
| 1300 | |
| 1301 | def nat_bsc_num_con(x): |
| 1302 | return len(x.vty.command("show bsc connections").split('\n')) |
| 1303 | |
Neels Hofmeyr | bcfee2a | 2017-02-03 16:09:17 +0100 | [diff] [blame] | 1304 | def nat_bsc_sock_test(nr, tk, verbose = False, proc=None): |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 1305 | bsc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
Holger Hans Peter Freyther | 2abf2b0 | 2016-04-14 21:13:51 -0400 | [diff] [blame] | 1306 | bsc.bind(('127.0.0.1', 0)) |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 1307 | bsc.connect(('127.0.0.1', 5000)) |
| 1308 | if (verbose): |
| 1309 | print "BSC%d " %nr |
| 1310 | print "\tconnected to %s:%d" % bsc.getpeername() |
Neels Hofmeyr | bcfee2a | 2017-02-03 16:09:17 +0100 | [diff] [blame] | 1311 | if proc: |
| 1312 | print "\tproc.poll() = %r" % proc.poll() |
| 1313 | print "\tproc.pid = %r" % proc.pid |
| 1314 | checkxxx() |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 1315 | ipa_handle_small(bsc, verbose) |
Neels Hofmeyr | bcfee2a | 2017-02-03 16:09:17 +0100 | [diff] [blame] | 1316 | checkxxx() |
| 1317 | ipa_handle_resp(bsc, tk, verbose, proc=proc) |
| 1318 | if proc: |
| 1319 | print "\tproc.poll() = %r" % proc.poll() |
| 1320 | checkxxx() |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 1321 | bsc.recv(27) # MGCP msg |
Neels Hofmeyr | bcfee2a | 2017-02-03 16:09:17 +0100 | [diff] [blame] | 1322 | if proc: |
| 1323 | print "\tproc.poll() = %r" % proc.poll() |
| 1324 | checkxxx() |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 1325 | ipa_handle_small(bsc, verbose) |
Neels Hofmeyr | bcfee2a | 2017-02-03 16:09:17 +0100 | [diff] [blame] | 1326 | checkxxx() |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 1327 | return bsc |
| 1328 | |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 1329 | def add_bsc_test(suite, workdir): |
| 1330 | if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")): |
| 1331 | print("Skipping the BSC test") |
| 1332 | return |
| 1333 | test = unittest.TestLoader().loadTestsFromTestCase(TestVTYBSC) |
| 1334 | suite.addTest(test) |
| 1335 | |
Jacob Erlbeck | 6d23371 | 2013-10-23 11:24:15 +0200 | [diff] [blame] | 1336 | def add_gbproxy_test(suite, workdir): |
| 1337 | if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-gbproxy")): |
| 1338 | print("Skipping the Gb-Proxy test") |
| 1339 | return |
| 1340 | test = unittest.TestLoader().loadTestsFromTestCase(TestVTYGbproxy) |
| 1341 | suite.addTest(test) |
| 1342 | |
Jacob Erlbeck | 144b8b1 | 2014-11-04 11:15:01 +0100 | [diff] [blame] | 1343 | def add_sgsn_test(suite, workdir): |
| 1344 | if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-sgsn")): |
| 1345 | print("Skipping the SGSN test") |
| 1346 | return |
| 1347 | test = unittest.TestLoader().loadTestsFromTestCase(TestVTYSGSN) |
| 1348 | suite.addTest(test) |
| 1349 | |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 1350 | if __name__ == '__main__': |
| 1351 | import argparse |
| 1352 | import sys |
| 1353 | |
| 1354 | workdir = '.' |
| 1355 | |
| 1356 | parser = argparse.ArgumentParser() |
| 1357 | parser.add_argument("-v", "--verbose", dest="verbose", |
| 1358 | action="store_true", help="verbose mode") |
| 1359 | parser.add_argument("-p", "--pythonconfpath", dest="p", |
| 1360 | help="searchpath for config") |
| 1361 | parser.add_argument("-w", "--workdir", dest="w", |
| 1362 | help="Working directory") |
| 1363 | args = parser.parse_args() |
| 1364 | |
| 1365 | verbose_level = 1 |
| 1366 | if args.verbose: |
| 1367 | verbose_level = 2 |
| 1368 | |
| 1369 | if args.w: |
| 1370 | workdir = args.w |
| 1371 | |
| 1372 | if args.p: |
| 1373 | confpath = args.p |
| 1374 | |
| 1375 | print "confpath %s, workdir %s" % (confpath, workdir) |
| 1376 | os.chdir(workdir) |
| 1377 | print "Running tests for specific VTY commands" |
| 1378 | suite = unittest.TestSuite() |
Holger Hans Peter Freyther | 8d998a7 | 2014-07-04 20:23:56 +0200 | [diff] [blame] | 1379 | suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYMGCP)) |
Holger Hans Peter Freyther | c63f6f1 | 2013-07-27 21:07:57 +0200 | [diff] [blame] | 1380 | suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYNITB)) |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 1381 | add_bsc_test(suite, workdir) |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 1382 | add_nat_test(suite, workdir) |
Jacob Erlbeck | 6d23371 | 2013-10-23 11:24:15 +0200 | [diff] [blame] | 1383 | add_gbproxy_test(suite, workdir) |
Jacob Erlbeck | 144b8b1 | 2014-11-04 11:15:01 +0100 | [diff] [blame] | 1384 | add_sgsn_test(suite, workdir) |
Neels Hofmeyr | 0a45c1e | 2016-09-28 23:48:02 +0200 | [diff] [blame] | 1385 | res = unittest.TextTestRunner(verbosity=verbose_level, stream=sys.stdout).run(suite) |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 1386 | sys.exit(len(res.errors) + len(res.failures)) |
Neels Hofmeyr | 23d37c9 | 2016-09-26 03:18:32 +0200 | [diff] [blame] | 1387 | |
Neels Hofmeyr | 0867b72 | 2016-09-28 23:28:06 +0200 | [diff] [blame] | 1388 | # vim: shiftwidth=4 expandtab nocin ai |