xenserver: Fix string compatibility in python3.
authorJoe Stringer <joe@ovn.org>
Tue, 24 May 2016 01:20:27 +0000 (18:20 -0700)
committerJoe Stringer <joe@ovn.org>
Tue, 7 Jun 2016 23:18:44 +0000 (16:18 -0700)
PEP 3120 made UTF-8 the default source encoding for python3 strings;
ensure that the output for strings are consistent between python2.7 and
python3.

Signed-off-by: Joe Stringer <joe@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
tests/interface-reconfigure.at
xenserver/opt_xensource_libexec_InterfaceReconfigure.py
xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py

index bb3756b..b4e455d 100644 (file)
@@ -708,7 +708,7 @@ action_up: xenbr2
 Writing network configuration for xenbr2
 Configuring xenbr2 using DHCP configuration
 configure_datapath: bridge      - xenbr2
-configure_datapath: physical    - [u'eth2']
+configure_datapath: physical    - ['eth2']
 configure_datapath: extra ports - []
 configure_datapath: extra bonds - []
 /usr/bin/ovs-vsctl -vconsole:off get-fail-mode xenbr2
@@ -762,7 +762,7 @@ action_down: xenbr2
 /sbin/ifdown xenbr2
 deconfigure ipdev xenbr2 on xenbr2
 deconfigure_bridge: bridge           - xenbr2
-action_down: bring down physical devices - [u'eth2']
+action_down: bring down physical devices - ['eth2']
 /sbin/ifconfig eth2 down
 /usr/bin/ovs-vsctl --timeout=20
     --with-iface --if-exists del-port xenbr2
@@ -785,7 +785,7 @@ action_up: xapi3
 Writing network configuration for xapi3
 Configuring xapi3 using None configuration
 configure_datapath: bridge      - xenbr3
-configure_datapath: physical    - [u'eth3']
+configure_datapath: physical    - ['eth3']
 configure_datapath: extra ports - []
 configure_datapath: extra bonds - []
 Applying changes to /etc/sysconfig/network-scripts/route-xapi3 configuration
@@ -836,7 +836,7 @@ deconfigure ipdev xapi3 on xenbr3
 deconfigure_bridge: bridge           - xapi3
 action_down: no more masters, bring down slave xenbr3
 deconfigure_bridge: bridge           - xenbr3
-action_down: bring down physical devices - [u'eth3']
+action_down: bring down physical devices - ['eth3']
 /sbin/ifconfig eth3 down
 /usr/bin/ovs-vsctl --timeout=20
     --with-iface --if-exists del-port xapi3
@@ -869,7 +869,7 @@ Configuring xapi1 using None configuration
 configure_datapath: leaving bond bond0 up
 configure_datapath: leaving bond bond0 up
 configure_datapath: bridge      - xapi1
-configure_datapath: physical    - [u'eth0', u'eth1']
+configure_datapath: physical    - ['eth0', 'eth1']
 configure_datapath: extra ports - []
 configure_datapath: extra bonds - []
 netdev: down: device xenbr0 does not exist, ignoring
@@ -926,7 +926,7 @@ action_down: xapi1
 /sbin/ifdown xapi1
 deconfigure ipdev xapi1 on xapi1
 deconfigure_bridge: bridge           - xapi1
-action_down: bring down physical devices - [u'eth0', u'eth1']
+action_down: bring down physical devices - ['eth0', 'eth1']
 /sbin/ifconfig eth0 down
 /sbin/ifconfig eth1 down
 /usr/bin/ovs-vsctl --timeout=20
@@ -959,7 +959,7 @@ Configuring xapi2 using None configuration
 configure_datapath: leaving bond bond0 up
 configure_datapath: leaving bond bond0 up
 configure_datapath: bridge      - xapi1
-configure_datapath: physical    - [u'eth0', u'eth1']
+configure_datapath: physical    - ['eth0', 'eth1']
 configure_datapath: extra ports - []
 configure_datapath: extra bonds - []
 netdev: down: device xenbr0 does not exist, ignoring
@@ -1022,7 +1022,7 @@ deconfigure ipdev xapi2 on xapi1
 deconfigure_bridge: bridge           - xapi2
 action_down: no more masters, bring down slave xapi1
 deconfigure_bridge: bridge           - xapi1
-action_down: bring down physical devices - [u'eth0', u'eth1']
+action_down: bring down physical devices - ['eth0', 'eth1']
 /sbin/ifconfig eth0 down
 /sbin/ifconfig eth1 down
 /usr/bin/ovs-vsctl --timeout=20
index f37e038..9cdb3bc 100644 (file)
@@ -758,15 +758,22 @@ def pif_ipdev_name(pif):
 def netdev_exists(netdev):
     return os.path.exists(root_prefix() + "/sys/class/net/" + netdev)
 
+
+def unicode_2to3(string):
+    if sys.version_info < (3,):
+        return string.encode()
+    return string
+
+
 def pif_netdev_name(pif):
     """Get the netdev name for a PIF."""
 
     pifrec = db().get_pif_record(pif)
 
     if pif_is_vlan(pif):
-        return "%(device)s.%(VLAN)s" % pifrec
+        return unicode_2to3("%(device)s.%(VLAN)s" % pifrec)
     else:
-        return pifrec['device']
+        return unicode_2to3(pifrec['device'])
 
 #
 # Bridges
index 30fc176..d70c249 100644 (file)
@@ -655,7 +655,7 @@ class DatapathVswitch(Datapath):
             for flow in self._bridge_flows:
                 if flow.find('in_port=%s') != -1 or flow.find('actions=%s') != -1:
                     for port in ofports:
-                        f = flow % (port)
+                        f = flow % (port.decode())
                         run_command(['/usr/bin/ovs-ofctl', 'add-flow', dpname, f])
                 else:
                     run_command(['/usr/bin/ovs-ofctl', 'add-flow', dpname, flow])