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: I344c49001fba23bdcfdef06ab174c52b60edd01c
This commit is contained in:
Oliver Smith 2019-12-10 12:58:48 +01:00 committed by osmith
parent feb6777c64
commit a8a646af16
2 changed files with 17 additions and 17 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
app_configs = { app_configs = {
"osmo-stp": ["doc/examples/osmo-stp.cfg"], "osmo-stp": ["doc/examples/osmo-stp.cfg"],

View File

@ -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 Katerina Barone-Adesi <kat.obsc@gmail.com>
# (C) 2013 by Holger Hans Peter Freyther # (C) 2013 by Holger Hans Peter Freyther
@ -35,9 +35,9 @@ class TestVTYBase(unittest.TestCase):
def checkForEndAndExit(self): def checkForEndAndExit(self):
res = self.vty.command("list") res = self.vty.command("list")
#print ('looking for "exit"\n') #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' #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' #print 'found "end"\n'
def vty_command(self): def vty_command(self):
@ -56,8 +56,8 @@ class TestVTYBase(unittest.TestCase):
try: try:
self.proc = osmoutil.popen_devnull(osmo_vty_cmd) self.proc = osmoutil.popen_devnull(osmo_vty_cmd)
except OSError: except OSError:
print >> sys.stderr, "Current directory: %s" % os.getcwd() print("Current directory: %s" % os.getcwd(), file=sys.stderr)
print >> sys.stderr, "Consider setting -b" print("Consider setting -b", file=sys.stderr)
appstring = self.vty_app()[2] appstring = self.vty_app()[2]
appport = self.vty_app()[0] appport = self.vty_app()[0]
@ -89,22 +89,22 @@ class TestVTYSTP(TestVTYBase):
line = fp.readline().strip() line = fp.readline().strip()
if not line: if not line:
return False return False
print "%s: parsing line: %s" %(path, line) print("%s: parsing line: %s" %(path, line))
it = line.split() it = line.split()
if lport == int(it[5]): if lport == int(it[5]):
print "%s: local port %d found" %(path, lport) print("%s: local port %d found" %(path, lport))
itaddr_list = it[8:] itaddr_list = it[8:]
if len(itaddr_list) != len(laddr_list): if len(itaddr_list) != len(laddr_list):
print "%s: addr list mismatch: %r vs %r" % (path, repr(itaddr_list), repr(laddr_list)) print("%s: addr list mismatch: %r vs %r" % (path, repr(itaddr_list), repr(laddr_list)))
continue continue
for addr in laddr_list: for addr in laddr_list:
if addr not in itaddr_list: if addr not in itaddr_list:
print "%s: addr not found in list: %s vs %r" % (path, addr, repr(itaddr_list)) print("%s: addr not found in list: %s vs %r" % (path, addr, repr(itaddr_list)))
return False return False
return True return True
return False return False
except IOError as e: except IOError as e:
print "I/O error({0}): {1}".format(e.errno, e.strerror) print("I/O error({0}): {1}".format(e.errno, e.strerror))
return False return False
def testMultiHome(self): def testMultiHome(self):
@ -115,9 +115,9 @@ class TestVTYSTP(TestVTYBase):
found = True found = True
break break
else: else:
print "[%d] osmo-stp not yet available, retrying in a second" % i print("[%d] osmo-stp not yet available, retrying in a second" % i)
time.sleep(1) time.sleep(1)
self.assert_(found) self.assertTrue(found)
try: try:
proto = socket.IPPROTO_SCTP proto = socket.IPPROTO_SCTP
except AttributeError: # it seems to be not defined under python2? except AttributeError: # it seems to be not defined under python2?
@ -128,8 +128,8 @@ class TestVTYSTP(TestVTYBase):
s.connect(('127.0.0.2',2905)) s.connect(('127.0.0.2',2905))
except socket.error as msg: except socket.error as msg:
s.close() s.close()
self.assert_(False) self.assertTrue(False)
print "Connected to STP through SCTP" print("Connected to STP through SCTP")
s.close() s.close()
if __name__ == '__main__': if __name__ == '__main__':
@ -158,9 +158,9 @@ if __name__ == '__main__':
if args.p: if args.p:
confpath = args.p confpath = args.p
print "confpath %s, workdir %s" % (confpath, workdir) print("confpath %s, workdir %s" % (confpath, workdir))
os.chdir(workdir) os.chdir(workdir)
print "Running tests for specific VTY commands" print("Running tests for specific VTY commands")
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYSTP)) suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVTYSTP))