Skip to content

Commit

Permalink
python: Resolve pep8 blank line errors.
Browse files Browse the repository at this point in the history
Resolve pep8 errors E302 and E303:

  E302 expected 2 blank lines, found 1
  E303 too many blank lines (3)

Signed-off-by: Russell Bryant <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
russellb committed Jan 5, 2016
1 parent e8049bc commit bdca6c4
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ endif
if HAVE_FLAKE8
ALL_LOCAL += flake8-check
flake8-check: $(FLAKE8_PYFILES)
$(AM_V_GEN) if flake8 $^ --ignore=E111,E112,E113,E123,E126,E127,E128,E129,E131,E201,E203,E222,E225,E226,E231,E241,E251,E261,E262,E265,E271,E302,E303,E501,E502,E703,E711,E713,E721,W601 ${FLAKE8_FLAGS}; then touch $@; else exit 1; fi
$(AM_V_GEN) if flake8 $^ --ignore=E111,E112,E113,E123,E126,E127,E128,E129,E131,E201,E203,E222,E225,E226,E231,E241,E251,E261,E262,E265,E271,E501,E502,E703,E711,E713,E721,W601 ${FLAKE8_FLAGS}; then touch $@; else exit 1; fi
endif

include $(srcdir)/manpages.mk
Expand Down
3 changes: 3 additions & 0 deletions ofproto/ipfix-gen-entities
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import sys
import xml.sax
import xml.sax.handler


class IpfixEntityHandler(xml.sax.handler.ContentHandler):

RECORD_FIELDS = ['name', 'dataType', 'elementId', 'status']
Expand Down Expand Up @@ -90,9 +91,11 @@ class IpfixEntityHandler(xml.sax.handler.ContentHandler):
if self.current_field_name is not None:
self.current_field_value.append(content)


def print_ipfix_entity_macros(xml_file):
xml.sax.parse(xml_file, IpfixEntityHandler())


def usage(name):
print """\
%(name)s: IPFIX entity definition generator
Expand Down
6 changes: 6 additions & 0 deletions python/build/nroff.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from ovs.db import error


def text_to_nroff(s, font=r'\fR'):
def escape(match):
c = match.group(0)
Expand Down Expand Up @@ -56,9 +57,11 @@ def escape(match):
s = re.sub('(-[0-9]|--|[-"\'\\\\.])', escape, s)
return s


def escape_nroff_literal(s, font=r'\fB'):
return font + r'%s\fR' % text_to_nroff(s, font)


def inline_xml_to_nroff(node, font, to_upper=False, newline='\n'):
if node.nodeType == node.TEXT_NODE:
if to_upper:
Expand Down Expand Up @@ -99,6 +102,7 @@ def inline_xml_to_nroff(node, font, to_upper=False, newline='\n'):
else:
raise error.Error("unknown node %s in inline xml" % node)


def pre_to_nroff(nodes, para, font):
# This puts 'font' at the beginning of each line so that leading and
# trailing whitespace stripping later doesn't removed leading spaces
Expand Down Expand Up @@ -168,6 +172,7 @@ def diagram_header_to_nroff(header_node):
text_s += "\n"
return pic_s, text_s


def diagram_to_nroff(nodes, para):
pic_s = ''
text_s = ''
Expand Down Expand Up @@ -210,6 +215,7 @@ def diagram_to_nroff(nodes, para):
.RE
\\}"""


def block_xml_to_nroff(nodes, para='.PP'):
s = ''
for node in nodes:
Expand Down
1 change: 1 addition & 0 deletions python/ovs/poller.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def _using_eventlet_green_select():
POLLHUP = 0x010
POLLNVAL = 0x020


# eventlet/gevent doesn't support select.poll. If select.poll is used,
# python interpreter is blocked as a whole instead of switching from the
# current thread that is about to block to other runnable thread.
Expand Down
3 changes: 3 additions & 0 deletions python/ovs/timeval.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class timespec(ctypes.Structure):
# Librt shared library could not be loaded
librt = None


def monotonic():
if not librt:
return time.time()
Expand All @@ -62,10 +63,12 @@ def monotonic():
# Kernel does not support CLOCK_MONOTONIC
return time.time()


