145 lines
7.3 KiB
Diff
145 lines
7.3 KiB
Diff
From fd341265d001d4e6545ffb2b7d154340cb1f1931 Mon Sep 17 00:00:00 2001
|
|
From: Matt Clay <matt@mystile.com>
|
|
Date: Wed, 10 May 2023 11:26:49 -0700
|
|
Subject: [PATCH] ansible-test - Avoid use of deprecated utcnow (#80750)
|
|
|
|
The timestamps are only used by ansible-test, not the junit callback, so this change only impacts ansible-test.
|
|
---
|
|
changelogs/fragments/ansible-test-utcnow.yml | 2 ++
|
|
lib/ansible/utils/_junit_xml.py | 6 +++++-
|
|
test/lib/ansible_test/_internal/commands/env/__init__.py | 2 +-
|
|
.../_internal/commands/integration/__init__.py | 2 +-
|
|
.../_internal/commands/integration/cloud/__init__.py | 2 +-
|
|
test/lib/ansible_test/_internal/commands/sanity/pylint.py | 8 ++++----
|
|
test/lib/ansible_test/_internal/test.py | 6 ++----
|
|
7 files changed, 16 insertions(+), 12 deletions(-)
|
|
create mode 100644 changelogs/fragments/ansible-test-utcnow.yml
|
|
|
|
diff --git a/changelogs/fragments/ansible-test-utcnow.yml b/changelogs/fragments/ansible-test-utcnow.yml
|
|
new file mode 100644
|
|
index 00000000000000..0781a0cb48a1f8
|
|
--- /dev/null
|
|
+++ b/changelogs/fragments/ansible-test-utcnow.yml
|
|
@@ -0,0 +1,2 @@
|
|
+minor_changes:
|
|
+ - ansible-test - Use ``datetime.datetime.now`` with ``tz`` specified instead of ``datetime.datetime.utcnow``.
|
|
diff --git a/lib/ansible/utils/_junit_xml.py b/lib/ansible/utils/_junit_xml.py
|
|
index 6b7c80f4cdf2de..8c4dba013edcb7 100644
|
|
--- a/lib/ansible/utils/_junit_xml.py
|
|
+++ b/lib/ansible/utils/_junit_xml.py
|
|
@@ -144,6 +144,10 @@ class TestSuite:
|
|
system_out: str | None = None
|
|
system_err: str | None = None
|
|
|
|
+ def __post_init__(self):
|
|
+ if self.timestamp and self.timestamp.tzinfo != datetime.timezone.utc:
|
|
+ raise ValueError(f'timestamp.tzinfo must be {datetime.timezone.utc!r}')
|
|
+
|
|
@property
|
|
def disabled(self) -> int:
|
|
"""The number of disabled test cases."""
|
|
@@ -187,7 +191,7 @@ def get_attributes(self) -> dict[str, str]:
|
|
skipped=self.skipped,
|
|
tests=self.tests,
|
|
time=self.time,
|
|
- timestamp=self.timestamp.isoformat(timespec='seconds') if self.timestamp else None,
|
|
+ timestamp=self.timestamp.replace(tzinfo=None).isoformat(timespec='seconds') if self.timestamp else None,
|
|
)
|
|
|
|
def get_xml_element(self) -> ET.Element:
|
|
diff --git a/test/lib/ansible_test/_internal/commands/env/__init__.py b/test/lib/ansible_test/_internal/commands/env/__init__.py
|
|
index 44f229f87999d7..6c0510566a052e 100644
|
|
--- a/test/lib/ansible_test/_internal/commands/env/__init__.py
|
|
+++ b/test/lib/ansible_test/_internal/commands/env/__init__.py
|
|
@@ -85,7 +85,7 @@ def show_dump_env(args: EnvConfig) -> None:
|
|
),
|
|
git=get_ci_provider().get_git_details(args),
|
|
platform=dict(
|
|
- datetime=datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ'),
|
|
+ datetime=datetime.datetime.now(tz=datetime.timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ'),
|
|
platform=platform.platform(),
|
|
uname=platform.uname(),
|
|
),
|
|
diff --git a/test/lib/ansible_test/_internal/commands/integration/__init__.py b/test/lib/ansible_test/_internal/commands/integration/__init__.py
|
|
index 0e5abbb6532193..5bd04407beeec5 100644
|
|
--- a/test/lib/ansible_test/_internal/commands/integration/__init__.py
|
|
+++ b/test/lib/ansible_test/_internal/commands/integration/__init__.py
|
|
@@ -566,7 +566,7 @@ def command_integration_filtered(
|
|
coverage_manager.teardown()
|
|
|
|
result_name = '%s-%s.json' % (
|
|
- args.command, re.sub(r'[^0-9]', '-', str(datetime.datetime.utcnow().replace(microsecond=0))))
|
|
+ args.command, re.sub(r'[^0-9]', '-', str(datetime.datetime.now(tz=datetime.timezone.utc).replace(microsecond=0, tzinfo=None))))
|
|
|
|
data = dict(
|
|
targets=results,
|
|
diff --git a/test/lib/ansible_test/_internal/commands/integration/cloud/__init__.py b/test/lib/ansible_test/_internal/commands/integration/cloud/__init__.py
|
|
index cad84a368924b2..eac9265a4f8c53 100644
|
|
--- a/test/lib/ansible_test/_internal/commands/integration/cloud/__init__.py
|
|
+++ b/test/lib/ansible_test/_internal/commands/integration/cloud/__init__.py
|
|
@@ -170,7 +170,7 @@ def cloud_init(args: IntegrationConfig, targets: tuple[IntegrationTarget, ...])
|
|
|
|
if not args.explain and results:
|
|
result_name = '%s-%s.json' % (
|
|
- args.command, re.sub(r'[^0-9]', '-', str(datetime.datetime.utcnow().replace(microsecond=0))))
|
|
+ args.command, re.sub(r'[^0-9]', '-', str(datetime.datetime.now(tz=datetime.timezone.utc).replace(microsecond=0, tzinfo=None))))
|
|
|
|
data = dict(
|
|
clouds=results,
|
|
diff --git a/test/lib/ansible_test/_internal/commands/sanity/pylint.py b/test/lib/ansible_test/_internal/commands/sanity/pylint.py
|
|
index fe5fbac9522fef..c089f834e50f89 100644
|
|
--- a/test/lib/ansible_test/_internal/commands/sanity/pylint.py
|
|
+++ b/test/lib/ansible_test/_internal/commands/sanity/pylint.py
|
|
@@ -156,19 +156,19 @@ def context_filter(path_to_filter: str) -> bool:
|
|
except CollectionDetailError as ex:
|
|
display.warning('Skipping pylint collection version checks since collection detail loading failed: %s' % ex.reason)
|
|
|
|
- test_start = datetime.datetime.utcnow()
|
|
+ test_start = datetime.datetime.now(tz=datetime.timezone.utc)
|
|
|
|
for context, context_paths in sorted(contexts):
|
|
if not context_paths:
|
|
continue
|
|
|
|
- context_start = datetime.datetime.utcnow()
|
|
+ context_start = datetime.datetime.now(tz=datetime.timezone.utc)
|
|
messages += self.pylint(args, context, context_paths, plugin_dir, plugin_names, python, collection_detail)
|
|
- context_end = datetime.datetime.utcnow()
|
|
+ context_end = datetime.datetime.now(tz=datetime.timezone.utc)
|
|
|
|
context_times.append('%s: %d (%s)' % (context, len(context_paths), context_end - context_start))
|
|
|
|
- test_end = datetime.datetime.utcnow()
|
|
+ test_end = datetime.datetime.now(tz=datetime.timezone.utc)
|
|
|
|
for context_time in context_times:
|
|
display.info(context_time, verbosity=4)
|
|
diff --git a/test/lib/ansible_test/_internal/test.py b/test/lib/ansible_test/_internal/test.py
|
|
index 4814ee3e25e525..fe5ef3f8d3472a 100644
|
|
--- a/test/lib/ansible_test/_internal/test.py
|
|
+++ b/test/lib/ansible_test/_internal/test.py
|
|
@@ -114,7 +114,7 @@ def save_junit(self, args: TestConfig, test_case: junit_xml.TestCase) -> None:
|
|
junit_xml.TestSuite(
|
|
name='ansible-test',
|
|
cases=[test_case],
|
|
- timestamp=datetime.datetime.utcnow(),
|
|
+ timestamp=datetime.datetime.now(tz=datetime.timezone.utc),
|
|
),
|
|
],
|
|
)
|
|
@@ -153,13 +153,11 @@ def write(self, args: TestConfig) -> None:
|
|
|
|
output += '\n\nConsult the console log for additional details on where the timeout occurred.'
|
|
|
|
- timestamp = datetime.datetime.utcnow()
|
|
-
|
|
suites = junit_xml.TestSuites(
|
|
suites=[
|
|
junit_xml.TestSuite(
|
|
name='ansible-test',
|
|
- timestamp=timestamp,
|
|
+ timestamp=datetime.datetime.now(tz=datetime.timezone.utc),
|
|
cases=[
|
|
junit_xml.TestCase(
|
|
name='timeout',
|