From 83d11bda0fde9956173cd24164c213b2c1360c1d Mon Sep 17 00:00:00 2001 From: abikouo <79859644+abikouo@users.noreply.github.com> Date: Tue, 22 Feb 2022 15:35:37 +0100 Subject: [PATCH] ansible-test-splitter: add target for lookup (#1359) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit aws test splitter - add lookup plugins Reviewed-by: Gonéri Le Bouder --- .../files/list_changed_targets.py | 42 ++++++++++++------- .../files/test_list_changed_targets.py | 2 + 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/roles/ansible-test-splitter/files/list_changed_targets.py b/roles/ansible-test-splitter/files/list_changed_targets.py index c25d46c0e..28e341633 100644 --- a/roles/ansible-test-splitter/files/list_changed_targets.py +++ b/roles/ansible-test-splitter/files/list_changed_targets.py @@ -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""" @@ -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): @@ -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() diff --git a/roles/ansible-test-splitter/files/test_list_changed_targets.py b/roles/ansible-test-splitter/files/test_list_changed_targets.py index 393a16dc3..325c24c56 100644 --- a/roles/ansible-test-splitter/files/test_list_changed_targets.py +++ b/roles/ansible-test-splitter/files/test_list_changed_targets.py @@ -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()) == [ @@ -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):