# Use time.monotonic() if Python version >= 3.3
if not hasattr(time, 'monotonic'):
time.monotonic = monotonic


def msec():
""" Returns the system's monotonic time if possible, otherwise returns the
current time as the amount of time since the epoch, in milliseconds, as a
Expand Down
1 change: 1 addition & 0 deletions python/ovs/unixctl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def command_register(name, usage, min_args, max_args, callback, aux):
commands[name] = _UnixctlCommand(usage, min_args, max_args, callback,
aux)


def socket_name_from_target(target):
assert isinstance(target, strtypes)

Expand Down
1 change: 1 addition & 0 deletions python/ovs/unixctl/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def _unixctl_version(conn, unused_argv, version):
version = "%s (Open vSwitch) %s" % (ovs.util.PROGRAM_NAME, version)
conn.reply(version)


class UnixctlServer(object):
def __init__(self, listener):
assert isinstance(listener, ovs.stream.PassiveStream)
Expand Down
2 changes: 2 additions & 0 deletions python/ovstest/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
CONTROL_PORT = 15531
DATA_PORT = 15532


def ip_address(string):
"""Verifies if string is a valid IP address"""
try:
Expand Down Expand Up @@ -246,6 +247,7 @@ def ovs_initialize_args():
'OuterIP.')
return parser.parse_args()


def l3_initialize_args():
"""
Initialize argument parsing for ovs-l3ping utility.
Expand Down
1 change: 0 additions & 1 deletion python/ovstest/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ def do_l3_tests(node1, node2, bandwidth, duration, ps, type):
server.del_bridge(DEFAULT_TEST_BRIDGE)



def do_vlan_tests(node1, node2, bandwidth, duration, ps, tag):
"""
Do VLAN tests between node1 and node2. Each node is given
Expand Down
1 change: 1 addition & 0 deletions python/ovstest/vswitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def ovs_vsctl_del_bridge(bridge):
ret, _out, _err = util.start_process(["ovs-vsctl", "del-br", bridge])
return ret


def ovs_vsctl_del_pbridge(bridge, iface):
"""
This function deletes the OVS bridge and assigns the bridge IP address
Expand Down
3 changes: 3 additions & 0 deletions tests/MockXenAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import re


def xapi_local():
return Session()

Expand Down Expand Up @@ -97,6 +98,7 @@ class Pool(Table):
def __init__(self):
Table.__init__(self, Pool.__records)


