From bb3fa51da47d4ea756fa5f84f24b7e85b3994779 Mon Sep 17 00:00:00 2001 From: Bill Wei Date: Thu, 2 Feb 2023 15:57:24 -0500 Subject: [PATCH] Remove unsed facts in code --- ansible_rulebook/builtin.py | 15 --------------- ansible_rulebook/engine.py | 8 -------- ansible_rulebook/rule_generator.py | 5 ----- ansible_rulebook/rule_types.py | 1 - tests/e2e/test_actions.py | 5 ++--- 5 files changed, 2 insertions(+), 32 deletions(-) diff --git a/ansible_rulebook/builtin.py b/ansible_rulebook/builtin.py index 78742e2f..3c071917 100644 --- a/ansible_rulebook/builtin.py +++ b/ansible_rulebook/builtin.py @@ -52,7 +52,6 @@ async def none( inventory: Dict, hosts: List, variables: Dict, - facts: Dict, project_data_file: str, source_ruleset_name: str, source_rule_name: str, @@ -99,7 +98,6 @@ async def print_event( inventory: Dict, hosts: List, variables: Dict, - facts: Dict, project_data_file: str, source_ruleset_name: str, source_rule_name: str, @@ -140,7 +138,6 @@ async def echo( inventory: Dict, hosts: List, variables: Dict, - facts: Dict, project_data_file: str, source_ruleset_name: str, source_rule_name: str, @@ -173,7 +170,6 @@ async def set_fact( inventory: Dict, hosts: List, variables: Dict, - facts: Dict, project_data_file: str, source_ruleset_name: str, source_rule_name: str, @@ -202,7 +198,6 @@ async def retract_fact( inventory: Dict, hosts: List, variables: Dict, - facts: Dict, project_data_file: str, source_ruleset_name: str, source_rule_name: str, @@ -230,7 +225,6 @@ async def post_event( inventory: Dict, hosts: List, variables: Dict, - facts: Dict, project_data_file: str, source_ruleset_name: str, source_rule_name: str, @@ -257,7 +251,6 @@ async def run_playbook( inventory: Dict, hosts: List, variables: Dict, - facts: Dict, project_data_file: str, source_ruleset_name: str, source_rule_name: str, @@ -281,7 +274,6 @@ async def run_playbook( event_log, inventory, variables, - facts, name, "run_playbook", var_root, @@ -356,7 +348,6 @@ async def run_module( inventory: Dict, hosts: List, variables: Dict, - facts: Dict, project_data_file: str, source_ruleset_name: str, source_rule_name: str, @@ -380,7 +371,6 @@ async def run_module( event_log, inventory, variables, - facts, name, "run_module", var_root, @@ -541,7 +531,6 @@ async def pre_process_runner( event_log, inventory: Dict, variables: Dict, - facts: Dict, name: str, action: str, var_root: Union[str, Dict, None] = None, @@ -555,9 +544,7 @@ async def pre_process_runner( private_data_dir = tempfile.mkdtemp(prefix=action) logger.debug("private data dir %s", private_data_dir) logger.debug("variables %s", variables) - logger.debug("facts %s", facts) - variables["facts"] = facts for k, v in kwargs.items(): variables[k] = v @@ -663,7 +650,6 @@ async def run_job_template( inventory: Dict, hosts: List, variables: Dict, - facts: Dict, project_data_file: str, source_ruleset_name: str, source_rule_name: str, @@ -784,7 +770,6 @@ async def shutdown( inventory: Dict, hosts: List, variables: Dict, - facts: Dict, project_data_file: str, source_ruleset_name: str, source_rule_name: str, diff --git a/ansible_rulebook/engine.py b/ansible_rulebook/engine.py index a7c048ff..25a9bd2c 100644 --- a/ansible_rulebook/engine.py +++ b/ansible_rulebook/engine.py @@ -318,7 +318,6 @@ async def _drain_actionplan_queue(self): action_item.variables, action_item.inventory, action_item.hosts, - action_item.facts, action_item.rule_engine_results, ) @@ -333,7 +332,6 @@ async def _call_action( variables: Dict, inventory: Dict, hosts: List, - facts: Dict, rules_engine_result, ) -> None: @@ -384,10 +382,6 @@ async def _call_action( } logger.info("action args: %s", action_args) - if facts is None: - facts = lang.get_facts(ruleset) - logger.info("facts: %s", facts) - if "ruleset" not in action_args: action_args["ruleset"] = ruleset @@ -396,7 +390,6 @@ async def _call_action( action_args["inventory"] = inventory action_args["hosts"] = hosts action_args["variables"] = variables_copy - action_args["facts"] = facts action_args["project_data_file"] = self.project_data_file action_args["source_ruleset_name"] = ruleset action_args["source_rule_name"] = rule @@ -409,7 +402,6 @@ async def _call_action( inventory=inventory, hosts=hosts, variables=variables_copy, - facts=facts, project_data_file=self.project_data_file, source_ruleset_name=ruleset, source_rule_name=rule, diff --git a/ansible_rulebook/rule_generator.py b/ansible_rulebook/rule_generator.py index 043689ca..79779272 100644 --- a/ansible_rulebook/rule_generator.py +++ b/ansible_rulebook/rule_generator.py @@ -39,7 +39,6 @@ def add_to_plan( variables: Dict, inventory: Dict, hosts: List, - facts: Dict, plan: Plan, rule_engine_results: Any, ) -> None: @@ -51,7 +50,6 @@ def add_to_plan( variables, inventory, hosts, - facts, rule_engine_results, ) ) @@ -63,7 +61,6 @@ def make_fn( variables: Dict, inventory: Dict, hosts: List, - facts: Dict, plan: Plan, ) -> Callable: def fn(rule_engine_results): @@ -75,7 +72,6 @@ def fn(rule_engine_results): variables, inventory, hosts, - facts, plan, rule_engine_results, ) @@ -106,7 +102,6 @@ def generate_rulesets( variables, inventory, ansible_ruleset.hosts, - {}, plan, ) drools_ruleset.add_rule( diff --git a/ansible_rulebook/rule_types.py b/ansible_rulebook/rule_types.py index c948103e..0d0dcf5a 100644 --- a/ansible_rulebook/rule_types.py +++ b/ansible_rulebook/rule_types.py @@ -76,7 +76,6 @@ class ActionContext(NamedTuple): variables: Dict inventory: Dict hosts: List[str] - facts: Dict rule_engine_results: Any diff --git a/tests/e2e/test_actions.py b/tests/e2e/test_actions.py index 81abfe53..17d75ac2 100644 --- a/tests/e2e/test_actions.py +++ b/tests/e2e/test_actions.py @@ -57,8 +57,7 @@ def test_actions_sanity(): "{'action': 'print_event'}" in result.stdout ), "print_event action failed" - event_debug_expected_output = """{'facts': {}, - 'hosts': ['all'], + event_debug_expected_output = """{'hosts': ['all'], 'inventory': {'all': {'hosts': {'localhost': {'ansible_connection': 'local'}}}}, 'project_data_file': None, 'ruleset': 'Test actions sanity', @@ -93,5 +92,5 @@ def test_actions_sanity(): assert "Echo action executed" in result.stdout assert ( - len(result.stdout.splitlines()) == 45 + len(result.stdout.splitlines()) == 44 ), "unexpected output from the rulebook"