From 93163a4aaa114eb1aaa605326f61524f5e2a4e2e Mon Sep 17 00:00:00 2001 From: Al Bailey Date: Sun, 11 Sep 2022 14:28:57 +0000 Subject: [PATCH] Minor sw-patch tox cleanup These changes will not affect the behaviour of sw-patch. - Remove fm-api from tox dependencies for sw-patch. - fm-api is not used by sw-patch - Cleanup flake8 error: H401 docstring should not start with a space - Cleanup pylint error: R1710 inconsistent-return-statements - Cleanup pylint error: W1505 deprecated-method The following are the deprecated methods - LOG.warn -> LOG.warning - ConfigParser.readfp -> ConfigParser.read_file - Added missing description for a suppressed pylint error - W3101 missing-timeout - Added two additional tox utilities: Neither tool is wired into the default tox, or zuul jobs. - tox -e prospector prospector calls multiple linters and validators - tox -e vulture vulture is a tool that detects unused code. Test Plan: - Run tox - Build / Install / Unlock AIO-DX - Apply a reboot required patch Story: 2009969 Task: 46265 Signed-off-by: Al Bailey Change-Id: I7fcd386d11ec3836059b1036fb334dcae9bedeb1 --- sw-patch/cgcs-patch/cgcs_patch/config.py | 5 ++--- sw-patch/cgcs-patch/cgcs_patch/patch_agent.py | 6 +++--- sw-patch/cgcs-patch/cgcs_patch/patch_client.py | 2 +- sw-patch/cgcs-patch/cgcs_patch/utils.py | 12 ++++++------ sw-patch/cgcs-patch/pylint.rc | 6 +++--- sw-patch/cgcs-patch/tox.ini | 16 +++++++++++++--- 6 files changed, 28 insertions(+), 19 deletions(-) diff --git a/sw-patch/cgcs-patch/cgcs_patch/config.py b/sw-patch/cgcs-patch/cgcs_patch/config.py index 31bed0fe..603d2fb8 100644 --- a/sw-patch/cgcs-patch/cgcs_patch/config.py +++ b/sw-patch/cgcs-patch/cgcs_patch/config.py @@ -66,7 +66,7 @@ def read_config(): # for ConfigParser. So we'll fake it out. ini_str = '[platform_conf]\n' + open(tsc.PLATFORM_CONF_FILE, 'r').read() ini_fp = io.StringIO(ini_str) - config.readfp(ini_fp) + config.read_file(ini_fp) try: value = str(config.get('platform_conf', 'nodetype')) @@ -75,7 +75,6 @@ def read_config(): nodetype = value except configparser.Error: logging.exception("Failed to read nodetype from config") - return False def get_mgmt_ip(): @@ -111,7 +110,7 @@ def get_mgmt_iface(): # for ConfigParser. So we'll fake it out. ini_str = '[platform_conf]\n' + open(tsc.PLATFORM_CONF_FILE, 'r').read() ini_fp = io.StringIO(ini_str) - config.readfp(ini_fp) + config.read_file(ini_fp) try: value = str(config.get('platform_conf', 'management_interface')) diff --git a/sw-patch/cgcs-patch/cgcs_patch/patch_agent.py b/sw-patch/cgcs-patch/cgcs_patch/patch_agent.py index 144b3e50..f97e52c3 100644 --- a/sw-patch/cgcs-patch/cgcs_patch/patch_agent.py +++ b/sw-patch/cgcs-patch/cgcs_patch/patch_agent.py @@ -344,7 +344,7 @@ class PatchAgent(PatchService): self.listener.listen(2) # Allow two connections, for two controllers def query(self): - """ Check current patch state """ + """Check current patch state """ if not check_install_uuid(): LOG.info("Failed install_uuid check. Skipping query") return False @@ -366,7 +366,7 @@ class PatchAgent(PatchService): try: self.latest_feed_commit = ostree_utils.get_feed_latest_commit(SW_VERSION) except OSTreeCommandFail: - LOG.warn("Unable to query latest feed commit") + LOG.warning("Unable to query latest feed commit") # latest_feed_commit will remain as None if self.latest_feed_commit: @@ -507,7 +507,7 @@ class PatchAgent(PatchService): self.query() if self.changes: - LOG.warn("Installing the patch did not change the patch current status") + LOG.warning("Installing the patch did not change the patch current status") # Send a hello to provide a state update if self.sock_out is not None: diff --git a/sw-patch/cgcs-patch/cgcs_patch/patch_client.py b/sw-patch/cgcs-patch/cgcs_patch/patch_client.py index 873c829b..7a78c26f 100644 --- a/sw-patch/cgcs-patch/cgcs_patch/patch_client.py +++ b/sw-patch/cgcs-patch/cgcs_patch/patch_client.py @@ -1085,7 +1085,7 @@ def patch_upload_dir_req(debug, args): def patch_install_local(debug, args): # pylint: disable=unused-argument - """ This function is used to trigger patch installation prior to configuration """ + """This function is used to trigger patch installation prior to configuration """ # Check to see if initial configuration has completed if os.path.isfile(INITIAL_CONTROLLER_CONFIG_COMPLETE): # Disallow the install diff --git a/sw-patch/cgcs-patch/cgcs_patch/utils.py b/sw-patch/cgcs-patch/cgcs_patch/utils.py index 340592fc..9760fd4e 100644 --- a/sw-patch/cgcs-patch/cgcs_patch/utils.py +++ b/sw-patch/cgcs-patch/cgcs_patch/utils.py @@ -24,7 +24,7 @@ def if_nametoindex(name): def gethostbyname(hostname): - """ gethostbyname with IPv6 support """ + """gethostbyname with IPv6 support """ try: return socket.getaddrinfo(hostname, None)[0][4][0] except Exception: @@ -32,7 +32,7 @@ def gethostbyname(hostname): def get_management_version(): - """ Determine whether management is IPv4 or IPv6 """ + """Determine whether management is IPv4 or IPv6 """ controller_ip_string = gethostbyname(constants.CONTROLLER_FLOATING_HOSTNAME) if controller_ip_string: controller_ip_address = IPAddress(controller_ip_string) @@ -58,7 +58,7 @@ def get_versioned_address_all(): def ip_to_url(ip_address_string): - """ Add brackets if an IPv6 address """ + """Add brackets if an IPv6 address """ try: ip_address = IPAddress(ip_address_string) if ip_address.version == constants.ADDRESS_VERSION_IPV6: @@ -70,7 +70,7 @@ def ip_to_url(ip_address_string): def ip_to_versioned_localhost(ip_address_string): - """ Add brackets if an IPv6 address """ + """Add brackets if an IPv6 address """ ip_address = IPAddress(ip_address_string) if ip_address.version == constants.ADDRESS_VERSION_IPV6: return "::1" @@ -108,8 +108,8 @@ def safe_rstrip(value, chars=None): """ if not isinstance(value, str): - LOG.warn("Failed to remove trailing character. Returning original " - "object. Supplied object is not a string: %s", value) + LOG.warning("Failed to remove trailing character. Returning original " + "object. Supplied object is not a string: %s", value) return value return value.rstrip(chars) or value diff --git a/sw-patch/cgcs-patch/pylint.rc b/sw-patch/cgcs-patch/pylint.rc index ee3cae4a..fc92ee06 100644 --- a/sw-patch/cgcs-patch/pylint.rc +++ b/sw-patch/cgcs-patch/pylint.rc @@ -73,7 +73,6 @@ extension-pkg-whitelist=lxml # R0915 too-many-statements # R1702 too-many-nested-blocks # R1705 no-else-return -# R1710 inconsistent-return-statements # R1714 consider-using-in # R1715 consider-using-get # R1722 consider-using-sys-exit @@ -89,12 +88,13 @@ extension-pkg-whitelist=lxml # W0707 raise-missing-from # W1505 deprecated-method # W1514 unspecified-encoding +# W3101 missing-timeout disable= C0103,C0114,C0115,C0116,C0201,C0206,C0209,C2801, C0301,C0302,C0325,C0411,C0415, R0205,R0402,R0801,R0902,R0903,R0904,R0911, - R0912,R0913,R0914,R0915,R1702,R1705,R1710,R1714, + R0912,R0913,R0914,R0915,R1702,R1705,R1714, R1715,R1722,R1724,R1725,R1732,R1735, - W0107,W0602,W0603,W0703,W0707,W1505,W1514,W3101 + W0107,W0602,W0603,W0703,W0707,W1514,W3101 [REPORTS] diff --git a/sw-patch/cgcs-patch/tox.ini b/sw-patch/cgcs-patch/tox.ini index 908f02e7..7f3fad39 100644 --- a/sw-patch/cgcs-patch/tox.ini +++ b/sw-patch/cgcs-patch/tox.ini @@ -16,7 +16,6 @@ basepython = python3 deps = -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt - -e{[tox]stxdir}/fault/fm-api/source -e{[tox]stxdir}/config/tsconfig/tsconfig install_command = pip install \ @@ -84,7 +83,6 @@ commands = bandit --ini tox.ini -n 5 -r cgcs_patch [flake8] # ignore below errors , will fix flake8 errors in future # H306 imports not in alphabetical order -# H401 docstring should not start with a space # H404 multi line docstring should start without a leading new line # H405 multi line docstring summary not separated with an empty line # Note: W503 and W504 are mutually exclusive. Must select one of them to suppress. @@ -92,7 +90,7 @@ commands = bandit --ini tox.ini -n 5 -r cgcs_patch # E501 line too long. skipped because some of the code files include templates # that end up quite wide show-source = True -ignore = H306,H401,H404,H405,W504,E501 +ignore = H306,H404,H405,W504,E501 exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build,release-tag-* # H106: Don't put vim configuration in source files (off by default). @@ -110,6 +108,18 @@ commands = flake8 {posargs} [testenv:pylint] commands = pylint cgcs_patch cgcs_make_patch --rcfile=./pylint.rc +[testenv:prospector] +basepython = python3.9 +deps = {[testenv]deps} + prospector +commands = prospector cgcs_patch + +[testenv:vulture] +basepython = python3.9 +deps = {[testenv]deps} + vulture +commands = vulture cgcs_make_patch cgcs_patch + [testenv:cover] setenv = PYTHONWARNINGS=ignore::DeprecationWarning,ignore::SyntaxWarning