aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Smith <osmith@sysmocom.de>2019-12-10 13:07:27 +0100
committerOliver Smith <osmith@sysmocom.de>2019-12-11 09:41:27 +0100
commit5997357c69ede30599a20be19ba35f0790ef57da (patch)
treee310f1c040f2a595fafceb77d0b5d307f3551aae
parentde67c001b78dfc08e8baa4b8e0ab7fe9ca1170b7 (diff)
osmoappdesc.py, tests: switch to python 3HEADosmith/fix-python3master
Make build and external tests work with python3, so we can drop the python2 dependency. This should be merged shortly after osmo-python-tests was migrated to python3, and the jenkins build slaves were (automatically) updated to have the new osmo-python-tests installed. Related: OS#2819 Depends: osmo-python-tests I3ffc3519bf6c22536a49dad7a966188ddad351a7 Change-Id: I8c07d99c1bc9f0383e4bce17544e0998998cc54d
-rw-r--r--osmoappdesc.py2
-rwxr-xr-xtests/ctrl_test_runner.py26
-rwxr-xr-xtests/vty_test_runner.py136
3 files changed, 82 insertions, 82 deletions
diff --git a/osmoappdesc.py b/osmoappdesc.py
index 08166a90..e91043f9 100644
--- a/osmoappdesc.py
+++ b/osmoappdesc.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# (C) 2013 by Katerina Barone-Adesi <kat.obsc@gmail.com>
# This program is free software: you can redistribute it and/or modify
diff --git a/tests/ctrl_test_runner.py b/tests/ctrl_test_runner.py
index 9c253fc6..69b24781 100755
--- a/tests/ctrl_test_runner.py
+++ b/tests/ctrl_test_runner.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
# (C) 2013 by Jacob Erlbeck <jerlbeck@sysmocom.de>
# (C) 2014 by Holger Hans Peter Freyther
@@ -53,8 +53,8 @@ class TestCtrlBase(unittest.TestCase):
try:
self.proc = osmoutil.popen_devnull(osmo_ctrl_cmd)
except OSError:
- print >> sys.stderr, "Current directory: %s" % os.getcwd()
- print >> sys.stderr, "Consider setting -b"
+ print("Current directory: %s" % os.getcwd(), file=sys.stderr)
+ print("Consider setting -b", file=sys.stderr)
time.sleep(2)
appstring = self.ctrl_app()[2]
@@ -72,7 +72,7 @@ class TestCtrlBase(unittest.TestCase):
def connect(self, host, port):
if verbose:
- print "Connecting to host %s:%i" % (host, port)
+ print("Connecting to host %s:%i" % (host, port))
retries = 30
while True:
@@ -92,7 +92,7 @@ class TestCtrlBase(unittest.TestCase):
def send(self, data):
if verbose:
- print "Sending \"%s\"" %(data)
+ print("Sending \"%s\"" %(data))
data = Ctrl().add_header(data)
return self.sock.send(data) == len(data)
@@ -121,9 +121,9 @@ class TestCtrlBase(unittest.TestCase):
data = self.sock.recv(4096)
while (len(data)>0):
(head, data) = IPA().split_combined(data)
- answer = Ctrl().rem_header(head)
+ answer = Ctrl().rem_header(head).decode()
if verbose:
- print "Got message:", answer
+ print("Got message:", answer)
(mtype, id, msg) = answer.split(None, 2)
id = int(id)
rsp = {'mtype': mtype, 'id': id}
@@ -139,7 +139,7 @@ class TestCtrlBase(unittest.TestCase):
responses[id] = rsp
if verbose:
- print "Decoded replies: ", responses
+ print("Decoded replies: ", responses)
return responses
@@ -154,9 +154,9 @@ class TestCtrlSGSN(TestCtrlBase):
def testListSubscribers(self):
# TODO. Add command to mark a subscriber as active
r = self.do_get('subscriber-list-active-v1')
- self.assertEquals(r['mtype'], 'GET_REPLY')
- self.assertEquals(r['var'], 'subscriber-list-active-v1')
- self.assertEquals(r['value'], None)
+ self.assertEqual(r['mtype'], 'GET_REPLY')
+ self.assertEqual(r['var'], 'subscriber-list-active-v1')
+ self.assertEqual(r['value'], None)
def add_sgsn_test(suite, workdir):
if not os.path.isfile(os.path.join(workdir, "src/sgsn/osmo-sgsn")):
@@ -191,9 +191,9 @@ if __name__ == '__main__':
if args.p:
confpath = args.p
- print "confpath %s, workdir %s" % (confpath, workdir)
+ print("confpath %s, workdir %s" % (confpath, workdir))
os.chdir(workdir)
- print "Running tests for specific control commands"
+ print("Running tests for specific control commands")
suite = unittest.TestSuite()
add_sgsn_test(suite, workdir)
res = unittest.TextTestRunner(verbosity=verbose_level).run(suite)
diff --git a/tests/vty_test_runner.py b/tests/vty_test_runner.py
index a925b6b6..ed52d5f9 100755
--- a/tests/vty_test_runner.py
+++ b/tests/vty_test_runner.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
# (C) 2013 by Katerina Barone-Adesi <kat.obsc@gmail.com>
# (C) 2013 by Holger Hans Peter Freyther
@@ -33,9 +33,9 @@ class TestVTYBase(unittest.TestCase):
def checkForEndAndExit(self):
res = self.vty.command("list")
#print ('looking for "exit"\n')
- self.assert_(res.find(' exit\r') > 0)
+ self.assertTrue(res.find(' exit\r') > 0)
#print 'found "exit"\nlooking for "end"\n'
- self.assert_(res.find(' end\r') > 0)
+ self.assertTrue(res.find(' end\r') > 0)
#print 'found "end"\n'
def vty_command(self):
@@ -54,8 +54,8 @@ class TestVTYBase(unittest.TestCase):
try:
self.proc = osmoutil.popen_devnull(osmo_vty_cmd)
except OSError:
- print >> sys.stderr, "Current directory: %s" % os.getcwd()
- print >> sys.stderr, "Consider setting -b"
+ print("Current directory: %s" % os.getcwd(), file=sys.stderr)
+ print("Consider setting -b", file=sys.stderr)
appstring = self.vty_app()[2]
appport = self.vty_app()[0]
@@ -80,41 +80,41 @@ class TestVTYGbproxy(TestVTYBase):
def testVtyTree(self):
self.vty.enable()
self.assertTrue(self.vty.verify('configure terminal', ['']))
- self.assertEquals(self.vty.node(), 'config')
+ self.assertEqual(self.vty.node(), 'config')
self.checkForEndAndExit()
self.assertTrue(self.vty.verify('ns', ['']))
- self.assertEquals(self.vty.node(), 'config-ns')
+ self.assertEqual(self.vty.node(), 'config-ns')
self.checkForEndAndExit()
self.assertTrue(self.vty.verify('exit', ['']))
- self.assertEquals(self.vty.node(), 'config')
+ self.assertEqual(self.vty.node(), 'config')
self.assertTrue(self.vty.verify('gbproxy', ['']))
- self.assertEquals(self.vty.node(), 'config-gbproxy')
+ self.assertEqual(self.vty.node(), 'config-gbproxy')
self.checkForEndAndExit()
self.assertTrue(self.vty.verify('exit', ['']))
- self.assertEquals(self.vty.node(), 'config')
+ self.assertEqual(self.vty.node(), 'config')
def testVtyShow(self):
res = self.vty.command("show ns")
- self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
+ self.assertTrue(res.find('Encapsulation NS-UDP-IP') >= 0)
res = self.vty.command("show gbproxy stats")
- self.assert_(res.find('GBProxy Global Statistics') >= 0)
+ self.assertTrue(res.find('GBProxy Global Statistics') >= 0)
def testVtyDeletePeer(self):
self.vty.enable()
self.assertTrue(self.vty.verify('delete-gbproxy-peer 9999 bvci 7777', ['BVC not found']))
res = self.vty.command("delete-gbproxy-peer 9999 all dry-run")
- self.assert_(res.find('Not Deleted 0 BVC') >= 0)
- self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
+ self.assertTrue(res.find('Not Deleted 0 BVC') >= 0)
+ self.assertTrue(res.find('Not Deleted 0 NS-VC') >= 0)
res = self.vty.command("delete-gbproxy-peer 9999 only-bvc dry-run")
- self.assert_(res.find('Not Deleted 0 BVC') >= 0)
- self.assert_(res.find('Not Deleted 0 NS-VC') < 0)
+ self.assertTrue(res.find('Not Deleted 0 BVC') >= 0)
+ self.assertTrue(res.find('Not Deleted 0 NS-VC') < 0)
res = self.vty.command("delete-gbproxy-peer 9999 only-nsvc dry-run")
- self.assert_(res.find('Not Deleted 0 BVC') < 0)
- self.assert_(res.find('Not Deleted 0 NS-VC') >= 0)
+ self.assertTrue(res.find('Not Deleted 0 BVC') < 0)
+ self.assertTrue(res.find('Not Deleted 0 NS-VC') >= 0)
res = self.vty.command("delete-gbproxy-peer 9999 all")
- self.assert_(res.find('Deleted 0 BVC') >= 0)
- self.assert_(res.find('Deleted 0 NS-VC') >= 0)
+ self.assertTrue(res.find('Deleted 0 BVC') >= 0)
+ self.assertTrue(res.find('Deleted 0 NS-VC') >= 0)
class TestVTYSGSN(TestVTYBase):
@@ -128,22 +128,22 @@ class TestVTYSGSN(TestVTYBase):
def testVtyTree(self):
self.vty.enable()
self.assertTrue(self.vty.verify('configure terminal', ['']))
- self.assertEquals(self.vty.node(), 'config')
+ self.assertEqual(self.vty.node(), 'config')
self.checkForEndAndExit()
self.assertTrue(self.vty.verify('ns', ['']))
- self.assertEquals(self.vty.node(), 'config-ns')
+ self.assertEqual(self.vty.node(), 'config-ns')
self.checkForEndAndExit()
self.assertTrue(self.vty.verify('exit', ['']))
- self.assertEquals(self.vty.node(), 'config')
+ self.assertEqual(self.vty.node(), 'config')
self.assertTrue(self.vty.verify('sgsn', ['']))
- self.assertEquals(self.vty.node(), 'config-sgsn')
+ self.assertEqual(self.vty.node(), 'config-sgsn')
self.checkForEndAndExit()
self.assertTrue(self.vty.verify('exit', ['']))
- self.assertEquals(self.vty.node(), 'config')
+ self.assertEqual(self.vty.node(), 'config')
def testVtyShow(self):
res = self.vty.command("show ns")
- self.assert_(res.find('Encapsulation NS-UDP-IP') >= 0)
+ self.assertTrue(res.find('Encapsulation NS-UDP-IP') >= 0)
self.assertTrue(self.vty.verify('show bssgp', ['']))
self.assertTrue(self.vty.verify('show bssgp stats', ['']))
self.assertTrue(self.vty.verify('show bssgp nsei 123', ['']))
@@ -154,57 +154,57 @@ class TestVTYSGSN(TestVTYBase):
self.assertTrue(self.vty.verify('show pdp-context all', ['']))
res = self.vty.command("show sndcp")
- self.assert_(res.find('State of SNDCP Entities') >= 0)
+ self.assertTrue(res.find('State of SNDCP Entities') >= 0)
res = self.vty.command("show llc")
- self.assert_(res.find('State of LLC Entities') >= 0)
+ self.assertTrue(res.find('State of LLC Entities') >= 0)
def testVtyAuth(self):
self.vty.enable()
self.assertTrue(self.vty.verify('configure terminal', ['']))
- self.assertEquals(self.vty.node(), 'config')
+ self.assertEqual(self.vty.node(), 'config')
self.assertTrue(self.vty.verify('sgsn', ['']))
- self.assertEquals(self.vty.node(), 'config-sgsn')
+ self.assertEqual(self.vty.node(), 'config-sgsn')
self.assertTrue(self.vty.verify('auth-policy accept-all', ['']))
res = self.vty.command("show running-config")
- self.assert_(res.find('auth-policy accept-all') > 0)
+ self.assertTrue(res.find('auth-policy accept-all') > 0)
self.assertTrue(self.vty.verify('auth-policy acl-only', ['']))
res = self.vty.command("show running-config")
- self.assert_(res.find('auth-policy acl-only') > 0)
+ self.assertTrue(res.find('auth-policy acl-only') > 0)
self.assertTrue(self.vty.verify('auth-policy closed', ['']))
res = self.vty.command("show running-config")
- self.assert_(res.find('auth-policy closed') > 0)
+ self.assertTrue(res.find('auth-policy closed') > 0)
self.assertTrue(self.vty.verify('gsup remote-ip 127.0.0.4', ['']))
self.assertTrue(self.vty.verify('gsup remote-port 2222', ['']))
self.assertTrue(self.vty.verify('auth-policy remote', ['']))
res = self.vty.command("show running-config")
- self.assert_(res.find('auth-policy remote') > 0)
+ self.assertTrue(res.find('auth-policy remote') > 0)
def testVtySubscriber(self):
self.vty.enable()
res = self.vty.command('show subscriber cache')
- self.assert_(res.find('1234567890') < 0)
+ self.assertTrue(res.find('1234567890') < 0)
self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 create', ['']))
res = self.vty.command('show subscriber cache')
- self.assert_(res.find('1234567890') >= 0)
- self.assert_(res.find('Authorized: 0') >= 0)
+ self.assertTrue(res.find('1234567890') >= 0)
+ self.assertTrue(res.find('Authorized: 0') >= 0)
self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 update-location-result ok', ['']))
res = self.vty.command('show subscriber cache')
- self.assert_(res.find('1234567890') >= 0)
- self.assert_(res.find('Authorized: 1') >= 0)
+ self.assertTrue(res.find('1234567890') >= 0)
+ self.assertTrue(res.find('Authorized: 1') >= 0)
self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 cancel update-procedure', ['']))
res = self.vty.command('show subscriber cache')
- self.assert_(res.find('1234567890') >= 0)
+ self.assertTrue(res.find('1234567890') >= 0)
self.assertTrue(self.vty.verify('update-subscriber imsi 1234567890 destroy', ['']))
res = self.vty.command('show subscriber cache')
- self.assert_(res.find('1234567890') < 0)
+ self.assertTrue(res.find('1234567890') < 0)
def testVtyGgsn(self):
self.vty.enable()
self.assertTrue(self.vty.verify('configure terminal', ['']))
- self.assertEquals(self.vty.node(), 'config')
+ self.assertEqual(self.vty.node(), 'config')
self.assertTrue(self.vty.verify('sgsn', ['']))
- self.assertEquals(self.vty.node(), 'config-sgsn')
+ self.assertEqual(self.vty.node(), 'config-sgsn')
self.assertTrue(self.vty.verify('ggsn 0 remote-ip 127.99.99.99', ['']))
self.assertTrue(self.vty.verify('ggsn 0 gtp-version 1', ['']))
self.assertTrue(self.vty.verify('apn * ggsn 0', ['']))
@@ -213,65 +213,65 @@ class TestVTYSGSN(TestVTYBase):
self.assertTrue(self.vty.verify('apn apn1.test imsi-prefix 123456 ggsn 0', ['']))
self.assertTrue(self.vty.verify('apn apn2.test imsi-prefix 123456 ggsn 0', ['']))
res = self.vty.command("show running-config")
- self.assert_(res.find('ggsn 0 remote-ip 127.99.99.99') >= 0)
- self.assert_(res.find('ggsn 0 gtp-version 1') >= 0)
- self.assert_(res.find('apn * ggsn 0') >= 0)
- self.assert_(res.find('apn apn1.test ggsn 0') >= 0)
- self.assert_(res.find('apn apn1.test imsi-prefix 123456 ggsn 0') >= 0)
- self.assert_(res.find('apn apn2.test imsi-prefix 123456 ggsn 0') >= 0)
+ self.assertTrue(res.find('ggsn 0 remote-ip 127.99.99.99') >= 0)
+ self.assertTrue(res.find('ggsn 0 gtp-version 1') >= 0)
+ self.assertTrue(res.find('apn * ggsn 0') >= 0)
+ self.assertTrue(res.find('apn apn1.test ggsn 0') >= 0)
+ self.assertTrue(res.find('apn apn1.test imsi-prefix 123456 ggsn 0') >= 0)
+ self.assertTrue(res.find('apn apn2.test imsi-prefix 123456 ggsn 0') >= 0)
def testVtyEasyAPN(self):
self.vty.enable()
self.assertTrue(self.vty.verify('configure terminal', ['']))
- self.assertEquals(self.vty.node(), 'config')
+ self.assertEqual(self.vty.node(), 'config')
self.assertTrue(self.vty.verify('sgsn', ['']))
- self.assertEquals(self.vty.node(), 'config-sgsn')
+ self.assertEqual(self.vty.node(), 'config-sgsn')
res = self.vty.command("show running-config")
- self.assertEquals(res.find("apn internet"), -1)
+ self.assertEqual(res.find("apn internet"), -1)
self.assertTrue(self.vty.verify("access-point-name internet.apn", ['']))
res = self.vty.command("show running-config")
- self.assert_(res.find("apn internet.apn ggsn 0") >= 0)
+ self.assertTrue(res.find("apn internet.apn ggsn 0") >= 0)
self.assertTrue(self.vty.verify("no access-point-name internet.apn", ['']))
res = self.vty.command("show running-config")
- self.assertEquals(res.find("apn internet"), -1)
+ self.assertEqual(res.find("apn internet"), -1)
def testVtyCDR(self):
self.vty.enable()
self.assertTrue(self.vty.verify('configure terminal', ['']))
- self.assertEquals(self.vty.node(), 'config')
+ self.assertEqual(self.vty.node(), 'config')
self.assertTrue(self.vty.verify('sgsn', ['']))
- self.assertEquals(self.vty.node(), 'config-sgsn')
+ self.assertEqual(self.vty.node(), 'config-sgsn')
res = self.vty.command("show running-config")
- self.assert_(res.find("no cdr filename") > 0)
+ self.assertTrue(res.find("no cdr filename") > 0)
self.vty.command("cdr filename bla.cdr")
res = self.vty.command("show running-config")
- self.assertEquals(res.find("no cdr filename"), -1)
- self.assert_(res.find(" cdr filename bla.cdr") > 0)
+ self.assertEqual(res.find("no cdr filename"), -1)
+ self.assertTrue(res.find(" cdr filename bla.cdr") > 0)
self.vty.command("no cdr filename")
res = self.vty.command("show running-config")
- self.assert_(res.find("no cdr filename") > 0)
- self.assertEquals(res.find(" cdr filename bla.cdr"), -1)
+ self.assertTrue(res.find("no cdr filename") > 0)
+ self.assertEqual(res.find(" cdr filename bla.cdr"), -1)
res = self.vty.command("show running-config")
- self.assert_(res.find(" cdr interval 600") > 0)
+ self.assertTrue(res.find(" cdr interval 600") > 0)
self.vty.command("cdr interval 900")
res = self.vty.command("show running-config")
- self.assert_(res.find(" cdr interval 900") > 0)
- self.assertEquals(res.find(" cdr interval 600"), -1)
+ self.assertTrue(res.find(" cdr interval 900") > 0)
+ self.assertEqual(res.find(" cdr interval 600"), -1)
def testVtyTimers(self):
self.vty.enable()
self.assertTrue(self.vty.verify('configure terminal', ['']))
- self.assertEquals(self.vty.node(), 'config')
+ self.assertEqual(self.vty.node(), 'config')
self.assertTrue(self.vty.verify('sgsn', ['']))
- self.assertEquals(self.vty.node(), 'config-sgsn')
+ self.assertEqual(self.vty.node(), 'config-sgsn')
for t in [3312, 3322, 3350, 3360, 3370, 3313, 3314, 3316, 3385, 3395, 3397]:
self.assertTrue(self.vty.verify('timer t%d 10' % t, ['']))
@@ -316,9 +316,9 @@ if __name__ == '__main__':
if args.p:
confpath = args.p
- print "confpath %s, workdir %s" % (confpath, workdir)
+ print("confpath %s, workdir %s" % (confpath, workdir))
os.chdir(workdir)
- print "Running tests for specific VTY commands"
+ print("Running tests for specific VTY commands")
suite = unittest.TestSuite()
add_gbproxy_test(suite, workdir)
add_sgsn_test(suite, workdir)