Skip to content

Commit

Permalink
ansible-test-splitter: add target for lookup (#1359)
Browse files Browse the repository at this point in the history
aws test splitter - add lookup plugins

Reviewed-by: Gonéri Le Bouder <[email protected]>
  • Loading branch information
abikouo authored Feb 22, 2022
1 parent 830aa42 commit 83d11bd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
42 changes: 27 additions & 15 deletions roles/ansible-test-splitter/files/list_changed_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,31 @@ def __init__(self, path, branch):
self.collection_path = path
self.branch = branch
self.collection_name = lambda: read_collection_name(path)
self.files = None

def changed_files(self):
"""List of changed files
Returns a list of pathlib.PosixPath
"""
return [
PosixPath(p)
for p in (
subprocess.check_output(
[
"git",
"diff",
f"origin/{self.branch}",
"--name-only",
],
cwd=self.collection_path,
if self.files is None:
self.files = [
PosixPath(p)
for p in (
subprocess.check_output(
[
"git",
"diff",
f"origin/{self.branch}",
"--name-only",
],
cwd=self.collection_path,
)
.decode()
.split("\n")
)
.decode()
.split("\n")
)
]
]
return self.files

def modules(self):
"""List the modules impacted by the change"""
Expand All @@ -120,6 +123,12 @@ def module_utils(self):
f"ansible_collections.{self.collection_name()}.plugins.module_utils.{d.stem}",
)

def lookup(self):
"""List the lookup plugins impacted by the change"""
for d in self.changed_files():
if str(d).startswith("plugins/lookup/"):
yield PosixPath(d)


class Target:
def __init__(self, path):
Expand Down Expand Up @@ -258,6 +267,9 @@ def build_result_struct(self, batches):
for c in collections:
c.add_target_to_plan(f"module_utils_{path.stem}")
c.cover_module_utils(pymod)
for path in whc.lookup():
for c in collections:
c.add_target_to_plan(f"lookup_{path.stem}")

egs = ElGrandeSeparator(collections)
egs.output()
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def test_what_changed_files():
PosixPath("tests/something"),
PosixPath("plugins/module_utils/core.py"),
PosixPath("plugins/modules/ec2.py"),
PosixPath("plugins/lookup/aws_test.py"),
]
assert list(whc.modules()) == [PosixPath("plugins/modules/ec2.py")]
assert list(whc.module_utils()) == [
Expand All @@ -53,6 +54,7 @@ def test_what_changed_files():
"ansible_collections.a.b.plugins.module_utils.core",
)
]
assert list(whc.lookup()) == [PosixPath("plugins/lookup/aws_test.py")]


def build_collection(aliases):
Expand Down

0 comments on commit 83d11bd

Please sign in to comment.