summaryrefslogtreecommitdiff
path: root/test/lib/ansible_test/_internal/commands/sanity
diff options
context:
space:
mode:
Diffstat (limited to 'test/lib/ansible_test/_internal/commands/sanity')
-rw-r--r--test/lib/ansible_test/_internal/commands/sanity/__init__.py7
-rw-r--r--test/lib/ansible_test/_internal/commands/sanity/validate_modules.py71
2 files changed, 73 insertions, 5 deletions
diff --git a/test/lib/ansible_test/_internal/commands/sanity/__init__.py b/test/lib/ansible_test/_internal/commands/sanity/__init__.py
index 3069511091..d09f94c5f8 100644
--- a/test/lib/ansible_test/_internal/commands/sanity/__init__.py
+++ b/test/lib/ansible_test/_internal/commands/sanity/__init__.py
@@ -159,6 +159,10 @@ def command_sanity(args): # type: (SanityConfig) -> None
if args.skip_test:
tests = [target for target in tests if target.name not in args.skip_test]
+ if not args.host_path:
+ for test in tests:
+ test.origin_hook(args)
+
targets_use_pypi = any(isinstance(test, SanityMultipleVersion) and test.needs_pypi for test in tests) and not args.list_tests
host_state = prepare_profiles(args, targets_use_pypi=targets_use_pypi) # sanity
@@ -756,6 +760,9 @@ class SanityTest(metaclass=abc.ABCMeta):
"""A tuple of supported Python versions or None if the test does not depend on specific Python versions."""
return CONTROLLER_PYTHON_VERSIONS
+ def origin_hook(self, args: SanityConfig) -> None:
+ """This method is called on the origin, before the test runs or delegation occurs."""
+
def filter_targets(self, targets): # type: (t.List[TestTarget]) -> t.List[TestTarget] # pylint: disable=unused-argument
"""Return the given list of test targets, filtered to include only those relevant for the test."""
if self.no_targets:
diff --git a/test/lib/ansible_test/_internal/commands/sanity/validate_modules.py b/test/lib/ansible_test/_internal/commands/sanity/validate_modules.py
index f1d448804c..3be19091e9 100644
--- a/test/lib/ansible_test/_internal/commands/sanity/validate_modules.py
+++ b/test/lib/ansible_test/_internal/commands/sanity/validate_modules.py
@@ -1,9 +1,12 @@
"""Sanity test using validate-modules."""
from __future__ import annotations
+import atexit
import collections
+import contextlib
import json
import os
+import tarfile
import typing as t
from . import (
@@ -16,6 +19,10 @@ from . import (
SANITY_ROOT,
)
+from ...io import (
+ make_dirs,
+)
+
from ...test import (
TestResult,
)
@@ -30,7 +37,9 @@ from ...util import (
)
from ...util_common import (
+ process_scoped_temporary_directory,
run_command,
+ ResultType,
)
from ...ansible_util import (
@@ -49,12 +58,21 @@ from ...ci import (
from ...data import (
data_context,
+ PayloadConfig,
)
from ...host_configs import (
PythonConfig,
)
+from ...git import (
+ Git,
+)
+
+from ...provider.source import (
+ SourceProvider as GitSourceProvider,
+)
+
class ValidateModulesTest(SanitySingleVersion):
"""Sanity test using validate-modules."""
@@ -130,14 +148,17 @@ class ValidateModulesTest(SanitySingleVersion):
except CollectionDetailError as ex:
display.warning('Skipping validate-modules collection version checks since collection detail loading failed: %s' % ex.reason)
else:
- base_branch = args.base_branch or get_ci_provider().get_base_branch()
+ path = self.get_archive_path(args)
+
+ if os.path.exists(path):
+ temp_dir = process_scoped_temporary_directory(args)
+
+ with tarfile.open(path) as file:
+ file.extractall(temp_dir)
- if base_branch:
cmd.extend([
- '--base-branch', base_branch,
+ '--original-plugins', temp_dir,
])
- else:
- display.warning('Cannot perform module comparison against the base branch because the base branch was not detected.')
errors = []
@@ -188,3 +209,43 @@ class ValidateModulesTest(SanitySingleVersion):
return SanityFailure(self.name, messages=all_errors)
return SanitySuccess(self.name)
+
+ def origin_hook(self, args: SanityConfig) -> None:
+ """This method is called on the origin, before the test runs or delegation occurs."""
+ if not data_context().content.is_ansible:
+ return
+
+ if not isinstance(data_context().source_provider, GitSourceProvider):
+ display.warning('The validate-modules sanity test cannot compare against the base commit because git is not being used.')
+ return
+
+ base_commit = args.base_branch or get_ci_provider().get_base_commit(args)
+
+ if not base_commit:
+ display.warning('The validate-modules sanity test cannot compare against the base commit because it was not detected.')
+ return
+
+ path = self.get_archive_path(args)
+
+ def cleanup() -> None:
+ """Cleanup callback called when the process exits."""
+ with contextlib.suppress(FileNotFoundError):
+ os.unlink(path)
+
+ def git_callback(payload_config: PayloadConfig) -> None:
+ """Include the previous plugin content archive in the payload."""
+ files = payload_config.files
+ files.append((path, os.path.relpath(path, data_context().content.root)))
+
+ atexit.register(cleanup)
+ data_context().register_payload_callback(git_callback)
+
+ make_dirs(os.path.dirname(path))
+
+ git = Git()
+ git.run_git(['archive', '--output', path, base_commit, 'lib/ansible/modules/', 'lib/ansible/plugins/'])
+
+ @staticmethod
+ def get_archive_path(args: SanityConfig) -> str:
+ """Return the path to the original plugin content archive."""
+ return os.path.join(ResultType.TMP.path, f'validate-modules-{args.metadata.session_id}.tar')