diff --git a/teuthology/lock/cli.py b/teuthology/lock/cli.py index c562a3d51..e5f97fb63 100644 --- a/teuthology/lock/cli.py +++ b/teuthology/lock/cli.py @@ -133,7 +133,7 @@ def main(ctx): for s in sorted(statuses, key=lambda s: s.get('name')): locked = 'unlocked' if s['locked'] == 0 else 'locked' up = 'up' if s['up'] else 'down' - mo = re.match('\w+@(\w+?)\..*', s['name']) + mo = re.match(r'\w+@(\w+?)\..*', s['name']) host = mo.group(1) if mo else s['name'] print(node_status_template.format( up=up, locked=locked, host=host, diff --git a/teuthology/task/kernel.py b/teuthology/task/kernel.py index ca4718784..59242d31b 100644 --- a/teuthology/task/kernel.py +++ b/teuthology/task/kernel.py @@ -1033,7 +1033,7 @@ def get_image_version(remote, path): raise UnsupportedPackageTypeError(remote) for file in files.split('\n'): - match = re.search('/lib/modules/(.*)/modules\.order$', file) + match = re.search(r'/lib/modules/(.*)/modules\.order$', file) if match: version = match.group(1) break diff --git a/teuthology/task/mpi.py b/teuthology/task/mpi.py index 6c709fd17..0e1b504dd 100644 --- a/teuthology/task/mpi.py +++ b/teuthology/task/mpi.py @@ -18,7 +18,7 @@ def _check_mpi_version(remotes): for remote in remotes: version_str = remote.sh("mpiexec --version") try: - version = re.search("^\s+Version:\s+(.+)$", version_str, re.MULTILINE).group(1) + version = re.search(r"^\s+Version:\s+(.+)$", version_str, re.MULTILINE).group(1) except AttributeError: raise RuntimeError("Malformed MPI version output: {0}".format(version_str)) else: diff --git a/teuthology/task/ssh_keys.py b/teuthology/task/ssh_keys.py index 9c899e8fa..0f497ebe9 100644 --- a/teuthology/task/ssh_keys.py +++ b/teuthology/task/ssh_keys.py @@ -54,7 +54,7 @@ def particular_ssh_key_test(line_to_test, ssh_key): """ Check the validity of the ssh_key """ - match = re.match('[\w-]+ {key} \S+@\S+'.format(key=re.escape(ssh_key)), line_to_test) + match = re.match(r'[\w-]+ {key} \S+@\S+'.format(key=re.escape(ssh_key)), line_to_test) if match: return False @@ -65,7 +65,7 @@ def ssh_keys_user_line_test(line_to_test, username ): """ Check the validity of the username """ - match = re.match('[\w-]+ \S+ {username}@\S+'.format(username=username), line_to_test) + match = re.match(r'[\w-]+ \S+ {username}@\S+'.format(username=username), line_to_test) if match: return False diff --git a/teuthology/timer.py b/teuthology/timer.py index 0119b8b3a..9ca5d76a7 100644 --- a/teuthology/timer.py +++ b/teuthology/timer.py @@ -2,7 +2,7 @@ import time import yaml -from datetime import datetime +import datetime log = logging.getLogger(__name__) @@ -68,8 +68,8 @@ def get_datetime_string(self, time): :param time: Time in seconds; like from time.time() """ - _datetime = datetime.utcfromtimestamp(time) - return datetime.strftime( + _datetime = datetime.datetime.fromtimestamp(time, datetime.timezone.utc) + return datetime.datetime.strftime( _datetime, self.datetime_format, ) diff --git a/teuthology/util/scanner.py b/teuthology/util/scanner.py index b67d88c92..421d5a028 100644 --- a/teuthology/util/scanner.py +++ b/teuthology/util/scanner.py @@ -130,7 +130,7 @@ def __init__(self, remote=None) -> None: def _parse(self, file_content: str) -> Tuple[Optional[str], Optional[dict]]: xml_tree = etree.fromstring(file_content) - if not xml_tree: + if xml_tree is None: return None, None error_tree = xml_tree.find('error')