2019-12-10 12:21:11 +00:00
|
|
|
#!/usr/bin/env python3
|
2013-06-24 13:47:34 +00:00
|
|
|
|
|
|
|
# (C) 2013 by Katerina Barone-Adesi <kat.obsc@gmail.com>
|
|
|
|
# (C) 2013 by Holger Hans Peter Freyther
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-11-16 13:55:21 +00:00
|
|
|
import os, sys
|
2013-06-24 13:47:34 +00:00
|
|
|
import time
|
|
|
|
import unittest
|
2013-08-14 09:10:34 +00:00
|
|
|
import socket
|
2017-02-03 15:09:17 +00:00
|
|
|
import subprocess
|
2013-06-24 13:47:34 +00:00
|
|
|
|
|
|
|
import osmopy.obscvty as obscvty
|
|
|
|
import osmopy.osmoutil as osmoutil
|
2017-11-23 15:33:33 +00:00
|
|
|
from osmopy.osmo_ipa import IPA
|
2016-11-16 13:55:21 +00:00
|
|
|
|
2017-02-24 16:55:11 +00:00
|
|
|
# to be able to find $top_srcdir/doc/...
|
|
|
|
confpath = os.path.join(sys.path[0], '..')
|
2013-06-24 13:47:34 +00:00
|
|
|
|
|
|
|
class TestVTYBase(unittest.TestCase):
|
|
|
|
|
2016-05-20 19:59:55 +00:00
|
|
|
def checkForEndAndExit(self):
|
|
|
|
res = self.vty.command("list")
|
|
|
|
#print ('looking for "exit"\n')
|
2019-12-10 12:21:11 +00:00
|
|
|
self.assertTrue(res.find(' exit\r') > 0)
|
2016-05-20 19:59:55 +00:00
|
|
|
#print 'found "exit"\nlooking for "end"\n'
|
2019-12-10 12:21:11 +00:00
|
|
|
self.assertTrue(res.find(' end\r') > 0)
|
2016-05-20 19:59:55 +00:00
|
|
|
#print 'found "end"\n'
|
|
|
|
|
2013-06-24 13:47:34 +00:00
|
|
|
def vty_command(self):
|
|
|
|
raise Exception("Needs to be implemented by a subclass")
|
|
|
|
|
|
|
|
def vty_app(self):
|
|
|
|
raise Exception("Needs to be implemented by a subclass")
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
osmo_vty_cmd = self.vty_command()[:]
|
|
|
|
config_index = osmo_vty_cmd.index('-c')
|
|
|
|
if config_index:
|
|
|
|
cfi = config_index + 1
|
|
|
|
osmo_vty_cmd[cfi] = os.path.join(confpath, osmo_vty_cmd[cfi])
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.proc = osmoutil.popen_devnull(osmo_vty_cmd)
|
|
|
|
except OSError:
|
2019-12-10 12:21:11 +00:00
|
|
|
print("Current directory: %s" % os.getcwd(), file=sys.stderr)
|
|
|
|
print("Consider setting -b", file=sys.stderr)
|
2013-06-24 13:47:34 +00:00
|
|
|
|
|
|
|
appstring = self.vty_app()[2]
|
|
|
|
appport = self.vty_app()[0]
|
|
|
|
self.vty = obscvty.VTYInteract(appstring, "127.0.0.1", appport)
|
|
|
|
|
|
|
|
def tearDown(self):
|
2017-02-24 16:54:22 +00:00
|
|
|
if self.vty:
|
|
|
|
self.vty._close_socket()
|
2013-06-24 13:47:34 +00:00
|
|
|
self.vty = None
|
|
|
|
osmoutil.end_proc(self.proc)
|
|
|
|
|
2016-05-20 19:59:55 +00:00
|
|
|
class TestVTYMSC(TestVTYBase):
|
2013-07-27 19:07:57 +00:00
|
|
|
|
|
|
|
def vty_command(self):
|
2016-05-20 19:59:55 +00:00
|
|
|
return ["./src/osmo-msc/osmo-msc", "-c",
|
|
|
|
"doc/examples/osmo-msc/osmo-msc.cfg"]
|
2013-07-27 19:07:57 +00:00
|
|
|
|
|
|
|
def vty_app(self):
|
2016-05-20 19:59:55 +00:00
|
|
|
return (4254, "./src/osmo-msc/osmo-msc", "OsmoMSC", "msc")
|
2013-07-27 19:07:57 +00:00
|
|
|
|
2016-05-20 19:59:55 +00:00
|
|
|
def testConfigNetworkTree(self, include_bsc_items=True):
|
|
|
|
self.vty.enable()
|
|
|
|
self.assertTrue(self.vty.verify("configure terminal",['']))
|
2019-12-10 12:21:11 +00:00
|
|
|
self.assertEqual(self.vty.node(), 'config')
|
2016-05-20 19:59:55 +00:00
|
|
|
self.checkForEndAndExit()
|
|
|
|
self.assertTrue(self.vty.verify("network",['']))
|
2019-12-10 12:21:11 +00:00
|
|
|
self.assertEqual(self.vty.node(), 'config-net')
|
2016-05-20 19:59:55 +00:00
|
|
|
self.checkForEndAndExit()
|
|
|
|
self.vty.command("write terminal")
|
|
|
|
self.assertTrue(self.vty.verify("exit",['']))
|
2019-12-10 12:21:11 +00:00
|
|
|
self.assertEqual(self.vty.node(), 'config')
|
2016-05-20 19:59:55 +00:00
|
|
|
self.assertTrue(self.vty.verify("exit",['']))
|
|
|
|
self.assertTrue(self.vty.node() is None)
|
2013-09-02 11:17:14 +00:00
|
|
|
|
2013-09-02 18:58:38 +00:00
|
|
|
def checkForSmpp(self):
|
|
|
|
"""SMPP is not always enabled, check if it is"""
|
|
|
|
res = self.vty.command("list")
|
|
|
|
return "smpp" in res
|
|
|
|
|
2015-07-06 14:41:30 +00:00
|
|
|
def testSmppFirst(self):
|
|
|
|
# enable the configuration
|
|
|
|
self.vty.enable()
|
|
|
|
self.vty.command("configure terminal")
|
2015-07-13 09:23:53 +00:00
|
|
|
|
|
|
|
if not self.checkForSmpp():
|
|
|
|
return
|
|
|
|
|
2015-07-06 14:41:30 +00:00
|
|
|
self.vty.command("smpp")
|
|
|
|
|
|
|
|
# check the default
|
|
|
|
res = self.vty.command("write terminal")
|
2019-12-10 12:21:11 +00:00
|
|
|
self.assertTrue(res.find(' no smpp-first') > 0)
|
2015-07-06 14:41:30 +00:00
|
|
|
|
|
|
|
self.vty.verify("smpp-first", [''])
|
|
|
|
res = self.vty.command("write terminal")
|
2019-12-10 12:21:11 +00:00
|
|
|
self.assertTrue(res.find(' smpp-first') > 0)
|
|
|
|
self.assertEqual(res.find('no smpp-first'), -1)
|
2015-07-06 14:41:30 +00:00
|
|
|
|
|
|
|
self.vty.verify("no smpp-first", [''])
|
|
|
|
res = self.vty.command("write terminal")
|
2019-12-10 12:21:11 +00:00
|
|
|
self.assertTrue(res.find('no smpp-first') > 0)
|
2015-07-06 14:41:30 +00:00
|
|
|
|
2013-09-02 11:17:14 +00:00
|
|
|
def testVtyTree(self):
|
|
|
|
self.vty.enable()
|
|
|
|
self.assertTrue(self.vty.verify("configure terminal", ['']))
|
2019-12-10 12:21:11 +00:00
|
|
|
self.assertEqual(self.vty.node(), 'config')
|
2013-10-29 08:30:31 +00:00
|
|
|
self.checkForEndAndExit()
|
2013-09-02 11:17:14 +00:00
|
|
|
self.assertTrue(self.vty.verify('mncc-int', ['']))
|
2019-12-10 12:21:11 +00:00
|
|
|
self.assertEqual(self.vty.node(), 'config-mncc-int')
|
2013-09-02 11:17:14 +00:00
|
|
|
self.checkForEndAndExit()
|
|
|
|
self.assertTrue(self.vty.verify('exit', ['']))
|
2013-09-02 18:58:38 +00:00
|
|
|
|
|
|
|
if self.checkForSmpp():
|
2019-12-10 12:21:11 +00:00
|
|
|
self.assertEqual(self.vty.node(), 'config')
|
2013-10-23 09:24:14 +00:00
|
|
|
self.assertTrue(self.vty.verify('smpp', ['']))
|
2019-12-10 12:21:11 +00:00
|
|
|
self.assertEqual(self.vty.node(), 'config-smpp')
|
2013-10-29 08:30:31 +00:00
|
|
|
self.checkForEndAndExit()
|
2013-10-23 09:24:14 +00:00
|
|
|
self.assertTrue(self.vty.verify("exit", ['']))
|
2013-09-02 18:58:38 +00:00
|
|
|
|
2019-12-10 12:21:11 +00:00
|
|
|
self.assertEqual(self.vty.node(), 'config')
|
2013-09-02 11:17:14 +00:00
|
|
|
self.assertTrue(self.vty.verify("exit", ['']))
|
|
|
|
self.assertTrue(self.vty.node() is None)
|
|
|
|
|
|
|
|
# Check searching for outer node's commands
|
|
|
|
self.vty.command("configure terminal")
|
|
|
|
self.vty.command('mncc-int')
|
2013-09-02 18:58:38 +00:00
|
|
|
|
|
|
|
if self.checkForSmpp():
|
|
|
|
self.vty.command('smpp')
|
2019-12-10 12:21:11 +00:00
|
|
|
self.assertEqual(self.vty.node(), 'config-smpp')
|
2013-09-02 18:58:38 +00:00
|
|
|
self.vty.command('mncc-int')
|
|
|
|
|
2019-12-10 12:21:11 +00:00
|
|
|
self.assertEqual(self.vty.node(), 'config-mncc-int')
|
2013-09-02 11:17:14 +00:00
|
|
|
|
2016-04-20 10:06:06 +00:00
|
|
|
def testSi2Q(self):
|
|
|
|
self.vty.enable()
|
|
|
|
self.vty.command("configure terminal")
|
|
|
|
self.vty.command("network")
|
|
|
|
self.vty.command("bts 0")
|
|
|
|
before = self.vty.command("show running-config")
|
|
|
|
self.vty.command("si2quater neighbor-list add earfcn 1911 threshold 11 2")
|
|
|
|
self.vty.command("si2quater neighbor-list add earfcn 1924 threshold 11 3")
|
|
|
|
self.vty.command("si2quater neighbor-list add earfcn 2111 threshold 11")
|
|
|
|
self.vty.command("si2quater neighbor-list del earfcn 1911")
|
|
|
|
self.vty.command("si2quater neighbor-list del earfcn 1924")
|
|
|
|
self.vty.command("si2quater neighbor-list del earfcn 2111")
|
2019-12-10 12:21:11 +00:00
|
|
|
self.assertEqual(before, self.vty.command("show running-config"))
|
2016-04-20 13:57:13 +00:00
|
|
|
self.vty.command("si2quater neighbor-list add uarfcn 1976 13 1")
|
|
|
|
self.vty.command("si2quater neighbor-list add uarfcn 1976 38 1")
|
|
|
|
self.vty.command("si2quater neighbor-list add uarfcn 1976 44 1")
|
|
|
|
self.vty.command("si2quater neighbor-list add uarfcn 1976 120 1")
|
|
|
|
self.vty.command("si2quater neighbor-list add uarfcn 1976 140 1")
|
|
|
|
self.vty.command("si2quater neighbor-list add uarfcn 1976 163 1")
|
|
|
|
self.vty.command("si2quater neighbor-list add uarfcn 1976 166 1")
|
|
|
|
self.vty.command("si2quater neighbor-list add uarfcn 1976 217 1")
|
|
|
|
self.vty.command("si2quater neighbor-list add uarfcn 1976 224 1")
|
|
|
|
self.vty.command("si2quater neighbor-list add uarfcn 1976 225 1")
|
|
|
|
self.vty.command("si2quater neighbor-list add uarfcn 1976 226 1")
|
|
|
|
self.vty.command("si2quater neighbor-list del uarfcn 1976 13")
|
|
|
|
self.vty.command("si2quater neighbor-list del uarfcn 1976 38")
|
|
|
|
self.vty.command("si2quater neighbor-list del uarfcn 1976 44")
|
|
|
|
self.vty.command("si2quater neighbor-list del uarfcn 1976 120")
|
|
|
|
self.vty.command("si2quater neighbor-list del uarfcn 1976 140")
|
|
|
|
self.vty.command("si2quater neighbor-list del uarfcn 1976 163")
|
|
|
|
self.vty.command("si2quater neighbor-list del uarfcn 1976 166")
|
|
|
|
self.vty.command("si2quater neighbor-list del uarfcn 1976 217")
|
|
|
|
self.vty.command("si2quater neighbor-list del uarfcn 1976 224")
|
|
|
|
self.vty.command("si2quater neighbor-list del uarfcn 1976 225")
|
|
|
|
self.vty.command("si2quater neighbor-list del uarfcn 1976 226")
|
2019-12-10 12:21:11 +00:00
|
|
|
self.assertEqual(before, self.vty.command("show running-config"))
|
2016-04-20 10:06:06 +00:00
|
|
|
|
2013-07-27 19:07:57 +00:00
|
|
|
def testEnableDisablePeriodicLU(self):
|
|
|
|
self.vty.enable()
|
|
|
|
self.vty.command("configure terminal")
|
|
|
|
self.vty.command("network")
|
|
|
|
self.vty.command("bts 0")
|
|
|
|
|
|
|
|
# Test invalid input
|
|
|
|
self.vty.verify("periodic location update 0", ['% Unknown command.'])
|
|
|
|
self.vty.verify("periodic location update 5", ['% Unknown command.'])
|
|
|
|
self.vty.verify("periodic location update 1531", ['% Unknown command.'])
|
|
|
|
|
2020-01-18 00:20:14 +00:00
|
|
|
depr_str = "% 'periodic location update' is now deprecated: " \
|
|
|
|
"use 'timer T3212' to change subscriber expiration timeout."
|
|
|
|
set_str = "% Setting T3212 to 121 minutes (emulating the old behaviour)."
|
|
|
|
|
|
|
|
# Enable periodic LU (deprecated command)
|
|
|
|
self.vty.verify("periodic location update 60", [depr_str, set_str])
|
2013-07-27 19:07:57 +00:00
|
|
|
res = self.vty.command("write terminal")
|
2020-01-18 00:20:14 +00:00
|
|
|
self.assertTrue(res.find('timer vlr T3212 121') > 0)
|
|
|
|
self.assertEqual(res.find('periodic location update 60'), -1)
|
2019-12-10 12:21:11 +00:00
|
|
|
self.assertEqual(res.find('no periodic location update'), -1)
|
2013-07-27 19:07:57 +00:00
|
|
|
|
2020-01-18 00:20:14 +00:00
|
|
|
# Now disable it (deprecated command)
|
|
|
|
self.vty.verify("no periodic location update", [depr_str])
|
2013-07-27 19:07:57 +00:00
|
|
|
res = self.vty.command("write terminal")
|
2020-01-18 00:20:14 +00:00
|
|
|
self.assertEqual(res.find('no periodic location update'), -1)
|
|
|
|
self.assertEqual(res.find('timer vlr T3212 121'), -1)
|
2013-06-24 13:47:34 +00:00
|
|
|
|
2014-03-06 16:20:55 +00:00
|
|
|
def testShowNetwork(self):
|
|
|
|
res = self.vty.command("show network")
|
2019-12-10 12:21:11 +00:00
|
|
|
self.assertTrue(res.startswith('BSC is on Country Code') >= 0)
|
2014-03-06 16:20:55 +00:00
|
|
|
|
2016-04-13 09:36:39 +00:00
|
|
|
def ipa_handle_small(x, verbose = False):
|
|
|
|
s = data2str(x.recv(4))
|
2017-02-03 03:23:46 +00:00
|
|
|
if len(s) != 4*2:
|
|
|
|
raise Exception("expected to receive 4 bytes, but got %d (%r)" % (len(s)/2, s))
|
2016-04-13 09:36:39 +00:00
|
|
|
if "0001fe00" == s:
|
|
|
|
if (verbose):
|
2019-12-10 12:21:11 +00:00
|
|
|
print("\tBSC <- NAT: PING?")
|
2016-11-16 13:55:21 +00:00
|
|
|
x.send(IPA().pong())
|
2016-04-13 09:36:39 +00:00
|
|
|
elif "0001fe06" == s:
|
|
|
|
if (verbose):
|
2019-12-10 12:21:11 +00:00
|
|
|
print("\tBSC <- NAT: IPA ID ACK")
|
2016-11-16 13:55:21 +00:00
|
|
|
x.send(IPA().id_ack())
|
2016-04-13 09:36:39 +00:00
|
|
|
elif "0001fe00" == s:
|
|
|
|
if (verbose):
|
2019-12-10 12:21:11 +00:00
|
|
|
print("\tBSC <- NAT: PONG!")
|
2016-04-13 09:36:39 +00:00
|
|
|
else:
|
|
|
|
if (verbose):
|
2019-12-10 12:21:11 +00:00
|
|
|
print("\tBSC <- NAT: ", s)
|
2016-04-13 09:36:39 +00:00
|
|
|
|
2017-02-03 15:09:17 +00:00
|
|
|
def ipa_handle_resp(x, tk, verbose = False, proc=None):
|
2016-04-13 09:36:39 +00:00
|
|
|
s = data2str(x.recv(38))
|
|
|
|
if "0023fe040108010701020103010401050101010011" in s:
|
2017-01-26 22:04:28 +00:00
|
|
|
retries = 3
|
|
|
|
while True:
|
2019-12-10 12:21:11 +00:00
|
|
|
print("\tsending IPA identity(%s) at %s" % (tk, time.strftime("%T")))
|
2017-01-26 22:04:28 +00:00
|
|
|
try:
|
|
|
|
x.send(IPA().id_resp(IPA().identity(name = tk.encode('utf-8'))))
|
2019-12-10 12:21:11 +00:00
|
|
|
print("\tdone sending IPA identity(%s) at %s" % (tk,
|
|
|
|
time.strftime("%T")))
|
2017-01-26 22:04:28 +00:00
|
|
|
break
|
|
|
|
except:
|
2019-12-10 12:21:11 +00:00
|
|
|
print("\tfailed sending IPA identity at", time.strftime("%T"))
|
2017-02-03 15:09:17 +00:00
|
|
|
if proc:
|
2019-12-10 12:21:11 +00:00
|
|
|
print("\tproc.poll() = %r" % proc.poll())
|
2017-01-26 22:04:28 +00:00
|
|
|
if retries < 1:
|
2019-12-10 12:21:11 +00:00
|
|
|
print("\tgiving up")
|
2017-01-26 22:04:28 +00:00
|
|
|
raise
|
2019-12-10 12:21:11 +00:00
|
|
|
print("\tretrying (%d attempts left)" % retries)
|
2017-01-26 22:04:28 +00:00
|
|
|
retries -= 1
|
2016-04-13 09:36:39 +00:00
|
|
|
else:
|
|
|
|
if (verbose):
|
2019-12-10 12:21:11 +00:00
|
|
|
print("\tBSC <- NAT: ", s)
|
2016-04-13 09:36:39 +00:00
|
|
|
|
2013-06-24 13:47:34 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
import argparse
|
|
|
|
import sys
|
|
|
|
|
|
|
|
workdir = '.'
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument("-v", "--verbose", dest="verbose",
|
|
|
|
action="store_true", help="verbose mode")
|
|
|
|
parser.add_argument("-p", "--pythonconfpath", dest="p",
|
|
|
|
help="searchpath for config")
|
|
|
|
parser.add_argument("-w", "--workdir", dest="w",
|
|
|
|
help="Working directory")
|
2017-02-28 01:43:29 +00:00
|
|
|
parser.add_argument("test_name", nargs="*", help="(parts of) test names to run, case-insensitive")
|
2013-06-24 13:47:34 +00:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
verbose_level = 1
|
|
|
|
if args.verbose:
|
|
|
|
verbose_level = 2
|
|
|
|
|
|
|
|
if args.w:
|
|
|
|
workdir = args.w
|
|
|
|
|
|
|
|
if args.p:
|
|
|
|
confpath = args.p
|
|
|
|
|
2019-12-10 12:21:11 +00:00
|
|
|
print("confpath %s, workdir %s" % (confpath, workdir))
|
2013-06-24 13:47:34 +00:00
|
|
|
os.chdir(workdir)
|
2019-12-10 12:21:11 +00:00
|
|
|
print("Running tests for specific VTY commands")
|
2013-06-24 13:47:34 +00:00
|
|
|
suite = unittest.TestSuite()
|
2016-05-20 19:59:55 +00:00
|
|
|
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYMSC))
|
2017-02-28 01:43:29 +00:00
|
|
|
|
|
|
|
if args.test_name:
|
|
|
|
osmoutil.pick_tests(suite, *args.test_name)
|
|
|
|
|
2016-09-28 21:48:02 +00:00
|
|
|
res = unittest.TextTestRunner(verbosity=verbose_level, stream=sys.stdout).run(suite)
|
2013-06-24 13:47:34 +00:00
|
|
|
sys.exit(len(res.errors) + len(res.failures))
|
2016-09-26 01:18:32 +00:00
|
|
|
|
2016-09-28 21:28:06 +00:00
|
|
|
# vim: shiftwidth=4 expandtab nocin ai
|