Skip to content

Commit

Permalink
Remove unused facts in code (#337)
Browse files Browse the repository at this point in the history
A followup of #333
  • Loading branch information
bzwei authored Feb 3, 2023
2 parents 3f27d0e + 06dd3bd commit ecdb2b5
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 32 deletions.
15 changes: 0 additions & 15 deletions ansible_rulebook/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -281,7 +274,6 @@ async def run_playbook(
event_log,
inventory,
variables,
facts,
name,
"run_playbook",
var_root,
Expand Down Expand Up @@ -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,
Expand All @@ -380,7 +371,6 @@ async def run_module(
event_log,
inventory,
variables,
facts,
name,
"run_module",
var_root,
Expand Down Expand Up @@ -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,
Expand All @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 0 additions & 8 deletions ansible_rulebook/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@ async def _drain_actionplan_queue(self):
action_item.variables,
action_item.inventory,
action_item.hosts,
action_item.facts,
action_item.rule_engine_results,
)

Expand All @@ -357,7 +356,6 @@ async def _call_action(
variables: Dict,
inventory: Dict,
hosts: List,
facts: Dict,
rules_engine_result,
) -> None:

Expand Down Expand Up @@ -408,10 +406,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

Expand All @@ -420,7 +414,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
Expand All @@ -433,7 +426,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,
Expand Down
5 changes: 0 additions & 5 deletions ansible_rulebook/rule_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def add_to_plan(
variables: Dict,
inventory: Dict,
hosts: List,
facts: Dict,
plan: Plan,
rule_engine_results: Any,
) -> None:
Expand All @@ -51,7 +50,6 @@ def add_to_plan(
variables,
inventory,
hosts,
facts,
rule_engine_results,
)
)
Expand All @@ -63,7 +61,6 @@ def make_fn(
variables: Dict,
inventory: Dict,
hosts: List,
facts: Dict,
plan: Plan,
) -> Callable:
def fn(rule_engine_results):
Expand All @@ -75,7 +72,6 @@ def fn(rule_engine_results):
variables,
inventory,
hosts,
facts,
plan,
rule_engine_results,
)
Expand Down Expand Up @@ -106,7 +102,6 @@ def generate_rulesets(
variables,
inventory,
ansible_ruleset.hosts,
{},
plan,
)
drools_ruleset.add_rule(
Expand Down
1 change: 0 additions & 1 deletion ansible_rulebook/rule_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ class ActionContext(NamedTuple):
variables: Dict
inventory: Dict
hosts: List[str]
facts: Dict
rule_engine_results: Any


Expand Down
5 changes: 2 additions & 3 deletions tests/e2e/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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"

0 comments on commit ecdb2b5

Please sign in to comment.