summaryrefslogtreecommitdiff
path: root/test/lib/ansible_test/_internal/provider
diff options
context:
space:
mode:
Diffstat (limited to 'test/lib/ansible_test/_internal/provider')
-rw-r--r--test/lib/ansible_test/_internal/provider/__init__.py13
-rw-r--r--test/lib/ansible_test/_internal/provider/layout/__init__.py64
-rw-r--r--test/lib/ansible_test/_internal/provider/layout/ansible.py42
-rw-r--r--test/lib/ansible_test/_internal/provider/layout/collection.py46
-rw-r--r--test/lib/ansible_test/_internal/provider/layout/unsupported.py38
-rw-r--r--test/lib/ansible_test/_internal/provider/source/__init__.py1
-rw-r--r--test/lib/ansible_test/_internal/provider/source/git.py1
-rw-r--r--test/lib/ansible_test/_internal/provider/source/installed.py1
-rw-r--r--test/lib/ansible_test/_internal/provider/source/unsupported.py1
-rw-r--r--test/lib/ansible_test/_internal/provider/source/unversioned.py1
10 files changed, 115 insertions, 93 deletions
diff --git a/test/lib/ansible_test/_internal/provider/__init__.py b/test/lib/ansible_test/_internal/provider/__init__.py
index 61d7baf915..9b73ae726f 100644
--- a/test/lib/ansible_test/_internal/provider/__init__.py
+++ b/test/lib/ansible_test/_internal/provider/__init__.py
@@ -16,11 +16,12 @@ def get_path_provider_classes(provider_type: t.Type[TPathProvider]) -> list[t.Ty
return sorted(get_subclasses(provider_type), key=lambda subclass: (subclass.priority, subclass.__name__))
-def find_path_provider(provider_type: t.Type[TPathProvider],
- provider_classes: list[t.Type[TPathProvider]],
- path: str,
- walk: bool,
- ) -> TPathProvider:
+def find_path_provider(
+ provider_type: t.Type[TPathProvider],
+ provider_classes: list[t.Type[TPathProvider]],
+ path: str,
+ walk: bool,
+) -> TPathProvider:
"""Return the first found path provider of the given type for the given path."""
sequences = sorted(set(pc.sequence for pc in provider_classes if pc.sequence > 0))
@@ -48,6 +49,7 @@ def find_path_provider(provider_type: t.Type[TPathProvider],
class ProviderNotFoundForPath(ApplicationError):
"""Exception generated when a path based provider cannot be found for a given path."""
+
def __init__(self, provider_type: t.Type, path: str) -> None:
super().__init__('No %s found for path: %s' % (provider_type.__name__, path))
@@ -57,6 +59,7 @@ class ProviderNotFoundForPath(ApplicationError):
class PathProvider(metaclass=abc.ABCMeta):
"""Base class for provider plugins that are path based."""
+
sequence = 500
priority = 500
diff --git a/test/lib/ansible_test/_internal/provider/layout/__init__.py b/test/lib/ansible_test/_internal/provider/layout/__init__.py
index aa6693f0a5..4eca05cedb 100644
--- a/test/lib/ansible_test/_internal/provider/layout/__init__.py
+++ b/test/lib/ansible_test/_internal/provider/layout/__init__.py
@@ -17,10 +17,12 @@ from .. import (
class Layout:
"""Description of content locations and helper methods to access content."""
- def __init__(self,
- root: str,
- paths: list[str],
- ) -> None:
+
+ def __init__(
+ self,
+ root: str,
+ paths: list[str],
+ ) -> None:
self.root = root
self.__paths = paths # contains both file paths and symlinked directory paths (ending with os.path.sep)
@@ -74,25 +76,27 @@ class Layout:
class ContentLayout(Layout):
"""Information about the current Ansible content being tested."""
- def __init__(self,
- root: str,
- paths: list[str],
- plugin_paths: dict[str, str],
- collection: t.Optional[CollectionDetail],
- test_path: str,
- results_path: str,
- sanity_path: str,
- sanity_messages: t.Optional[LayoutMessages],
- integration_path: str,
- integration_targets_path: str,
- integration_vars_path: str,
- integration_messages: t.Optional[LayoutMessages],
- unit_path: str,
- unit_module_path: str,
- unit_module_utils_path: str,
- unit_messages: t.Optional[LayoutMessages],
- unsupported: bool = False,
- ) -> None:
+
+ def __init__(
+ self,
+ root: str,
+ paths: list[str],
+ plugin_paths: dict[str, str],
+ collection: t.Optional[CollectionDetail],
+ test_path: str,
+ results_path: str,
+ sanity_path: str,
+ sanity_messages: t.Optional[LayoutMessages],
+ integration_path: str,
+ integration_targets_path: str,
+ integration_vars_path: str,
+ integration_messages: t.Optional[LayoutMessages],
+ unit_path: str,
+ unit_module_path: str,
+ unit_module_utils_path: str,
+ unit_messages: t.Optional[LayoutMessages],
+ unsupported: bool = False,
+ ) -> None:
super().__init__(root, paths)
self.plugin_paths = plugin_paths
@@ -150,6 +154,7 @@ class ContentLayout(Layout):
class LayoutMessages:
"""Messages generated during layout creation that should be deferred for later display."""
+
def __init__(self) -> None:
self.info: list[str] = []
self.warning: list[str] = []
@@ -158,11 +163,13 @@ class LayoutMessages:
class CollectionDetail:
"""Details about the layout of the current collection."""
- def __init__(self,
- name: str,
- namespace: str,
- root: str,
- ) -> None:
+
+ def __init__(
+ self,
+ name: str,
+ namespace: str,
+ root: str,
+ ) -> None:
self.name = name
self.namespace = namespace
self.root = root
@@ -173,6 +180,7 @@ class CollectionDetail:
class LayoutProvider(PathProvider):
"""Base class for layout providers."""
+
PLUGIN_TYPES = (
'action',
'become',
diff --git a/test/lib/ansible_test/_internal/provider/layout/ansible.py b/test/lib/ansible_test/_internal/provider/layout/ansible.py
index e8d01919cf..d2f8cc818a 100644
--- a/test/lib/ansible_test/_internal/provider/layout/ansible.py
+++ b/test/lib/ansible_test/_internal/provider/layout/ansible.py
@@ -11,6 +11,7 @@ from . import (
class AnsibleLayout(LayoutProvider):
"""Layout provider for Ansible source."""
+
@staticmethod
def is_content_root(path: str) -> bool:
"""Return True if the given path is a content root for this provider."""
@@ -20,25 +21,26 @@ class AnsibleLayout(LayoutProvider):
"""Create a Layout using the given root and paths."""
plugin_paths = dict((p, os.path.join('lib/ansible/plugins', p)) for p in self.PLUGIN_TYPES)
- plugin_paths.update(dict(
+ plugin_paths.update(
modules='lib/ansible/modules',
module_utils='lib/ansible/module_utils',
- ))
-
- return ContentLayout(root,
- paths,
- plugin_paths=plugin_paths,
- collection=None,
- test_path='test',
- results_path='test/results',
- sanity_path='test/sanity',
- sanity_messages=None,
- integration_path='test/integration',
- integration_targets_path='test/integration/targets',
- integration_vars_path='test/integration/integration_config.yml',
- integration_messages=None,
- unit_path='test/units',
- unit_module_path='test/units/modules',
- unit_module_utils_path='test/units/module_utils',
- unit_messages=None,
- )
+ )
+
+ return ContentLayout(
+ root,
+ paths,
+ plugin_paths=plugin_paths,
+ collection=None,
+ test_path='test',
+ results_path='test/results',
+ sanity_path='test/sanity',
+ sanity_messages=None,
+ integration_path='test/integration',
+ integration_targets_path='test/integration/targets',
+ integration_vars_path='test/integration/integration_config.yml',
+ integration_messages=None,
+ unit_path='test/units',
+ unit_module_path='test/units/modules',
+ unit_module_utils_path='test/units/module_utils',
+ unit_messages=None,
+ )
diff --git a/test/lib/ansible_test/_internal/provider/layout/collection.py b/test/lib/ansible_test/_internal/provider/layout/collection.py
index 299d0bc6df..d747f31f31 100644
--- a/test/lib/ansible_test/_internal/provider/layout/collection.py
+++ b/test/lib/ansible_test/_internal/provider/layout/collection.py
@@ -17,6 +17,7 @@ from ...util import (
class CollectionLayout(LayoutProvider):
"""Layout provider for Ansible collections."""
+
@staticmethod
def is_content_root(path: str) -> bool:
"""Return True if the given path is a content root for this provider."""
@@ -52,28 +53,29 @@ class CollectionLayout(LayoutProvider):
integration_targets_path = self.__check_integration_path(paths, integration_messages)
self.__check_unit_path(paths, unit_messages)
- return ContentLayout(root,
- paths,
- plugin_paths=plugin_paths,
- collection=CollectionDetail(
- name=collection_name,
- namespace=collection_namespace,
- root=collection_root,
- ),
- test_path='tests',
- results_path='tests/output',
- sanity_path='tests/sanity',
- sanity_messages=sanity_messages,
- integration_path='tests/integration',
- integration_targets_path=integration_targets_path.rstrip(os.path.sep),
- integration_vars_path='tests/integration/integration_config.yml',
- integration_messages=integration_messages,
- unit_path='tests/unit',
- unit_module_path='tests/unit/plugins/modules',
- unit_module_utils_path='tests/unit/plugins/module_utils',
- unit_messages=unit_messages,
- unsupported=not (is_valid_identifier(collection_namespace) and is_valid_identifier(collection_name)),
- )
+ return ContentLayout(
+ root,
+ paths,
+ plugin_paths=plugin_paths,
+ collection=CollectionDetail(
+ name=collection_name,
+ namespace=collection_namespace,
+ root=collection_root,
+ ),
+ test_path='tests',
+ results_path='tests/output',
+ sanity_path='tests/sanity',
+ sanity_messages=sanity_messages,
+ integration_path='tests/integration',
+ integration_targets_path=integration_targets_path.rstrip(os.path.sep),
+ integration_vars_path='tests/integration/integration_config.yml',
+ integration_messages=integration_messages,
+ unit_path='tests/unit',
+ unit_module_path='tests/unit/plugins/modules',
+ unit_module_utils_path='tests/unit/plugins/module_utils',
+ unit_messages=unit_messages,
+ unsupported=not (is_valid_identifier(collection_namespace) and is_valid_identifier(collection_name)),
+ )
@staticmethod
def __check_test_path(paths: list[str], messages: LayoutMessages) -> None:
diff --git a/test/lib/ansible_test/_internal/provider/layout/unsupported.py b/test/lib/ansible_test/_internal/provider/layout/unsupported.py
index 16aa254c0a..e3d81e63e9 100644
--- a/test/lib/ansible_test/_internal/provider/layout/unsupported.py
+++ b/test/lib/ansible_test/_internal/provider/layout/unsupported.py
@@ -9,6 +9,7 @@ from . import (
class UnsupportedLayout(LayoutProvider):
"""Layout provider for an unsupported directory layout."""
+
sequence = 0 # disable automatic detection
@staticmethod
@@ -20,21 +21,22 @@ class UnsupportedLayout(LayoutProvider):
"""Create a Layout using the given root and paths."""
plugin_paths = dict((p, p) for p in self.PLUGIN_TYPES)
- return ContentLayout(root,
- paths,
- plugin_paths=plugin_paths,
- collection=None,
- test_path='',
- results_path='',
- sanity_path='',
- sanity_messages=None,
- integration_path='',
- integration_targets_path='',
- integration_vars_path='',
- integration_messages=None,
- unit_path='',
- unit_module_path='',
- unit_module_utils_path='',
- unit_messages=None,
- unsupported=True,
- )
+ return ContentLayout(
+ root,
+ paths,
+ plugin_paths=plugin_paths,
+ collection=None,
+ test_path='',
+ results_path='',
+ sanity_path='',
+ sanity_messages=None,
+ integration_path='',
+ integration_targets_path='',
+ integration_vars_path='',
+ integration_messages=None,
+ unit_path='',
+ unit_module_path='',
+ unit_module_utils_path='',
+ unit_messages=None,
+ unsupported=True,
+ )
diff --git a/test/lib/ansible_test/_internal/provider/source/__init__.py b/test/lib/ansible_test/_internal/provider/source/__init__.py
index aa8ca47faa..68fe380f11 100644
--- a/test/lib/ansible_test/_internal/provider/source/__init__.py
+++ b/test/lib/ansible_test/_internal/provider/source/__init__.py
@@ -10,6 +10,7 @@ from .. import (
class SourceProvider(PathProvider):
"""Base class for source providers."""
+
@abc.abstractmethod
def get_paths(self, path: str) -> list[str]:
"""Return the list of available content paths under the given path."""
diff --git a/test/lib/ansible_test/_internal/provider/source/git.py b/test/lib/ansible_test/_internal/provider/source/git.py
index 37f16bfa23..f8637edd44 100644
--- a/test/lib/ansible_test/_internal/provider/source/git.py
+++ b/test/lib/ansible_test/_internal/provider/source/git.py
@@ -22,6 +22,7 @@ from . import (
class GitSource(SourceProvider):
"""Source provider for a content root managed by git version control."""
+
@staticmethod
def is_content_root(path: str) -> bool:
"""Return True if the given path is a content root for this provider."""
diff --git a/test/lib/ansible_test/_internal/provider/source/installed.py b/test/lib/ansible_test/_internal/provider/source/installed.py
index 6b8218881c..1e5a6ba203 100644
--- a/test/lib/ansible_test/_internal/provider/source/installed.py
+++ b/test/lib/ansible_test/_internal/provider/source/installed.py
@@ -10,6 +10,7 @@ from . import (
class InstalledSource(SourceProvider):
"""Source provider for content which has been installed."""
+
sequence = 0 # disable automatic detection
@staticmethod
diff --git a/test/lib/ansible_test/_internal/provider/source/unsupported.py b/test/lib/ansible_test/_internal/provider/source/unsupported.py
index e2f8953eb7..caa4994167 100644
--- a/test/lib/ansible_test/_internal/provider/source/unsupported.py
+++ b/test/lib/ansible_test/_internal/provider/source/unsupported.py
@@ -8,6 +8,7 @@ from . import (
class UnsupportedSource(SourceProvider):
"""Source provider to use when the layout is unsupported."""
+
sequence = 0 # disable automatic detection
@staticmethod
diff --git a/test/lib/ansible_test/_internal/provider/source/unversioned.py b/test/lib/ansible_test/_internal/provider/source/unversioned.py
index d8eff5d181..699de889d3 100644
--- a/test/lib/ansible_test/_internal/provider/source/unversioned.py
+++ b/test/lib/ansible_test/_internal/provider/source/unversioned.py
@@ -18,6 +18,7 @@ from . import (
class UnversionedSource(SourceProvider):
"""Fallback source provider when no other provider matches the content root."""
+
sequence = 0 # disable automatic detection
@staticmethod