Skip to content

Commit ab83169

Browse files
committed
Fix Python 3.14 SyntaxWarnings for invalid escape sequences
Convert regular strings with escape sequences to raw strings (r'...') to fix SyntaxWarnings that appear with Python 3.14. These warnings occur because escape sequences like \[, \(, $, \d, \w are invalid in regular strings and will not work in future Python versions. Files modified: - common/OPexpect.py: Fixed regex patterns with \[, \d - common/OpTestIPMI.py: Fixed regex patterns with \( - common/OpTestUtil.py: Fixed prompt patterns and sed commands with \[, $, \x1b - common/OpTestHost.py: Fixed regex patterns - testcases/*.py: Fixed various regex patterns and escape sequences All changes use raw strings (r'...') which treat backslashes literally, making them suitable for regex patterns and shell commands. The changes are backward compatible with older Python versions. Signed-off-by: Sachin Sant <sachinp@linux.ibm.com>
1 parent 8ee238b commit ab83169

32 files changed

Lines changed: 100 additions & 100 deletions

common/OPexpect.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def expect(self, pattern, timeout=-1, searchwindowsize=-1):
7171
"watchdog: .* detected hard LOCKUP on other CPUs",
7272
"Watchdog .* detected Hard LOCKUP other CPUS",
7373
"watchdog: BUG: soft lockup",
74-
"\[[0-9. ]+,0\] Assert fail:",
75-
"\[[0-9. ]+,[0-9]\] Unexpected exception",
74+
r"\[[0-9. ]+,0\] Assert fail:",
75+
r"\[[0-9. ]+,[0-9]\] Unexpected exception",
7676
"OPAL exiting with locks held",
7777
"LOCK ERROR: Releasing lock we don't hold",
7878
"OPAL: Reboot requested due to Platform error."
@@ -113,7 +113,7 @@ def expect(self, pattern, timeout=-1, searchwindowsize=-1):
113113
"Watchdog .* Hard LOCKUP",
114114
"Sending IPI to other CPUs",
115115
":mon>",
116-
"Rebooting in \d+ seconds",
116+
r"Rebooting in \d+ seconds",
117117
"Kernel panic - not syncing: Fatal exception",
118118
"Kernel panic - not syncing: Hard LOCKUP",
119119
"opal_cec_reboot2", pexpect.TIMEOUT],

common/OpTestHost.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ def host_get_list_of_chips(self, console=0):
821821
"PATH=/usr/local/sbin:$PATH getscom -l", console=console)
822822
chips = []
823823
for line in res:
824-
matchObj = re.search("(\d{8}).*processor", line)
824+
matchObj = re.search(r"(\d{8}).*processor", line)
825825
if matchObj:
826826
chips.append(matchObj.group(1))
827827
if not chips:
@@ -834,7 +834,7 @@ def host_get_cores(self, console=0):
834834
proc_gen = self.host_get_proc_gen(console=console)
835835
core_ids = {}
836836
cpu_pirs = self.host_run_command(
837-
"find /sys/devices/system/cpu/*/pir -exec cat {} \;", console=console)
837+
r"find /sys/devices/system/cpu/*/pir -exec cat {} \;", console=console)
838838
for pir in cpu_pirs:
839839
if proc_gen in ["POWER8", "POWER8E"]:
840840
core_id = hex((int("0x%s" % pir, 16) >> 3) & 0xf)
@@ -904,7 +904,7 @@ def host_get_online_cpus(self, console=0):
904904

905905
def host_gather_debug_logs(self, console=0):
906906
self.host_run_command(
907-
"grep ',[0-4]\]' /sys/firmware/opal/msglog", console=console)
907+
r"grep ',[0-4]\]' /sys/firmware/opal/msglog", console=console)
908908
self.host_run_command(
909909
"dmesg -T --level=alert,crit,err,warn", console=console)
910910

common/OpTestIPMI.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,7 @@ def is_tpm_enabled(self):
13921392
def ipmi_get_golden_side_sensor_id(self):
13931393
cmd = "sdr elist -v | grep -i 'BIOS Golden'"
13941394
output = self.ipmitool.run(cmd)
1395-
matchObj = re.search("BIOS Golden Side \((.*)\)", output)
1395+
matchObj = re.search(r"BIOS Golden Side \((.*)\)", output)
13961396
id = None
13971397
if matchObj:
13981398
id = matchObj.group(1)
@@ -1401,7 +1401,7 @@ def ipmi_get_golden_side_sensor_id(self):
14011401
def ipmi_get_boot_count_sensor_id(self):
14021402
cmd = "sdr elist -v | grep -i 'Boot Count'"
14031403
output = self.ipmitool.run(cmd)
1404-
matchObj = re.search("Boot Count \((.*)\)", output)
1404+
matchObj = re.search(r"Boot Count \((.*)\)", output)
14051405
id = None
14061406
if matchObj:
14071407
id = matchObj.group(1)

common/OpTestUtil.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,9 +1291,9 @@ def build_prompt(self, prompt=None, ssh=False):
12911291
built_prompt = prompt
12921292
else:
12931293
if ssh:
1294-
built_prompt = "\[ssh-expect\]#"
1294+
built_prompt = r"\[ssh-expect\]#"
12951295
else:
1296-
built_prompt = "\[console-expect\]#"
1296+
built_prompt = r"\[console-expect\]#"
12971297

12981298
return built_prompt
12991299

@@ -1727,7 +1727,7 @@ def get_login(self, host, term_obj, pty, prompt):
17271727
if rc == 0:
17281728
pty.sendline(my_pwd)
17291729
time.sleep(0.5)
1730-
rc = pty.expect(['login: $', ".*#$", ".*# $", ".*\$", "~ #", ":~",
1730+
rc = pty.expect(['login: $', ".*#$", ".*# $", r".*\$", "~ #", ":~",
17311731
'Petitboot', pexpect.TIMEOUT, pexpect.EOF], timeout=60)
17321732
if rc not in [1, 2, 3, 4, 5]:
17331733
if term_obj.setup_term_quiet == 0:
@@ -1761,7 +1761,7 @@ def get_login(self, host, term_obj, pty, prompt):
17611761
if rc == 0:
17621762
pty.sendline(my_pwd)
17631763
time.sleep(0.5)
1764-
rc = pty.expect(['login: $', ".*#$", ".*# $", ".*\$", "~ #", ":~",
1764+
rc = pty.expect(['login: $', ".*#$", ".*# $", r".*\$", "~ #", ":~",
17651765
'Petitboot', pexpect.TIMEOUT, pexpect.EOF], timeout=60)
17661766
if rc not in [1, 2, 3, 4, 5]:
17671767
if term_obj.setup_term_quiet == 0:
@@ -1902,7 +1902,7 @@ def setup_term(self, system, pty, ssh_obj=None, block=0):
19021902
if system_obj.state == 3: # OpSystemState.PETITBOOT
19031903
return
19041904

1905-
rc = pty.expect(['login: $', ".*#$", ".*# $", ".*\$", "~>", "~ #",
1905+
rc = pty.expect(['login: $', ".*#$", ".*# $", r".*\$", "~>", "~ #",
19061906
'Petitboot', pexpect.TIMEOUT, pexpect.EOF], timeout=60)
19071907
if rc == 0:
19081908
track_obj.PS1_set, track_obj.LOGIN_set = self.get_login(
@@ -1932,8 +1932,8 @@ def setup_term(self, system, pty, ssh_obj=None, block=0):
19321932
pty.sendcontrol('l')
19331933
# Ctrl-L may cause a esc[J (erase) character to appear in the buffer.
19341934
# Include this in the patterns that expect $ (end of line)
1935-
rc = pty.expect(['login: (\x1b\[J)*$', ".*#(\x1b\[J)*$", ".*# (\x1b\[J)*$", ".*\$(\x1b\[J)*",
1936-
"~>(\x1b\[J)", "~ #(\x1b\[J)", ":~(\x1b\[J)*", 'Petitboot', pexpect.TIMEOUT, pexpect.EOF], timeout=30)
1935+
rc = pty.expect([r'login: (\x1b\[J)*$', r".*#(\x1b\[J)*$", r".*# (\x1b\[J)*$", r".*\$(\x1b\[J)*",
1936+
r"~>(\x1b\[J)", r"~ #(\x1b\[J)", r":~(\x1b\[J)*", 'Petitboot', pexpect.TIMEOUT, pexpect.EOF], timeout=30)
19371937
if rc == 0:
19381938
track_obj.PS1_set, track_obj.LOGIN_set = self.get_login(
19391939
system_obj.cv_HOST, term_obj, pty, self.build_prompt(system_obj.prompt, ssh=is_ssh))
@@ -2710,7 +2710,7 @@ def get_email(self, commit_id):
27102710
connection = self.conf.host()
27112711
try :
27122712
connection.host_run_command("git config --global color.ui true")
2713-
result = connection.host_run_command("git show --format=%ce {} | sed -r 's/\x1B\[[0-9:]*[JKsu]//g'".format(commit_id))
2713+
result = connection.host_run_command(r"git show --format=%ce {} | sed -r 's/\x1B\[[0-9:]*[JKsu]//g'".format(commit_id))
27142714
return result[0]
27152715
except subprocess.CalledProcessError as e:
27162716
log.info(e)
@@ -2746,7 +2746,7 @@ def get_commit_message(self, linux_path, commit_sha):
27462746
connection = self.conf.host()
27472747
try:
27482748
connection.host_run_command(" if [ '$(pwd)' != {} ]; then cd {} || exit 1 ; fi ".format(linux_path,linux_path))
2749-
commit_message = connection.host_run_command("git log -n 1 --pretty=format:%s {} | sed -r 's/\x1B\[[0-9:]*[JKsu]//g'".format(commit_sha))
2749+
commit_message = connection.host_run_command(r"git log -n 1 --pretty=format:%s {} | sed -r 's/\x1B\[[0-9:]*[JKsu]//g'".format(commit_sha))
27502750
except subprocess.CalledProcessError as e:
27512751
log.info(e)
27522752
commit_message = None
@@ -2900,7 +2900,7 @@ def login(self, username=None, password=None):
29002900
.format(r.status_code, r.text, r.headers,
29012901
r.request.headers, username, password))
29022902
cookie = r.headers['Set-Cookie']
2903-
match = re.search('SESSION=(\w+);', cookie)
2903+
match = re.search(r'SESSION=(\w+);', cookie)
29042904
if match:
29052905
self.xAuthHeader['X-Auth-Token'] = match.group(1)
29062906
self.jsonHeader.update(self.xAuthHeader)

testcases/BMCResetTorture.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def RunBMCReset(self):
8585
cmd = "dmesg -T --level=emerg,alert,crit,err,warn"
8686
con.run_command_ignore_fail(cmd)
8787
con.run_command_ignore_fail(
88-
"grep ',[0-4]\]' /sys/firmware/opal/msglog")
88+
r"grep ',[0-4]\]' /sys/firmware/opal/msglog")
8989

9090

9191
class Skiroot(RuntimeBMCResetTorture, unittest.TestCase):
@@ -139,5 +139,5 @@ def runTest(self):
139139
self.cv_SYSTEM.goto_state(OpSystemState.PETITBOOT_SHELL)
140140
self.c.run_command_ignore_fail("dmesg -r|grep '<[4321]>'")
141141
self.c.run_command_ignore_fail(
142-
"grep ',[0-4]\]' /sys/firmware/opal/msglog")
142+
r"grep ',[0-4]\]' /sys/firmware/opal/msglog")
143143
self.cv_SYSTEM.goto_state(OpSystemState.OFF)

testcases/BasicIPL.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def runTest(self):
146146
console = self.cv_SYSTEM.console
147147
console.run_command_ignore_fail("dmesg -r|grep '<[4321]>'")
148148
console.run_command_ignore_fail(
149-
"grep ',[0-4]\]' /sys/firmware/opal/msglog")
149+
r"grep ',[0-4]\]' /sys/firmware/opal/msglog")
150150
console.pty.sendline("reboot")
151151
self.cv_SYSTEM.set_state(OpSystemState.IPLing)
152152
try:

testcases/BootTorture.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def runTest(self):
116116

117117
self.c.run_command_ignore_fail("dmesg -r|grep '<[4321]>'")
118118
self.c.run_command_ignore_fail(
119-
"grep ',[0-4]\]' /sys/firmware/opal/msglog")
119+
r"grep ',[0-4]\]' /sys/firmware/opal/msglog")
120120

121121

122122
class BootTorture10(BootTorture, unittest.TestCase):
@@ -163,7 +163,7 @@ def runTest(self):
163163
.format(self.conf.lspci_file(), ('\n'.join(i for i in compare_results))))
164164
self.c.run_command_ignore_fail("dmesg -r|grep '<[4321]>'")
165165
self.c.run_command_ignore_fail(
166-
"grep ',[0-4]\]' /sys/firmware/opal/msglog")
166+
r"grep ',[0-4]\]' /sys/firmware/opal/msglog")
167167
self.c.pty.sendline("echo 10 > /proc/sys/kernel/printk")
168168
self.c.pty.sendline("reboot")
169169
self.cv_SYSTEM.set_state(OpSystemState.IPLing)

testcases/DeviceTreeValidation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def dt_prop_read_str_arr(self, prop):
105105
res = res[1:]
106106
list = []
107107
for line in res:
108-
line = re.sub("\(.*\)", "", line)
108+
line = re.sub(r"\(.*\)", "", line)
109109
list = list + line.strip("\t\r\n ").split(" ")
110110
return list
111111

testcases/DeviceTreeWarnings.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ def runTest(self):
5353
self.setup_test()
5454
filter_out = [
5555
# As of skiboot 6.0.1 on POWER9 we produce the following warnings:
56-
'dts: Warning \(reg_format\): "reg" property in '
56+
r'dts: Warning \(reg_format\): "reg" property in '
5757
'(/ibm,opal/flash@0) has invalid length',
5858

59-
'dts: Warning \(unit_address_vs_reg\): Node /imc-counters/nx '
59+
r'dts: Warning \(unit_address_vs_reg\): Node /imc-counters/nx '
6060
'has a reg or ranges property, but no unit name',
6161

62-
"dts: Warning \((pci_device_reg|pci_device_bus_num|"
63-
"simple_bus_reg)\): Failed prerequisite 'reg_format'",
62+
r"dts: Warning \((pci_device_reg|pci_device_bus_num|"
63+
r"simple_bus_reg)\): Failed prerequisite 'reg_format'",
6464
]
6565
log_entries = self.c.run_command(
6666
"dtc -I fs /proc/device-tree -O dts -o dts")

testcases/EPOW.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def setUp(self):
7777

7878
def get_epow_limits(self):
7979
fsp_MTM = self.cv_FSP.get_raw_mtm()
80-
matchObj = re.search("-\d{2}.", fsp_MTM)
80+
matchObj = re.search(r"-\d{2}.", fsp_MTM)
8181
if matchObj:
8282
x = matchObj.group()
8383
y = x[1:3]
@@ -89,7 +89,7 @@ def get_epow_limits(self):
8989
file = '/opt/fips/components/engd/power_management_tul_%s.def' % (
9090
var)
9191
elif self.proc_gen in ["POWER9", "POWER9P"]:
92-
file = '/opt/fips/components/engd/power_management_zz_%s.def' % (
92+
file = '/opt/fips/components/engd/power_management_zz_%s.defr' % (
9393
var)
9494

9595
# Check for Nebs enable\disable

0 commit comments

Comments
 (0)