[WIP] ONOS-8091 Port python script and utilities to python3
Steps performed so far:
- Updated bash scripts and similar to explicitly invoke python3 (instead of python)
- Updated all python scripts using 2to3
Testing these changes will be a major headache because:
- different scripts are executed in different environments
(e.g., Jenkins, cell servers, tutorial VMs, etc.)
- we don’t have control on all environments
- some environments we used to control have been dismissed
(e.g., cell servers)
The approach for now is to focus on the essentials:
- Jenkins jobs for pre-merge and release
Test and fix everything else as the need arises.
Change-Id: I943e214760c9dea9a7ded0d47ef08adbc0ed0bec
diff --git a/tools/dev/mininet/examples/ha.py b/tools/dev/mininet/examples/ha.py
index 18f1222..1ec6932 100755
--- a/tools/dev/mininet/examples/ha.py
+++ b/tools/dev/mininet/examples/ha.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
"""
NOTES
@@ -196,13 +196,13 @@
def start( self ):
output( "(starting HTTP Server)" )
# start python web server as a bg process
- self.cmd( 'python -m SimpleHTTPServer &> web.log &' )
+ self.cmd( 'python3 -m SimpleHTTPServer &> web.log &' )
def stop( self ):
# XXX is this ever called?
- print "Stopping HTTP Server..."
- print self.cmd( 'fg' )
- print self.cmd( '\x03' ) # ctrl-c
+ print("Stopping HTTP Server...")
+ print(self.cmd( 'fg' ))
+ print(self.cmd( '\x03' )) # ctrl-c
class DynamicONOSNode( onos.ONOSNode ):
@@ -278,7 +278,7 @@
l.rotate( -1 )
return perms
- print "Generating %s with %s" % ( location, str(nodes) )
+ print("Generating %s with %s" % ( location, str(nodes) ))
port = 9876
ips = [ node.IP() for node in nodes ]
node = lambda k: { 'id': k, 'ip': k, 'port': port }
@@ -411,7 +411,7 @@
for node in cluster.activeNodes:
node.shouldStart = True
else:
- print "Incorrect test"
+ print("Incorrect test")
return
net.start()
if args.interactive:
diff --git a/tools/dev/mininet/examples/multicluster.py b/tools/dev/mininet/examples/multicluster.py
index 29e2b56..1ad7c5b 100755
--- a/tools/dev/mininet/examples/multicluster.py
+++ b/tools/dev/mininet/examples/multicluster.py
@@ -1,5 +1,4 @@
-#!/usr/bin/python
-
+#!/usr/bin/python3
"""
multicluster.py: multiple ONOS clusters example
@@ -85,7 +84,7 @@
cmap.setdefault( c, [] ).append( s.name )
for c in sorted( cmap.keys() ):
switches = ' '.join( cmap[ c ] )
- print '%s: %s' % ( c, switches )
+ print('%s: %s' % ( c, switches ))
ONOSCLI.do_controllers = do_controllers
diff --git a/tools/dev/mininet/onos.py b/tools/dev/mininet/onos.py
index f8e3703..8e22e5b 100755
--- a/tools/dev/mininet/onos.py
+++ b/tools/dev/mininet/onos.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python3
"""
onos.py: ONOS cluster and control network in Mininet
@@ -113,7 +113,7 @@
# Get rid of stale junk
for var in 'ONOS_CELL', 'ONOS_INSTANCES':
env[ var ] = ''
- for var in environ.keys():
+ for var in list(environ.keys()):
if var.startswith( 'OC' ):
env[ var ] = ''
for index, node in enumerate( nodes, 1 ):
@@ -285,7 +285,7 @@
def intfsDown( self ):
"""Bring all interfaces down"""
- for intf in self.intfs.values():
+ for intf in list(self.intfs.values()):
cmdOutput = intf.ifconfig( 'down' )
# no output indicates success
if cmdOutput:
@@ -293,7 +293,7 @@
def intfsUp( self ):
"""Bring all interfaces up"""
- for intf in self.intfs.values():
+ for intf in list(self.intfs.values()):
cmdOutput = intf.ifconfig( 'up' )
if cmdOutput:
error( "Error setting %s up: %s " % ( intf.name, cmdOutput ) )
@@ -338,7 +338,7 @@
def memAvailable( self ):
"Return available memory in KB (or -1 if we can't tell)"
lines = open( '/proc/meminfo' ).read().strip().split( '\n' )
- entries = map( str.split, lines )
+ entries = list(map( str.split, lines ))
index = { entry[ 0 ]: entry for entry in entries }
# Check MemAvailable if present
default = ( None, '-1', 'kB' )
@@ -411,7 +411,7 @@
"Update environment variables"
cmd = ';'.join( ( 'export %s="%s"' % ( var, val )
if val else 'unset %s' % var )
- for var, val in envDict.iteritems() )
+ for var, val in envDict.items() )
self.cmd( cmd )
def ucmd( self, *args, **_kwargs ):