From 55c7c987bd5e377db9bcaeb9a4f487397c12a128 Mon Sep 17 00:00:00 2001 From: Oyvind Albrigtsen Date: Wed, 20 Mar 2024 12:21:48 +0100 Subject: [PATCH] lib/all agents: use r"" for all regular expressions to avoid SyntaxWarning errors --- agents/alom/fence_alom.py | 2 +- agents/amt/fence_amt.py | 2 +- agents/apc/fence_apc.py | 18 +++++++++--------- agents/azure_arm/fence_azure_arm.py | 2 +- agents/cdu/fence_cdu.py | 8 ++++---- agents/cisco_ucs/fence_cisco_ucs.py | 14 +++++++------- agents/gce/fence_gce.py | 6 +++--- agents/ilo/fence_ilo.py | 2 +- agents/ilo_mp/fence_ilo_mp.py | 2 +- agents/ilo_ssh/fence_ilo_ssh.py | 2 +- agents/ipmilan/fence_ipmilan.py | 6 +++--- agents/ironic/fence_ironic.py | 4 ++-- agents/lpar/fence_lpar.py | 10 +++++----- agents/netio/fence_netio.py | 2 +- agents/raritan/fence_raritan.py | 2 +- agents/rhevm/fence_rhevm.py | 10 +++++----- agents/rsa/fence_rsa.py | 2 +- agents/wti/fence_wti.py | 6 +++--- lib/azure_fence.py.py | 2 +- lib/fencing.py.py | 12 ++++++------ lib/fencing_snmp.py.py | 2 +- 21 files changed, 58 insertions(+), 58 deletions(-) diff --git a/agents/alom/fence_alom.py b/agents/alom/fence_alom.py index a8e216f3f..e593f16b5 100644 --- a/agents/alom/fence_alom.py +++ b/agents/alom/fence_alom.py @@ -13,7 +13,7 @@ def get_power_status(conn, options): conn.send_eol("showplatform") conn.log_expect(options["--command-prompt"], int(options["--shell-timeout"])) - status = re.search("standby", conn.before.lower()) + status = re.search(r"standby", conn.before.lower()) result = (status != None and "off" or "on") return result diff --git a/agents/amt/fence_amt.py b/agents/amt/fence_amt.py index 183bbc713..67e2112d3 100644 --- a/agents/amt/fence_amt.py +++ b/agents/amt/fence_amt.py @@ -13,7 +13,7 @@ def get_power_status(_, options): output = amt_run_command(options, create_command(options, "status")) - match = re.search('Powerstate:[\\s]*(..)', str(output)) + match = re.search(r'Powerstate:[\s]*(..)', str(output)) status = match.group(1) if match else None if status == None: diff --git a/agents/apc/fence_apc.py b/agents/apc/fence_apc.py index bc52aa244..805b83141 100644 --- a/agents/apc/fence_apc.py +++ b/agents/apc/fence_apc.py @@ -36,21 +36,21 @@ def get_power_status(conn, options): admin = 0 switch = 0 - if None != re.compile('.* MasterSwitch plus.*', re.IGNORECASE | re.S).match(conn.before): + if None != re.compile(r'.* MasterSwitch plus.*', re.IGNORECASE | re.S).match(conn.before): switch = 1 - if None != re.compile('.* MasterSwitch plus 2', re.IGNORECASE | re.S).match(conn.before): + if None != re.compile(r'.* MasterSwitch plus 2', re.IGNORECASE | re.S).match(conn.before): if "--switch" not in options: fail_usage("Failed: You have to enter physical switch number") else: if "--switch" not in options: options["--switch"] = "1" - if None == re.compile('.*Outlet Management.*', re.IGNORECASE | re.S).match(conn.before): + if None == re.compile(r'.*Outlet Management.*', re.IGNORECASE | re.S).match(conn.before): version = 2 else: version = 3 - if None == re.compile('.*Outlet Control/Configuration.*', re.IGNORECASE | re.S).match(conn.before): + if None == re.compile(r'.*Outlet Control/Configuration.*', re.IGNORECASE | re.S).match(conn.before): admin = 0 else: admin = 1 @@ -109,26 +109,26 @@ def set_power_status(conn, options): admin3 = 0 switch = 0 - if None != re.compile('.* MasterSwitch plus.*', re.IGNORECASE | re.S).match(conn.before): + if None != re.compile(r'.* MasterSwitch plus.*', re.IGNORECASE | re.S).match(conn.before): switch = 1 ## MasterSwitch has different schema for on/off actions action = { 'on' : "1", 'off': "3" }[options["--action"]] - if None != re.compile('.* MasterSwitch plus 2', re.IGNORECASE | re.S).match(conn.before): + if None != re.compile(r'.* MasterSwitch plus 2', re.IGNORECASE | re.S).match(conn.before): if "--switch" not in options: fail_usage("Failed: You have to enter physical switch number") else: if "--switch" not in options: options["--switch"] = 1 - if None == re.compile('.*Outlet Management.*', re.IGNORECASE | re.S).match(conn.before): + if None == re.compile(r'.*Outlet Management.*', re.IGNORECASE | re.S).match(conn.before): version = 2 else: version = 3 - if None == re.compile('.*Outlet Control/Configuration.*', re.IGNORECASE | re.S).match(conn.before): + if None == re.compile(r'.*Outlet Control/Configuration.*', re.IGNORECASE | re.S).match(conn.before): admin2 = 0 else: admin2 = 1 @@ -142,7 +142,7 @@ def set_power_status(conn, options): else: conn.send_eol("2") conn.log_expect(options["--command-prompt"], int(options["--shell-timeout"])) - if None == re.compile('.*2- Outlet Restriction.*', re.IGNORECASE | re.S).match(conn.before): + if None == re.compile(r'.*2- Outlet Restriction.*', re.IGNORECASE | re.S).match(conn.before): admin3 = 0 else: admin3 = 1 diff --git a/agents/azure_arm/fence_azure_arm.py b/agents/azure_arm/fence_azure_arm.py index 0dca8f30d..227a7c2e2 100755 --- a/agents/azure_arm/fence_azure_arm.py +++ b/agents/azure_arm/fence_azure_arm.py @@ -251,7 +251,7 @@ def main(): except ImportError: fail_usage("Azure Resource Manager Python SDK not found or not accessible") except Exception as e: - fail_usage("Failed: %s" % re.sub("^, ", "", str(e))) + fail_usage("Failed: %s" % re.sub(r"^, ", r"", str(e))) if "--network-fencing" in options: # use off-action to quickly return off once network is fenced instead of diff --git a/agents/cdu/fence_cdu.py b/agents/cdu/fence_cdu.py index ba76e6d76..6373158e9 100644 --- a/agents/cdu/fence_cdu.py +++ b/agents/cdu/fence_cdu.py @@ -51,11 +51,11 @@ def get_power_status(conn, options): if options["api-version"] == "8": # AA13 Arm-Console3 Wake On On Normal # AA14 Master_Outlet_14 Wake On On Normal - show_re = re.compile('(\w+)\s+(\S+)\s+(On|Idle On|Off|Wake On)\s+(On|Off)') + show_re = re.compile(r'(\w+)\s+(\S+)\s+(On|Idle On|Off|Wake On)\s+(On|Off)') else: # .A12 TowerA_Outlet12 On Idle On # .A12 test-01 On Idle On - show_re = re.compile('(\.\w+)\s+(\w+|\w+\W\w+)\s+(On|Off)\s+(On|Idle On|Off|Wake On)') + show_re = re.compile(r'(\.\w+)\s+(\w+|\w+\W\w+)\s+(On|Off)\s+(On|Idle On|Off|Wake On)') for line in lines: res = show_re.search(line) if res != None: @@ -89,7 +89,7 @@ def set_power_status(conn, options): # else: # .A12 TowerA_Outlet12 # .A12 test-01 - show_re = re.compile('(\S+)\s+(\w+|\w+\W\w+)\s+') + show_re = re.compile(r'(\S+)\s+(\w+|\w+\W\w+)\s+') for line in lines: res = show_re.search(line) if res != None: @@ -112,7 +112,7 @@ def get_version(conn, options): conn.send("VERSION\r\n") conn.log_expect(options["--command-prompt"], int(options["--shell-timeout"])) lines = conn.before.split("\n") - show_re = re.compile('Sentry Switched [PC]DU Version (\d)(.\d|)(\w)\r') + show_re = re.compile(r'Sentry Switched [PC]DU Version (\d)(.\d|)(\w)\r') for line in lines: res = show_re.search(line) if res != None: diff --git a/agents/cisco_ucs/fence_cisco_ucs.py b/agents/cisco_ucs/fence_cisco_ucs.py index cada20d5e..bcfabdbaa 100644 --- a/agents/cisco_ucs/fence_cisco_ucs.py +++ b/agents/cisco_ucs/fence_cisco_ucs.py @@ -8,13 +8,13 @@ from fencing import * from fencing import fail, EC_STATUS, EC_LOGIN_DENIED, run_delay -RE_COOKIE = re.compile("(.*?)", re.IGNORECASE) -RE_STATE = re.compile("(.*?)", re.IGNORECASE) -RE_GET_NAME = re.compile("(.*?)", re.IGNORECASE) +RE_GET_ID = re.compile(r"(.*?)", re.IGNORECASE) +RE_STATE = re.compile(r"(.*?)", re.IGNORECASE) +RE_GET_NAME = re.compile(r"(.*?)", re.IGNORECASE) def get_power_status(conn, options): del conn @@ -80,7 +80,7 @@ def send_command(opt, command, method="GET"): if opt["--api-version"] == "auto": opt["--api-version"] = "4" res = send_command(opt, "") - if re.search("Error", res): + if re.search(r"Error", res): opt["--api-version"] = "3" logging.debug("auto-detected API version: " + opt["--api-version"]) diff --git a/agents/rsa/fence_rsa.py b/agents/rsa/fence_rsa.py index 79ed109eb..6efde753c 100644 --- a/agents/rsa/fence_rsa.py +++ b/agents/rsa/fence_rsa.py @@ -16,7 +16,7 @@ def get_power_status(conn, options): conn.send_eol("power state") conn.log_expect(options["--command-prompt"], int(options["--shell-timeout"])) - match = re.compile("Power: (.*)", re.IGNORECASE).search(conn.before) + match = re.compile(r"Power: (.*)", re.IGNORECASE).search(conn.before) if match != None: status = match.group(1) else: diff --git a/agents/wti/fence_wti.py b/agents/wti/fence_wti.py index ffa3d019c..9c16f364d 100644 --- a/agents/wti/fence_wti.py +++ b/agents/wti/fence_wti.py @@ -27,7 +27,7 @@ def get_listing(conn, options, listing_command): re_all = list(options["--command-prompt"]) else: re_all = [options["--command-prompt"]] - re_next = re.compile("Enter: ", re.IGNORECASE) + re_next = re.compile(r"Enter: ", re.IGNORECASE) re_all.append(re_next) result = conn.log_expect(re_all, int(options["--shell-timeout"])) @@ -208,8 +208,8 @@ def main(): conn.send("set binary\n") conn.send("open %s -%s\n"%(options["--ip"], options["--ipport"])) - re_login = re.compile("(login: )|(Login Name: )|(username: )|(User Name :)", re.IGNORECASE) - re_prompt = re.compile("|".join(["(" + x + ")" for x in options["--command-prompt"]]), re.IGNORECASE) + re_login = re.compile(r"(login: )|(Login Name: )|(username: )|(User Name :)", re.IGNORECASE) + re_prompt = re.compile(r"|".join(["(" + x + ")" for x in options["--command-prompt"]]), re.IGNORECASE) result = conn.log_expect([re_login, "Password: ", re_prompt], int(options["--shell-timeout"])) if result == 0: diff --git a/lib/azure_fence.py.py b/lib/azure_fence.py.py index ab40b483a..fcbc40ab0 100644 --- a/lib/azure_fence.py.py +++ b/lib/azure_fence.py.py @@ -49,7 +49,7 @@ def get_from_metadata(parameter): return None def get_azure_resource(id): - match = re.match('(/subscriptions/([^/]*)/resourceGroups/([^/]*))(/providers/([^/]*/[^/]*)/([^/]*))?((/([^/]*)/([^/]*))*)', id) + match = re.match(r'(/subscriptions/([^/]*)/resourceGroups/([^/]*))(/providers/([^/]*/[^/]*)/([^/]*))?((/([^/]*)/([^/]*))*)', id) if not match: fail_usage("{get_azure_resource} cannot parse resource id %s" % id) diff --git a/lib/fencing.py.py b/lib/fencing.py.py index 3a60f53ee..511eb2689 100644 --- a/lib/fencing.py.py +++ b/lib/fencing.py.py @@ -614,7 +614,7 @@ def metadata(options, avail_opt, docs): sorted_list.sort(key=lambda x: (x[1]["order"], x[0])) if options["--action"] == "metadata": - docs["longdesc"] = re.sub("\\\\f[BPIR]|\.P|\.TP|\.br\n", "", docs["longdesc"]) + docs["longdesc"] = re.sub(r"\\f[BPIR]|\.P|\.TP|\.br\n", r"", docs["longdesc"]) print("") print("