diff --git a/src/saltext/apache/modules/apache.py b/src/saltext/apache/modules/apache.py index 0425528..b38135e 100644 --- a/src/saltext/apache/modules/apache.py +++ b/src/saltext/apache/modules/apache.py @@ -44,10 +44,9 @@ def _detect_os(): os_family = __grains__["os_family"] if os_family == "RedHat": return "apachectl" - elif os_family == "Debian" or os_family == "Suse": + if os_family in ("Debian", "Suse"): return "apache2ctl" - else: - return "apachectl" + return "apachectl" def version(): @@ -204,6 +203,7 @@ def vhosts(): return ret +# pylint: disable=redefined-outer-name def signal(signal=None): """ Signals httpd to start, restart, or stop. @@ -218,7 +218,7 @@ def signal(signal=None): valid_signals = ("start", "stop", "restart", "graceful", "graceful-stop") if signal not in valid_signals and signal not in no_extra_args: - return + return None # Make sure you use the right arguments if signal in valid_signals: arguments = f" -k {signal}" @@ -344,7 +344,8 @@ def server_status(profile="default"): # get http data url += "?auto" try: - response = urllib.request.urlopen(url, timeout=timeout).read().splitlines() + with urllib.request.urlopen(url, timeout=timeout) as http_response: + response = http_response.read().splitlines() except urllib.error.URLError: return "error" diff --git a/src/saltext/apache/modules/deb_apache.py b/src/saltext/apache/modules/deb_apache.py index ce257fd..2a37f64 100644 --- a/src/saltext/apache/modules/deb_apache.py +++ b/src/saltext/apache/modules/deb_apache.py @@ -36,10 +36,9 @@ def _detect_os(): # TODO: Add pillar support for the apachectl location if __grains__["os_family"] == "RedHat": return "apachectl" - elif __grains__["os_family"] == "Debian": + if __grains__["os_family"] == "Debian": return "apache2ctl" - else: - return "apachectl" + return "apachectl" def check_site_enabled(site): @@ -62,10 +61,9 @@ def check_site_enabled(site): site_file = f"{site}.conf" if os.path.islink(f"{SITE_ENABLED_DIR}/{site_file}"): return True - elif site == "default" and os.path.islink(f"{SITE_ENABLED_DIR}/000-{site_file}"): + if site == "default" and os.path.islink(f"{SITE_ENABLED_DIR}/000-{site_file}"): return True - else: - return False + return False def a2ensite(site): diff --git a/src/saltext/apache/states/apache.py b/src/saltext/apache/states/apache.py index 60ed48f..d8c004b 100644 --- a/src/saltext/apache/states/apache.py +++ b/src/saltext/apache/states/apache.py @@ -109,7 +109,7 @@ def configfile(name, config): ret["result"] = True ret["comment"] = "Configuration is up to date." return ret - elif __opts__["test"]: + if __opts__["test"]: ret["comment"] = "Configuration will update." ret["changes"] = {"old": current_configs, "new": configs} ret["result"] = None @@ -121,7 +121,7 @@ def configfile(name, config): ret["changes"] = {"old": current_configs, "new": configs} ret["result"] = True ret["comment"] = "Successfully created configuration." - except Exception as exc: # pylint: disable=broad-except + except Exception: # pylint: disable=broad-except ret["result"] = False ret["comment"] = "Failed to create apache configuration."