Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
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 | 60383a1 | 2017-11-23 16:33:33 +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 | 84da6b1 | 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') |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 36 | self.assertTrue(res.find(' exit\r') > 0) |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 37 | #print 'found "exit"\nlooking for "end"\n' |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 38 | self.assertTrue(res.find(' end\r') > 0) |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 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: |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 57 | print("Current directory: %s" % os.getcwd(), file=sys.stderr) |
| 58 | print("Consider setting -b", file=sys.stderr) |
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 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 70 | class TestVTYMSC(TestVTYBase): |
Holger Hans Peter Freyther | c63f6f1 | 2013-07-27 21:07:57 +0200 | [diff] [blame] | 71 | |
| 72 | def vty_command(self): |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 73 | return ["./src/osmo-msc/osmo-msc", "-c", |
| 74 | "doc/examples/osmo-msc/osmo-msc.cfg"] |
Holger Hans Peter Freyther | c63f6f1 | 2013-07-27 21:07:57 +0200 | [diff] [blame] | 75 | |
| 76 | def vty_app(self): |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 77 | return (4254, "./src/osmo-msc/osmo-msc", "OsmoMSC", "msc") |
Holger Hans Peter Freyther | c63f6f1 | 2013-07-27 21:07:57 +0200 | [diff] [blame] | 78 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 79 | def testConfigNetworkTree(self, include_bsc_items=True): |
| 80 | self.vty.enable() |
| 81 | self.assertTrue(self.vty.verify("configure terminal",[''])) |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 82 | self.assertEqual(self.vty.node(), 'config') |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 83 | self.checkForEndAndExit() |
| 84 | self.assertTrue(self.vty.verify("network",[''])) |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 85 | self.assertEqual(self.vty.node(), 'config-net') |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 86 | self.checkForEndAndExit() |
| 87 | self.vty.command("write terminal") |
| 88 | self.assertTrue(self.vty.verify("exit",[''])) |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 89 | self.assertEqual(self.vty.node(), 'config') |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 90 | self.assertTrue(self.vty.verify("exit",[''])) |
| 91 | self.assertTrue(self.vty.node() is None) |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 92 | |
Holger Hans Peter Freyther | 0df1ab9 | 2013-09-02 20:58:38 +0200 | [diff] [blame] | 93 | def checkForSmpp(self): |
| 94 | """SMPP is not always enabled, check if it is""" |
| 95 | res = self.vty.command("list") |
| 96 | return "smpp" in res |
| 97 | |
Holger Hans Peter Freyther | 42cf2e0 | 2015-07-06 16:41:30 +0200 | [diff] [blame] | 98 | def testSmppFirst(self): |
Holger Hans Peter Freyther | 42cf2e0 | 2015-07-06 16:41:30 +0200 | [diff] [blame] | 99 | # enable the configuration |
| 100 | self.vty.enable() |
| 101 | self.vty.command("configure terminal") |
Holger Hans Peter Freyther | a2c41c4 | 2015-07-13 11:23:53 +0200 | [diff] [blame] | 102 | |
| 103 | if not self.checkForSmpp(): |
| 104 | return |
| 105 | |
Holger Hans Peter Freyther | 42cf2e0 | 2015-07-06 16:41:30 +0200 | [diff] [blame] | 106 | self.vty.command("smpp") |
| 107 | |
| 108 | # check the default |
| 109 | res = self.vty.command("write terminal") |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 110 | self.assertTrue(res.find(' no smpp-first') > 0) |
Holger Hans Peter Freyther | 42cf2e0 | 2015-07-06 16:41:30 +0200 | [diff] [blame] | 111 | |
| 112 | self.vty.verify("smpp-first", ['']) |
| 113 | res = self.vty.command("write terminal") |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 114 | self.assertTrue(res.find(' smpp-first') > 0) |
| 115 | self.assertEqual(res.find('no smpp-first'), -1) |
Holger Hans Peter Freyther | 42cf2e0 | 2015-07-06 16:41:30 +0200 | [diff] [blame] | 116 | |
| 117 | self.vty.verify("no smpp-first", ['']) |
| 118 | res = self.vty.command("write terminal") |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 119 | self.assertTrue(res.find('no smpp-first') > 0) |
Holger Hans Peter Freyther | 42cf2e0 | 2015-07-06 16:41:30 +0200 | [diff] [blame] | 120 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 121 | def testVtyTree(self): |
| 122 | self.vty.enable() |
| 123 | self.assertTrue(self.vty.verify("configure terminal", [''])) |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 124 | self.assertEqual(self.vty.node(), 'config') |
Jacob Erlbeck | 6e919db | 2013-10-29 09:30:31 +0100 | [diff] [blame] | 125 | self.checkForEndAndExit() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 126 | self.assertTrue(self.vty.verify('mncc-int', [''])) |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 127 | self.assertEqual(self.vty.node(), 'config-mncc-int') |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 128 | self.checkForEndAndExit() |
| 129 | self.assertTrue(self.vty.verify('exit', [''])) |
Holger Hans Peter Freyther | 0df1ab9 | 2013-09-02 20:58:38 +0200 | [diff] [blame] | 130 | |
| 131 | if self.checkForSmpp(): |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 132 | self.assertEqual(self.vty.node(), 'config') |
Jacob Erlbeck | 7587727 | 2013-10-23 11:24:14 +0200 | [diff] [blame] | 133 | self.assertTrue(self.vty.verify('smpp', [''])) |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 134 | self.assertEqual(self.vty.node(), 'config-smpp') |
Jacob Erlbeck | 6e919db | 2013-10-29 09:30:31 +0100 | [diff] [blame] | 135 | self.checkForEndAndExit() |
Jacob Erlbeck | 7587727 | 2013-10-23 11:24:14 +0200 | [diff] [blame] | 136 | self.assertTrue(self.vty.verify("exit", [''])) |
Holger Hans Peter Freyther | 0df1ab9 | 2013-09-02 20:58:38 +0200 | [diff] [blame] | 137 | |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 138 | self.assertEqual(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 | |
| 142 | # Check searching for outer node's commands |
| 143 | self.vty.command("configure terminal") |
| 144 | self.vty.command('mncc-int') |
Holger Hans Peter Freyther | 0df1ab9 | 2013-09-02 20:58:38 +0200 | [diff] [blame] | 145 | |
| 146 | if self.checkForSmpp(): |
| 147 | self.vty.command('smpp') |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 148 | self.assertEqual(self.vty.node(), 'config-smpp') |
Holger Hans Peter Freyther | 0df1ab9 | 2013-09-02 20:58:38 +0200 | [diff] [blame] | 149 | self.vty.command('mncc-int') |
| 150 | |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 151 | self.assertEqual(self.vty.node(), 'config-mncc-int') |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 152 | |
Max | 0c1bc26 | 2016-04-20 12:06:06 +0200 | [diff] [blame] | 153 | def testSi2Q(self): |
| 154 | self.vty.enable() |
| 155 | self.vty.command("configure terminal") |
| 156 | self.vty.command("network") |
| 157 | self.vty.command("bts 0") |
| 158 | before = self.vty.command("show running-config") |
| 159 | self.vty.command("si2quater neighbor-list add earfcn 1911 threshold 11 2") |
| 160 | self.vty.command("si2quater neighbor-list add earfcn 1924 threshold 11 3") |
| 161 | self.vty.command("si2quater neighbor-list add earfcn 2111 threshold 11") |
| 162 | self.vty.command("si2quater neighbor-list del earfcn 1911") |
| 163 | self.vty.command("si2quater neighbor-list del earfcn 1924") |
| 164 | self.vty.command("si2quater neighbor-list del earfcn 2111") |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 165 | self.assertEqual(before, self.vty.command("show running-config")) |
Max | 26679e0 | 2016-04-20 15:57:13 +0200 | [diff] [blame] | 166 | self.vty.command("si2quater neighbor-list add uarfcn 1976 13 1") |
| 167 | self.vty.command("si2quater neighbor-list add uarfcn 1976 38 1") |
| 168 | self.vty.command("si2quater neighbor-list add uarfcn 1976 44 1") |
| 169 | self.vty.command("si2quater neighbor-list add uarfcn 1976 120 1") |
| 170 | self.vty.command("si2quater neighbor-list add uarfcn 1976 140 1") |
| 171 | self.vty.command("si2quater neighbor-list add uarfcn 1976 163 1") |
| 172 | self.vty.command("si2quater neighbor-list add uarfcn 1976 166 1") |
| 173 | self.vty.command("si2quater neighbor-list add uarfcn 1976 217 1") |
| 174 | self.vty.command("si2quater neighbor-list add uarfcn 1976 224 1") |
| 175 | self.vty.command("si2quater neighbor-list add uarfcn 1976 225 1") |
| 176 | self.vty.command("si2quater neighbor-list add uarfcn 1976 226 1") |
| 177 | self.vty.command("si2quater neighbor-list del uarfcn 1976 13") |
| 178 | self.vty.command("si2quater neighbor-list del uarfcn 1976 38") |
| 179 | self.vty.command("si2quater neighbor-list del uarfcn 1976 44") |
| 180 | self.vty.command("si2quater neighbor-list del uarfcn 1976 120") |
| 181 | self.vty.command("si2quater neighbor-list del uarfcn 1976 140") |
| 182 | self.vty.command("si2quater neighbor-list del uarfcn 1976 163") |
| 183 | self.vty.command("si2quater neighbor-list del uarfcn 1976 166") |
| 184 | self.vty.command("si2quater neighbor-list del uarfcn 1976 217") |
| 185 | self.vty.command("si2quater neighbor-list del uarfcn 1976 224") |
| 186 | self.vty.command("si2quater neighbor-list del uarfcn 1976 225") |
| 187 | self.vty.command("si2quater neighbor-list del uarfcn 1976 226") |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 188 | self.assertEqual(before, self.vty.command("show running-config")) |
Max | 0c1bc26 | 2016-04-20 12:06:06 +0200 | [diff] [blame] | 189 | |
Holger Hans Peter Freyther | c63f6f1 | 2013-07-27 21:07:57 +0200 | [diff] [blame] | 190 | def testEnableDisablePeriodicLU(self): |
| 191 | self.vty.enable() |
| 192 | self.vty.command("configure terminal") |
| 193 | self.vty.command("network") |
| 194 | self.vty.command("bts 0") |
| 195 | |
| 196 | # Test invalid input |
| 197 | self.vty.verify("periodic location update 0", ['% Unknown command.']) |
| 198 | self.vty.verify("periodic location update 5", ['% Unknown command.']) |
| 199 | self.vty.verify("periodic location update 1531", ['% Unknown command.']) |
| 200 | |
Vadim Yanitskiy | fc2b019 | 2020-01-18 07:20:14 +0700 | [diff] [blame] | 201 | depr_str = "% 'periodic location update' is now deprecated: " \ |
| 202 | "use 'timer T3212' to change subscriber expiration timeout." |
| 203 | set_str = "% Setting T3212 to 121 minutes (emulating the old behaviour)." |
| 204 | |
| 205 | # Enable periodic LU (deprecated command) |
| 206 | self.vty.verify("periodic location update 60", [depr_str, set_str]) |
Holger Hans Peter Freyther | c63f6f1 | 2013-07-27 21:07:57 +0200 | [diff] [blame] | 207 | res = self.vty.command("write terminal") |
Vadim Yanitskiy | fc2b019 | 2020-01-18 07:20:14 +0700 | [diff] [blame] | 208 | self.assertTrue(res.find('timer vlr T3212 121') > 0) |
| 209 | self.assertEqual(res.find('periodic location update 60'), -1) |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 210 | self.assertEqual(res.find('no periodic location update'), -1) |
Holger Hans Peter Freyther | c63f6f1 | 2013-07-27 21:07:57 +0200 | [diff] [blame] | 211 | |
Vadim Yanitskiy | fc2b019 | 2020-01-18 07:20:14 +0700 | [diff] [blame] | 212 | # Now disable it (deprecated command) |
| 213 | self.vty.verify("no periodic location update", [depr_str]) |
Holger Hans Peter Freyther | c63f6f1 | 2013-07-27 21:07:57 +0200 | [diff] [blame] | 214 | res = self.vty.command("write terminal") |
Vadim Yanitskiy | fc2b019 | 2020-01-18 07:20:14 +0700 | [diff] [blame] | 215 | self.assertEqual(res.find('no periodic location update'), -1) |
| 216 | self.assertEqual(res.find('timer vlr T3212 121'), -1) |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 217 | |
Ciaby | ec6e4f8 | 2014-03-06 17:20:55 +0100 | [diff] [blame] | 218 | def testShowNetwork(self): |
| 219 | res = self.vty.command("show network") |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 220 | self.assertTrue(res.startswith('BSC is on Country Code') >= 0) |
Ciaby | ec6e4f8 | 2014-03-06 17:20:55 +0100 | [diff] [blame] | 221 | |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 222 | def ipa_handle_small(x, verbose = False): |
| 223 | s = data2str(x.recv(4)) |
Neels Hofmeyr | ba1468e | 2017-02-03 04:23:46 +0100 | [diff] [blame] | 224 | if len(s) != 4*2: |
| 225 | 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] | 226 | if "0001fe00" == s: |
| 227 | if (verbose): |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 228 | print("\tBSC <- NAT: PING?") |
Max | 3e67689 | 2016-11-16 14:55:21 +0100 | [diff] [blame] | 229 | x.send(IPA().pong()) |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 230 | elif "0001fe06" == s: |
| 231 | if (verbose): |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 232 | print("\tBSC <- NAT: IPA ID ACK") |
Max | 3e67689 | 2016-11-16 14:55:21 +0100 | [diff] [blame] | 233 | x.send(IPA().id_ack()) |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 234 | elif "0001fe00" == s: |
| 235 | if (verbose): |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 236 | print("\tBSC <- NAT: PONG!") |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 237 | else: |
| 238 | if (verbose): |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 239 | print("\tBSC <- NAT: ", s) |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 240 | |
Neels Hofmeyr | bcfee2a | 2017-02-03 16:09:17 +0100 | [diff] [blame] | 241 | def ipa_handle_resp(x, tk, verbose = False, proc=None): |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 242 | s = data2str(x.recv(38)) |
| 243 | if "0023fe040108010701020103010401050101010011" in s: |
Neels Hofmeyr | 7d17c3e | 2017-01-26 23:04:28 +0100 | [diff] [blame] | 244 | retries = 3 |
| 245 | while True: |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 246 | print("\tsending IPA identity(%s) at %s" % (tk, time.strftime("%T"))) |
Neels Hofmeyr | 7d17c3e | 2017-01-26 23:04:28 +0100 | [diff] [blame] | 247 | try: |
| 248 | x.send(IPA().id_resp(IPA().identity(name = tk.encode('utf-8')))) |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 249 | print("\tdone sending IPA identity(%s) at %s" % (tk, |
| 250 | time.strftime("%T"))) |
Neels Hofmeyr | 7d17c3e | 2017-01-26 23:04:28 +0100 | [diff] [blame] | 251 | break |
| 252 | except: |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 253 | print("\tfailed sending IPA identity at", time.strftime("%T")) |
Neels Hofmeyr | bcfee2a | 2017-02-03 16:09:17 +0100 | [diff] [blame] | 254 | if proc: |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 255 | print("\tproc.poll() = %r" % proc.poll()) |
Neels Hofmeyr | 7d17c3e | 2017-01-26 23:04:28 +0100 | [diff] [blame] | 256 | if retries < 1: |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 257 | print("\tgiving up") |
Neels Hofmeyr | 7d17c3e | 2017-01-26 23:04:28 +0100 | [diff] [blame] | 258 | raise |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 259 | print("\tretrying (%d attempts left)" % retries) |
Neels Hofmeyr | 7d17c3e | 2017-01-26 23:04:28 +0100 | [diff] [blame] | 260 | retries -= 1 |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 261 | else: |
| 262 | if (verbose): |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 263 | print("\tBSC <- NAT: ", s) |
Max | 4936448 | 2016-04-13 11:36:39 +0200 | [diff] [blame] | 264 | |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 265 | if __name__ == '__main__': |
| 266 | import argparse |
| 267 | import sys |
| 268 | |
| 269 | workdir = '.' |
| 270 | |
| 271 | parser = argparse.ArgumentParser() |
| 272 | parser.add_argument("-v", "--verbose", dest="verbose", |
| 273 | action="store_true", help="verbose mode") |
| 274 | parser.add_argument("-p", "--pythonconfpath", dest="p", |
| 275 | help="searchpath for config") |
| 276 | parser.add_argument("-w", "--workdir", dest="w", |
| 277 | help="Working directory") |
Neels Hofmeyr | 3f8a8f7 | 2017-02-28 02:43:29 +0100 | [diff] [blame] | 278 | 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] | 279 | args = parser.parse_args() |
| 280 | |
| 281 | verbose_level = 1 |
| 282 | if args.verbose: |
| 283 | verbose_level = 2 |
| 284 | |
| 285 | if args.w: |
| 286 | workdir = args.w |
| 287 | |
| 288 | if args.p: |
| 289 | confpath = args.p |
| 290 | |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 291 | print("confpath %s, workdir %s" % (confpath, workdir)) |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 292 | os.chdir(workdir) |
Oliver Smith | 6dbdf14 | 2019-12-10 13:21:11 +0100 | [diff] [blame] | 293 | print("Running tests for specific VTY commands") |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 294 | suite = unittest.TestSuite() |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 295 | suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYMSC)) |
Neels Hofmeyr | 3f8a8f7 | 2017-02-28 02:43:29 +0100 | [diff] [blame] | 296 | |
| 297 | if args.test_name: |
| 298 | osmoutil.pick_tests(suite, *args.test_name) |
| 299 | |
Neels Hofmeyr | 0a45c1e | 2016-09-28 23:48:02 +0200 | [diff] [blame] | 300 | 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] | 301 | sys.exit(len(res.errors) + len(res.failures)) |
Neels Hofmeyr | 23d37c9 | 2016-09-26 03:18:32 +0200 | [diff] [blame] | 302 | |
Neels Hofmeyr | 0867b72 | 2016-09-28 23:28:06 +0200 | [diff] [blame] | 303 | # vim: shiftwidth=4 expandtab nocin ai |