Skip to content

Commit

Permalink
exit Monkeyble on missing var
Browse files Browse the repository at this point in the history
  • Loading branch information
Sispheor committed Feb 2, 2023
1 parent 3a0e4ec commit 8a08084
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion plugins/callback/monkeyble_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ def v2_playbook_on_play_start(self, play):

# variable placed into the monkeyble config need to be instantiated with extra vars
templar = Templar(loader=DataLoader(), variables=self.extra_vars)
self.monkeyble_config = templar.template(loaded_monkeyble_config)
try:
self.monkeyble_config = templar.template(loaded_monkeyble_config)
except Exception as e:
raise MonkeybleException(message=str(e),
scenario_description=monkeyble_scenario)

self.display_message_ok(f"monkeyble_scenario: {monkeyble_scenario}")
self.monkeyble_scenario_description = monkeyble_scenario
Expand Down
19 changes: 19 additions & 0 deletions tests/units/test_callback/test_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,22 @@ def test_v2_runner_on_start_input_test_fail(self, mock_exit_playbook):
'monkeyble_passed_test': []
}
self.assertDictEqual(self.test_callback._last_check_input_result, expected_last_check_input_result)

@patch('sys.exit')
def test_v2_runner_on_start_fail_on_missing_var(self, mock_exit):
self.test_callback.monkeyble_config = {
"name": "Validate this",
"tasks_to_test": [
]
}
self.var_manager.extra_vars = {
"monkeyble_scenario": "test_scenario",
"monkeyble_scenarios": {
"test_scenario": {
"name": "{{ not_declared_anywhere }}"
}
}
}
with self.assertRaises(MonkeybleException):
self.test_callback.v2_playbook_on_play_start(self.play)
mock_exit.assert_called()

0 comments on commit 8a08084

Please sign in to comment.