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