diff --git a/.github/actions/ansible_test_splitter/REAME.md b/.github/actions/ansible_test_splitter/README.md similarity index 78% rename from .github/actions/ansible_test_splitter/REAME.md rename to .github/actions/ansible_test_splitter/README.md index f6ce97fe..423cae4f 100644 --- a/.github/actions/ansible_test_splitter/REAME.md +++ b/.github/actions/ansible_test_splitter/README.md @@ -76,6 +76,26 @@ _Example_: For any change on `plugins/lookup/random.py`, this action will produce `lookup_random` and `test_random` as impacted targets. +## Relationship between extensions and targets + +This action reads elements to test from `extensions` directory and corresponding tests from `tests/integration/targets` directory. Here after more details on the relationship between extensions and integration tests targets: + +- `audit`, the test target name should have prefix `node_query_` or defines the `indirect_node_count` line into the `aliases` file, when `event_query.yml` file changed. + +_Example_: + +``` + |___extensions/audit/event_query.yml + |___tests + |___integration + |___targets + |___node_query_database_cluster + |___query_instance_ec2 + |___aliases (contains this line indirect_node_count) +``` + +For any change on `extensions/audit/event_query.yml` file, this action will produce `node_query_database_cluster` and `query_instance_ec2` as impacted targets. + ## Debugging - Set the label `test-all-the-targets` on the pull request to run the full test suite instead of the impacted changes. diff --git a/.github/actions/ansible_test_splitter/list_changed_common.py b/.github/actions/ansible_test_splitter/list_changed_common.py index fb721080..3c363d3c 100644 --- a/.github/actions/ansible_test_splitter/list_changed_common.py +++ b/.github/actions/ansible_test_splitter/list_changed_common.py @@ -272,6 +272,14 @@ def plugin_utils(self) -> Generator[tuple[PosixPath, str], None, None]: """ yield from self._util_matches("plugins/plugin_utils/", "plugin_utils") + def extensions_audit_event_query(self) -> bool: + """Return true when the extensions/audit/event_query.yml file has been updated""" + event_query_files = ( + "extensions/audit/event_query.yml", + "extensions/audit/event_query.yaml", + ) + return any([str(d) in event_query_files for d in self.changed_files()]) + class Target: """A class to store information about a specific target.""" @@ -427,6 +435,21 @@ def add_target_to_plan(self, target_name: str) -> None: if t.is_alias_of(target_name) and self.is_candidate_target(t): self._my_test_plan.append(t) + def add_targets_to_plan_from_aliases_or_prefix_name(self, alias_line="", prefix_name=""): + """Add targets to the plan from aliases line or prefix name.""" + for t in self._targets(): + if not self.is_candidate_target(t): + continue + # Add the target to the plan if either the name starts with `prefix_name` or + # The aliases file contains the line `alias_line` + if t.is_alias_of(alias_line) or t.name.startswith(prefix_name): + self._my_test_plan.append(t) + + def add_indirect_node_count_targets_to_plan(self): + alias_line = "indirect_node_count" + prefix_name = "node_query_" + self.add_targets_to_plan_from_aliases_or_prefix_name(alias_line, prefix_name) + def cover_all(self) -> None: """Cover all the targets available.""" for cover_target in self.targets(): diff --git a/.github/actions/ansible_test_splitter/list_changed_targets.py b/.github/actions/ansible_test_splitter/list_changed_targets.py index 94db2641..a2c86d7e 100644 --- a/.github/actions/ansible_test_splitter/list_changed_targets.py +++ b/.github/actions/ansible_test_splitter/list_changed_targets.py @@ -116,6 +116,10 @@ def _add_changed_target( _add_changed_target(whc.collection_name, target, "targets") for role in whc.roles(): _add_changed_target(whc.collection_name, role, "roles") + # indirect node count targets + if whc.extensions_audit_event_query(): + for collection in collections: + collection.add_indirect_node_count_targets_to_plan() print("----------- Test plan -----------") for collection in collections: