Skip to content

Commit

Permalink
xenserver: Fix string compatibility in python3.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
joestringer committed Jun 7, 2016
1 parent 8b35f04 commit 1ea636e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
16 changes: 8 additions & 8 deletions tests/interface-reconfigure.at
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions xenserver/opt_xensource_libexec_InterfaceReconfigure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ def configure(self):
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])
Expand Down

0 comments on commit 1ea636e

Please sign in to comment.