Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add possibility to define dicts w/o values in checks and report #101

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions panos_upgrade_assurance/check_firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,10 +949,10 @@ def run_readiness_checks(
for check in checks_list:
if isinstance(check, dict):
check_type, check_config = next(iter(check.items()))
# check_result = self._check_method_mapping[check_type](check_config)
if check_config is None:
alperenkose marked this conversation as resolved.
Show resolved Hide resolved
check_config = {}
elif isinstance(check, str):
check_type, check_config = check, {}
# check_result = self._check_method_mapping[check_type]()
else:
raise exceptions.WrongDataTypeException(
f"Wrong configuration format for check: {check}."
Expand Down
2 changes: 2 additions & 0 deletions panos_upgrade_assurance/snapshot_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def compare_snapshots(self, reports: Optional[List[Union[dict, str]]] = None) ->
for report in reports:
if isinstance(report, dict):
report_type, report_config = list(report.items())[0]
if report_config is None:
report_config = {}
report_config.update({"report_type": report_type})
elif isinstance(report, str):
report_type = report
Expand Down
17 changes: 17 additions & 0 deletions tests/test_check_firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,23 @@ def test_run_readiness_checks(self, check_firewall_mock):
check_firewall_mock._check_method_mapping["check1"].assert_called_once_with()
check_firewall_mock._check_method_mapping["check2"].assert_called_once_with(param1=123)

def test_run_readiness_checks_empty_dict(self, check_firewall_mock):
check_firewall_mock._check_method_mapping = {
"check1": MagicMock(return_value=True),
}

checks_configuration = [{"check1": None}]
report_style = False

result = check_firewall_mock.run_readiness_checks(checks_configuration, report_style)

expected_result = {
"check1": {"state": True, "reason": "True"},
}
assert result == expected_result

check_firewall_mock._check_method_mapping["check1"].assert_called_once_with()

def test_run_readiness_checks_wrong_data_type_exception(self, check_firewall_mock):
# Set up the input parameters for the method
checks_configuration = ["check1", [123]]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_snapshot_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def test_get_count_change_percentage(self, thresholds, expected_result):
},
),
(
["routes"],
[{"routes": None}],
{
"routes": {
"added": {"added_keys": [], "passed": True},
Expand Down
5 changes: 5 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ def _is_element_included_mock(*args, **kwargs):
[
(valid_check_types, [], valid_check_types),
(valid_check_types, ["all"], valid_check_types),
(
valid_check_types,
[{"ha": None}, "content_version", {"free_disk_space": {"image_version": "10.1.1"}}],
[{"ha": None}, "content_version", {"free_disk_space": {"image_version": "10.1.1"}}],
),
(
valid_check_types,
["!ha", "!ntp_sync"],
Expand Down