Change in osmo-msc[master]: osmoappdesc.py, tests: switch to python 3

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

osmith gerrit-no-reply at lists.osmocom.org
Wed Dec 11 11:12:19 UTC 2019


osmith has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-msc/+/16550 )


Change subject: osmoappdesc.py, tests: switch to python 3
......................................................................

osmoappdesc.py, tests: switch to python 3

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: I53ccde96dd3785098df0f7d693c504c8b8302e90
---
M osmoappdesc.py
M tests/ctrl_test_runner.py
M tests/smpp_test_runner.py
M tests/vty_test_runner.py
4 files changed, 60 insertions(+), 60 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-msc refs/changes/50/16550/1

diff --git a/osmoappdesc.py b/osmoappdesc.py
index bd7fea3..b7a274c 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 at 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 f652a67..d24cc00 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 at sysmocom.de>
 # (C) 2014 by Holger Hans Peter Freyther
@@ -53,8 +53,8 @@
         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 @@
 
     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 @@
 
     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)
 
@@ -123,7 +123,7 @@
             (head, data) = IPA().split_combined(data)
             answer = Ctrl().rem_header(head)
             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 @@
             responses[id] = rsp
 
         if verbose:
-            print "Decoded replies: ", responses
+            print("Decoded replies: ", responses)
 
         return responses
 
@@ -183,9 +183,9 @@
     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()
     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestCtrlMSC))
     res = unittest.TextTestRunner(verbosity=verbose_level).run(suite)
diff --git a/tests/smpp_test_runner.py b/tests/smpp_test_runner.py
index f6567d9..b8c6e1c 100755
--- a/tests/smpp_test_runner.py
+++ b/tests/smpp_test_runner.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
 
 # (C) 2014 by Holger Hans Peter Freyther
 # based on vty_test_runner.py:
@@ -46,8 +46,8 @@
         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]
@@ -73,14 +73,14 @@
         # Enable the configuration
         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('smpp', ['']))
-        self.assertEquals(self.vty.node(), 'config-smpp')
+        self.assertEqual(self.vty.node(), 'config-smpp')
         self.assertTrue(self.vty.verify('system-id test', ['']))
         self.assertTrue(self.vty.verify('local-tcp-port 2775', ['']))
         self.assertTrue(self.vty.verify('esme test', ['']))
-        self.assertEquals(self.vty.node(), 'config-smpp-esme')
+        self.assertEqual(self.vty.node(), 'config-smpp-esme')
         self.assertTrue(self.vty.verify('default-route', ['']))
         self.assertTrue(self.vty.verify('end', ['']))
 
@@ -88,7 +88,7 @@
         sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         sck.setblocking(1)
         sck.connect(('0.0.0.0', 2775))
-        sck.sendall('\x00\x00\x00\x02\x00')
+        sck.sendall(b'\x00\x00\x00\x02\x00')
         sck.close()
 
         # Check if the VTY is still there
@@ -98,7 +98,7 @@
         sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         sck.setblocking(1)
         sck.connect(('0.0.0.0', 2775))
-        sck.sendall('\x00\x01\x00\x01\x01')
+        sck.sendall(b'\x00\x01\x00\x01\x01')
         sck.close()
 
         self.vty.verify('enable',[''])
@@ -128,9 +128,9 @@
     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 SMPP"
+    print("Running tests for specific SMPP")
     suite = unittest.TestSuite()
     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestSMPPMSC))
     res = unittest.TextTestRunner(verbosity=verbose_level).run(suite)
diff --git a/tests/vty_test_runner.py b/tests/vty_test_runner.py
index 471ecf6..f954b5d 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 at gmail.com>
 # (C) 2013 by Holger Hans Peter Freyther
@@ -33,9 +33,9 @@
     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 @@
         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]
@@ -79,14 +79,14 @@
     def testConfigNetworkTree(self, include_bsc_items=True):
         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("network",['']))
-        self.assertEquals(self.vty.node(), 'config-net')
+        self.assertEqual(self.vty.node(), 'config-net')
         self.checkForEndAndExit()
         self.vty.command("write terminal")
         self.assertTrue(self.vty.verify("exit",['']))
-        self.assertEquals(self.vty.node(), 'config')
+        self.assertEqual(self.vty.node(), 'config')
         self.assertTrue(self.vty.verify("exit",['']))
         self.assertTrue(self.vty.node() is None)
 
@@ -107,35 +107,35 @@
 
         # check the default
         res = self.vty.command("write terminal")
-        self.assert_(res.find(' no smpp-first') > 0)
+        self.assertTrue(res.find(' no smpp-first') > 0)
 
         self.vty.verify("smpp-first", [''])
         res = self.vty.command("write terminal")
-        self.assert_(res.find(' smpp-first') > 0)
-        self.assertEquals(res.find('no smpp-first'), -1)
+        self.assertTrue(res.find(' smpp-first') > 0)
+        self.assertEqual(res.find('no smpp-first'), -1)
 
         self.vty.verify("no smpp-first", [''])
         res = self.vty.command("write terminal")
-        self.assert_(res.find('no smpp-first') > 0)
+        self.assertTrue(res.find('no smpp-first') > 0)
 
     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('mncc-int', ['']))
