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