From aac1c82d814116d274b530386c3c8f1021701437 Mon Sep 17 00:00:00 2001
From: Erik Reid <erik.reid@geant.org>
Date: Sun, 11 Nov 2018 14:37:22 +0100
Subject: [PATCH] pep8

---
 inventory_provider/alarmsdb.py          |  1 +
 inventory_provider/config.py            |  7 ++++---
 inventory_provider/juniper.py           | 19 ++++++++++++++-----
 inventory_provider/router_interfaces.py | 13 +++++--------
 inventory_provider/snmp.py              | 15 ++++++++++-----
 test/data/update_test_data.py           | 12 +++++++++---
 test/test_juniper_data.py               |  8 +++-----
 7 files changed, 46 insertions(+), 29 deletions(-)

diff --git a/inventory_provider/alarmsdb.py b/inventory_provider/alarmsdb.py
index ff6c04ff..01a4390b 100644
--- a/inventory_provider/alarmsdb.py
+++ b/inventory_provider/alarmsdb.py
@@ -31,6 +31,7 @@ def cursor(cnx):
         if csr:
             csr.close()
 
+
 def _db_test(db, router):
     database_logger = logging.getLogger(DATABASE_LOGGER_NAME)
     with cursor(db) as crs:
diff --git a/inventory_provider/config.py b/inventory_provider/config.py
index af13e2f4..b6631ad3 100644
--- a/inventory_provider/config.py
+++ b/inventory_provider/config.py
@@ -55,7 +55,10 @@ def _load_routers(config_file):
     :return:
     """
     for line in config_file:
-        m = re.match(r'^([a-z\d]+\.[a-z\d]{3,4}\.[a-z\d]{2}\.(geant|eumedconnect)\d*\.net)\s*=([^,]+)\s*,(.*)\s*$', line)
+        m = re.match(
+            r'^([a-z\d]+\.[a-z\d]{3,4}\.[a-z\d]{2}'
+            r'\.(geant|eumedconnect)\d*\.net)\s*=([^,]+)\s*,(.*)\s*$',
+            line)
         if not m:
             logging.warning("malformed config file line: '%s'" % line.strip())
             continue
@@ -66,7 +69,6 @@ def _load_routers(config_file):
         }
 
 
-
 def load(f):
     """
     loads, validates and returns configuration parameters
@@ -81,4 +83,3 @@ def load(f):
     with open(config["routers_community.conf"]) as f:
         config["routers"] = list(_load_routers(f))
     return config