-        self.assertEquals(self.vty.node(), 'config-mncc-int')
+        self.assertEqual(self.vty.node(), 'config-mncc-int')
         self.checkForEndAndExit()
         self.assertTrue(self.vty.verify('exit', ['']))
 
         if self.checkForSmpp():
-            self.assertEquals(self.vty.node(), 'config')
+            self.assertEqual(self.vty.node(), 'config')
             self.assertTrue(self.vty.verify('smpp', ['']))
-            self.assertEquals(self.vty.node(), 'config-smpp')
+            self.assertEqual(self.vty.node(), 'config-smpp')
             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("exit", ['']))
         self.assertTrue(self.vty.node() is None)
 
@@ -145,10 +145,10 @@
 
         if self.checkForSmpp():
             self.vty.command('smpp')
-            self.assertEquals(self.vty.node(), 'config-smpp')
+            self.assertEqual(self.vty.node(), 'config-smpp')
             self.vty.command('mncc-int')
 
-        self.assertEquals(self.vty.node(), 'config-mncc-int')
+        self.assertEqual(self.vty.node(), 'config-mncc-int')
 
     def testSi2Q(self):
         self.vty.enable()
@@ -162,7 +162,7 @@
         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")
-        self.assertEquals(before, self.vty.command("show running-config"))
+        self.assertEqual(before, self.vty.command("show running-config"))
         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")
@@ -185,7 +185,7 @@
         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")
-        self.assertEquals(before, self.vty.command("show running-config"))
+        self.assertEqual(before, self.vty.command("show running-config"))
 
     def testEnableDisablePeriodicLU(self):
         self.vty.enable()
@@ -201,18 +201,18 @@
         # Enable periodic lu..
         self.vty.verify("periodic location update 60", [''])
         res = self.vty.command("write terminal")
-        self.assert_(res.find('periodic location update 60') > 0)
-        self.assertEquals(res.find('no periodic location update'), -1)
+        self.assertTrue(res.find('periodic location update 60') > 0)
+        self.assertEqual(res.find('no periodic location update'), -1)
 
         # Now disable it..
         self.vty.verify("no periodic location update", [''])
         res = self.vty.command("write terminal")
-        self.assertEquals(res.find('periodic location update 60'), -1)
-        self.assert_(res.find('no periodic location update') > 0)
+        self.assertEqual(res.find('periodic location update 60'), -1)
+        self.assertTrue(res.find('no periodic location update') > 0)
 
     def testShowNetwork(self):
         res = self.vty.command("show network")
-        self.assert_(res.startswith('BSC is on Country Code') >= 0)
+        self.assertTrue(res.startswith('BSC is on Country Code') >= 0)
 
 def ipa_handle_small(x, verbose = False):
     s = data2str(x.recv(4))
@@ -220,42 +220,42 @@
       raise Exception("expected to receive 4 bytes, but got %d (%r)" % (len(s)/2, s))
     if "0001fe00" == s:
         if (verbose):
-            print "\tBSC <- NAT: PING?"
+            print("\tBSC <- NAT: PING?")
         x.send(IPA().pong())
     elif "0001fe06" == s:
         if (verbose):
-            print "\tBSC <- NAT: IPA ID ACK"
+            print("\tBSC <- NAT: IPA ID ACK")
         x.send(IPA().id_ack())
     elif "0001fe00" == s:
         if (verbose):
-            print "\tBSC <- NAT: PONG!"
+            print("\tBSC <- NAT: PONG!")
     else:
         if (verbose):
-            print "\tBSC <- NAT: ", s
+            print("\tBSC <- NAT: ", s)
 
 def ipa_handle_resp(x, tk, verbose = False, proc=None):
     s = data2str(x.recv(38))
     if "0023fe040108010701020103010401050101010011" in s:
         retries = 3
         while True:
-            print "\tsending IPA identity(%s) at %s" % (tk, time.strftime("%T"))
+            print("\tsending IPA identity(%s) at %s" % (tk, time.strftime("%T")))
             try:
                 x.send(IPA().id_resp(IPA().identity(name = tk.encode('utf-8'))))
-                print "\tdone sending IPA identity(%s) at %s" % (tk,
-                                                            time.strftime("%T"))
+                print("\tdone sending IPA identity(%s) at %s" % (tk,
+                                                            time.strftime("%T")))
                 break
             except:
-                print "\tfailed sending IPA identity at", time.strftime("%T")
+                print("\tfailed sending IPA identity at", time.strftime("%T"))
                 if proc:
-                  print "\tproc.poll() = %r" % proc.poll()
+                  print("\tproc.poll() = %r" % proc.poll())
                 if retries < 1:
-                    print "\tgiving up"
+                    print("\tgiving up")
                     raise
-                print "\tretrying (%d attempts left)" % retries
+                print("\tretrying (%d attempts left)" % retries)
                 retries -= 1
     else:
         if (verbose):
-            print "\tBSC <- NAT: ", s
+            print("\tBSC <- NAT: ", s)
 
 if __name__ == '__main__':
     import argparse
@@ -283,9 +283,9 @@
     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()
     suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYMSC))
 

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-msc/+/16550
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-msc
Gerrit-Branch: master
Gerrit-Change-Id: I53ccde96dd3785098df0f7d693c504c8b8302e90
Gerrit-Change-Number: 16550
Gerrit-PatchSet: 1
Gerrit-Owner: osmith <osmith at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20191211/20c2d1ca/attachment.htm>


More information about the gerrit-log mailing list