diff mbox

[ovs-dev,2/6] xenserver: Fix string compatibility in python3.

Message ID 1464052831-17278-3-git-send-email-joe@ovn.org
State Accepted
Headers show

Commit Message

Joe Stringer May 24, 2016, 1:20 a.m. UTC
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>
---
 tests/interface-reconfigure.at                           | 16 ++++++++--------
 xenserver/opt_xensource_libexec_InterfaceReconfigure.py  | 11 +++++++++--
 .../opt_xensource_libexec_InterfaceReconfigureVswitch.py |  2 +-
 3 files changed, 18 insertions(+), 11 deletions(-)
diff mbox

Patch

diff --git a/tests/interface-reconfigure.at b/tests/interface-reconfigure.at
index bb3756be2f82..b4e455d94228 100644
--- a/tests/interface-reconfigure.at
+++ b/tests/interface-reconfigure.at
@@ -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
diff --git a/xenserver/opt_xensource_libexec_InterfaceReconfigure.py b/xenserver/opt_xensource_libexec_InterfaceReconfigure.py
index f37e038635de..9cdb3bc27fa6 100644
--- a/xenserver/opt_xensource_libexec_InterfaceReconfigure.py
+++ b/xenserver/opt_xensource_libexec_InterfaceReconfigure.py
@@ -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
diff --git a/xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py b/xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py
index 30fc176694a9..d70c249146fb 100644
--- a/xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py
+++ b/xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py
@@ -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])