Support delegation testing collections with deps.
All collections in the same collection root as the collection being tested will be sent to the remote system/container.
This commit is contained in:
parent
27cac742ca
commit
8a7b89c66f
4 changed files with 47 additions and 8 deletions
|
@ -13,6 +13,7 @@ from .util import (
|
||||||
ANSIBLE_LIB_ROOT,
|
ANSIBLE_LIB_ROOT,
|
||||||
ANSIBLE_TEST_ROOT,
|
ANSIBLE_TEST_ROOT,
|
||||||
ANSIBLE_SOURCE_ROOT,
|
ANSIBLE_SOURCE_ROOT,
|
||||||
|
display,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .provider import (
|
from .provider import (
|
||||||
|
@ -57,6 +58,7 @@ class DataContext:
|
||||||
layout_providers = get_path_provider_classes(LayoutProvider)
|
layout_providers = get_path_provider_classes(LayoutProvider)
|
||||||
source_providers = get_path_provider_classes(SourceProvider)
|
source_providers = get_path_provider_classes(SourceProvider)
|
||||||
|
|
||||||
|
self.__layout_providers = layout_providers
|
||||||
self.__source_providers = source_providers
|
self.__source_providers = source_providers
|
||||||
self.__ansible_source = None # type: t.Optional[t.Tuple[t.Tuple[str, str], ...]]
|
self.__ansible_source = None # type: t.Optional[t.Tuple[t.Tuple[str, str], ...]]
|
||||||
|
|
||||||
|
@ -72,6 +74,44 @@ class DataContext:
|
||||||
self.content = content # type: ContentLayout
|
self.content = content # type: ContentLayout
|
||||||
self.results = os.path.join(self.content.root, 'test', 'results')
|
self.results = os.path.join(self.content.root, 'test', 'results')
|
||||||
|
|
||||||
|
def create_collection_layouts(self): # type: () -> t.List[ContentLayout]
|
||||||
|
"""
|
||||||
|
Return a list of collection layouts, one for each collection in the same collection root as the current collection layout.
|
||||||
|
An empty list is returned if the current content layout is not a collection layout.
|
||||||
|
"""
|
||||||
|
layout = self.content
|
||||||
|
collection = layout.collection
|
||||||
|
|
||||||
|
if not collection:
|
||||||
|
return []
|
||||||
|
|
||||||
|
root_path = os.path.join(collection.root, 'ansible_collections')
|
||||||
|
display.info('Scanning collection root: %s' % root_path, verbosity=1)
|
||||||
|
namespace_names = sorted(name for name in os.listdir(root_path) if os.path.isdir(os.path.join(root_path, name)))
|
||||||
|
collections = []
|
||||||
|
|
||||||
|
for namespace_name in namespace_names:
|
||||||
|
namespace_path = os.path.join(root_path, namespace_name)
|
||||||
|
collection_names = sorted(name for name in os.listdir(namespace_path) if os.path.isdir(os.path.join(namespace_path, name)))
|
||||||
|
|
||||||
|
for collection_name in collection_names:
|
||||||
|
collection_path = os.path.join(namespace_path, collection_name)
|
||||||
|
|
||||||
|
if collection_path == os.path.join(collection.root, collection.directory):
|
||||||
|
collection_layout = layout
|
||||||
|
else:
|
||||||
|
collection_layout = self.__create_content_layout(self.__layout_providers, self.__source_providers, collection_path, False)
|
||||||
|
|
||||||
|
file_count = len(collection_layout.all_files())
|
||||||
|
|
||||||
|
if not file_count:
|
||||||
|
continue
|
||||||
|
|
||||||
|
display.info('Including collection: %s (%d files)' % (collection_layout.collection.full_name, file_count), verbosity=1)
|
||||||
|
collections.append(collection_layout)
|
||||||
|
|
||||||
|
return collections
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __create_content_layout(layout_providers, # type: t.List[t.Type[LayoutProvider]]
|
def __create_content_layout(layout_providers, # type: t.List[t.Type[LayoutProvider]]
|
||||||
source_providers, # type: t.List[t.Type[SourceProvider]]
|
source_providers, # type: t.List[t.Type[SourceProvider]]
|
||||||
|
|
|
@ -81,10 +81,11 @@ def create_payload(args, dst_path): # type: (CommonConfig, str) -> None
|
||||||
# exclude built-in ansible modules when they are not needed
|
# exclude built-in ansible modules when they are not needed
|
||||||
files = [f for f in files if not is_subdir(f[1], 'lib/ansible/modules/') or f[1] == 'lib/ansible/modules/__init__.py']
|
files = [f for f in files if not is_subdir(f[1], 'lib/ansible/modules/') or f[1] == 'lib/ansible/modules/__init__.py']
|
||||||
|
|
||||||
if data_context().content.collection:
|
collection_layouts = data_context().create_collection_layouts()
|
||||||
# include collections content for testing
|
|
||||||
files.extend((os.path.join(data_context().content.root, path), os.path.join(data_context().content.collection.directory, path))
|
for layout in collection_layouts:
|
||||||
for path in data_context().content.all_files())
|
# include files from each collection in the same collection root as the content being tested
|
||||||
|
files.extend((os.path.join(layout.root, path), os.path.join(layout.collection.directory, path)) for path in layout.all_files())
|
||||||
|
|
||||||
for callback in data_context().payload_callbacks:
|
for callback in data_context().payload_callbacks:
|
||||||
callback(files)
|
callback(files)
|
||||||
|
|
|
@ -135,12 +135,12 @@ class CollectionDetail:
|
||||||
name, # type: str
|
name, # type: str
|
||||||
namespace, # type: str
|
namespace, # type: str
|
||||||
root, # type: str
|
root, # type: str
|
||||||
prefix, # type: str
|
|
||||||
): # type: (...) -> None
|
): # type: (...) -> None
|
||||||
self.name = name
|
self.name = name
|
||||||
self.namespace = namespace
|
self.namespace = namespace
|
||||||
self.root = root
|
self.root = root
|
||||||
self.prefix = prefix
|
self.full_name = '%s.%s' % (namespace, name)
|
||||||
|
self.prefix = '%s.' % self.full_name
|
||||||
self.directory = os.path.join('ansible_collections', namespace, name)
|
self.directory = os.path.join('ansible_collections', namespace, name)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@ class CollectionLayout(LayoutProvider):
|
||||||
collection_dir = os.path.relpath(root, collection_root)
|
collection_dir = os.path.relpath(root, collection_root)
|
||||||
collection_namespace, collection_name = collection_dir.split(os.sep)
|
collection_namespace, collection_name = collection_dir.split(os.sep)
|
||||||
|
|
||||||
collection_prefix = '%s.%s.' % (collection_namespace, collection_name)
|
|
||||||
collection_root = os.path.dirname(collection_root)
|
collection_root = os.path.dirname(collection_root)
|
||||||
|
|
||||||
return ContentLayout(root,
|
return ContentLayout(root,
|
||||||
|
@ -44,7 +43,6 @@ class CollectionLayout(LayoutProvider):
|
||||||
name=collection_name,
|
name=collection_name,
|
||||||
namespace=collection_namespace,
|
namespace=collection_namespace,
|
||||||
root=collection_root,
|
root=collection_root,
|
||||||
prefix=collection_prefix,
|
|
||||||
),
|
),
|
||||||
unit_path='test/unit',
|
unit_path='test/unit',
|
||||||
unit_module_path='test/unit/plugins/modules',
|
unit_module_path='test/unit/plugins/modules',
|
||||||
|
|
Loading…
Reference in a new issue