Jacob Erlbeck | 5741e1f | 2013-09-16 11:20:28 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # (C) 2013 by Jacob Erlbeck <jerlbeck@sysmocom.de> |
Holger Hans Peter Freyther | eab2a3f | 2014-03-04 17:16:58 +0100 | [diff] [blame] | 4 | # (C) 2014 by Holger Hans Peter Freyther |
Jacob Erlbeck | 5741e1f | 2013-09-16 11:20:28 +0200 | [diff] [blame] | 5 | # based on vty_test_runner.py: |
| 6 | # (C) 2013 by Katerina Barone-Adesi <kat.obsc@gmail.com> |
| 7 | # (C) 2013 by Holger Hans Peter Freyther |
| 8 | # based on bsc_control.py. |
| 9 | |
| 10 | # This program is free software: you can redistribute it and/or modify |
| 11 | # it under the terms of the GNU General Public License as published by |
| 12 | # the Free Software Foundation, either version 3 of the License, or |
| 13 | # (at your option) any later version. |
| 14 | |
| 15 | # This program is distributed in the hope that it will be useful, |
| 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | # GNU General Public License for more details. |
| 19 | |
| 20 | # You should have received a copy of the GNU General Public License |
| 21 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | |
| 23 | import os |
| 24 | import time |
| 25 | import unittest |
| 26 | import socket |
| 27 | import sys |
| 28 | import struct |
| 29 | |
| 30 | import osmopy.obscvty as obscvty |
| 31 | import osmopy.osmoutil as osmoutil |
| 32 | |
Neels Hofmeyr | 6226a36 | 2017-02-24 17:55:11 +0100 | [diff] [blame] | 33 | # to be able to find $top_srcdir/doc/... |
| 34 | confpath = os.path.join(sys.path[0], '..') |
Jacob Erlbeck | 5741e1f | 2013-09-16 11:20:28 +0200 | [diff] [blame] | 35 | verbose = False |
| 36 | |
| 37 | class TestCtrlBase(unittest.TestCase): |
| 38 | |
| 39 | def ctrl_command(self): |
| 40 | raise Exception("Needs to be implemented by a subclass") |
| 41 | |
| 42 | def ctrl_app(self): |
| 43 | raise Exception("Needs to be implemented by a subclass") |
| 44 | |
| 45 | def setUp(self): |
| 46 | osmo_ctrl_cmd = self.ctrl_command()[:] |
| 47 | config_index = osmo_ctrl_cmd.index('-c') |
| 48 | if config_index: |
| 49 | cfi = config_index + 1 |
| 50 | osmo_ctrl_cmd[cfi] = os.path.join(confpath, osmo_ctrl_cmd[cfi]) |
| 51 | |
| 52 | try: |
Jacob Erlbeck | 5741e1f | 2013-09-16 11:20:28 +0200 | [diff] [blame] | 53 | self.proc = osmoutil.popen_devnull(osmo_ctrl_cmd) |
| 54 | except OSError: |
| 55 | print >> sys.stderr, "Current directory: %s" % os.getcwd() |
| 56 | print >> sys.stderr, "Consider setting -b" |
| 57 | time.sleep(2) |
| 58 | |
| 59 | appstring = self.ctrl_app()[2] |
| 60 | appport = self.ctrl_app()[0] |
| 61 | self.connect("127.0.0.1", appport) |
| 62 | self.next_id = 1000 |
| 63 | |
| 64 | def tearDown(self): |
| 65 | self.disconnect() |
| 66 | osmoutil.end_proc(self.proc) |
| 67 | |
| 68 | def prefix_ipa_ctrl_header(self, data): |
| 69 | return struct.pack(">HBB", len(data)+1, 0xee, 0) + data |
| 70 | |
| 71 | def remove_ipa_ctrl_header(self, data): |
| 72 | if (len(data) < 4): |
| 73 | raise BaseException("Answer too short!") |
| 74 | (plen, ipa_proto, osmo_proto) = struct.unpack(">HBB", data[:4]) |
| 75 | if (plen + 3 > len(data)): |
| 76 | print "Warning: Wrong payload length (expected %i, got %i)" % (plen, len(data) - 3) |
| 77 | if (ipa_proto != 0xee or osmo_proto != 0): |
| 78 | raise BaseException("Wrong protocol in answer!") |
| 79 | |
| 80 | return data[4:plen+3], data[plen+3:] |
| 81 | |
| 82 | def disconnect(self): |
| 83 | if not (self.sock is None): |
| 84 | self.sock.close() |
| 85 | |
| 86 | def connect(self, host, port): |
| 87 | if verbose: |
| 88 | print "Connecting to host %s:%i" % (host, port) |
| 89 | |
Neels Hofmeyr | fd32c9f | 2017-02-27 02:01:37 +0100 | [diff] [blame] | 90 | retries = 30 |
| 91 | while True: |
| 92 | try: |
| 93 | sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 94 | sck.setblocking(1) |
| 95 | sck.connect((host, port)) |
| 96 | except IOError: |
| 97 | retries -= 1 |
| 98 | if retries <= 0: |
| 99 | raise |
| 100 | time.sleep(.1) |
| 101 | continue |
| 102 | break |
Jacob Erlbeck | 5741e1f | 2013-09-16 11:20:28 +0200 | [diff] [blame] | 103 | self.sock = sck |
| 104 | return sck |
| 105 | |
| 106 | def send(self, data): |
| 107 | if verbose: |
| 108 | print "Sending \"%s\"" %(data) |
| 109 | data = self.prefix_ipa_ctrl_header(data) |
| 110 | return self.sock.send(data) == len(data) |
| 111 | |
| 112 | def send_set(self, var, value, id): |
| 113 | setmsg = "SET %s %s %s" %(id, var, value) |
| 114 | return self.send(setmsg) |
| 115 | |
| 116 | def send_get(self, var, id): |
| 117 | getmsg = "GET %s %s" %(id, var) |
| 118 | return self.send(getmsg) |
| 119 | |
| 120 | def do_set(self, var, value): |
| 121 | id = self.next_id |
| 122 | self.next_id += 1 |
| 123 | self.send_set(var, value, id) |
| 124 | return self.recv_msgs()[id] |
| 125 | |
| 126 | def do_get(self, var): |
| 127 | id = self.next_id |
| 128 | self.next_id += 1 |
| 129 | self.send_get(var, id) |
| 130 | return self.recv_msgs()[id] |
| 131 | |
| 132 | def recv_msgs(self): |
| 133 | responses = {} |
| 134 | data = self.sock.recv(4096) |
| 135 | while (len(data)>0): |
| 136 | (answer, data) = self.remove_ipa_ctrl_header(data) |
| 137 | if verbose: |
| 138 | print "Got message:", answer |
| 139 | (mtype, id, msg) = answer.split(None, 2) |
| 140 | id = int(id) |
| 141 | rsp = {'mtype': mtype, 'id': id} |
| 142 | if mtype == "ERROR": |
| 143 | rsp['error'] = msg |
| 144 | else: |
Holger Hans Peter Freyther | 842137a | 2014-03-04 15:38:00 +0100 | [diff] [blame] | 145 | split = msg.split(None, 1) |
| 146 | rsp['var'] = split[0] |
| 147 | if len(split) > 1: |
| 148 | rsp['value'] = split[1] |
| 149 | else: |
| 150 | rsp['value'] = None |
Jacob Erlbeck | 5741e1f | 2013-09-16 11:20:28 +0200 | [diff] [blame] | 151 | responses[id] = rsp |
| 152 | |
| 153 | if verbose: |
| 154 | print "Decoded replies: ", responses |
| 155 | |
| 156 | return responses |
| 157 | |
| 158 | |
| 159 | class TestCtrlBSC(TestCtrlBase): |
| 160 | |
| 161 | def tearDown(self): |
| 162 | TestCtrlBase.tearDown(self) |
| 163 | os.unlink("tmp_dummy_sock") |
| 164 | |
| 165 | def ctrl_command(self): |
| 166 | return ["./src/osmo-bsc/osmo-bsc", "-r", "tmp_dummy_sock", "-c", |
| 167 | "doc/examples/osmo-bsc/osmo-bsc.cfg"] |
| 168 | |
| 169 | def ctrl_app(self): |
| 170 | return (4249, "./src/osmo-bsc/osmo-bsc", "OsmoBSC", "bsc") |
| 171 | |
| 172 | def testCtrlErrs(self): |
| 173 | r = self.do_get('invalid') |
| 174 | self.assertEquals(r['mtype'], 'ERROR') |
| 175 | self.assertEquals(r['error'], 'Command not found') |
| 176 | |
Jacob Erlbeck | 21f6d15 | 2013-09-16 11:20:29 +0200 | [diff] [blame] | 177 | r = self.do_set('rf_locked', '999') |
| 178 | self.assertEquals(r['mtype'], 'ERROR') |
| 179 | self.assertEquals(r['error'], 'Value failed verification.') |
| 180 | |
Jacob Erlbeck | 5741e1f | 2013-09-16 11:20:28 +0200 | [diff] [blame] | 181 | r = self.do_get('bts') |
| 182 | self.assertEquals(r['mtype'], 'ERROR') |
| 183 | self.assertEquals(r['error'], 'Error while parsing the index.') |
| 184 | |
| 185 | r = self.do_get('bts.999') |
| 186 | self.assertEquals(r['mtype'], 'ERROR') |
| 187 | self.assertEquals(r['error'], 'Error while resolving object') |
| 188 | |
Holger Hans Peter Freyther | ba8679d | 2014-11-10 11:41:03 +0100 | [diff] [blame] | 189 | def testBtsLac(self): |
| 190 | r = self.do_get('bts.0.location-area-code') |
| 191 | self.assertEquals(r['mtype'], 'GET_REPLY') |
| 192 | self.assertEquals(r['var'], 'bts.0.location-area-code') |
| 193 | self.assertEquals(r['value'], '1') |
| 194 | |
| 195 | r = self.do_set('bts.0.location-area-code', '23') |
| 196 | self.assertEquals(r['mtype'], 'SET_REPLY') |
| 197 | self.assertEquals(r['var'], 'bts.0.location-area-code') |
| 198 | self.assertEquals(r['value'], '23') |
| 199 | |
| 200 | r = self.do_get('bts.0.location-area-code') |
| 201 | self.assertEquals(r['mtype'], 'GET_REPLY') |
| 202 | self.assertEquals(r['var'], 'bts.0.location-area-code') |
| 203 | self.assertEquals(r['value'], '23') |
| 204 | |
| 205 | r = self.do_set('bts.0.location-area-code', '-1') |
| 206 | self.assertEquals(r['mtype'], 'ERROR') |
| 207 | self.assertEquals(r['error'], 'Input not within the range') |
| 208 | |
Holger Hans Peter Freyther | 982bb29 | 2014-11-21 10:54:42 +0100 | [diff] [blame] | 209 | def testBtsCi(self): |
| 210 | r = self.do_get('bts.0.cell-identity') |
| 211 | self.assertEquals(r['mtype'], 'GET_REPLY') |
| 212 | self.assertEquals(r['var'], 'bts.0.cell-identity') |
| 213 | self.assertEquals(r['value'], '0') |
| 214 | |
| 215 | r = self.do_set('bts.0.cell-identity', '23') |
| 216 | self.assertEquals(r['mtype'], 'SET_REPLY') |
| 217 | self.assertEquals(r['var'], 'bts.0.cell-identity') |
| 218 | self.assertEquals(r['value'], '23') |
| 219 | |
| 220 | r = self.do_get('bts.0.cell-identity') |
| 221 | self.assertEquals(r['mtype'], 'GET_REPLY') |
| 222 | self.assertEquals(r['var'], 'bts.0.cell-identity') |
| 223 | self.assertEquals(r['value'], '23') |
| 224 | |
| 225 | r = self.do_set('bts.0.cell-identity', '-1') |
| 226 | self.assertEquals(r['mtype'], 'ERROR') |
| 227 | self.assertEquals(r['error'], 'Input not within the range') |
| 228 | |
Holger Hans Peter Freyther | d0284c8 | 2014-11-21 11:18:45 +0100 | [diff] [blame] | 229 | def testBtsGenerateSystemInformation(self): |
| 230 | r = self.do_get('bts.0.send-new-system-informations') |
| 231 | self.assertEquals(r['mtype'], 'ERROR') |
Max | 78a5803 | 2017-01-11 18:37:55 +0100 | [diff] [blame] | 232 | self.assertEquals(r['error'], 'Write Only attribute') |
Holger Hans Peter Freyther | d0284c8 | 2014-11-21 11:18:45 +0100 | [diff] [blame] | 233 | |
| 234 | # No RSL links so it will fail |
| 235 | r = self.do_set('bts.0.send-new-system-informations', '1') |
| 236 | self.assertEquals(r['mtype'], 'ERROR') |
| 237 | self.assertEquals(r['error'], 'Failed to generate SI') |
| 238 | |
Holger Hans Peter Freyther | 9fe9846 | 2014-12-05 12:03:24 +0100 | [diff] [blame] | 239 | def testBtsChannelLoad(self): |
| 240 | r = self.do_set('bts.0.channel-load', '1') |
| 241 | self.assertEquals(r['mtype'], 'ERROR') |
Max | 78a5803 | 2017-01-11 18:37:55 +0100 | [diff] [blame] | 242 | self.assertEquals(r['error'], 'Read Only attribute') |
Holger Hans Peter Freyther | 9fe9846 | 2014-12-05 12:03:24 +0100 | [diff] [blame] | 243 | |
| 244 | # No RSL link so everything is 0 |
| 245 | r = self.do_get('bts.0.channel-load') |
| 246 | self.assertEquals(r['mtype'], 'GET_REPLY') |
Neels Hofmeyr | 266e7e0 | 2016-07-23 16:14:06 +0200 | [diff] [blame] | 247 | self.assertEquals(r['value'], |
| 248 | 'CCCH+SDCCH4,0,0 TCH/F,0,0 TCH/H,0,0 SDCCH8,0,0' |
| 249 | + ' TCH/F_PDCH,0,0 CCCH+SDCCH4+CBCH,0,0' |
| 250 | + ' SDCCH8+CBCH,0,0 TCH/F_TCH/H_PDCH,0,0') |
Holger Hans Peter Freyther | 9fe9846 | 2014-12-05 12:03:24 +0100 | [diff] [blame] | 251 | |
Holger Hans Peter Freyther | 0c47d9e | 2014-12-05 14:44:21 +0100 | [diff] [blame] | 252 | def testBtsOmlConnectionState(self): |
| 253 | """Check OML state. It will not be connected""" |
| 254 | r = self.do_set('bts.0.oml-connection-state', '1') |
| 255 | self.assertEquals(r['mtype'], 'ERROR') |
Max | 78a5803 | 2017-01-11 18:37:55 +0100 | [diff] [blame] | 256 | self.assertEquals(r['error'], 'Read Only attribute') |
Holger Hans Peter Freyther | 0c47d9e | 2014-12-05 14:44:21 +0100 | [diff] [blame] | 257 | |
| 258 | # No RSL link so everything is 0 |
| 259 | r = self.do_get('bts.0.oml-connection-state') |
| 260 | self.assertEquals(r['mtype'], 'GET_REPLY') |
| 261 | self.assertEquals(r['value'], 'disconnected') |
| 262 | |
Holger Hans Peter Freyther | 2de4689 | 2014-03-23 11:17:27 +0100 | [diff] [blame] | 263 | def testTrxPowerRed(self): |
| 264 | r = self.do_get('bts.0.trx.0.max-power-reduction') |
| 265 | self.assertEquals(r['mtype'], 'GET_REPLY') |
| 266 | self.assertEquals(r['var'], 'bts.0.trx.0.max-power-reduction') |
| 267 | self.assertEquals(r['value'], '20') |
| 268 | |
| 269 | r = self.do_set('bts.0.trx.0.max-power-reduction', '22') |
| 270 | self.assertEquals(r['mtype'], 'SET_REPLY') |
| 271 | self.assertEquals(r['var'], 'bts.0.trx.0.max-power-reduction') |
| 272 | self.assertEquals(r['value'], '22') |
| 273 | |
| 274 | r = self.do_get('bts.0.trx.0.max-power-reduction') |
| 275 | self.assertEquals(r['mtype'], 'GET_REPLY') |
| 276 | self.assertEquals(r['var'], 'bts.0.trx.0.max-power-reduction') |
| 277 | self.assertEquals(r['value'], '22') |
| 278 | |
| 279 | r = self.do_set('bts.0.trx.0.max-power-reduction', '1') |
| 280 | self.assertEquals(r['mtype'], 'ERROR') |
| 281 | self.assertEquals(r['error'], 'Value must be even') |
| 282 | |
Holger Hans Peter Freyther | b96705b | 2013-01-09 19:55:04 +0100 | [diff] [blame] | 283 | def testTrxArfcn(self): |
| 284 | r = self.do_get('bts.0.trx.0.arfcn') |
| 285 | self.assertEquals(r['mtype'], 'GET_REPLY') |
| 286 | self.assertEquals(r['var'], 'bts.0.trx.0.arfcn') |
| 287 | self.assertEquals(r['value'], '871') |
| 288 | |
| 289 | r = self.do_set('bts.0.trx.0.arfcn', '873') |
| 290 | self.assertEquals(r['mtype'], 'SET_REPLY') |
| 291 | self.assertEquals(r['var'], 'bts.0.trx.0.arfcn') |
| 292 | self.assertEquals(r['value'], '873') |
| 293 | |
| 294 | r = self.do_get('bts.0.trx.0.arfcn') |
| 295 | self.assertEquals(r['mtype'], 'GET_REPLY') |
| 296 | self.assertEquals(r['var'], 'bts.0.trx.0.arfcn') |
| 297 | self.assertEquals(r['value'], '873') |
| 298 | |
| 299 | r = self.do_set('bts.0.trx.0.arfcn', '2000') |
| 300 | self.assertEquals(r['mtype'], 'ERROR') |
| 301 | self.assertEquals(r['error'], 'Input not within the range') |
| 302 | |
Jacob Erlbeck | 5741e1f | 2013-09-16 11:20:28 +0200 | [diff] [blame] | 303 | def testRfLock(self): |
| 304 | r = self.do_get('bts.0.rf_state') |
| 305 | self.assertEquals(r['mtype'], 'GET_REPLY') |
| 306 | self.assertEquals(r['var'], 'bts.0.rf_state') |
| 307 | self.assertEquals(r['value'], 'inoperational,unlocked,on') |
| 308 | |
| 309 | r = self.do_set('rf_locked', '1') |
| 310 | self.assertEquals(r['mtype'], 'SET_REPLY') |
| 311 | self.assertEquals(r['var'], 'rf_locked') |
| 312 | self.assertEquals(r['value'], '1') |
| 313 | |
| 314 | time.sleep(1.5) |
| 315 | |
| 316 | r = self.do_get('bts.0.rf_state') |
| 317 | self.assertEquals(r['mtype'], 'GET_REPLY') |
| 318 | self.assertEquals(r['var'], 'bts.0.rf_state') |
| 319 | self.assertEquals(r['value'], 'inoperational,locked,off') |
| 320 | |
Holger Hans Peter Freyther | d476a80 | 2015-02-10 23:03:25 +0100 | [diff] [blame] | 321 | r = self.do_get('rf_locked') |
| 322 | self.assertEquals(r['mtype'], 'GET_REPLY') |
| 323 | self.assertEquals(r['var'], 'rf_locked') |
| 324 | self.assertEquals(r['value'], 'state=off,policy=off') |
| 325 | |
Jacob Erlbeck | 5741e1f | 2013-09-16 11:20:28 +0200 | [diff] [blame] | 326 | r = self.do_set('rf_locked', '0') |
| 327 | self.assertEquals(r['mtype'], 'SET_REPLY') |
| 328 | self.assertEquals(r['var'], 'rf_locked') |
| 329 | self.assertEquals(r['value'], '0') |
| 330 | |
| 331 | time.sleep(1.5) |
| 332 | |
| 333 | r = self.do_get('bts.0.rf_state') |
| 334 | self.assertEquals(r['mtype'], 'GET_REPLY') |
| 335 | self.assertEquals(r['var'], 'bts.0.rf_state') |
| 336 | self.assertEquals(r['value'], 'inoperational,unlocked,on') |
| 337 | |
Holger Hans Peter Freyther | d476a80 | 2015-02-10 23:03:25 +0100 | [diff] [blame] | 338 | r = self.do_get('rf_locked') |
| 339 | self.assertEquals(r['mtype'], 'GET_REPLY') |
| 340 | self.assertEquals(r['var'], 'rf_locked') |
| 341 | self.assertEquals(r['value'], 'state=off,policy=on') |
| 342 | |
Jacob Erlbeck | 64e143a | 2013-10-01 13:26:42 +0200 | [diff] [blame] | 343 | def testTimezone(self): |
Neels Hofmeyr | 21edaef | 2016-05-10 13:29:33 +0200 | [diff] [blame] | 344 | r = self.do_get('timezone') |
Jacob Erlbeck | 64e143a | 2013-10-01 13:26:42 +0200 | [diff] [blame] | 345 | self.assertEquals(r['mtype'], 'GET_REPLY') |
Neels Hofmeyr | 21edaef | 2016-05-10 13:29:33 +0200 | [diff] [blame] | 346 | self.assertEquals(r['var'], 'timezone') |
Jacob Erlbeck | 64e143a | 2013-10-01 13:26:42 +0200 | [diff] [blame] | 347 | self.assertEquals(r['value'], 'off') |
| 348 | |
Neels Hofmeyr | 21edaef | 2016-05-10 13:29:33 +0200 | [diff] [blame] | 349 | r = self.do_set('timezone', '-2,15,2') |
Jacob Erlbeck | 64e143a | 2013-10-01 13:26:42 +0200 | [diff] [blame] | 350 | self.assertEquals(r['mtype'], 'SET_REPLY') |
Neels Hofmeyr | 21edaef | 2016-05-10 13:29:33 +0200 | [diff] [blame] | 351 | self.assertEquals(r['var'], 'timezone') |
Jacob Erlbeck | 64e143a | 2013-10-01 13:26:42 +0200 | [diff] [blame] | 352 | self.assertEquals(r['value'], '-2,15,2') |
| 353 | |
Neels Hofmeyr | 21edaef | 2016-05-10 13:29:33 +0200 | [diff] [blame] | 354 | r = self.do_get('timezone') |
Jacob Erlbeck | 64e143a | 2013-10-01 13:26:42 +0200 | [diff] [blame] | 355 | self.assertEquals(r['mtype'], 'GET_REPLY') |
Neels Hofmeyr | 21edaef | 2016-05-10 13:29:33 +0200 | [diff] [blame] | 356 | self.assertEquals(r['var'], 'timezone') |
Jacob Erlbeck | 64e143a | 2013-10-01 13:26:42 +0200 | [diff] [blame] | 357 | self.assertEquals(r['value'], '-2,15,2') |
| 358 | |
| 359 | # Test invalid input |
Neels Hofmeyr | 21edaef | 2016-05-10 13:29:33 +0200 | [diff] [blame] | 360 | r = self.do_set('timezone', '-2,15,2,5,6,7') |
Jacob Erlbeck | 64e143a | 2013-10-01 13:26:42 +0200 | [diff] [blame] | 361 | self.assertEquals(r['mtype'], 'SET_REPLY') |
Neels Hofmeyr | 21edaef | 2016-05-10 13:29:33 +0200 | [diff] [blame] | 362 | self.assertEquals(r['var'], 'timezone') |
Jacob Erlbeck | 64e143a | 2013-10-01 13:26:42 +0200 | [diff] [blame] | 363 | self.assertEquals(r['value'], '-2,15,2') |
| 364 | |
Neels Hofmeyr | 21edaef | 2016-05-10 13:29:33 +0200 | [diff] [blame] | 365 | r = self.do_set('timezone', '-2,15') |
Jacob Erlbeck | 64e143a | 2013-10-01 13:26:42 +0200 | [diff] [blame] | 366 | self.assertEquals(r['mtype'], 'ERROR') |
Neels Hofmeyr | 21edaef | 2016-05-10 13:29:33 +0200 | [diff] [blame] | 367 | r = self.do_set('timezone', '-2') |
Jacob Erlbeck | 64e143a | 2013-10-01 13:26:42 +0200 | [diff] [blame] | 368 | self.assertEquals(r['mtype'], 'ERROR') |
Neels Hofmeyr | 21edaef | 2016-05-10 13:29:33 +0200 | [diff] [blame] | 369 | r = self.do_set('timezone', '1') |
Jacob Erlbeck | 64e143a | 2013-10-01 13:26:42 +0200 | [diff] [blame] | 370 | |
Neels Hofmeyr | 21edaef | 2016-05-10 13:29:33 +0200 | [diff] [blame] | 371 | r = self.do_set('timezone', 'off') |
Jacob Erlbeck | 64e143a | 2013-10-01 13:26:42 +0200 | [diff] [blame] | 372 | self.assertEquals(r['mtype'], 'SET_REPLY') |
Neels Hofmeyr | 21edaef | 2016-05-10 13:29:33 +0200 | [diff] [blame] | 373 | self.assertEquals(r['var'], 'timezone') |
Jacob Erlbeck | 64e143a | 2013-10-01 13:26:42 +0200 | [diff] [blame] | 374 | self.assertEquals(r['value'], 'off') |
| 375 | |
Neels Hofmeyr | 21edaef | 2016-05-10 13:29:33 +0200 | [diff] [blame] | 376 | r = self.do_get('timezone') |
Jacob Erlbeck | 64e143a | 2013-10-01 13:26:42 +0200 | [diff] [blame] | 377 | self.assertEquals(r['mtype'], 'GET_REPLY') |
Neels Hofmeyr | 21edaef | 2016-05-10 13:29:33 +0200 | [diff] [blame] | 378 | self.assertEquals(r['var'], 'timezone') |
Jacob Erlbeck | 64e143a | 2013-10-01 13:26:42 +0200 | [diff] [blame] | 379 | self.assertEquals(r['value'], 'off') |
| 380 | |
Holger Hans Peter Freyther | f9fe323 | 2014-04-24 10:30:05 +0200 | [diff] [blame] | 381 | def testMcc(self): |
| 382 | r = self.do_set('mcc', '23') |
| 383 | r = self.do_get('mcc') |
| 384 | self.assertEquals(r['mtype'], 'GET_REPLY') |
| 385 | self.assertEquals(r['var'], 'mcc') |
| 386 | self.assertEquals(r['value'], '23') |
| 387 | |
| 388 | r = self.do_set('mcc', '023') |
| 389 | r = self.do_get('mcc') |
| 390 | self.assertEquals(r['mtype'], 'GET_REPLY') |
| 391 | self.assertEquals(r['var'], 'mcc') |
| 392 | self.assertEquals(r['value'], '23') |
| 393 | |
| 394 | def testMnc(self): |
| 395 | r = self.do_set('mnc', '9') |
| 396 | r = self.do_get('mnc') |
| 397 | self.assertEquals(r['mtype'], 'GET_REPLY') |
| 398 | self.assertEquals(r['var'], 'mnc') |
| 399 | self.assertEquals(r['value'], '9') |
| 400 | |
| 401 | r = self.do_set('mnc', '09') |
| 402 | r = self.do_get('mnc') |
| 403 | self.assertEquals(r['mtype'], 'GET_REPLY') |
| 404 | self.assertEquals(r['var'], 'mnc') |
| 405 | self.assertEquals(r['value'], '9') |
| 406 | |
| 407 | |
Holger Hans Peter Freyther | eab2a3f | 2014-03-04 17:16:58 +0100 | [diff] [blame] | 408 | def testMccMncApply(self): |
| 409 | # Test some invalid input |
| 410 | r = self.do_set('mcc-mnc-apply', 'WRONG') |
| 411 | self.assertEquals(r['mtype'], 'ERROR') |
| 412 | |
| 413 | r = self.do_set('mcc-mnc-apply', '1,') |
| 414 | self.assertEquals(r['mtype'], 'ERROR') |
| 415 | |
| 416 | r = self.do_set('mcc-mnc-apply', '200,3') |
| 417 | self.assertEquals(r['mtype'], 'SET_REPLY') |
| 418 | self.assertEquals(r['var'], 'mcc-mnc-apply') |
| 419 | self.assertEquals(r['value'], 'Tried to drop the BTS') |
| 420 | |
| 421 | # Set it again |
| 422 | r = self.do_set('mcc-mnc-apply', '200,3') |
| 423 | self.assertEquals(r['mtype'], 'SET_REPLY') |
| 424 | self.assertEquals(r['var'], 'mcc-mnc-apply') |
| 425 | self.assertEquals(r['value'], 'Nothing changed') |
| 426 | |
| 427 | # Change it |
| 428 | r = self.do_set('mcc-mnc-apply', '200,4') |
| 429 | self.assertEquals(r['mtype'], 'SET_REPLY') |
| 430 | self.assertEquals(r['var'], 'mcc-mnc-apply') |
| 431 | self.assertEquals(r['value'], 'Tried to drop the BTS') |
| 432 | |
| 433 | # Change it |
| 434 | r = self.do_set('mcc-mnc-apply', '201,4') |
| 435 | self.assertEquals(r['mtype'], 'SET_REPLY') |
| 436 | self.assertEquals(r['var'], 'mcc-mnc-apply') |
| 437 | self.assertEquals(r['value'], 'Tried to drop the BTS') |
| 438 | |
| 439 | # Verify |
| 440 | r = self.do_get('mnc') |
| 441 | self.assertEquals(r['mtype'], 'GET_REPLY') |
| 442 | self.assertEquals(r['var'], 'mnc') |
| 443 | self.assertEquals(r['value'], '4') |
| 444 | |
| 445 | r = self.do_get('mcc') |
| 446 | self.assertEquals(r['mtype'], 'GET_REPLY') |
| 447 | self.assertEquals(r['var'], 'mcc') |
| 448 | self.assertEquals(r['value'], '201') |
| 449 | |
Holger Hans Peter Freyther | f9fe323 | 2014-04-24 10:30:05 +0200 | [diff] [blame] | 450 | # Change it |
| 451 | r = self.do_set('mcc-mnc-apply', '202,03') |
| 452 | self.assertEquals(r['mtype'], 'SET_REPLY') |
| 453 | self.assertEquals(r['var'], 'mcc-mnc-apply') |
| 454 | self.assertEquals(r['value'], 'Tried to drop the BTS') |
| 455 | |
| 456 | r = self.do_get('mnc') |
| 457 | self.assertEquals(r['mtype'], 'GET_REPLY') |
| 458 | self.assertEquals(r['var'], 'mnc') |
| 459 | self.assertEquals(r['value'], '3') |
| 460 | |
| 461 | r = self.do_get('mcc') |
| 462 | self.assertEquals(r['mtype'], 'GET_REPLY') |
| 463 | self.assertEquals(r['var'], 'mcc') |
| 464 | self.assertEquals(r['value'], '202') |
| 465 | |
Holger Hans Peter Freyther | fba0316 | 2014-03-23 12:06:36 +0100 | [diff] [blame] | 466 | class TestCtrlNITB(TestCtrlBase): |
| 467 | |
| 468 | def tearDown(self): |
| 469 | TestCtrlBase.tearDown(self) |
| 470 | os.unlink("test_hlr.sqlite3") |
| 471 | |
| 472 | def ctrl_command(self): |
| 473 | return ["./src/osmo-nitb/osmo-nitb", "-c", |
| 474 | "doc/examples/osmo-nitb/nanobts/openbsc.cfg", "-l", "test_hlr.sqlite3"] |
| 475 | |
| 476 | def ctrl_app(self): |
| 477 | return (4249, "./src/osmo-nitb/osmo-nitb", "OsmoBSC", "nitb") |
| 478 | |
Holger Hans Peter Freyther | bbd8ea1 | 2015-02-10 21:55:37 +0100 | [diff] [blame] | 479 | def testNumberOfBTS(self): |
| 480 | r = self.do_get('number-of-bts') |
| 481 | self.assertEquals(r['mtype'], 'GET_REPLY') |
| 482 | self.assertEquals(r['var'], 'number-of-bts') |
| 483 | self.assertEquals(r['value'], '1') |
| 484 | |
Holger Hans Peter Freyther | 7bd1b70 | 2016-04-06 22:41:12 +0200 | [diff] [blame] | 485 | def testSubscriberAddWithKi(self): |
| 486 | """Test that we can set the algorithm to none, xor, comp128v1""" |
| 487 | |
| 488 | r = self.do_set('subscriber-modify-v1', '2620345,445566') |
| 489 | self.assertEquals(r['mtype'], 'SET_REPLY') |
| 490 | self.assertEquals(r['var'], 'subscriber-modify-v1') |
| 491 | self.assertEquals(r['value'], 'OK') |
| 492 | |
| 493 | r = self.do_set('subscriber-modify-v1', '2620345,445566,none') |
| 494 | self.assertEquals(r['mtype'], 'SET_REPLY') |
| 495 | self.assertEquals(r['var'], 'subscriber-modify-v1') |
| 496 | self.assertEquals(r['value'], 'OK') |
| 497 | |
| 498 | r = self.do_set('subscriber-modify-v1', '2620345,445566,xor') |
| 499 | self.assertEquals(r['mtype'], 'ERROR') |
| 500 | self.assertEquals(r['error'], 'Value failed verification.') |
| 501 | |
| 502 | r = self.do_set('subscriber-modify-v1', '2620345,445566,comp128v1,00112233445566778899AABBCCDDEEFF') |
| 503 | self.assertEquals(r['mtype'], 'SET_REPLY') |
| 504 | self.assertEquals(r['var'], 'subscriber-modify-v1') |
| 505 | self.assertEquals(r['value'], 'OK') |
| 506 | |
| 507 | r = self.do_set('subscriber-modify-v1', '2620345,445566,none') |
| 508 | self.assertEquals(r['mtype'], 'SET_REPLY') |
| 509 | self.assertEquals(r['var'], 'subscriber-modify-v1') |
| 510 | self.assertEquals(r['value'], 'OK') |
| 511 | |
Holger Hans Peter Freyther | c652a5d | 2014-03-23 14:01:08 +0100 | [diff] [blame] | 512 | def testSubscriberAddRemove(self): |
Holger Hans Peter Freyther | fba0316 | 2014-03-23 12:06:36 +0100 | [diff] [blame] | 513 | r = self.do_set('subscriber-modify-v1', '2620345,445566') |
| 514 | self.assertEquals(r['mtype'], 'SET_REPLY') |
| 515 | self.assertEquals(r['var'], 'subscriber-modify-v1') |
| 516 | self.assertEquals(r['value'], 'OK') |
| 517 | |
| 518 | r = self.do_set('subscriber-modify-v1', '2620345,445567') |
| 519 | self.assertEquals(r['mtype'], 'SET_REPLY') |
| 520 | self.assertEquals(r['var'], 'subscriber-modify-v1') |
| 521 | self.assertEquals(r['value'], 'OK') |
| 522 | |
| 523 | # TODO. verify that the entry has been created and modified? Invoke |
| 524 | # the sqlite3 CLI or do it through the DB libraries? |
| 525 | |
Holger Hans Peter Freyther | c652a5d | 2014-03-23 14:01:08 +0100 | [diff] [blame] | 526 | r = self.do_set('subscriber-delete-v1', '2620345') |
| 527 | self.assertEquals(r['mtype'], 'SET_REPLY') |
| 528 | self.assertEquals(r['value'], 'Removed') |
| 529 | |
| 530 | r = self.do_set('subscriber-delete-v1', '2620345') |
| 531 | self.assertEquals(r['mtype'], 'ERROR') |
| 532 | self.assertEquals(r['error'], 'Failed to find subscriber') |
| 533 | |
Holger Hans Peter Freyther | d41b7b7 | 2014-03-23 16:22:55 +0100 | [diff] [blame] | 534 | def testSubscriberList(self): |
| 535 | # TODO. Add command to mark a subscriber as active |
| 536 | r = self.do_get('subscriber-list-active-v1') |
| 537 | self.assertEquals(r['mtype'], 'GET_REPLY') |
| 538 | self.assertEquals(r['var'], 'subscriber-list-active-v1') |
| 539 | self.assertEquals(r['value'], None) |
| 540 | |
Holger Hans Peter Freyther | 87b35d5 | 2014-11-21 10:20:29 +0100 | [diff] [blame] | 541 | def testApplyConfiguration(self): |
| 542 | r = self.do_get('bts.0.apply-configuration') |
| 543 | self.assertEquals(r['mtype'], 'ERROR') |
Max | 78a5803 | 2017-01-11 18:37:55 +0100 | [diff] [blame] | 544 | self.assertEquals(r['error'], 'Write Only attribute') |
Holger Hans Peter Freyther | 87b35d5 | 2014-11-21 10:20:29 +0100 | [diff] [blame] | 545 | |
| 546 | r = self.do_set('bts.0.apply-configuration', '1') |
| 547 | self.assertEquals(r['mtype'], 'SET_REPLY') |
| 548 | self.assertEquals(r['value'], 'Tried to drop the BTS') |
| 549 | |
Holger Hans Peter Freyther | 611f775 | 2015-01-31 22:16:00 +0100 | [diff] [blame] | 550 | def testGprsMode(self): |
| 551 | r = self.do_get('bts.0.gprs-mode') |
| 552 | self.assertEquals(r['mtype'], 'GET_REPLY') |
| 553 | self.assertEquals(r['var'], 'bts.0.gprs-mode') |
| 554 | self.assertEquals(r['value'], 'none') |
| 555 | |
| 556 | r = self.do_set('bts.0.gprs-mode', 'bla') |
| 557 | self.assertEquals(r['mtype'], 'ERROR') |
| 558 | self.assertEquals(r['error'], 'Mode is not known') |
| 559 | |
| 560 | r = self.do_set('bts.0.gprs-mode', 'egprs') |
| 561 | self.assertEquals(r['mtype'], 'SET_REPLY') |
| 562 | self.assertEquals(r['value'], 'egprs') |
| 563 | |
| 564 | r = self.do_get('bts.0.gprs-mode') |
| 565 | self.assertEquals(r['mtype'], 'GET_REPLY') |
| 566 | self.assertEquals(r['var'], 'bts.0.gprs-mode') |
| 567 | self.assertEquals(r['value'], 'egprs') |
| 568 | |
Holger Hans Peter Freyther | 842137a | 2014-03-04 15:38:00 +0100 | [diff] [blame] | 569 | class TestCtrlNAT(TestCtrlBase): |
| 570 | |
| 571 | def ctrl_command(self): |
| 572 | return ["./src/osmo-bsc_nat/osmo-bsc_nat", "-c", |
| 573 | "doc/examples/osmo-bsc_nat/osmo-bsc_nat.cfg"] |
| 574 | |
| 575 | def ctrl_app(self): |
| 576 | return (4250, "./src/osmo-bsc_nat/osmo-bsc_nat", "OsmoNAT", "nat") |
| 577 | |
| 578 | def testAccessList(self): |
| 579 | r = self.do_get('net.0.bsc_cfg.0.access-list-name') |
| 580 | self.assertEquals(r['mtype'], 'GET_REPLY') |
| 581 | self.assertEquals(r['var'], 'net') |
| 582 | self.assertEquals(r['value'], None) |
| 583 | |
| 584 | r = self.do_set('net.0.bsc_cfg.0.access-list-name', 'bla') |
| 585 | self.assertEquals(r['mtype'], 'SET_REPLY') |
| 586 | self.assertEquals(r['var'], 'net') |
| 587 | self.assertEquals(r['value'], 'bla') |
| 588 | |
| 589 | r = self.do_get('net.0.bsc_cfg.0.access-list-name') |
| 590 | self.assertEquals(r['mtype'], 'GET_REPLY') |
| 591 | self.assertEquals(r['var'], 'net') |
| 592 | self.assertEquals(r['value'], 'bla') |
| 593 | |
| 594 | r = self.do_set('net.0.bsc_cfg.0.no-access-list-name', '1') |
| 595 | self.assertEquals(r['mtype'], 'SET_REPLY') |
| 596 | self.assertEquals(r['var'], 'net') |
| 597 | self.assertEquals(r['value'], None) |
| 598 | |
Holger Hans Peter Freyther | 56ec6a7 | 2014-12-09 19:13:00 +0100 | [diff] [blame] | 599 | r = self.do_get('net.0.bsc_cfg.0.access-list-name') |
| 600 | self.assertEquals(r['mtype'], 'GET_REPLY') |
Holger Hans Peter Freyther | 842137a | 2014-03-04 15:38:00 +0100 | [diff] [blame] | 601 | self.assertEquals(r['var'], 'net') |
| 602 | self.assertEquals(r['value'], None) |
Holger Hans Peter Freyther | eab2a3f | 2014-03-04 17:16:58 +0100 | [diff] [blame] | 603 | |
Holger Hans Peter Freyther | 5bb90f5 | 2015-04-05 15:15:36 +0200 | [diff] [blame] | 604 | def testAccessListManagement(self): |
| 605 | r = self.do_set("net.0.add.allow.access-list.404", "abc") |
| 606 | self.assertEquals(r['mtype'], 'ERROR') |
| 607 | |
| 608 | r = self.do_set("net.0.add.allow.access-list.bla", "^234$") |
| 609 | self.assertEquals(r['mtype'], 'SET_REPLY') |
| 610 | self.assertEquals(r['var'], 'net.0.add.allow.access-list.bla') |
| 611 | self.assertEquals(r['value'], 'IMSI allow added to access list') |
| 612 | |
| 613 | # TODO.. find a way to actually see if this rule has been |
| 614 | # added. e.g. by implementing a get for the list. |
| 615 | |
Holger Hans Peter Freyther | e8e5ef2 | 2014-03-23 18:08:26 +0100 | [diff] [blame] | 616 | class TestCtrlSGSN(TestCtrlBase): |
| 617 | def ctrl_command(self): |
| 618 | return ["./src/gprs/osmo-sgsn", "-c", |
| 619 | "doc/examples/osmo-sgsn/osmo-sgsn.cfg"] |
| 620 | |
| 621 | def ctrl_app(self): |
| 622 | return (4251, "./src/gprs/osmo-sgsn", "OsmoSGSN", "sgsn") |
| 623 | |
| 624 | def testListSubscribers(self): |
| 625 | # TODO. Add command to mark a subscriber as active |
| 626 | r = self.do_get('subscriber-list-active-v1') |
| 627 | self.assertEquals(r['mtype'], 'GET_REPLY') |
| 628 | self.assertEquals(r['var'], 'subscriber-list-active-v1') |
| 629 | self.assertEquals(r['value'], None) |
| 630 | |
Jacob Erlbeck | 5741e1f | 2013-09-16 11:20:28 +0200 | [diff] [blame] | 631 | def add_bsc_test(suite, workdir): |
| 632 | if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc/osmo-bsc")): |
| 633 | print("Skipping the BSC test") |
| 634 | return |
| 635 | test = unittest.TestLoader().loadTestsFromTestCase(TestCtrlBSC) |
| 636 | suite.addTest(test) |
| 637 | |
Holger Hans Peter Freyther | fba0316 | 2014-03-23 12:06:36 +0100 | [diff] [blame] | 638 | def add_nitb_test(suite, workdir): |
| 639 | test = unittest.TestLoader().loadTestsFromTestCase(TestCtrlNITB) |
| 640 | suite.addTest(test) |
| 641 | |
Holger Hans Peter Freyther | 842137a | 2014-03-04 15:38:00 +0100 | [diff] [blame] | 642 | def add_nat_test(suite, workdir): |
| 643 | if not os.path.isfile(os.path.join(workdir, "src/osmo-bsc_nat/osmo-bsc_nat")): |
| 644 | print("Skipping the NAT test") |
| 645 | return |
| 646 | test = unittest.TestLoader().loadTestsFromTestCase(TestCtrlNAT) |
| 647 | suite.addTest(test) |
| 648 | |
Holger Hans Peter Freyther | e8e5ef2 | 2014-03-23 18:08:26 +0100 | [diff] [blame] | 649 | def add_sgsn_test(suite, workdir): |
| 650 | if not os.path.isfile(os.path.join(workdir, "src/gprs/osmo-sgsn")): |
| 651 | print("Skipping the SGSN test") |
| 652 | return |
| 653 | test = unittest.TestLoader().loadTestsFromTestCase(TestCtrlSGSN) |
| 654 | suite.addTest(test) |
| 655 | |
Jacob Erlbeck | 5741e1f | 2013-09-16 11:20:28 +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") |
| 669 | args = parser.parse_args() |
| 670 | |
| 671 | verbose_level = 1 |
| 672 | if args.verbose: |
| 673 | verbose_level = 2 |
| 674 | verbose = True |
| 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 control commands" |
| 685 | suite = unittest.TestSuite() |
| 686 | add_bsc_test(suite, workdir) |
Holger Hans Peter Freyther | fba0316 | 2014-03-23 12:06:36 +0100 | [diff] [blame] | 687 | add_nitb_test(suite, workdir) |
Holger Hans Peter Freyther | 842137a | 2014-03-04 15:38:00 +0100 | [diff] [blame] | 688 | add_nat_test(suite, workdir) |
Holger Hans Peter Freyther | e8e5ef2 | 2014-03-23 18:08:26 +0100 | [diff] [blame] | 689 | add_sgsn_test(suite, workdir) |
Jacob Erlbeck | 5741e1f | 2013-09-16 11:20:28 +0200 | [diff] [blame] | 690 | res = unittest.TextTestRunner(verbosity=verbose_level).run(suite) |
| 691 | sys.exit(len(res.errors) + len(res.failures)) |