class VIF(Table):
__records = ({"uuid": "6ab1b260-398e-49ba-827b-c7696108964c",
"other_config":
Expand All @@ -105,6 +107,7 @@ class VIF(Table):
def __init__(self):
Table.__init__(self, VIF.__records)


class VM(Table):
__records = ({"uuid": "fcb8a3f6-dc04-41d2-8b8a-55afd2b755b8",
"other_config":
Expand Down
2 changes: 2 additions & 0 deletions tests/test-unix-socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import ovs.socket_util


def main(argv):
if len(argv) not in (2, 3):
sys.stderr.write("usage: %s SOCKETNAME1 [SOCKETNAME2]", argv[0])
Expand Down Expand Up @@ -52,5 +53,6 @@ def main(argv):
os.strerror(error)))
sys.exit(1)


if __name__ == '__main__':
main(sys.argv)
1 change: 1 addition & 0 deletions tests/test-unixctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
vlog = ovs.vlog.Vlog("test-unixctl")
exiting = False


def unixctl_exit(conn, unused_argv, aux):
assert aux == "aux_exit"
global exiting
Expand Down
3 changes: 3 additions & 0 deletions utilities/ovs-pcap.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ import getopt
import struct
import sys


class PcapException(Exception):
pass


class PcapReader(object):
def __init__(self, file_name):
self.file = open(file_name, "rb")
Expand Down Expand Up @@ -53,6 +55,7 @@ class PcapReader(object):
return packet
argv0 = sys.argv[0]


def usage():
print """\
%(argv0)s: print pcap file packet data as hex
Expand Down
15 changes: 14 additions & 1 deletion vtep/ovs-vtep
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ tun_id = 0
bfd_bridge = "vtep_bfd"
bfd_ref = {}


def call_prog(prog, args_list):
cmd = [prog, "-vconsole:off"] + args_list
output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()
Expand All @@ -58,12 +59,15 @@ def call_prog(prog, args_list):
output = output[0].strip()
return output


def ovs_vsctl(args):
return call_prog("ovs-vsctl", shlex.split(args))


def ovs_ofctl(args):
return call_prog("ovs-ofctl", shlex.split(args))


def vtep_ctl(args):
return call_prog("vtep-ctl", shlex.split(args))

Expand Down Expand Up @@ -325,6 +329,7 @@ class Logical_Switch(object):
self.update_remote_macs()
self.update_stats()


def get_vtep_tunnel(remote_ip):
# Get the physical_locator record for the local tunnel end point.
column = vtep_ctl("--columns=_uuid find physical_locator "
Expand All @@ -346,6 +351,7 @@ def get_vtep_tunnel(remote_ip):

return (local, remote, tunnel)


def create_vtep_tunnel(remote_ip):
local, remote, tunnel = get_vtep_tunnel(remote_ip)
if not local or not remote:
Expand All @@ -359,6 +365,7 @@ def create_vtep_tunnel(remote_ip):
%(ps_name, local, remote))
return tunnel


def destroy_vtep_tunnel(remote_ip):
local, remote, tunnel = get_vtep_tunnel(remote_ip)
if tunnel:
Expand All @@ -368,6 +375,7 @@ def destroy_vtep_tunnel(remote_ip):
"-- --if-exists destroy tunnel %s"
% (ps_name, tunnel, tunnel))


def add_bfd(remote_ip):
# The VTEP emulator creates one OVS bridge for every logical switch.
# Multiple logical switches can have multiple OVS tunnels to the
Expand Down Expand Up @@ -397,6 +405,7 @@ def add_bfd(remote_ip):
# conditions, pass the responsibility of creating a 'tunnel' record
# to run_bfd() which runs more often.


def del_bfd(remote_ip):
if remote_ip in bfd_ref:
if bfd_ref[remote_ip] == 1:
Expand All @@ -408,6 +417,7 @@ def del_bfd(remote_ip):
else:
bfd_ref[remote_ip] -= 1


def run_bfd():
bfd_ports = ovs_vsctl("list-ports %s" % bfd_bridge).split()
for port in bfd_ports:
Expand Down Expand Up @@ -475,6 +485,7 @@ def run_bfd():
bfd_lconf_default['bfd_config_local:bfd_dst_mac'],
bfd_dst_mac))


def add_binding(binding, ls):
vlog.info("adding binding %s" % binding)

Expand Down Expand Up @@ -516,6 +527,7 @@ def add_binding(binding, ls):
ls.add_lbinding(lbinding)
Bindings[binding] = ls.name


def del_binding(binding, ls):
vlog.info("removing binding %s" % binding)

Expand Down Expand Up @@ -545,6 +557,7 @@ def del_binding(binding, ls):

del Bindings[binding]


def handle_physical():
# Gather physical ports except the patch ports we created
ovs_ports = ovs_vsctl("list-ports %s" % ps_name).split()
Expand Down Expand Up @@ -582,7 +595,6 @@ def handle_physical():

add_binding(binding, ls)


dead_bindings = set(Bindings.keys()).difference(new_bindings)
for binding in dead_bindings:
ls_name = Bindings[binding]
Expand All @@ -596,6 +608,7 @@ def handle_physical():
vtep_ctl("clear-local-macs %s" % Lswitches[ls_name].name)
del Lswitches[ls_name]


def setup():
br_list = ovs_vsctl("list-br").split()
if (ps_name not in br_list):
Expand Down
2 changes: 2 additions & 0 deletions xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def get_network_by_bridge(br_name):

return None


# There are possibilities when multiple xs-network-uuids are set for a bridge.
# In cases like that, we should choose the bridge-id associated with the bridge
# name.
Expand All @@ -101,6 +102,7 @@ def get_single_bridge_id(bridge_ids, br_name, default=None):
xapi_down = True
return default


# By default, the "bridge-id" external id in the Bridge table is the
# same as "xs-network-uuids". This may be overridden by defining a
# "nicira-bridge-id" key in the "other_config" field of the network
Expand Down

0 comments on commit bdca6c4

Please sign in to comment.