-
diff --git a/inventory_provider/juniper.py b/inventory_provider/juniper.py
index 90cff088..54411375 100644
--- a/inventory_provider/juniper.py
+++ b/inventory_provider/juniper.py
@@ -22,7 +22,9 @@ def neighbors(
                     for bgp in prot.get("bgp", []):
                         for g in bgp.get("group", []):
                             if group_expression and not \
-                                    re.match(group_expression, g["name"]["data"]):
+                                    re.match(
+                                        group_expression,
+                                        g["name"]["data"]):
                                 continue
                             for n in g["neighbor"]:
                                 yield n
@@ -44,9 +46,14 @@ def interfaces(parsed_json_output):
 
 @contextlib.contextmanager
 def ssh_connection(hostname, ssh_params):
+    # TODO: remove this relative path logic!!
     import os
-    key_filename = os.path.join(os.path.dirname(__file__), ssh_params["private-key"])
-    known_hosts = os.path.join(os.path.dirname(__file__), ssh_params["known-hosts"])
+    key_filename = os.path.join(
+        os.path.dirname(__file__),
+        ssh_params["private-key"])
+    known_hosts = os.path.join(
+        os.path.dirname(__file__),
+        ssh_params["known-hosts"])
     k = paramiko.DSSKey.from_private_key_file(key_filename)
 
     with paramiko.SSHClient() as ssh:
@@ -109,13 +116,15 @@ def shell_commands():
             return {}
 
     yield {
-        "command": 'show configuration routing-instances IAS protocols bgp | display json',
+        "command": ('show configuration routing-instances'
+                    ' IAS protocols bgp | display json'),
         "key": "bgp",
         "parser": _parse_bgp_output
     }
 
     yield {
-        "command": 'show configuration logical-systems VRR protocols bgp | display json',
+        "command": ('show configuration logical-systems '
+                    'VRR protocols bgp | display json'),
         "key": "vrr",
         "parser": lambda txt: _loads(txt) if txt else {}
     }
diff --git a/inventory_provider/router_interfaces.py b/inventory_provider/router_interfaces.py
index f4cd737d..84127bbf 100644
--- a/inventory_provider/router_interfaces.py
+++ b/inventory_provider/router_interfaces.py
@@ -52,10 +52,6 @@ def get_router_details(router, params, q):
     command_output = commands_proc_queue.get()
     assert len(command_output) == len(commands)
 
-    # for c, o in zip(commands, command_output):
-    #     with open("/tmp/%s-%s.output" % (router["hostname"], c["key"]), "w") as f:
-    #         f.write(o)
-
     result = {}
     for c, o in zip(commands, command_output):
         if c["key"]:
@@ -87,10 +83,12 @@ def load_network_details(params):
 
     result = {}
     for p in processes:
-        threading_logger.debug("waiting for get_router_details result: %r" % p["router"])
+        threading_logger.debug(
+            "waiting for get_router_details result: %r" % p["router"])
         result[p["router"]["hostname"]] = p["queue"].get()
         p["process"].join()
-        threading_logger.debug("got result and joined get_router_details proc: %r" % p["router"])
+        threading_logger.debug(
+            "got result and joined get_router_details proc: %r" % p["router"])
 
     return result
 
@@ -102,7 +100,7 @@ def _validate_config(ctx, param, value):
 @click.command()
 @click.option(
     "--params",
-#    required=True,
+    # required=True,
     type=click.File(),
     help="Configuration filename",
     default=open("config.json"),
@@ -122,4 +120,3 @@ if __name__ == "__main__":
     logging.getLogger(constants.JUNIPER_LOGGER_NAME).setLevel(logging.DEBUG)
     logging.getLogger(constants.DATABASE_LOGGER_NAME).setLevel(logging.DEBUG)
     cli()
-
diff --git a/inventory_provider/snmp.py b/inventory_provider/snmp.py
index dc647597..5d588403 100644
--- a/inventory_provider/snmp.py
+++ b/inventory_provider/snmp.py
@@ -3,7 +3,8 @@ import re
 
 from pysnmp.hlapi import nextCmd, SnmpEngine, CommunityData, \
         UdpTransportTarget, ContextData, ObjectType, ObjectIdentity
-from pysnmp.smi import builder, view, compiler, rfc1902
+from pysnmp.smi import builder, compiler
+# from pysnmp.smi import view, rfc1902
 
 from inventory_provider.constants import SNMP_LOGGER_NAME
 
@@ -32,10 +33,15 @@ def walk(agent_hostname, community, base_oid):
     snmp_logger = logging.getLogger(SNMP_LOGGER_NAME)
 
     mibBuilder = builder.MibBuilder()
-    mibViewController = view.MibViewController(mibBuilder)
-    compiler.addMibCompiler(mibBuilder, sources=['http://mibs.snmplabs.com/asn1/@mib@'])
+    # mibViewController = view.MibViewController(mibBuilder)
+    compiler.addMibCompiler(
+        mibBuilder,
+        sources=['http://mibs.snmplabs.com/asn1/@mib@'])
     # Pre-load MIB modules we expect to work with
-    mibBuilder.loadModules('SNMPv2-MIB', 'SNMP-COMMUNITY-MIB', 'RFC1213-MIB')
+    mibBuilder.loadModules(
+        'SNMPv2-MIB',
+        'SNMP-COMMUNITY-MIB',
+        'RFC1213-MIB')
 
     snmp_logger.debug("walking %s: %s" % (agent_hostname, base_oid))
 
@@ -76,7 +82,6 @@ def get_router_interfaces(router, config):
         assert m, "sanity failure parsing oid: " + v4IfcName["oid"]
         v4IfcNames[m.group(1)] = v4IfcName["value"]
 
-    interfaces = []
     for v4Address, v4Mask, v4InterfaceOID in zip(
             details["v4Address"],
             details["v4Mask"],
diff --git a/test/data/update_test_data.py b/test/data/update_test_data.py
index a0e819f9..d8ee14cd 100644
--- a/test/data/update_test_data.py
+++ b/test/data/update_test_data.py
@@ -28,12 +28,18 @@ for c in juniper.shell_commands():
 
 SHELL_COMMANDS.append({
     "key": "bgpv4",
-    "command": r'show configuration routing-instances IAS protocols bgp | display set | match neighbor | match description | match "GEANT-IX | GEANT-IX-"'
+    "command": (r'show configuration routing-instances IAS '
+                r'protocols bgp | display set | match neighbor'
+                r' | match description'
+                r' | match "GEANT-IX | GEANT-IX-"')
 })
 
 SHELL_COMMANDS.append({
     "key": "bgpv6",
-    "command": r'show configuration routing-instances IAS protocols bgp | display set | match neighbor | match description | match "GEANT-IXv6 | GEANT-IXv6-"'
+    "command": (r'show configuration routing-instances IAS'
+                r' protocols bgp | display set | match neighbor'
+                r' | match description'
+                r' | match "GEANT-IXv6 | GEANT-IXv6-"')
 })
 
 
@@ -109,4 +115,4 @@ def main():
 
 if __name__ == "__main__":
     logging.basicConfig(level=logging.DEBUG)
-    main()
\ No newline at end of file
+    main()
diff --git a/test/test_juniper_data.py b/test/test_juniper_data.py
index f2ba03b0..3157a7d5 100644
--- a/test/test_juniper_data.py
+++ b/test/test_juniper_data.py
@@ -77,7 +77,6 @@ CACHE_SCHEMA = {
 }
 
 
-
 @pytest.fixture
 def cached_test_data():
     with open("router-info.json") as f:
@@ -98,7 +97,7 @@ def _parsed_old_style_output_data(s):
              r'neighbor\s+([a-f\d\.:]+)\s+'
              r'description\s+"?([^"]+)"?\s*$'), l)
         assert m
-        
+
         yield {
             "routing-instances": m.group(1),
             "protocols": m.group(2),
@@ -130,7 +129,7 @@ def test_ipv4_neighbors(router_output):
     parsers = dict([(c["key"], c["parser"]) for c in juniper.shell_commands()])
     neighbors = parsers["bgp"](
         router_output["bgp"],
-        group_expression = r'^GEANT-IX[\s-].*$')
+        group_expression=r'^GEANT-IX[\s-].*$')
 
     assert len(neighbors) == len(old_v4_data)
     for n in neighbors:
@@ -149,7 +148,7 @@ def test_ipv6_neighbors(router_output):
     parsers = dict([(c["key"], c["parser"]) for c in juniper.shell_commands()])
     neighbors = parsers["bgp"](
         router_output["bgp"],
-        group_expression = r'^GEANT-IXv6[\s-].*$')
+        group_expression=r'^GEANT-IXv6[\s-].*$')
 
     assert len(neighbors) == len(old_v6_data)
     for n in neighbors:
@@ -171,4 +170,3 @@ def test_juniper_shell_output_parsing(router_output):
         if c["key"] is None:
             continue
         c["parser"](router_output[c["key"]])
-
-- 
GitLab