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 | |
| 18 | import os |
| 19 | import time |
| 20 | import unittest |
Jacob Erlbeck | 6cb2ccc | 2013-08-14 11:10:34 +0200 | [diff] [blame] | 21 | import socket |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 22 | |
| 23 | import osmopy.obscvty as obscvty |
| 24 | import osmopy.osmoutil as osmoutil |
| 25 | |
| 26 | confpath = '.' |
| 27 | |
| 28 | class TestVTYBase(unittest.TestCase): |
| 29 | |
| 30 | def vty_command(self): |
| 31 | raise Exception("Needs to be implemented by a subclass") |
| 32 | |
| 33 | def vty_app(self): |
| 34 | raise Exception("Needs to be implemented by a subclass") |
| 35 | |
| 36 | def setUp(self): |
| 37 | osmo_vty_cmd = self.vty_command()[:] |
| 38 | config_index = osmo_vty_cmd.index('-c') |
| 39 | if config_index: |
| 40 | cfi = config_index + 1 |
| 41 | osmo_vty_cmd[cfi] = os.path.join(confpath, osmo_vty_cmd[cfi]) |
| 42 | |
| 43 | try: |
| 44 | print "Launch: %s from %s" % (' '.join(osmo_vty_cmd), os.getcwd()) |
| 45 | self.proc = osmoutil.popen_devnull(osmo_vty_cmd) |
| 46 | except OSError: |
| 47 | print >> sys.stderr, "Current directory: %s" % os.getcwd() |
| 48 | print >> sys.stderr, "Consider setting -b" |
| 49 | time.sleep(1) |
| 50 | |
| 51 | appstring = self.vty_app()[2] |
| 52 | appport = self.vty_app()[0] |
| 53 | self.vty = obscvty.VTYInteract(appstring, "127.0.0.1", appport) |
| 54 | |
| 55 | def tearDown(self): |
| 56 | self.vty = None |
| 57 | osmoutil.end_proc(self.proc) |
| 58 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 59 | |
| 60 | class TestVTYGenericBSC(TestVTYBase): |
| 61 | |
| 62 | def checkForEndAndExit(self): |
| 63 | res = self.vty.command("list") |
| 64 | #print ('looking for "exit"\n') |
| 65 | self.assert_(res.find(' exit\r') > 0) |
| 66 | #print 'found "exit"\nlooking for "end"\n' |
| 67 | self.assert_(res.find(' end\r') > 0) |
| 68 | #print 'found "end"\n' |
| 69 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 70 | def _testConfigNetworkTree(self): |
| 71 | self.vty.enable() |
| 72 | self.assertTrue(self.vty.verify("configure terminal",[''])) |
| 73 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 6e919db | 2013-10-29 09:30:31 +0100 | [diff] [blame] | 74 | self.checkForEndAndExit() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 75 | self.assertTrue(self.vty.verify("network",[''])) |
| 76 | self.assertEquals(self.vty.node(), 'config-net') |
| 77 | self.checkForEndAndExit() |
| 78 | self.assertTrue(self.vty.verify("bts 0",[''])) |
| 79 | self.assertEquals(self.vty.node(), 'config-net-bts') |
| 80 | self.checkForEndAndExit() |
| 81 | self.assertTrue(self.vty.verify("trx 0",[''])) |
| 82 | self.assertEquals(self.vty.node(), 'config-net-bts-trx') |
| 83 | self.checkForEndAndExit() |
Jacob Erlbeck | 733bec8 | 2013-09-11 10:46:56 +0200 | [diff] [blame] | 84 | self.vty.command("write terminal") |
| 85 | self.assertTrue(self.vty.verify("exit",[''])) |
| 86 | self.assertEquals(self.vty.node(), 'config-net-bts') |
| 87 | self.assertTrue(self.vty.verify("exit",[''])) |
| 88 | self.assertTrue(self.vty.verify("bts 1",[''])) |
| 89 | self.assertEquals(self.vty.node(), 'config-net-bts') |
| 90 | self.checkForEndAndExit() |
| 91 | self.assertTrue(self.vty.verify("trx 1",[''])) |
| 92 | self.assertEquals(self.vty.node(), 'config-net-bts-trx') |
| 93 | self.checkForEndAndExit() |
| 94 | self.vty.command("write terminal") |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 95 | self.assertTrue(self.vty.verify("exit",[''])) |
| 96 | self.assertEquals(self.vty.node(), 'config-net-bts') |
| 97 | self.assertTrue(self.vty.verify("exit",[''])) |
| 98 | self.assertEquals(self.vty.node(), 'config-net') |
| 99 | self.assertTrue(self.vty.verify("exit",[''])) |
| 100 | self.assertEquals(self.vty.node(), 'config') |
| 101 | self.assertTrue(self.vty.verify("exit",[''])) |
| 102 | self.assertTrue(self.vty.node() is None) |
| 103 | |
| 104 | class TestVTYNITB(TestVTYGenericBSC): |
Holger Hans Peter Freyther | c63f6f1 | 2013-07-27 21:07:57 +0200 | [diff] [blame] | 105 | |
| 106 | def vty_command(self): |
| 107 | return ["./src/osmo-nitb/osmo-nitb", "-c", |
| 108 | "doc/examples/osmo-nitb/nanobts/openbsc.cfg"] |
| 109 | |
| 110 | def vty_app(self): |
| 111 | return (4242, "./src/osmo-nitb/osmo-nitb", "OpenBSC", "nitb") |
| 112 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 113 | def testConfigNetworkTree(self): |
Jacob Erlbeck | 7587727 | 2013-10-23 11:24:14 +0200 | [diff] [blame] | 114 | self._testConfigNetworkTree() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 115 | |
Holger Hans Peter Freyther | 0df1ab9 | 2013-09-02 20:58:38 +0200 | [diff] [blame] | 116 | def checkForSmpp(self): |
| 117 | """SMPP is not always enabled, check if it is""" |
| 118 | res = self.vty.command("list") |
| 119 | return "smpp" in res |
| 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", [''])) |
| 124 | self.assertEquals(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', [''])) |
| 127 | self.assertEquals(self.vty.node(), 'config-mncc-int') |
| 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(): |
| 132 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 7587727 | 2013-10-23 11:24:14 +0200 | [diff] [blame] | 133 | self.assertTrue(self.vty.verify('smpp', [''])) |
| 134 | self.assertEquals(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 | |
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 | |
| 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') |
| 148 | self.assertEquals(self.vty.node(), 'config-smpp') |
| 149 | self.vty.command('mncc-int') |
| 150 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 151 | self.assertEquals(self.vty.node(), 'config-mncc-int') |
| 152 | |
Holger Hans Peter Freyther | c63f6f1 | 2013-07-27 21:07:57 +0200 | [diff] [blame] | 153 | def testEnableDisablePeriodicLU(self): |
| 154 | self.vty.enable() |
| 155 | self.vty.command("configure terminal") |
| 156 | self.vty.command("network") |
| 157 | self.vty.command("bts 0") |
| 158 | |
| 159 | # Test invalid input |
| 160 | self.vty.verify("periodic location update 0", ['% Unknown command.']) |
| 161 | self.vty.verify("periodic location update 5", ['% Unknown command.']) |
| 162 | self.vty.verify("periodic location update 1531", ['% Unknown command.']) |
| 163 | |
| 164 | # Enable periodic lu.. |
| 165 | self.vty.verify("periodic location update 60", ['']) |
| 166 | res = self.vty.command("write terminal") |
Holger Hans Peter Freyther | c0438e3 | 2013-07-27 22:23:25 +0200 | [diff] [blame] | 167 | self.assert_(res.find('periodic location update 60') > 0) |
Holger Hans Peter Freyther | c63f6f1 | 2013-07-27 21:07:57 +0200 | [diff] [blame] | 168 | self.assertEquals(res.find('no periodic location update'), -1) |
| 169 | |
| 170 | # Now disable it.. |
| 171 | self.vty.verify("no periodic location update", ['']) |
| 172 | res = self.vty.command("write terminal") |
| 173 | self.assertEquals(res.find('periodic location update 60'), -1) |
Holger Hans Peter Freyther | c0438e3 | 2013-07-27 22:23:25 +0200 | [diff] [blame] | 174 | self.assert_(res.find('no periodic location update') > 0) |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 175 | |
Jacob Erlbeck | 65d114f | 2014-01-16 11:02:14 +0100 | [diff] [blame] | 176 | def testEnableDisableSiHacks(self): |
| 177 | self.vty.enable() |
| 178 | self.vty.command("configure terminal") |
| 179 | self.vty.command("network") |
| 180 | self.vty.command("bts 0") |
| 181 | |
| 182 | # Enable periodic lu.. |
| 183 | self.vty.verify("force-combined-si", ['']) |
| 184 | res = self.vty.command("write terminal") |
| 185 | self.assert_(res.find(' force-combined-si') > 0) |
| 186 | self.assertEquals(res.find('no force-combined-si'), -1) |
| 187 | |
| 188 | # Now disable it.. |
| 189 | self.vty.verify("no force-combined-si", ['']) |
| 190 | res = self.vty.command("write terminal") |
| 191 | self.assertEquals(res.find(' force-combined-si'), -1) |
| 192 | self.assert_(res.find('no force-combined-si') > 0) |
| 193 | |
Ivan Kluchnikov | 6792059 | 2013-09-16 13:13:04 +0400 | [diff] [blame] | 194 | def testRachAccessControlClass(self): |
| 195 | self.vty.enable() |
| 196 | self.vty.command("configure terminal") |
| 197 | self.vty.command("network") |
| 198 | self.vty.command("bts 0") |
| 199 | |
| 200 | # Test invalid input |
| 201 | self.vty.verify("rach access-control-class", ['% Command incomplete.']) |
| 202 | self.vty.verify("rach access-control-class 1", ['% Command incomplete.']) |
| 203 | self.vty.verify("rach access-control-class -1", ['% Unknown command.']) |
| 204 | self.vty.verify("rach access-control-class 10", ['% Unknown command.']) |
| 205 | self.vty.verify("rach access-control-class 16", ['% Unknown command.']) |
| 206 | |
| 207 | # Barred rach access control classes |
| 208 | for classNum in range(16): |
| 209 | if classNum != 10: |
| 210 | self.vty.verify("rach access-control-class " + str(classNum) + " barred", ['']) |
| 211 | |
| 212 | # Verify settings |
| 213 | res = self.vty.command("write terminal") |
| 214 | for classNum in range(16): |
| 215 | if classNum != 10: |
| 216 | self.assert_(res.find("rach access-control-class " + str(classNum) + " barred") > 0) |
| 217 | |
| 218 | # Allowed rach access control classes |
| 219 | for classNum in range(16): |
| 220 | if classNum != 10: |
| 221 | self.vty.verify("rach access-control-class " + str(classNum) + " allowed", ['']) |
| 222 | |
| 223 | # Verify settings |
| 224 | res = self.vty.command("write terminal") |
| 225 | for classNum in range(16): |
| 226 | if classNum != 10: |
| 227 | self.assertEquals(res.find("rach access-control-class " + str(classNum) + " barred"), -1) |
| 228 | |
Alexander Chemeris | bd6d40f | 2013-10-04 23:54:17 +0200 | [diff] [blame] | 229 | def testSubscriberCreate(self): |
| 230 | self.vty.enable() |
| 231 | |
| 232 | imsi = "204300854013739" |
| 233 | |
| 234 | # Initially we don't have this subscriber |
| 235 | self.vty.verify('show subscriber imsi '+imsi, ['% No subscriber found for imsi '+imsi]) |
| 236 | |
| 237 | # Lets create one |
| 238 | res = self.vty.command('subscriber create imsi '+imsi) |
| 239 | self.assert_(res.find(" IMSI: "+imsi) > 0) |
| 240 | |
| 241 | # Now we have it |
| 242 | res = self.vty.command('show subscriber imsi '+imsi) |
| 243 | self.assert_(res.find(" IMSI: "+imsi) > 0) |
| 244 | |
Holger Hans Peter Freyther | ec37bb2 | 2013-02-05 09:39:09 +0100 | [diff] [blame] | 245 | def testShowPagingGroup(self): |
| 246 | res = self.vty.command("show paging-group 255 1234567") |
| 247 | self.assertEqual(res, "% can't find BTS 255") |
| 248 | res = self.vty.command("show paging-group 0 1234567") |
| 249 | self.assertEquals(res, "%Paging group for IMSI 1234567 on BTS #0 is 7") |
| 250 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 251 | class TestVTYBSC(TestVTYGenericBSC): |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 252 | |
| 253 | def vty_command(self): |
| 254 | return ["./src/osmo-bsc/osmo-bsc", "-c", |
| 255 | "doc/examples/osmo-bsc/osmo-bsc.cfg"] |
| 256 | |
| 257 | def vty_app(self): |
| 258 | return (4242, "./src/osmo-bsc/osmo-bsc", "OsmoBSC", "bsc") |
| 259 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 260 | def testConfigNetworkTree(self): |
Jacob Erlbeck | 7587727 | 2013-10-23 11:24:14 +0200 | [diff] [blame] | 261 | self._testConfigNetworkTree() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 262 | |
| 263 | def testVtyTree(self): |
| 264 | self.vty.enable() |
| 265 | self.assertTrue(self.vty.verify("configure terminal", [''])) |
| 266 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 6e919db | 2013-10-29 09:30:31 +0100 | [diff] [blame] | 267 | self.checkForEndAndExit() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 268 | self.assertTrue(self.vty.verify("msc 0", [''])) |
| 269 | self.assertEquals(self.vty.node(), 'config-msc') |
Jacob Erlbeck | 0ae92a9 | 2013-09-02 13:17:16 +0200 | [diff] [blame] | 270 | self.checkForEndAndExit() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 271 | self.assertTrue(self.vty.verify("exit", [''])) |
Jacob Erlbeck | 0ae92a9 | 2013-09-02 13:17:16 +0200 | [diff] [blame] | 272 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 273 | self.assertTrue(self.vty.verify("bsc", [''])) |
| 274 | self.assertEquals(self.vty.node(), 'config-bsc') |
Jacob Erlbeck | 0ae92a9 | 2013-09-02 13:17:16 +0200 | [diff] [blame] | 275 | self.checkForEndAndExit() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 276 | self.assertTrue(self.vty.verify("exit", [''])) |
Jacob Erlbeck | 0ae92a9 | 2013-09-02 13:17:16 +0200 | [diff] [blame] | 277 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 278 | self.assertTrue(self.vty.verify("exit", [''])) |
| 279 | self.assertTrue(self.vty.node() is None) |
| 280 | |
| 281 | # Check searching for outer node's commands |
| 282 | self.vty.command("configure terminal") |
| 283 | self.vty.command('msc 0') |
| 284 | self.vty.command("bsc") |
| 285 | self.assertEquals(self.vty.node(), 'config-bsc') |
| 286 | self.vty.command("msc 0") |
| 287 | self.assertEquals(self.vty.node(), 'config-msc') |
| 288 | |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 289 | def testUssdNotificationsMsc(self): |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 290 | self.vty.enable() |
| 291 | self.vty.command("configure terminal") |
| 292 | self.vty.command("msc") |
| 293 | |
| 294 | # Test invalid input |
| 295 | self.vty.verify("bsc-msc-lost-text", ['% Command incomplete.']) |
Jacob Erlbeck | 97e139f | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 296 | self.vty.verify("bsc-welcome-text", ['% Command incomplete.']) |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 297 | self.vty.verify("bsc-grace-text", ['% Command incomplete.']) |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 298 | |
| 299 | # Enable USSD notifications |
| 300 | self.vty.verify("bsc-msc-lost-text MSC disconnected", ['']) |
Jacob Erlbeck | 97e139f | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 301 | self.vty.verify("bsc-welcome-text Hello MS", ['']) |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 302 | self.vty.verify("bsc-grace-text In grace period", ['']) |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 303 | |
| 304 | # Verify settings |
| 305 | res = self.vty.command("write terminal") |
| 306 | self.assert_(res.find('bsc-msc-lost-text MSC disconnected') > 0) |
| 307 | self.assertEquals(res.find('no bsc-msc-lost-text'), -1) |
Jacob Erlbeck | 97e139f | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 308 | self.assert_(res.find('bsc-welcome-text Hello MS') > 0) |
| 309 | self.assertEquals(res.find('no bsc-welcome-text'), -1) |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 310 | self.assert_(res.find('bsc-grace-text In grace period') > 0) |
| 311 | self.assertEquals(res.find('no bsc-grace-text'), -1) |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 312 | |
| 313 | # Now disable it.. |
| 314 | self.vty.verify("no bsc-msc-lost-text", ['']) |
Jacob Erlbeck | 97e139f | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 315 | self.vty.verify("no bsc-welcome-text", ['']) |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 316 | self.vty.verify("no bsc-grace-text", ['']) |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 317 | |
| 318 | # Verify settings |
| 319 | res = self.vty.command("write terminal") |
| 320 | self.assertEquals(res.find('bsc-msc-lost-text MSC disconnected'), -1) |
| 321 | self.assert_(res.find('no bsc-msc-lost-text') > 0) |
Jacob Erlbeck | 97e139f | 2013-08-28 10:16:55 +0200 | [diff] [blame] | 322 | self.assertEquals(res.find('bsc-welcome-text Hello MS'), -1) |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 323 | self.assert_(res.find('no bsc-welcome-text') > 0) |
| 324 | self.assertEquals(res.find('bsc-grace-text In grace period'), -1) |
| 325 | self.assert_(res.find('no bsc-grace-text') > 0) |
| 326 | |
| 327 | def testUssdNotificationsBsc(self): |
| 328 | self.vty.enable() |
| 329 | self.vty.command("configure terminal") |
| 330 | self.vty.command("bsc") |
| 331 | |
| 332 | # Test invalid input |
| 333 | self.vty.verify("missing-msc-text", ['% Command incomplete.']) |
| 334 | |
| 335 | # Enable USSD notifications |
| 336 | self.vty.verify("missing-msc-text No MSC found", ['']) |
| 337 | |
| 338 | # Verify settings |
| 339 | res = self.vty.command("write terminal") |
| 340 | self.assert_(res.find('missing-msc-text No MSC found') > 0) |
| 341 | self.assertEquals(res.find('no missing-msc-text'), -1) |
| 342 | |
| 343 | # Now disable it.. |
| 344 | self.vty.verify("no missing-msc-text", ['']) |
| 345 | |
| 346 | # Verify settings |
| 347 | res = self.vty.command("write terminal") |
| 348 | self.assertEquals(res.find('missing-msc-text No MSC found'), -1) |
| 349 | self.assert_(res.find('no missing-msc-text') > 0) |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 350 | |
Jacob Erlbeck | 946d141 | 2013-09-17 13:59:29 +0200 | [diff] [blame] | 351 | def testNetworkTimezone(self): |
| 352 | self.vty.enable() |
| 353 | self.vty.verify("configure terminal", ['']) |
| 354 | self.vty.verify("network", ['']) |
| 355 | self.vty.verify("bts 0", ['']) |
| 356 | |
| 357 | # Test invalid input |
| 358 | self.vty.verify("timezone", ['% Command incomplete.']) |
| 359 | self.vty.verify("timezone 20 0", ['% Unknown command.']) |
| 360 | self.vty.verify("timezone 0 11", ['% Unknown command.']) |
| 361 | self.vty.verify("timezone 0 0 99", ['% Unknown command.']) |
| 362 | |
| 363 | # Set time zone without DST |
| 364 | self.vty.verify("timezone 2 30", ['']) |
| 365 | |
| 366 | # Verify settings |
| 367 | res = self.vty.command("write terminal") |
| 368 | self.assert_(res.find('timezone 2 30') > 0) |
| 369 | self.assertEquals(res.find('timezone 2 30 '), -1) |
| 370 | |
| 371 | # Set time zone with DST |
| 372 | self.vty.verify("timezone 2 30 1", ['']) |
| 373 | |
| 374 | # Verify settings |
| 375 | res = self.vty.command("write terminal") |
| 376 | self.assert_(res.find('timezone 2 30 1') > 0) |
| 377 | |
| 378 | # Now disable it.. |
| 379 | self.vty.verify("no timezone", ['']) |
| 380 | |
| 381 | # Verify settings |
| 382 | res = self.vty.command("write terminal") |
| 383 | self.assertEquals(res.find(' timezone'), -1) |
| 384 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 385 | class TestVTYNAT(TestVTYGenericBSC): |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 386 | |
| 387 | def vty_command(self): |
| 388 | return ["./src/osmo-bsc_nat/osmo-bsc_nat", "-c", |
| 389 | "doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg"] |
| 390 | |
| 391 | def vty_app(self): |
| 392 | return (4244, "src/osmo-bsc_nat/osmo-bsc_nat", "OsmoBSCNAT", "nat") |
| 393 | |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 394 | def testVtyTree(self): |
| 395 | self.vty.enable() |
| 396 | self.assertTrue(self.vty.verify('configure terminal', [''])) |
| 397 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 6e919db | 2013-10-29 09:30:31 +0100 | [diff] [blame] | 398 | self.checkForEndAndExit() |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 399 | self.assertTrue(self.vty.verify('mgcp', [''])) |
| 400 | self.assertEquals(self.vty.node(), 'config-mgcp') |
| 401 | self.checkForEndAndExit() |
| 402 | self.assertTrue(self.vty.verify('exit', [''])) |
| 403 | self.assertEquals(self.vty.node(), 'config') |
| 404 | self.assertTrue(self.vty.verify('nat', [''])) |
| 405 | self.assertEquals(self.vty.node(), 'config-nat') |
| 406 | self.checkForEndAndExit() |
| 407 | self.assertTrue(self.vty.verify('bsc 0', [''])) |
| 408 | self.assertEquals(self.vty.node(), 'config-nat-bsc') |
| 409 | self.checkForEndAndExit() |
| 410 | self.assertTrue(self.vty.verify('exit', [''])) |
| 411 | self.assertEquals(self.vty.node(), 'config-nat') |
| 412 | self.assertTrue(self.vty.verify('exit', [''])) |
| 413 | self.assertEquals(self.vty.node(), 'config') |
| 414 | self.assertTrue(self.vty.verify('exit', [''])) |
| 415 | self.assertTrue(self.vty.node() is None) |
| 416 | |
| 417 | # Check searching for outer node's commands |
| 418 | self.vty.command('configure terminal') |
| 419 | self.vty.command('mgcp') |
| 420 | self.vty.command('nat') |
| 421 | self.assertEquals(self.vty.node(), 'config-nat') |
Jacob Erlbeck | 4c9dff5 | 2013-09-02 13:17:17 +0200 | [diff] [blame] | 422 | self.vty.command('mgcp') |
| 423 | self.assertEquals(self.vty.node(), 'config-mgcp') |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 424 | self.vty.command('nat') |
| 425 | self.assertEquals(self.vty.node(), 'config-nat') |
| 426 | self.vty.command('bsc 0') |
Jacob Erlbeck | 4c9dff5 | 2013-09-02 13:17:17 +0200 | [diff] [blame] | 427 | self.vty.command('mgcp') |
| 428 | self.assertEquals(self.vty.node(), 'config-mgcp') |
Jacob Erlbeck | 96903c4 | 2013-09-02 13:17:14 +0200 | [diff] [blame] | 429 | |
Holger Hans Peter Freyther | b718ad3 | 2013-06-25 09:08:02 +0200 | [diff] [blame] | 430 | def testRewriteNoRewrite(self): |
| 431 | self.vty.enable() |
| 432 | res = self.vty.command("configure terminal") |
| 433 | res = self.vty.command("nat") |
| 434 | res = self.vty.command("number-rewrite rewrite.cfg") |
| 435 | res = self.vty.command("no number-rewrite") |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 436 | |
Holger Hans Peter Freyther | 67e423c | 2013-06-25 15:38:31 +0200 | [diff] [blame] | 437 | def testRewritePostNoRewrite(self): |
| 438 | self.vty.enable() |
| 439 | self.vty.command("configure terminal") |
| 440 | self.vty.command("nat") |
| 441 | self.vty.verify("number-rewrite-post rewrite.cfg", ['']) |
| 442 | self.vty.verify("no number-rewrite-post", ['']) |
| 443 | |
| 444 | |
Holger Hans Peter Freyther | ddf191e | 2013-06-25 11:44:01 +0200 | [diff] [blame] | 445 | def testPrefixTreeLoading(self): |
| 446 | cfg = os.path.join(confpath, "tests/bsc-nat-trie/prefixes.csv") |
| 447 | |
| 448 | self.vty.enable() |
| 449 | self.vty.command("configure terminal") |
| 450 | self.vty.command("nat") |
| 451 | res = self.vty.command("prefix-tree %s" % cfg) |
| 452 | self.assertEqual(res, "% prefix-tree loaded 17 rules.") |
| 453 | self.vty.command("end") |
| 454 | |
| 455 | res = self.vty.command("show prefix-tree") |
| 456 | 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') |
| 457 | |
| 458 | self.vty.command("configure terminal") |
| 459 | self.vty.command("nat") |
| 460 | self.vty.command("no prefix-tree") |
| 461 | self.vty.command("end") |
| 462 | |
| 463 | res = self.vty.command("show prefix-tree") |
| 464 | self.assertEqual(res, "% there is now prefix tree loaded.") |
| 465 | |
Jacob Erlbeck | 6cb2ccc | 2013-08-14 11:10:34 +0200 | [diff] [blame] | 466 | def testUssdSideChannelProvider(self): |
| 467 | self.vty.command("end") |
| 468 | self.vty.enable() |
| 469 | self.vty.command("configure terminal") |
| 470 | self.vty.command("nat") |
| 471 | self.vty.command("ussd-token key") |
| 472 | self.vty.command("end") |
| 473 | |
| 474 | res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.']) |
| 475 | self.assertTrue(res) |
| 476 | |
| 477 | ussdSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 478 | ussdSocket.connect(('127.0.0.1', 5001)) |
| 479 | ussdSocket.settimeout(2.0) |
| 480 | print "Connected to %s:%d" % ussdSocket.getpeername() |
| 481 | |
| 482 | print "Expecting ID_GET request" |
| 483 | data = ussdSocket.recv(4) |
| 484 | self.assertEqual(data, "\x00\x01\xfe\x04") |
| 485 | |
| 486 | print "Going to send ID_RESP response" |
| 487 | res = ussdSocket.send("\x00\x07\xfe\x05\x00\x04\x01\x6b\x65\x79") |
| 488 | self.assertEqual(res, 10) |
| 489 | |
| 490 | # initiating PING/PONG cycle to know, that the ID_RESP message has been processed |
| 491 | |
| 492 | print "Going to send PING request" |
| 493 | res = ussdSocket.send("\x00\x01\xfe\x00") |
| 494 | self.assertEqual(res, 4) |
| 495 | |
| 496 | print "Expecting PONG response" |
| 497 | data = ussdSocket.recv(4) |
| 498 | self.assertEqual(data, "\x00\x01\xfe\x01") |
| 499 | |
| 500 | res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is connected and authorized.']) |
| 501 | self.assertTrue(res) |
| 502 | |
| 503 | print "Going to shut down connection" |
| 504 | ussdSocket.shutdown(socket.SHUT_WR) |
| 505 | |
| 506 | print "Expecting EOF" |
| 507 | data = ussdSocket.recv(4) |
| 508 | self.assertEqual(data, "") |
| 509 | |
| 510 | ussdSocket.close() |
| 511 | |
| 512 | res = self.vty.verify("show ussd-connection", ['The USSD side channel provider is not connected and not authorized.']) |
| 513 | self.assertTrue(res) |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 514 | |
Jacob Erlbeck | 6d23371 | 2013-10-23 11:24:15 +0200 | [diff] [blame] | 515 | class TestVTYGbproxy(TestVTYGenericBSC): |
| 516 | |
| 517 | def vty_command(self): |
| 518 | return ["./src/gprs/osmo-gbproxy", "-c", |
| 519 | "doc/examples/osmo-gbproxy/osmo-gbproxy.cfg"] |
| 520 | |
| 521 | def vty_app(self): |
| 522 | return (4246, "./src/gprs/osmo-gbproxy", "OsmoGbProxy", "bsc") |
| 523 | |
| 524 | def testVtyTree(self): |
| 525 | self.vty.enable() |
| 526 | self.assertTrue(self.vty.verify('configure terminal', [''])) |
| 527 | self.assertEquals(self.vty.node(), 'config') |
Jacob Erlbeck | 6e919db | 2013-10-29 09:30:31 +0100 | [diff] [blame] | 528 | self.checkForEndAndExit() |
Jacob Erlbeck | 6d23371 | 2013-10-23 11:24:15 +0200 | [diff] [blame] | 529 | self.assertTrue(self.vty.verify('ns', [''])) |
| 530 | self.assertEquals(self.vty.node(), 'config-ns') |
| 531 | self.checkForEndAndExit() |
| 532 | self.assertTrue(self.vty.verify('exit', [''])) |
| 533 | self.assertEquals(self.vty.node(), 'config') |
| 534 | self.assertTrue(self.vty.verify('gbproxy', [''])) |
| 535 | self.assertEquals(self.vty.node(), 'config-gbproxy') |
| 536 | self.checkForEndAndExit() |
| 537 | self.assertTrue(self.vty.verify('exit', [''])) |
| 538 | self.assertEquals(self.vty.node(), 'config') |
| 539 | |
| 540 | def testVtyShow(self): |
| 541 | res = self.vty.command("show ns") |
| 542 | self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0) |
| 543 | |
| 544 | res = self.vty.command("show gbproxy stats") |
| 545 | self.assert_(res.find('GBProxy Global Statistics') >= 0) |
| 546 | |
Jacob Erlbeck | 4211d79 | 2013-10-24 12:48:23 +0200 | [diff] [blame] | 547 | def testVtyDeletePeer(self): |
| 548 | self.vty.enable() |
| 549 | self.assertTrue(self.vty.verify('delete-gbproxy-peer 9999 bvci 7777', ['BVC not found'])) |
| 550 | res = self.vty.command("delete-gbproxy-peer 9999 all dry-run") |
| 551 | self.assert_(res.find('Not Deleted 0 BVC') >= 0) |
| 552 | self.assert_(res.find('Not Deleted 0 NS-VC') >= 0) |
| 553 | res = self.vty.command("delete-gbproxy-peer 9999 only-bvc dry-run") |
| 554 | self.assert_(res.find('Not Deleted 0 BVC') >= 0) |
| 555 | self.assert_(res.find('Not Deleted 0 NS-VC') < 0) |
| 556 | res = self.vty.command("delete-gbproxy-peer 9999 only-nsvc dry-run") |
| 557 | self.assert_(res.find('Not Deleted 0 BVC') < 0) |
| 558 | self.assert_(res.find('Not Deleted 0 NS-VC') >= 0) |
| 559 | res = self.vty.command("delete-gbproxy-peer 9999 all") |
| 560 | self.assert_(res.find('Deleted 0 BVC') >= 0) |
| 561 | self.assert_(res.find('Deleted 0 NS-VC') >= 0) |
| 562 | |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 563 | def add_nat_test(suite, workdir): |
| 564 | if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")): |
| 565 | print("Skipping the NAT test") |
| 566 | return |
| 567 | test = unittest.TestLoader().loadTestsFromTestCase(TestVTYNAT) |
| 568 | suite.addTest(test) |
| 569 | |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 570 | def add_bsc_test(suite, workdir): |
| 571 | if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")): |
| 572 | print("Skipping the BSC test") |
| 573 | return |
| 574 | test = unittest.TestLoader().loadTestsFromTestCase(TestVTYBSC) |
| 575 | suite.addTest(test) |
| 576 | |
Jacob Erlbeck | 6d23371 | 2013-10-23 11:24:15 +0200 | [diff] [blame] | 577 | def add_gbproxy_test(suite, workdir): |
| 578 | if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-gbproxy")): |
| 579 | print("Skipping the Gb-Proxy test") |
| 580 | return |
| 581 | test = unittest.TestLoader().loadTestsFromTestCase(TestVTYGbproxy) |
| 582 | suite.addTest(test) |
| 583 | |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 584 | if __name__ == '__main__': |
| 585 | import argparse |
| 586 | import sys |
| 587 | |
| 588 | workdir = '.' |
| 589 | |
| 590 | parser = argparse.ArgumentParser() |
| 591 | parser.add_argument("-v", "--verbose", dest="verbose", |
| 592 | action="store_true", help="verbose mode") |
| 593 | parser.add_argument("-p", "--pythonconfpath", dest="p", |
| 594 | help="searchpath for config") |
| 595 | parser.add_argument("-w", "--workdir", dest="w", |
| 596 | help="Working directory") |
| 597 | args = parser.parse_args() |
| 598 | |
| 599 | verbose_level = 1 |
| 600 | if args.verbose: |
| 601 | verbose_level = 2 |
| 602 | |
| 603 | if args.w: |
| 604 | workdir = args.w |
| 605 | |
| 606 | if args.p: |
| 607 | confpath = args.p |
| 608 | |
| 609 | print "confpath %s, workdir %s" % (confpath, workdir) |
| 610 | os.chdir(workdir) |
| 611 | print "Running tests for specific VTY commands" |
| 612 | suite = unittest.TestSuite() |
Holger Hans Peter Freyther | c63f6f1 | 2013-07-27 21:07:57 +0200 | [diff] [blame] | 613 | suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYNITB)) |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 614 | add_bsc_test(suite, workdir) |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 615 | add_nat_test(suite, workdir) |
Jacob Erlbeck | 6d23371 | 2013-10-23 11:24:15 +0200 | [diff] [blame] | 616 | add_gbproxy_test(suite, workdir) |
Holger Hans Peter Freyther | eb0acb6 | 2013-06-24 15:47:34 +0200 | [diff] [blame] | 617 | res = unittest.TextTestRunner(verbosity=verbose_level).run(suite) |
| 618 | sys.exit(len(res.errors) + len(res.failures)) |