Skip to content

Commit

Permalink
ovs-vtep: Make compatible with python2.7 and 3.
Browse files Browse the repository at this point in the history
Translate commandline calls to UTF-8, appease flake8 and use six's
integer types. This allows the testsuite to pass when using python3 as
your default system python version.

Signed-off-by: Joe Stringer <[email protected]>
Tested-by: Darrell Ball <[email protected]>
  • Loading branch information
joestringer committed May 31, 2016
1 parent ff26170 commit 7d8eadc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion utilities/ovs-pcap.in
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ if __name__ == "__main__":
if packet is None:
break

print(binascii.hexlify(packet))
print(binascii.hexlify(packet).decode().strip())

except PcapException as e:
sys.stderr.write("%s: %s\n" % (argv0, e))
Expand Down
25 changes: 12 additions & 13 deletions vtep/ovs-vtep
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import shlex
import subprocess
import sys
import time
import types

import ovs.dirs
import ovs.util
Expand Down Expand Up @@ -58,7 +57,7 @@ def call_prog(prog, args_list):
if len(output) == 0 or output[0] is None:
output = ""
else:
output = output[0].strip()
output = output[0].decode().strip()
return output


Expand Down Expand Up @@ -101,9 +100,9 @@ class Logical_Switch(object):

def setup_ls(self):
column = vtep_ctl("--columns=tunnel_key find logical_switch "
"name=%s" % self.name)
"name=%s" % self.name)
tunnel_key = column.partition(":")[2].strip()
if tunnel_key and isinstance(eval(tunnel_key), types.IntType):
if tunnel_key and isinstance(eval(tunnel_key), six.integer_types):
self.tunnel_key = tunnel_key
vlog.info("using tunnel key %s in %s"
% (self.tunnel_key, self.name))
Expand Down Expand Up @@ -140,7 +139,7 @@ class Logical_Switch(object):
for tunnel in self.unknown_dsts:
port_no = self.tunnels[tunnel][0]
ovs_ofctl("add-flow %s table=1,priority=1,in_port=%s,action=%s"
% (self.short_name, port_no, ",".join(flood_ports)))
% (self.short_name, port_no, ",".join(flood_ports)))

# Traffic coming from a VTEP physical port should always be flooded to
# all the other physical ports that belong to that VTEP device and
Expand Down Expand Up @@ -217,7 +216,7 @@ class Logical_Switch(object):

port_no, tun_name, remote_ip = self.tunnels[tunnel]
ovs_ofctl("del-flows %s table=0,in_port=%s"
% (self.short_name, port_no))
% (self.short_name, port_no))
ovs_vsctl("del-port %s %s" % (self.short_name, tun_name))

del_bfd(remote_ip)
Expand Down Expand Up @@ -349,9 +348,9 @@ class Logical_Switch(object):

for mapfrom, mapto in six.iteritems(stats_map):
value = ovs_vsctl("get interface %s statistics:%s"
% (interface, mapfrom)).strip('"')
% (interface, mapfrom)).strip('"')
vtep_ctl("set logical_binding_stats %s %s=%s"
% (uuid, mapto, value))
% (uuid, mapto, value))

def run(self):
self.update_local_macs()
Expand Down Expand Up @@ -465,7 +464,7 @@ def run_bfd():

for key, default in six.iteritems(bfd_params_default):
column = vtep_ctl("--if-exists get tunnel %s %s"
% (tunnel, key))
% (tunnel, key))
if not column:
bfd_params_values[key] = default
else:
Expand All @@ -492,7 +491,7 @@ def run_bfd():
# Add the defaults as described in VTEP schema to make it explicit.
bfd_lconf_default = {'bfd_config_local:bfd_dst_ip': '169.254.1.0',
'bfd_config_local:bfd_dst_mac':
'00:23:20:00:00:01'}
'00:23:20:00:00:01'}
for key, value in six.iteritems(bfd_lconf_default):
vtep_ctl("set tunnel %s %s=%s" % (tunnel, key, value))

Expand All @@ -504,15 +503,15 @@ def run_bfd():
bfd_dst_ip = "169.254.1.1"

bfd_dst_mac = vtep_ctl("--if-exists get tunnel %s "
"bfd_config_remote:bfd_dst_mac" % (tunnel))
"bfd_config_remote:bfd_dst_mac" % (tunnel))
if not bfd_dst_mac:
bfd_dst_mac = "00:23:20:00:00:01"

ovs_vsctl("set interface %s bfd:bfd_dst_ip=%s "
"bfd:bfd_remote_dst_mac=%s bfd:bfd_local_dst_mac=%s"
% (port, bfd_dst_ip,
bfd_lconf_default['bfd_config_local:bfd_dst_mac'],
bfd_dst_mac))
bfd_lconf_default['bfd_config_local:bfd_dst_mac'],
bfd_dst_mac))


def add_binding(binding, ls):
Expand Down

0 comments on commit 7d8eadc

Please sign in to comment.