From 093d1500b9a1524b89de63e3a432315ffffe80cb Mon Sep 17 00:00:00 2001 From: Paul Belanger Date: Mon, 16 Dec 2019 08:24:38 -0500 Subject: [PATCH] Clean up flake8 for ansible.netcommon collection (#65842) We noticed the following flake8 errors when we ran the migration script for ansible.netcommon. Signed-off-by: Paul Belanger --- lib/ansible/module_utils/network/common/config.py | 1 - lib/ansible/module_utils/network/common/utils.py | 6 +++--- lib/ansible/plugins/action/net_get.py | 3 +-- lib/ansible/plugins/action/net_put.py | 1 - lib/ansible/plugins/action/network.py | 1 - lib/ansible/plugins/connection/netconf.py | 2 +- lib/ansible/plugins/httpapi/restconf.py | 1 - lib/ansible/plugins/netconf/default.py | 2 +- test/units/plugins/connection/test_network_cli.py | 2 +- test/units/plugins/filter/test_network.py | 4 +--- 10 files changed, 8 insertions(+), 15 deletions(-) diff --git a/lib/ansible/module_utils/network/common/config.py b/lib/ansible/module_utils/network/common/config.py index 5bb12671497..974d346098b 100644 --- a/lib/ansible/module_utils/network/common/config.py +++ b/lib/ansible/module_utils/network/common/config.py @@ -30,7 +30,6 @@ import hashlib from ansible.module_utils.six.moves import zip from ansible.module_utils._text import to_bytes, to_native -from ansible.module_utils.network.common.utils import to_list DEFAULT_COMMENT_TOKENS = ['#', '!', '/*', '*/', 'echo'] diff --git a/lib/ansible/module_utils/network/common/utils.py b/lib/ansible/module_utils/network/common/utils.py index e41bacc2cc2..14077e84262 100644 --- a/lib/ansible/module_utils/network/common/utils.py +++ b/lib/ansible/module_utils/network/common/utils.py @@ -35,8 +35,6 @@ import socket import json from itertools import chain -from socket import inet_aton -from json import dumps from ansible.module_utils._text import to_text, to_bytes from ansible.module_utils.common._collections_compat import Mapping @@ -45,7 +43,9 @@ from ansible.module_utils import basic from ansible.module_utils.parsing.convert_bool import boolean # Backwards compatibility for 3rd party modules -from ansible.module_utils.common.network import ( +# TODO(pabelanger): With move to ansible.netcommon, we should clean this code +# up and have modules import directly themself. +from ansible.module_utils.common.network import ( # noqa: F401 to_bits, is_netmask, is_masklen, to_netmask, to_masklen, to_subnet, to_ipv6_network, VALID_MASKS ) diff --git a/lib/ansible/plugins/action/net_get.py b/lib/ansible/plugins/action/net_get.py index b19c44824cf..4f96f9d9615 100644 --- a/lib/ansible/plugins/action/net_get.py +++ b/lib/ansible/plugins/action/net_get.py @@ -17,7 +17,6 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import copy import os import re import uuid @@ -37,7 +36,7 @@ class ActionModule(ActionBase): def run(self, tmp=None, task_vars=None): socket_path = None - network_os = self._get_network_os(task_vars) + self._get_network_os(task_vars) persistent_connection = self._play_context.connection.split('.')[-1] result = super(ActionModule, self).run(task_vars=task_vars) diff --git a/lib/ansible/plugins/action/net_put.py b/lib/ansible/plugins/action/net_put.py index bd844a12166..a1b83fc6c42 100644 --- a/lib/ansible/plugins/action/net_put.py +++ b/lib/ansible/plugins/action/net_put.py @@ -17,7 +17,6 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import copy import os import uuid import hashlib diff --git a/lib/ansible/plugins/action/network.py b/lib/ansible/plugins/action/network.py index d91c9b2af92..24b1ca32c6a 100644 --- a/lib/ansible/plugins/action/network.py +++ b/lib/ansible/plugins/action/network.py @@ -21,7 +21,6 @@ __metaclass__ = type import os import time -import glob import re from ansible.errors import AnsibleError diff --git a/lib/ansible/plugins/connection/netconf.py b/lib/ansible/plugins/connection/netconf.py index 47d5e12ee2b..a45d25a9ca6 100644 --- a/lib/ansible/plugins/connection/netconf.py +++ b/lib/ansible/plugins/connection/netconf.py @@ -329,7 +329,7 @@ class Connection(NetworkConnectionBase): self._manager._timeout = self.get_option('persistent_command_timeout') except SSHUnknownHostError as exc: raise AnsibleConnectionFailure(to_native(exc)) - except ImportError as exc: + except ImportError: raise AnsibleError("connection=netconf is not supported on {0}".format(self._network_os)) if not self._manager.connected: diff --git a/lib/ansible/plugins/httpapi/restconf.py b/lib/ansible/plugins/httpapi/restconf.py index ad5bd999188..7d121ff1bd1 100644 --- a/lib/ansible/plugins/httpapi/restconf.py +++ b/lib/ansible/plugins/httpapi/restconf.py @@ -42,7 +42,6 @@ options: import json from ansible.module_utils._text import to_text -from ansible.module_utils.network.common.utils import to_list from ansible.module_utils.connection import ConnectionError from ansible.module_utils.six.moves.urllib.error import HTTPError from ansible.plugins.httpapi import HttpApiBase diff --git a/lib/ansible/plugins/netconf/default.py b/lib/ansible/plugins/netconf/default.py index dabebaaf06b..f59b7b97730 100644 --- a/lib/ansible/plugins/netconf/default.py +++ b/lib/ansible/plugins/netconf/default.py @@ -21,7 +21,7 @@ __metaclass__ = type import json -from ansible.module_utils._text import to_text, to_bytes +from ansible.module_utils._text import to_text from ansible.plugins.netconf import NetconfBase diff --git a/test/units/plugins/connection/test_network_cli.py b/test/units/plugins/connection/test_network_cli.py index 2268721bf77..e439db669ad 100644 --- a/test/units/plugins/connection/test_network_cli.py +++ b/test/units/plugins/connection/test_network_cli.py @@ -127,7 +127,7 @@ class TestConnectionClass(unittest.TestCase): """ mock__shell.recv.side_effect = [response, None] - output = conn.send(b'command') + conn.send(b'command') mock__shell.sendall.assert_called_with(b'command\r') self.assertEqual(to_text(conn._command_response), 'command response') diff --git a/test/units/plugins/filter/test_network.py b/test/units/plugins/filter/test_network.py index cbce8c823fa..04e328a754d 100644 --- a/test/units/plugins/filter/test_network.py +++ b/test/units/plugins/filter/test_network.py @@ -20,8 +20,6 @@ __metaclass__ = type import os import sys -import pytest - from units.compat import unittest from ansible.plugins.filter.network import parse_xml, type5_pw, hash_salt, comp_type5, vlan_parser @@ -141,7 +139,7 @@ class TestHashSalt(unittest.TestCase): def test_unparseable_salt(self): password = '$nTc1$Z28sUTcWfXlvVe2x.3XAa.' with self.assertRaises(Exception) as e: - parsed = hash_salt(password) + hash_salt(password) self.assertEqual("Could not parse salt out password correctly from $nTc1$Z28sUTcWfXlvVe2x.3XAa.", str(e.exception))