From: Zack Cerza Date: Fri, 20 Jan 2023 19:25:30 +0000 (-0700) Subject: Fix 'invalid escape sequence' deprecation warnings X-Git-Tag: 1.2.0~133^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a106217a990efa3b5af540d3cef712047f7b1d2a;p=teuthology.git Fix 'invalid escape sequence' deprecation warnings Signed-off-by: Zack Cerza --- diff --git a/teuthology/ls.py b/teuthology/ls.py index a50a59d17..de8e6d4bc 100644 --- a/teuthology/ls.py +++ b/teuthology/ls.py @@ -43,7 +43,7 @@ def get_jobs(archive_dir): dir_contents = os.listdir(archive_dir) def is_job_dir(parent, subdir): - if (os.path.isdir(os.path.join(parent, subdir)) and re.match('\d+$', + if (os.path.isdir(os.path.join(parent, subdir)) and re.match(r'\d+$', subdir)): return True return False diff --git a/teuthology/misc.py b/teuthology/misc.py index 26a9d2438..140c14993 100644 --- a/teuthology/misc.py +++ b/teuthology/misc.py @@ -52,7 +52,7 @@ def host_shortname(hostname): def canonicalize_hostname(hostname, user='ubuntu'): hostname_expr = hostname_expr_templ.format( - lab_domain=config.lab_domain.replace('.', '\.')) + lab_domain=config.lab_domain.replace('.', r'\.')) match = re.match(hostname_expr, hostname) if _is_ipv4(hostname) or _is_ipv6(hostname): return "%s@%s" % (user, hostname) @@ -82,7 +82,7 @@ def canonicalize_hostname(hostname, user='ubuntu'): def decanonicalize_hostname(hostname): lab_domain = '' if config.lab_domain: - lab_domain='\.' + config.lab_domain.replace('.', '\.') + lab_domain=r'\.' + config.lab_domain.replace('.', r'\.') hostname_expr = hostname_expr_templ.format(lab_domain=lab_domain) match = re.match(hostname_expr, hostname) if match: diff --git a/teuthology/nuke/actions.py b/teuthology/nuke/actions.py index 854ca27d4..3e427c6fb 100644 --- a/teuthology/nuke/actions.py +++ b/teuthology/nuke/actions.py @@ -118,7 +118,7 @@ def remove_osd_tmpfs(ctx): log.info('Unmount any osd tmpfs dirs...') ctx.cluster.run( args=[ - 'egrep', 'tmpfs\s+/mnt', '/etc/mtab', run.Raw('|'), + 'egrep', r'tmpfs\s+/mnt', '/etc/mtab', run.Raw('|'), 'awk', '{print $2}', run.Raw('|'), 'xargs', '-r', 'sudo', 'umount', run.Raw(';'), @@ -229,7 +229,7 @@ def remove_yum_timedhosts(ctx): if remote.os.package_type != 'rpm': continue remote.run( - args="sudo find /var/cache/yum -name 'timedhosts' -exec rm {} \;", + args=r"sudo find /var/cache/yum -name 'timedhosts' -exec rm {} \;", check_status=False, timeout=180 ) diff --git a/teuthology/openstack/__init__.py b/teuthology/openstack/__init__.py index 43f568737..bdfde2956 100644 --- a/teuthology/openstack/__init__.py +++ b/teuthology/openstack/__init__.py @@ -123,7 +123,7 @@ class OpenStackInstance(object): with safe_while(sleep=2, tries=30, action="get ip " + self['id']) as proceed: while proceed(): - found = re.match('.*\d+', self['addresses']) + found = re.match(r'.*\d+', self['addresses']) if found: return self['addresses'] self.set_info() @@ -165,7 +165,7 @@ class OpenStackInstance(object): self.private_ip = self.get_ip_neutron() except Exception as e: log.debug("ignoring get_ip_neutron exception " + str(e)) - self.private_ip = re.findall(network + '=([\d.]+)', + self.private_ip = re.findall(network + r'=([\d.]+)', self.get_addresses())[0] return self.private_ip diff --git a/teuthology/orchestra/daemon/systemd.py b/teuthology/orchestra/daemon/systemd.py index fd833b84f..9a4bc4374 100644 --- a/teuthology/orchestra/daemon/systemd.py +++ b/teuthology/orchestra/daemon/systemd.py @@ -86,7 +86,7 @@ class SystemDState(DaemonState): self.status_cmd + " | grep 'Main.*code=exited'", ) line = out.strip().split('\n')[-1] - exit_code = int(re.match('.*status=(\d+).*', line).groups()[0]) + exit_code = int(re.match(r'.*status=(\d+).*', line).groups()[0]) if exit_code: self.remote.run( args=self.output_cmd diff --git a/teuthology/provision/openstack.py b/teuthology/provision/openstack.py index 23066cda3..f8d3eda85 100644 --- a/teuthology/provision/openstack.py +++ b/teuthology/provision/openstack.py @@ -151,7 +151,7 @@ class ProvisionOpenStack(OpenStack): """ return the instance name suffixed with the IP address. """ - digits = map(int, re.findall('(\d+)\.(\d+)\.(\d+)\.(\d+)', ip)[0]) + digits = map(int, re.findall(r'(\d+)\.(\d+)\.(\d+)\.(\d+)', ip)[0]) return prefix + "%03d%03d%03d%03d" % tuple(digits) def create(self, num, os_type, os_version, arch, resources_hint): diff --git a/teuthology/provision/test/test_init_provision.py b/teuthology/provision/test/test_init_provision.py index 390385037..11c67679b 100644 --- a/teuthology/provision/test/test_init_provision.py +++ b/teuthology/provision/test/test_init_provision.py @@ -37,10 +37,10 @@ class TestInitProvision(object): teuthology.provision.reimage(ctx, 'f.q.d.n.org', 'not-defined-type') e_str = str(e_info) print("Caught exception: " + e_str) - assert e_str.find("configured\sprovisioners") == -1 + assert e_str.find(r"configured\sprovisioners") == -1 with raises(Exception) as e_info: teuthology.provision.reimage(ctx, 'f.q.d.n.org', 'common_type') e_str = str(e_info) print("Caught exception: " + e_str) - assert e_str.find("used\swith\sone\sprovisioner\sonly") == -1 + assert e_str.find(r"used\swith\sone\sprovisioner\sonly") == -1 diff --git a/teuthology/provision/test/test_pelagos.py b/teuthology/provision/test/test_pelagos.py index a8969d4b4..3a8a0c4f9 100644 --- a/teuthology/provision/test/test_pelagos.py +++ b/teuthology/provision/test/test_pelagos.py @@ -42,5 +42,5 @@ class TestPelagos(object): teuthology.provision.reimage(ctx, 'f.q.d.n.org', 'ptype1') e_str = str(e_info) print("Caught exception: " + e_str) - assert e_str.find("Name\sor\sservice\snot\sknown") == -1 + assert e_str.find(r"Name\sor\sservice\snot\sknown") == -1 diff --git a/teuthology/repo_utils.py b/teuthology/repo_utils.py index ffccc00f3..1fe189dfb 100644 --- a/teuthology/repo_utils.py +++ b/teuthology/repo_utils.py @@ -50,7 +50,7 @@ def build_git_url(project, project_owner='ceph'): base = config.get_ceph_git_url() else: base = 'https://github.com/{project_owner}/{project}' - url_templ = re.sub('\.git$', '', base) + url_templ = re.sub(r'\.git$', '', base) return url_templ.format(project_owner=project_owner, project=project) diff --git a/teuthology/report.py b/teuthology/report.py index d7375f361..edf01cfdb 100644 --- a/teuthology/report.py +++ b/teuthology/report.py @@ -143,7 +143,7 @@ class ResultsSerializer(object): return {} jobs = {} for item in os.listdir(archive_dir): - if not re.match('\d+$', item): + if not re.match(r'\d+$', item): continue job_id = item job_dir = os.path.join(archive_dir, job_id) diff --git a/teuthology/scrape.py b/teuthology/scrape.py index 0a737683f..a73ec1db6 100644 --- a/teuthology/scrape.py +++ b/teuthology/scrape.py @@ -83,9 +83,9 @@ class GenericReason(Reason): else: if "Test failure:" in self.failure_reason: return self.failure_reason == job.get_failure_reason() - elif re.search("workunit test (.*)\) on ", self.failure_reason): - workunit_name = re.search("workunit test (.*)\) on ", self.failure_reason).group(1) - other_match = re.search("workunit test (.*)\) on ", job.get_failure_reason()) + elif re.search(r"workunit test (.*)\) on ", self.failure_reason): + workunit_name = re.search(r"workunit test (.*)\) on ", self.failure_reason).group(1) + other_match = re.search(r"workunit test (.*)\) on ", job.get_failure_reason()) return other_match is not None and workunit_name == other_match.group(1) else: reason_ratio = difflib.SequenceMatcher(None, self.failure_reason, job.get_failure_reason()).ratio() @@ -357,7 +357,7 @@ class Job(object): for line in grep(tlog_path, "command crashed with signal"): log.debug("Found a crash indication: {0}".format(line)) # tasks.ceph.osd.1.plana82.stderr - match = re.search("tasks.ceph.([^\.]+).([^\.]+).([^\.]+).stderr", line) + match = re.search(r"tasks.ceph.([^\.]+).([^\.]+).([^\.]+).stderr", line) if not match: log.warning("Not-understood crash indication {0}".format(line)) continue diff --git a/teuthology/suite/placeholder.py b/teuthology/suite/placeholder.py index 37f538e6f..20b191d1d 100644 --- a/teuthology/suite/placeholder.py +++ b/teuthology/suite/placeholder.py @@ -73,8 +73,8 @@ dict_templ = { } }, 'flavor': Placeholder('flavor'), - 'log-ignorelist': ['\(MDS_ALL_DOWN\)', - '\(MDS_UP_LESS_THAN_MAX\)'], + 'log-ignorelist': [r'\(MDS_ALL_DOWN\)', + r'\(MDS_UP_LESS_THAN_MAX\)'], 'sha1': Placeholder('ceph_hash'), }, 'ceph-deploy': { diff --git a/teuthology/suite/run.py b/teuthology/suite/run.py index ab2d8f064..32bb80c51 100644 --- a/teuthology/suite/run.py +++ b/teuthology/suite/run.py @@ -294,7 +294,7 @@ class Run(object): @staticmethod def _repo_name(url): - return re.sub('\.git$', '', url.split('/')[-1]) + return re.sub(r'\.git$', '', url.split('/')[-1]) def choose_suite_branch(self): suite_repo_name = self.suite_repo_name diff --git a/teuthology/task/install/deb.py b/teuthology/task/install/deb.py index 92ad7b2d6..e1a290f78 100644 --- a/teuthology/task/install/deb.py +++ b/teuthology/task/install/deb.py @@ -142,7 +142,7 @@ def _remove(ctx, config, remote, debs): run.Raw('|'), # Any package that is unpacked or half-installed and also requires # reinstallation - 'grep', '^.\(U\|H\)R', + 'grep', r'^.\(U\|H\)R', run.Raw('|'), 'awk', '{print $2}', run.Raw('|'), diff --git a/teuthology/task/kernel.py b/teuthology/task/kernel.py index 23c164cd5..8879963ca 100644 --- a/teuthology/task/kernel.py +++ b/teuthology/task/kernel.py @@ -982,14 +982,14 @@ def generate_legacy_grub_entry(remote, newversion): if re.match('^title', line): titleline = line titlelinenum = linenum - if re.match('(^\s+)root', line): + if re.match(r'(^\s+)root', line): rootline = line - if re.match('(^\s+)kernel', line): + if re.match(r'(^\s+)kernel', line): kernelline = line for word in line.split(' '): if 'vmlinuz' in word: kernelversion = word.split('vmlinuz-')[-1] - if re.match('(^\s+)initrd', line): + if re.match(r'(^\s+)initrd', line): initline = line if (kernelline != '') and (initline != ''): break diff --git a/teuthology/task/selinux.py b/teuthology/task/selinux.py index de4314822..d28d606ef 100644 --- a/teuthology/task/selinux.py +++ b/teuthology/task/selinux.py @@ -141,7 +141,7 @@ class SELinux(Task): se_allowlist = self.config.get('allowlist', []) if se_allowlist: known_denials.extend(se_allowlist) - ignore_known_denials = '\'\(' + str.join('\|', known_denials) + '\)\'' + ignore_known_denials = r'\'\(' + str.join(r'\|', known_denials) + r'\)\'' for remote in self.cluster.remotes.keys(): proc = remote.run( args=['sudo', 'grep', '-a', 'avc: .*denied',