Pau Espin Pedrol | 7e78681 | 2017-11-24 12:00:35 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python2 |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 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 |
Max | f8dc526 | 2017-12-19 18:04:18 +0100 | [diff] [blame] | 26 | from osmopy.osmo_ipa import IPA |
Max | 3e67689 | 2016-11-16 14:55:21 +0100 | [diff] [blame] | 27 | |
Neels Hofmeyr | 476c4bb | 2017-02-24 17:55:11 +0100 | [diff] [blame] | 28 | # to be able to find $top_srcdir/doc/... |
| 29 | confpath = os.path.join(sys.path[0], '..') |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 30 | |
| 31 | class TestVTYBase(unittest.TestCase): |
| 32 | |
Neels Hofmeyr | c29505e | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 33 | def checkForEndAndExit(self): |
| 34 | res = self.vty.command("list") |
| 35 | #print ('looking for "exit"\n') |
| 36 | self.assert_(res.find(' exit\r') > 0) |
| 37 | #print 'found "exit"\nlooking for "end"\n' |
| 38 | self.assert_(res.find(' end\r') > 0) |
| 39 | #print 'found "end"\n' |
| 40 | |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 41 | def vty_command(self): |
| 42 | raise Exception("Needs to be implemented by a subclass") |
| 43 | |
| 44 | def vty_app(self): |
| 45 | raise Exception("Needs to be implemented by a subclass") |
| 46 | |
| 47 | def setUp(self): |
| 48 | osmo_vty_cmd = self.vty_command()[:] |
| 49 | config_index = osmo_vty_cmd.index('-c') |
| 50 | if config_index: |
| 51 | cfi = config_index + 1 |
| 52 | osmo_vty_cmd[cfi] = os.path.join(confpath, osmo_vty_cmd[cfi]) |
| 53 | |
| 54 | try: |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 55 | self.proc = osmoutil.popen_devnull(osmo_vty_cmd) |
| 56 | except OSError: |
| 57 | print >> sys.stderr, "Current directory: %s" % os.getcwd() |
| 58 | print >> sys.stderr, "Consider setting -b" |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 59 | |
| 60 | appstring = self.vty_app()[2] |
| 61 | appport = self.vty_app()[0] |
| 62 | self.vty = obscvty.VTYInteract(appstring, "127.0.0.1", appport) |
| 63 | |
| 64 | def tearDown(self): |
Neels Hofmeyr | 40a91b3 | 2017-02-24 17:54:22 +0100 | [diff] [blame] | 65 | if self.vty: |
| 66 | self.vty._close_socket() |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 67 | self.vty = None |
| 68 | osmoutil.end_proc(self.proc) |
| 69 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 70 | |
| 71 | class TestVTYGenericBSC(TestVTYBase): |
| 72 | |
Neels Hofmeyr | c29505e | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 73 | def _testConfigNetworkTree(self, include_bsc_items=True): |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 74 | self.vty.enable() |
| 75 | self.assertTrue(self.vty.verify("configure terminal",[''])) |
| 76 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 6e919db | 2013-10-29 09:30:31 +0100 | [diff] [blame] | 77 | self.checkForEndAndExit() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 78 | self.assertTrue(self.vty.verify("network",[''])) |
| 79 | self.assertEquals(self.vty.node(), 'config-net') |
| 80 | self.checkForEndAndExit() |
| 81 | self.assertTrue(self.vty.verify("bts 0",[''])) |
| 82 | self.assertEquals(self.vty.node(), 'config-net-bts') |
| 83 | self.checkForEndAndExit() |
| 84 | self.assertTrue(self.vty.verify("trx 0",[''])) |
| 85 | self.assertEquals(self.vty.node(), 'config-net-bts-trx') |
| 86 | self.checkForEndAndExit() |
Jacob Erlbeck | 733bec8 | 2013-09-11 10:46:56 +0200 | [diff] [blame] | 87 | self.vty.command("write terminal") |
| 88 | self.assertTrue(self.vty.verify("exit",[''])) |
| 89 | self.assertEquals(self.vty.node(), 'config-net-bts') |
| 90 | self.assertTrue(self.vty.verify("exit",[''])) |
| 91 | self.assertTrue(self.vty.verify("bts 1",[''])) |
| 92 | self.assertEquals(self.vty.node(), 'config-net-bts') |
| 93 | self.checkForEndAndExit() |
| 94 | self.assertTrue(self.vty.verify("trx 1",[''])) |
| 95 | self.assertEquals(self.vty.node(), 'config-net-bts-trx') |
| 96 | self.checkForEndAndExit() |
| 97 | self.vty.command("write terminal") |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 98 | self.assertTrue(self.vty.verify("exit",[''])) |
| 99 | self.assertEquals(self.vty.node(), 'config-net-bts') |
| 100 | self.assertTrue(self.vty.verify("exit",[''])) |
| 101 | self.assertEquals(self.vty.node(), 'config-net') |
| 102 | self.assertTrue(self.vty.verify("exit",[''])) |
| 103 | self.assertEquals(self.vty.node(), 'config') |
| 104 | self.assertTrue(self.vty.verify("exit",[''])) |
| 105 | self.assertTrue(self.vty.node() is None) |
| 106 | |
Holger Hans Peter Freyther | 8657326 | 2015-01-31 09:47:37 +0100 | [diff] [blame] | 107 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 108 | class TestVTYBSC(TestVTYGenericBSC): |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 109 | |
| 110 | def vty_command(self): |
| 111 | return ["./src/osmo-bsc/osmo-bsc", "-c", |
| 112 | "doc/examples/osmo-bsc/osmo-bsc.cfg"] |
| 113 | |
| 114 | def vty_app(self): |
| 115 | return (4242, "./src/osmo-bsc/osmo-bsc", "OsmoBSC", "bsc") |
| 116 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 117 | def testConfigNetworkTree(self): |
Jacob Erlbeck | 7587727 | 2013-10-23 11:24:14 +0200 | [diff] [blame] | 118 | self._testConfigNetworkTree() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 119 | |
| 120 | def testVtyTree(self): |
| 121 | self.vty.enable() |
| 122 | self.assertTrue(self.vty.verify("configure terminal", [''])) |
| 123 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 6e919db | 2013-10-29 09:30:31 +0100 | [diff] [blame] | 124 | self.checkForEndAndExit() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 125 | self.assertTrue(self.vty.verify("msc 0", [''])) |
| 126 | self.assertEquals(self.vty.node(), 'config-msc') |
Jacob Erlbeck | 0ae92a9 | 2013-09-02 13:17:16 +0200 | [diff] [blame] | 127 | self.checkForEndAndExit() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 128 | self.assertTrue(self.vty.verify("exit", [''])) |
Jacob Erlbeck | 0ae92a9 | 2013-09-02 13:17:16 +0200 | [diff] [blame] | 129 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 130 | self.assertTrue(self.vty.verify("bsc", [''])) |
| 131 | self.assertEquals(self.vty.node(), 'config-bsc') |
Jacob Erlbeck | 0ae92a9 | 2013-09-02 13:17:16 +0200 | [diff] [blame] | 132 | self.checkForEndAndExit() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 133 | self.assertTrue(self.vty.verify("exit", [''])) |
Jacob Erlbeck | 0ae92a9 | 2013-09-02 13:17:16 +0200 | [diff] [blame] | 134 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 135 | self.assertTrue(self.vty.verify("exit", [''])) |
| 136 | self.assertTrue(self.vty.node() is None) |
| 137 | |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 138 | def testUssdNotificationsMsc(self): |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 139 | self.vty.enable() |
| 140 | self.vty.command("configure terminal") |
| 141 | self.vty.command("msc") |
| 142 | |
| 143 | # Test invalid input |
| 144 | self.vty.verify("bsc-msc-lost-text", ['% Command incomplete.']) |
Jacob Erlbeck | 97e139f | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 145 | self.vty.verify("bsc-welcome-text", ['% Command incomplete.']) |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 146 | self.vty.verify("bsc-grace-text", ['% Command incomplete.']) |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 147 | |
| 148 | # Enable USSD notifications |
| 149 | self.vty.verify("bsc-msc-lost-text MSC disconnected", ['']) |
Jacob Erlbeck | 97e139f | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 150 | self.vty.verify("bsc-welcome-text Hello MS", ['']) |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 151 | self.vty.verify("bsc-grace-text In grace period", ['']) |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 152 | |
| 153 | # Verify settings |
| 154 | res = self.vty.command("write terminal") |
| 155 | self.assert_(res.find('bsc-msc-lost-text MSC disconnected') > 0) |
| 156 | self.assertEquals(res.find('no bsc-msc-lost-text'), -1) |
Jacob Erlbeck | 97e139f | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 157 | self.assert_(res.find('bsc-welcome-text Hello MS') > 0) |
| 158 | self.assertEquals(res.find('no bsc-welcome-text'), -1) |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 159 | self.assert_(res.find('bsc-grace-text In grace period') > 0) |
| 160 | self.assertEquals(res.find('no bsc-grace-text'), -1) |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 161 | |
| 162 | # Now disable it.. |
| 163 | self.vty.verify("no bsc-msc-lost-text", ['']) |
Jacob Erlbeck | 97e139f | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 164 | self.vty.verify("no bsc-welcome-text", ['']) |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 165 | self.vty.verify("no bsc-grace-text", ['']) |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 166 | |
| 167 | # Verify settings |
| 168 | res = self.vty.command("write terminal") |
| 169 | self.assertEquals(res.find('bsc-msc-lost-text MSC disconnected'), -1) |
| 170 | self.assert_(res.find('no bsc-msc-lost-text') > 0) |
Jacob Erlbeck | 97e139f | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 171 | self.assertEquals(res.find('bsc-welcome-text Hello MS'), -1) |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 172 | self.assert_(res.find('no bsc-welcome-text') > 0) |
| 173 | self.assertEquals(res.find('bsc-grace-text In grace period'), -1) |
| 174 | self.assert_(res.find('no bsc-grace-text') > 0) |
| 175 | |
| 176 | def testUssdNotificationsBsc(self): |
| 177 | self.vty.enable() |
| 178 | self.vty.command("configure terminal") |
| 179 | self.vty.command("bsc") |
| 180 | |
| 181 | # Test invalid input |
| 182 | self.vty.verify("missing-msc-text", ['% Command incomplete.']) |
| 183 | |
| 184 | # Enable USSD notifications |
| 185 | self.vty.verify("missing-msc-text No MSC found", ['']) |
| 186 | |
| 187 | # Verify settings |
| 188 | res = self.vty.command("write terminal") |
| 189 | self.assert_(res.find('missing-msc-text No MSC found') > 0) |
| 190 | self.assertEquals(res.find('no missing-msc-text'), -1) |
| 191 | |
| 192 | # Now disable it.. |
| 193 | self.vty.verify("no missing-msc-text", ['']) |
| 194 | |
| 195 | # Verify settings |
| 196 | res = self.vty.command("write terminal") |
| 197 | self.assertEquals(res.find('missing-msc-text No MSC found'), -1) |
| 198 | self.assert_(res.find('no missing-msc-text') > 0) |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 199 | |
Jacob Erlbeck | 946d141 | 2013-09-17 13:59:29 +0200 | [diff] [blame] | 200 | def testNetworkTimezone(self): |
| 201 | self.vty.enable() |
| 202 | self.vty.verify("configure terminal", ['']) |
| 203 | self.vty.verify("network", ['']) |
Jacob Erlbeck | 946d141 | 2013-09-17 13:59:29 +0200 | [diff] [blame] | 204 | |
| 205 | # Test invalid input |
| 206 | self.vty.verify("timezone", ['% Command incomplete.']) |
| 207 | self.vty.verify("timezone 20 0", ['% Unknown command.']) |
| 208 | self.vty.verify("timezone 0 11", ['% Unknown command.']) |
| 209 | self.vty.verify("timezone 0 0 99", ['% Unknown command.']) |
| 210 | |
| 211 | # Set time zone without DST |
| 212 | self.vty.verify("timezone 2 30", ['']) |
| 213 | |
| 214 | # Verify settings |
| 215 | res = self.vty.command("write terminal") |
| 216 | self.assert_(res.find('timezone 2 30') > 0) |
| 217 | self.assertEquals(res.find('timezone 2 30 '), -1) |
| 218 | |
| 219 | # Set time zone with DST |
| 220 | self.vty.verify("timezone 2 30 1", ['']) |
| 221 | |
| 222 | # Verify settings |
| 223 | res = self.vty.command("write terminal") |
| 224 | self.assert_(res.find('timezone 2 30 1') > 0) |
| 225 | |
| 226 | # Now disable it.. |
| 227 | self.vty.verify("no timezone", ['']) |
| 228 | |
| 229 | # Verify settings |
| 230 | res = self.vty.command("write terminal") |
| 231 | self.assertEquals(res.find(' timezone'), -1) |
| 232 | |
Ciaby | ec6e4f8 | 2014-03-06 17:20:55 +0100 | [diff] [blame] | 233 | def testShowNetwork(self): |
| 234 | res = self.vty.command("show network") |
| 235 | self.assert_(res.startswith('BSC is on Country Code') >= 0) |
| 236 | |
Holger Hans Peter Freyther | db64f2e | 2014-10-29 10:06:15 +0100 | [diff] [blame] | 237 | def testPingPongConfiguration(self): |
| 238 | self.vty.enable() |
| 239 | self.vty.verify("configure terminal", ['']) |
Holger Hans Peter Freyther | db64f2e | 2014-10-29 10:06:15 +0100 | [diff] [blame] | 240 | self.vty.verify("msc 0", ['']) |
| 241 | |
| 242 | self.vty.verify("timeout-ping 12", ['']) |
| 243 | self.vty.verify("timeout-pong 14", ['']) |
| 244 | res = self.vty.command("show running-config") |
| 245 | self.assert_(res.find(" timeout-ping 12") > 0) |
| 246 | self.assert_(res.find(" timeout-pong 14") > 0) |
| 247 | self.assert_(res.find(" no timeout-ping advanced") > 0) |
| 248 | |
| 249 | self.vty.verify("timeout-ping advanced", ['']) |
| 250 | res = self.vty.command("show running-config") |
| 251 | self.assert_(res.find(" timeout-ping 12") > 0) |
| 252 | self.assert_(res.find(" timeout-pong 14") > 0) |
| 253 | self.assert_(res.find(" timeout-ping advanced") > 0) |
| 254 | |
| 255 | self.vty.verify("no timeout-ping advanced", ['']) |
| 256 | res = self.vty.command("show running-config") |
| 257 | self.assert_(res.find(" timeout-ping 12") > 0) |
| 258 | self.assert_(res.find(" timeout-pong 14") > 0) |
| 259 | self.assert_(res.find(" no timeout-ping advanced") > 0) |
| 260 | |
| 261 | self.vty.verify("no timeout-ping", ['']) |
| 262 | res = self.vty.command("show running-config") |
| 263 | self.assertEquals(res.find(" timeout-ping 12"), -1) |
| 264 | self.assertEquals(res.find(" timeout-pong 14"), -1) |
| 265 | self.assertEquals(res.find(" no timeout-ping advanced"), -1) |
| 266 | self.assert_(res.find(" no timeout-ping") > 0) |
| 267 | |
| 268 | self.vty.verify("timeout-ping advanced", ['%ping handling is disabled. Enable it first.']) |
| 269 | |
| 270 | # And back to enabling it |
| 271 | self.vty.verify("timeout-ping 12", ['']) |
| 272 | self.vty.verify("timeout-pong 14", ['']) |
| 273 | res = self.vty.command("show running-config") |
| 274 | self.assert_(res.find(" timeout-ping 12") > 0) |
| 275 | self.assert_(res.find(" timeout-pong 14") > 0) |
| 276 | self.assert_(res.find(" timeout-ping advanced") > 0) |
| 277 | |
Holger Hans Peter Freyther | 32dd2f3 | 2015-04-01 18:15:48 +0200 | [diff] [blame] | 278 | def testMscDataCoreLACCI(self): |
| 279 | self.vty.enable() |
| 280 | res = self.vty.command("show running-config") |
| 281 | self.assertEquals(res.find("core-location-area-code"), -1) |
| 282 | self.assertEquals(res.find("core-cell-identity"), -1) |
| 283 | |
Neels Hofmeyr | 0867b72 | 2016-09-28 23:28:06 +0200 | [diff] [blame] | 284 | self.vty.command("configure terminal") |
Holger Hans Peter Freyther | 32dd2f3 | 2015-04-01 18:15:48 +0200 | [diff] [blame] | 285 | self.vty.command("msc 0") |
| 286 | self.vty.command("core-location-area-code 666") |
| 287 | self.vty.command("core-cell-identity 333") |
| 288 | |
| 289 | res = self.vty.command("show running-config") |
| 290 | self.assert_(res.find("core-location-area-code 666") > 0) |
| 291 | self.assert_(res.find("core-cell-identity 333") > 0) |
| 292 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 293 | class TestVTYNAT(TestVTYGenericBSC): |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 294 | |
| 295 | def vty_command(self): |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 296 | 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] | 297 | "doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg"] |
| 298 | |
| 299 | def vty_app(self): |
| 300 | return (4244, "src/osmo-bsc_nat/osmo-bsc_nat", "OsmoBSCNAT", "nat") |
| 301 | |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 302 | def testBSCreload(self): |
Holger Hans Peter Freyther | 44ed497 | 2016-04-14 10:05:13 -0400 | [diff] [blame] | 303 | # Use different port for the mock msc to avoid clashing with |
| 304 | # the osmo-bsc_nat itself |
Holger Hans Peter Freyther | f1a61bb | 2016-04-14 08:50:25 -0400 | [diff] [blame] | 305 | ip = "127.0.0.1" |
Holger Hans Peter Freyther | e98c9c7 | 2016-04-14 10:58:58 -0400 | [diff] [blame] | 306 | port = 5522 |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 307 | self.vty.enable() |
| 308 | bscs1 = self.vty.command("show bscs-config") |
| 309 | nat_bsc_reload(self) |
| 310 | bscs2 = self.vty.command("show bscs-config") |
| 311 | # check that multiple calls to bscs-config-file give the same result |
| 312 | self.assertEquals(bscs1, bscs2) |
| 313 | |
| 314 | # add new bsc |
| 315 | self.vty.command("configure terminal") |
| 316 | self.vty.command("nat") |
| 317 | self.vty.command("bsc 5") |
| 318 | self.vty.command("token key") |
| 319 | self.vty.command("location_area_code 666") |
| 320 | self.vty.command("end") |
| 321 | |
| 322 | # update bsc token |
| 323 | self.vty.command("configure terminal") |
| 324 | self.vty.command("nat") |
| 325 | self.vty.command("bsc 1") |
| 326 | self.vty.command("token xyu") |
| 327 | self.vty.command("end") |
| 328 | |
Holger Hans Peter Freyther | 44ed497 | 2016-04-14 10:05:13 -0400 | [diff] [blame] | 329 | nat_msc_ip(self, ip, port) |
Neels Hofmeyr | 0b61932 | 2017-02-28 02:37:39 +0100 | [diff] [blame] | 330 | msc_socket, msc = nat_msc_test(self, ip, port, verbose=True) |
| 331 | try: |
| 332 | b0 = nat_bsc_sock_test(0, "lol", verbose=True, proc=self.proc) |
| 333 | b1 = nat_bsc_sock_test(1, "xyu", verbose=True, proc=self.proc) |
| 334 | b2 = nat_bsc_sock_test(5, "key", verbose=True, proc=self.proc) |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 335 | |
Neels Hofmeyr | 0b61932 | 2017-02-28 02:37:39 +0100 | [diff] [blame] | 336 | self.assertEquals("3 BSCs configured", self.vty.command("show nat num-bscs-configured")) |
| 337 | self.assertTrue(3 == nat_bsc_num_con(self)) |
| 338 | self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection")) |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 339 | |
Neels Hofmeyr | 0b61932 | 2017-02-28 02:37:39 +0100 | [diff] [blame] | 340 | nat_bsc_reload(self) |
| 341 | bscs2 = self.vty.command("show bscs-config") |
| 342 | # check that the reset to initial config succeeded |
| 343 | self.assertEquals(bscs1, bscs2) |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 344 | |
Neels Hofmeyr | 0b61932 | 2017-02-28 02:37:39 +0100 | [diff] [blame] | 345 | self.assertEquals("2 BSCs configured", self.vty.command("show nat num-bscs-configured")) |
| 346 | self.assertTrue(1 == nat_bsc_num_con(self)) |
| 347 | rem = self.vty.command("show bsc connections").split(' ') |
| 348 | # remaining connection is for BSC0 |
| 349 | self.assertEquals('0', rem[2]) |
| 350 | # remaining connection is authorized |
| 351 | self.assertEquals('1', rem[4]) |
| 352 | self.assertEquals("MSC is connected: 1", self.vty.command("show msc connection")) |
| 353 | finally: |
| 354 | msc.close() |
| 355 | msc_socket.close() |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 356 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 357 | def testVtyTree(self): |
| 358 | self.vty.enable() |
| 359 | self.assertTrue(self.vty.verify('configure terminal', [''])) |
| 360 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 6e919db | 2013-10-29 09:30:31 +0100 | [diff] [blame] | 361 | self.checkForEndAndExit() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 362 | self.assertTrue(self.vty.verify('mgcp', [''])) |
| 363 | self.assertEquals(self.vty.node(), 'config-mgcp') |
| 364 | self.checkForEndAndExit() |
| 365 | self.assertTrue(self.vty.verify('exit', [''])) |
| 366 | self.assertEquals(self.vty.node(), 'config') |
| 367 | self.assertTrue(self.vty.verify('nat', [''])) |
| 368 | self.assertEquals(self.vty.node(), 'config-nat') |
| 369 | self.checkForEndAndExit() |
| 370 | self.assertTrue(self.vty.verify('bsc 0', [''])) |
| 371 | self.assertEquals(self.vty.node(), 'config-nat-bsc') |
| 372 | self.checkForEndAndExit() |
| 373 | self.assertTrue(self.vty.verify('exit', [''])) |
| 374 | self.assertEquals(self.vty.node(), 'config-nat') |
| 375 | self.assertTrue(self.vty.verify('exit', [''])) |
| 376 | self.assertEquals(self.vty.node(), 'config') |
| 377 | self.assertTrue(self.vty.verify('exit', [''])) |
| 378 | self.assertTrue(self.vty.node() is None) |
| 379 | |
Holger Hans Peter Freyther | b718ad3 | 2013-06-25 09:08:02 +0200 | [diff] [blame] | 380 | def testRewriteNoRewrite(self): |
| 381 | self.vty.enable() |
| 382 | res = self.vty.command("configure terminal") |
| 383 | res = self.vty.command("nat") |
| 384 | res = self.vty.command("number-rewrite rewrite.cfg") |
| 385 | res = self.vty.command("no number-rewrite") |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 386 | |
Holger Hans Peter Freyther | 7f100c9 | 2015-04-23 20:25:17 -0400 | [diff] [blame] | 387 | def testEnsureNoEnsureModeSet(self): |
| 388 | self.vty.enable() |
| 389 | res = self.vty.command("configure terminal") |
| 390 | res = self.vty.command("nat") |
| 391 | |
| 392 | # Ensure the default |
| 393 | res = self.vty.command("show running-config") |
| 394 | self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0) |
| 395 | |
| 396 | self.vty.command("sdp-ensure-amr-mode-set") |
| 397 | res = self.vty.command("show running-config") |
| 398 | self.assert_(res.find('\n sdp-ensure-amr-mode-set') > 0) |
| 399 | |
| 400 | self.vty.command("no sdp-ensure-amr-mode-set") |
| 401 | res = self.vty.command("show running-config") |
| 402 | self.assert_(res.find('\n no sdp-ensure-amr-mode-set') > 0) |
| 403 | |
Holger Hans Peter Freyther | 67e423c | 2013-06-25 15:38:31 +0200 | [diff] [blame] | 404 | def testRewritePostNoRewrite(self): |
| 405 | self.vty.enable() |
| 406 | self.vty.command("configure terminal") |
| 407 | self.vty.command("nat") |
| 408 | self.vty.verify("number-rewrite-post rewrite.cfg", ['']) |
| 409 | self.vty.verify("no number-rewrite-post", ['']) |
| 410 | |
| 411 | |
Holger Hans Peter Freyther | ddf191e | 2013-06-25 11:44:01 +0200 | [diff] [blame] | 412 | def testPrefixTreeLoading(self): |
| 413 | cfg = os.path.join(confpath, "tests/bsc-nat-trie/prefixes.csv") |
| 414 | |
| 415 | self.vty.enable() |
| 416 | self.vty.command("configure terminal") |
| 417 | self.vty.command("nat") |
| 418 | res = self.vty.command("prefix-tree %s" % cfg) |
| 419 | self.assertEqual(res, "% prefix-tree loaded 17 rules.") |
| 420 | self.vty.command("end") |
| 421 | |
| 422 | res = self.vty.command("show prefix-tree") |
| 423 | self.assertEqual(res, '1,1\r\n12,2\r\n123,3\r\n1234,4\r\n12345,5\r\n123456,6\r\n1234567,7\r\n12345678,8\r\n123456789,9\r\n1234567890,10\r\n13,11\r\n14,12\r\n15,13\r\n16,14\r\n82,16\r\n823455,15\r\n+49123,17') |
| 424 | |
| 425 | self.vty.command("configure terminal") |
| 426 | self.vty.command("nat") |
| 427 | self.vty.command("no prefix-tree") |
| 428 | self.vty.command("end") |
| 429 | |
| 430 | res = self.vty.command("show prefix-tree") |
| 431 | self.assertEqual(res, "% there is now prefix tree loaded.") |
| 432 | |
Jacob Erlbeck | 6cb2ccc | 2013-08-14 11:10:34 +0200 | [diff] [blame] | 433 | def testUssdSideChannelProvider(self): |
| 434 | self.vty.command("end") |
| 435 | self.vty.enable() |
| 436 | self.vty.command("configure terminal") |
| 437 | self.vty.command("nat") |
| 438 | self.vty.command("ussd-token key") |
| 439 | self.vty.command("end") |
| 440 | |
| 441 | res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.']) |
| 442 | self.assertTrue(res) |
| 443 | |
| 444 | ussdSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 445 | ussdSocket.connect(('127.0.0.1', 5001)) |
| 446 | ussdSocket.settimeout(2.0) |
| 447 | print "Connected to %s:%d" % ussdSocket.getpeername() |
| 448 | |
| 449 | print "Expecting ID_GET request" |
| 450 | data = ussdSocket.recv(4) |
| 451 | self.assertEqual(data, "\x00\x01\xfe\x04") |
| 452 | |
| 453 | print "Going to send ID_RESP response" |
Max | 3e67689 | 2016-11-16 14:55:21 +0100 | [diff] [blame] | 454 | res = ussdSocket.send(IPA().id_resp(IPA().tag_name('key'))) |
Jacob Erlbeck | 6cb2ccc | 2013-08-14 11:10:34 +0200 | [diff] [blame] | 455 | self.assertEqual(res, 10) |
| 456 | |
| 457 | # initiating PING/PONG cycle to know, that the ID_RESP message has been processed |
| 458 | |
| 459 | print "Going to send PING request" |
Max | 3e67689 | 2016-11-16 14:55:21 +0100 | [diff] [blame] | 460 | res = ussdSocket.send(IPA().ping()) |
Jacob Erlbeck | 6cb2ccc | 2013-08-14 11:10:34 +0200 | [diff] [blame] | 461 | self.assertEqual(res, 4) |
| 462 | |
| 463 | print "Expecting PONG response" |
| 464 | data = ussdSocket.recv(4) |
| 465 | self.assertEqual(data, "\x00\x01\xfe\x01") |
| 466 | |
| 467 | res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is connected and authorized.']) |
| 468 | self.assertTrue(res) |
| 469 | |
| 470 | print "Going to shut down connection" |
| 471 | ussdSocket.shutdown(socket.SHUT_WR) |
| 472 | |
| 473 | print "Expecting EOF" |
| 474 | data = ussdSocket.recv(4) |
| 475 | self.assertEqual(data, "") |
| 476 | |
| 477 | ussdSocket.close() |
| 478 | |
| 479 | res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.']) |
| 480 | self.assertTrue(res) |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 481 | |
Holger Hans Peter Freyther | 6419018 | 2014-01-20 10:14:05 +0100 | [diff] [blame] | 482 | def testAccessList(self): |
| 483 | """ |
| 484 | Verify that the imsi-deny can have a reject cause or no reject cause |
| 485 | """ |
| 486 | self.vty.enable() |
| 487 | self.vty.command("configure terminal") |
| 488 | self.vty.command("nat") |
| 489 | |
| 490 | # Old default |
| 491 | self.vty.command("access-list test-default imsi-deny ^123[0-9]*$") |
| 492 | res = self.vty.command("show running-config").split("\r\n") |
| 493 | asserted = False |
| 494 | for line in res: |
Holger Hans Peter Freyther | 4ecc687 | 2014-03-04 15:38:00 +0100 | [diff] [blame] | 495 | if line.startswith(" access-list test-default"): |
Holger Hans Peter Freyther | 6419018 | 2014-01-20 10:14:05 +0100 | [diff] [blame] | 496 | self.assertEqual(line, " access-list test-default imsi-deny ^123[0-9]*$ 11 11") |
| 497 | asserted = True |
| 498 | self.assert_(asserted) |
| 499 | |
| 500 | # Check the optional CM Service Reject Cause |
| 501 | self.vty.command("access-list test-cm-deny imsi-deny ^123[0-9]*$ 42").split("\r\n") |
| 502 | res = self.vty.command("show running-config").split("\r\n") |
| 503 | asserted = False |
| 504 | for line in res: |
| 505 | if line.startswith(" access-list test-cm"): |
| 506 | self.assertEqual(line, " access-list test-cm-deny imsi-deny ^123[0-9]*$ 42 11") |
| 507 | asserted = True |
| 508 | self.assert_(asserted) |
| 509 | |
| 510 | # Check the optional LU Reject Cause |
| 511 | self.vty.command("access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42").split("\r\n") |
| 512 | res = self.vty.command("show running-config").split("\r\n") |
| 513 | asserted = False |
| 514 | for line in res: |
| 515 | if line.startswith(" access-list test-lu"): |
| 516 | self.assertEqual(line, " access-list test-lu-deny imsi-deny ^123[0-9]*$ 23 42") |
| 517 | asserted = True |
| 518 | self.assert_(asserted) |
| 519 | |
Holger Hans Peter Freyther | c15c61c | 2015-05-06 17:46:08 +0200 | [diff] [blame] | 520 | |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 521 | def add_nat_test(suite, workdir): |
| 522 | if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")): |
| 523 | print("Skipping the NAT test") |
| 524 | return |
| 525 | test = unittest.TestLoader().loadTestsFromTestCase(TestVTYNAT) |
| 526 | suite.addTest(test) |
| 527 | |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 528 | def nat_bsc_reload(x): |
| 529 | x.vty.command("configure terminal") |
| 530 | x.vty.command("nat") |
Neels Hofmeyr | 5809e1e | 2017-07-20 17:57:37 +0200 | [diff] [blame] | 531 | x.vty.command("bscs-config-file bscs.cfg") |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 532 | x.vty.command("end") |
| 533 | |
Holger Hans Peter Freyther | 44ed497 | 2016-04-14 10:05:13 -0400 | [diff] [blame] | 534 | def nat_msc_ip(x, ip, port): |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 535 | x.vty.command("configure terminal") |
| 536 | x.vty.command("nat") |
| 537 | x.vty.command("msc ip " + ip) |
Holger Hans Peter Freyther | 84ae27e | 2016-04-14 10:40:06 -0400 | [diff] [blame] | 538 | x.vty.command("msc port " + str(port)) |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 539 | x.vty.command("end") |
| 540 | |
| 541 | def data2str(d): |
Holger Hans Peter Freyther | 8bb6204 | 2016-04-14 21:40:04 -0400 | [diff] [blame] | 542 | return d.encode('hex').lower() |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 543 | |
Holger Hans Peter Freyther | 44ed497 | 2016-04-14 10:05:13 -0400 | [diff] [blame] | 544 | def nat_msc_test(x, ip, port, verbose = False): |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 545 | msc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
Neels Hofmeyr | 5340345 | 2017-02-28 02:38:43 +0100 | [diff] [blame] | 546 | msc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
Neels Hofmeyr | caeb62d | 2016-09-28 23:38:45 +0200 | [diff] [blame] | 547 | msc.settimeout(5) |
Holger Hans Peter Freyther | 44ed497 | 2016-04-14 10:05:13 -0400 | [diff] [blame] | 548 | msc.bind((ip, port)) |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 549 | msc.listen(5) |
| 550 | if (verbose): |
| 551 | print "MSC is ready at " + ip |
Neels Hofmeyr | 89d20b6 | 2016-09-26 12:59:36 +0200 | [diff] [blame] | 552 | conn = None |
Neels Hofmeyr | caeb62d | 2016-09-28 23:38:45 +0200 | [diff] [blame] | 553 | while True: |
| 554 | vty_response = x.vty.command("show msc connection") |
| 555 | print "'show msc connection' says: %r" % vty_response |
| 556 | if vty_response == "MSC is connected: 1": |
| 557 | # success |
| 558 | break; |
| 559 | if vty_response != "MSC is connected: 0": |
| 560 | raise Exception("Unexpected response to 'show msc connection'" |
| 561 | " vty command: %r" % vty_response) |
| 562 | |
| 563 | timeout_retries = 6 |
| 564 | while timeout_retries > 0: |
| 565 | try: |
| 566 | conn, addr = msc.accept() |
| 567 | print "MSC got connection from ", addr |
| 568 | break |
| 569 | except socket.timeout: |
| 570 | print "socket timed out." |
| 571 | timeout_retries -= 1 |
| 572 | continue |
| 573 | |
Neels Hofmeyr | 89d20b6 | 2016-09-26 12:59:36 +0200 | [diff] [blame] | 574 | if not conn: |
Neels Hofmeyr | 0867b72 | 2016-09-28 23:28:06 +0200 | [diff] [blame] | 575 | raise Exception("VTY reports MSC is connected, but I haven't" |
| 576 | " connected yet: %r %r" % (ip, port)) |
Neels Hofmeyr | 0b61932 | 2017-02-28 02:37:39 +0100 | [diff] [blame] | 577 | return msc, conn |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 578 | |
| 579 | def ipa_handle_small(x, verbose = False): |
| 580 | s = data2str(x.recv(4)) |
Neels Hofmeyr | ba1468e | 2017-02-03 04:23:46 +0100 | [diff] [blame] | 581 | if len(s) != 4*2: |
| 582 | 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] | 583 | if "0001fe00" == s: |
| 584 | if (verbose): |
| 585 | print "\tBSC <- NAT: PING?" |
Max | 3e67689 | 2016-11-16 14:55:21 +0100 | [diff] [blame] | 586 | x.send(IPA().pong()) |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 587 | elif "0001fe06" == s: |
| 588 | if (verbose): |
| 589 | print "\tBSC <- NAT: IPA ID ACK" |
Max | 3e67689 | 2016-11-16 14:55:21 +0100 | [diff] [blame] | 590 | x.send(IPA().id_ack()) |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 591 | elif "0001fe00" == s: |
| 592 | if (verbose): |
| 593 | print "\tBSC <- NAT: PONG!" |
| 594 | else: |
| 595 | if (verbose): |
| 596 | print "\tBSC <- NAT: ", s |
| 597 | |
Neels Hofmeyr | bcfee2a | 2017-02-03 16:09:17 +0100 | [diff] [blame] | 598 | def ipa_handle_resp(x, tk, verbose = False, proc=None): |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 599 | s = data2str(x.recv(38)) |
| 600 | if "0023fe040108010701020103010401050101010011" in s: |
Neels Hofmeyr | 7d17c3e | 2017-01-26 23:04:28 +0100 | [diff] [blame] | 601 | retries = 3 |
| 602 | while True: |
| 603 | print "\tsending IPA identity(%s) at %s" % (tk, time.strftime("%T")) |
| 604 | try: |
| 605 | x.send(IPA().id_resp(IPA().identity(name = tk.encode('utf-8')))) |
| 606 | print "\tdone sending IPA identity(%s) at %s" % (tk, |
| 607 | time.strftime("%T")) |
| 608 | break |
| 609 | except: |
| 610 | print "\tfailed sending IPA identity at", time.strftime("%T") |
Neels Hofmeyr | bcfee2a | 2017-02-03 16:09:17 +0100 | [diff] [blame] | 611 | if proc: |
| 612 | print "\tproc.poll() = %r" % proc.poll() |
Neels Hofmeyr | 7d17c3e | 2017-01-26 23:04:28 +0100 | [diff] [blame] | 613 | if retries < 1: |
| 614 | print "\tgiving up" |
| 615 | raise |
Neels Hofmeyr | e02e1e7 | 2017-02-03 05:55:26 +0100 | [diff] [blame] | 616 | print "\tretrying (%d attempts left)" % retries |
Neels Hofmeyr | 7d17c3e | 2017-01-26 23:04:28 +0100 | [diff] [blame] | 617 | retries -= 1 |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 618 | else: |
| 619 | if (verbose): |
| 620 | print "\tBSC <- NAT: ", s |
| 621 | |
| 622 | def nat_bsc_num_con(x): |
| 623 | return len(x.vty.command("show bsc connections").split('\n')) |
| 624 | |
Neels Hofmeyr | bcfee2a | 2017-02-03 16:09:17 +0100 | [diff] [blame] | 625 | def nat_bsc_sock_test(nr, tk, verbose = False, proc=None): |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 626 | bsc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
Holger Hans Peter Freyther | 2abf2b0 | 2016-04-14 21:13:51 -0400 | [diff] [blame] | 627 | bsc.bind(('127.0.0.1', 0)) |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 628 | bsc.connect(('127.0.0.1', 5000)) |
| 629 | if (verbose): |
| 630 | print "BSC%d " %nr |
| 631 | print "\tconnected to %s:%d" % bsc.getpeername() |
Neels Hofmeyr | bcfee2a | 2017-02-03 16:09:17 +0100 | [diff] [blame] | 632 | if proc: |
| 633 | print "\tproc.poll() = %r" % proc.poll() |
| 634 | print "\tproc.pid = %r" % proc.pid |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 635 | ipa_handle_small(bsc, verbose) |
Neels Hofmeyr | bcfee2a | 2017-02-03 16:09:17 +0100 | [diff] [blame] | 636 | ipa_handle_resp(bsc, tk, verbose, proc=proc) |
| 637 | if proc: |
| 638 | print "\tproc.poll() = %r" % proc.poll() |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 639 | bsc.recv(27) # MGCP msg |
Neels Hofmeyr | bcfee2a | 2017-02-03 16:09:17 +0100 | [diff] [blame] | 640 | if proc: |
| 641 | print "\tproc.poll() = %r" % proc.poll() |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 642 | ipa_handle_small(bsc, verbose) |
| 643 | return bsc |
| 644 | |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 645 | def add_bsc_test(suite, workdir): |
| 646 | if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")): |
| 647 | print("Skipping the BSC test") |
| 648 | return |
| 649 | test = unittest.TestLoader().loadTestsFromTestCase(TestVTYBSC) |
| 650 | suite.addTest(test) |
| 651 | |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 652 | if __name__ == '__main__': |
| 653 | import argparse |
| 654 | import sys |
| 655 | |
| 656 | workdir = '.' |
| 657 | |
| 658 | parser = argparse.ArgumentParser() |
| 659 | parser.add_argument("-v", "--verbose", dest="verbose", |
| 660 | action="store_true", help="verbose mode") |
| 661 | parser.add_argument("-p", "--pythonconfpath", dest="p", |
| 662 | help="searchpath for config") |
| 663 | parser.add_argument("-w", "--workdir", dest="w", |
| 664 | help="Working directory") |
Neels Hofmeyr | 3f8a8f7 | 2017-02-28 02:43:29 +0100 | [diff] [blame] | 665 | 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] | 666 | args = parser.parse_args() |
| 667 | |
| 668 | verbose_level = 1 |
| 669 | if args.verbose: |
| 670 | verbose_level = 2 |
| 671 | |
| 672 | if args.w: |
| 673 | workdir = args.w |
| 674 | |
| 675 | if args.p: |
| 676 | confpath = args.p |
| 677 | |
| 678 | print "confpath %s, workdir %s" % (confpath, workdir) |
| 679 | os.chdir(workdir) |
| 680 | print "Running tests for specific VTY commands" |
| 681 | suite = unittest.TestSuite() |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 682 | add_bsc_test(suite, workdir) |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 683 | add_nat_test(suite, workdir) |
Neels Hofmeyr | 3f8a8f7 | 2017-02-28 02:43:29 +0100 | [diff] [blame] | 684 | |
| 685 | if args.test_name: |
| 686 | osmoutil.pick_tests(suite, *args.test_name) |
| 687 | |
Neels Hofmeyr | 0a45c1e | 2016-09-28 23:48:02 +0200 | [diff] [blame] | 688 | 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] | 689 | sys.exit(len(res.errors) + len(res.failures)) |
Neels Hofmeyr | 23d37c9 | 2016-09-26 03:18:32 +0200 | [diff] [blame] | 690 | |
Neels Hofmeyr | 0867b72 | 2016-09-28 23:28:06 +0200 | [diff] [blame] | 691 | # vim: shiftwidth=4 expandtab nocin ai |