From bdca6c4b56b9951b95c02f1fc13cbc78b16eee28 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Fri, 11 Dec 2015 22:28:31 -0500 Subject: [PATCH] python: Resolve pep8 blank line errors. Resolve pep8 errors E302 and E303: E302 expected 2 blank lines, found 1 E303 too many blank lines (3) Signed-off-by: Russell Bryant Acked-by: Ben Pfaff --- Makefile.am | 2 +- ofproto/ipfix-gen-entities | 3 +++ python/build/nroff.py | 6 ++++++ python/ovs/poller.py | 1 + python/ovs/timeval.py | 3 +++ python/ovs/unixctl/__init__.py | 1 + python/ovs/unixctl/server.py | 1 + python/ovstest/args.py | 2 ++ python/ovstest/tests.py | 1 - python/ovstest/vswitch.py | 1 + tests/MockXenAPI.py | 3 +++ tests/test-unix-socket.py | 2 ++ tests/test-unixctl.py | 1 + utilities/ovs-pcap.in | 3 +++ vtep/ovs-vtep | 15 ++++++++++++++- .../usr_share_openvswitch_scripts_ovs-xapi-sync | 2 ++ 16 files changed, 44 insertions(+), 3 deletions(-) diff --git a/Makefile.am b/Makefile.am index d224a39f9..030021cac 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/ofproto/ipfix-gen-entities b/ofproto/ipfix-gen-entities index 7cd0b03b7..6fd76b117 100755 --- a/ofproto/ipfix-gen-entities +++ b/ofproto/ipfix-gen-entities @@ -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'] @@ -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 diff --git a/python/build/nroff.py b/python/build/nroff.py index 674fdfea3..58c006c1f 100644 --- a/python/build/nroff.py +++ b/python/build/nroff.py @@ -17,6 +17,7 @@ import sys from ovs.db import error + def text_to_nroff(s, font=r'\fR'): def escape(match): c = match.group(0) @@ -56,9 +57,11 @@ def text_to_nroff(s, font=r'\fR'): 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: @@ -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 @@ -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 = '' @@ -210,6 +215,7 @@ fillval = .2 .RE \\}""" + def block_xml_to_nroff(nodes, para='.PP'): s = '' for node in nodes: diff --git a/python/ovs/poller.py b/python/ovs/poller.py index b67cfc578..f6161267d 100644 --- a/python/ovs/poller.py +++ b/python/ovs/poller.py @@ -35,6 +35,7 @@ POLLERR = 0x008 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. diff --git a/python/ovs/timeval.py b/python/ovs/timeval.py index a16bf60d4..9a0cf6762 100644 --- a/python/ovs/timeval.py +++ b/python/ovs/timeval.py @@ -52,6 +52,7 @@ except: # Librt shared library could not be loaded librt = None + def monotonic(): if not librt: return time.time() @@ -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 diff --git a/python/ovs/unixctl/__init__.py b/python/ovs/unixctl/__init__.py index 715f2db5f..c6484c446 100644 --- a/python/ovs/unixctl/__init__.py +++ b/python/ovs/unixctl/__init__.py @@ -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) diff --git a/python/ovs/unixctl/server.py b/python/ovs/unixctl/server.py index 18e1cf20b..c750fe920 100644 --- a/python/ovs/unixctl/server.py +++ b/python/ovs/unixctl/server.py @@ -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) diff --git a/python/ovstest/args.py b/python/ovstest/args.py index e90db2a53..434497974 100644 --- a/python/ovstest/args.py +++ b/python/ovstest/args.py @@ -24,6 +24,7 @@ import sys CONTROL_PORT = 15531 DATA_PORT = 15532 + def ip_address(string): """Verifies if string is a valid IP address""" try: @@ -246,6 +247,7 @@ def ovs_initialize_args(): 'OuterIP.') return parser.parse_args() + def l3_initialize_args(): """ Initialize argument parsing for ovs-l3ping utility. diff --git a/python/ovstest/tests.py b/python/ovstest/tests.py index 5d5a85f28..26befef4e 100644 --- a/python/ovstest/tests.py +++ b/python/ovstest/tests.py @@ -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 diff --git a/python/ovstest/vswitch.py b/python/ovstest/vswitch.py index be66a2ebd..1c6726ea0 100644 --- a/python/ovstest/vswitch.py +++ b/python/ovstest/vswitch.py @@ -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 diff --git a/tests/MockXenAPI.py b/tests/MockXenAPI.py index cca1571fe..b8de4ee71 100644 --- a/tests/MockXenAPI.py +++ b/tests/MockXenAPI.py @@ -14,6 +14,7 @@ import re + def xapi_local(): return Session() @@ -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": @@ -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": diff --git a/tests/test-unix-socket.py b/tests/test-unix-socket.py index f55f6c3f9..ebfa05442 100644 --- a/tests/test-unix-socket.py +++ b/tests/test-unix-socket.py @@ -20,6 +20,7 @@ import sys import ovs.socket_util + def main(argv): if len(argv) not in (2, 3): sys.stderr.write("usage: %s SOCKETNAME1 [SOCKETNAME2]", argv[0]) @@ -52,5 +53,6 @@ def main(argv): os.strerror(error))) sys.exit(1) + if __name__ == '__main__': main(sys.argv) diff --git a/tests/test-unixctl.py b/tests/test-unixctl.py index ab03479be..49a3b617d 100644 --- a/tests/test-unixctl.py +++ b/tests/test-unixctl.py @@ -22,6 +22,7 @@ import ovs.unixctl.server vlog = ovs.vlog.Vlog("test-unixctl") exiting = False + def unixctl_exit(conn, unused_argv, aux): assert aux == "aux_exit" global exiting diff --git a/utilities/ovs-pcap.in b/utilities/ovs-pcap.in index 530648035..5253c3157 100755 --- a/utilities/ovs-pcap.in +++ b/utilities/ovs-pcap.in @@ -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") @@ -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 diff --git a/vtep/ovs-vtep b/vtep/ovs-vtep index 9b6799e33..1811e29ac 100755 --- a/vtep/ovs-vtep +++ b/vtep/ovs-vtep @@ -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() @@ -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)) @@ -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 " @@ -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: @@ -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: @@ -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 @@ -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: @@ -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: @@ -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) @@ -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) @@ -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() @@ -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] @@ -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): diff --git a/xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync b/xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync index cb1f175a6..583356c36 100755 --- a/xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync +++ b/xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync @@ -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. @@ -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 -- 2.20.1