From 82980a9340aed187e3f81cd1e0b65afbe666ae08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pawl=C4=99ga?= Date: Fri, 28 Jul 2023 15:14:28 +0200 Subject: [PATCH 1/5] init --- panos_upgrade_assurance/check_firewall.py | 4 ++-- panos_upgrade_assurance/snapshot_compare.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/panos_upgrade_assurance/check_firewall.py b/panos_upgrade_assurance/check_firewall.py index b28ac06..b2f9525 100644 --- a/panos_upgrade_assurance/check_firewall.py +++ b/panos_upgrade_assurance/check_firewall.py @@ -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 == None: + 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}." diff --git a/panos_upgrade_assurance/snapshot_compare.py b/panos_upgrade_assurance/snapshot_compare.py index a8fbc70..648d714 100644 --- a/panos_upgrade_assurance/snapshot_compare.py +++ b/panos_upgrade_assurance/snapshot_compare.py @@ -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 == None: + report_config = {} report_config.update({"report_type": report_type}) elif isinstance(report, str): report_type = report From 2d17a2b05153f662af61edfe09894b7bad72cb0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pawl=C4=99ga?= Date: Fri, 28 Jul 2023 15:19:39 +0200 Subject: [PATCH 2/5] fix linter errors --- coverage.xml | 827 ++++++++++++++++++++ panos_upgrade_assurance/check_firewall.py | 2 +- panos_upgrade_assurance/snapshot_compare.py | 2 +- 3 files changed, 829 insertions(+), 2 deletions(-) create mode 100644 coverage.xml diff --git a/coverage.xml b/coverage.xml new file mode 100644 index 0000000..376c61f --- /dev/null +++ b/coverage.xml @@ -0,0 +1,827 @@ + + + + + + /Users/lpawlega/Git/public_code/pan-os-upgrade-assurance/panos_upgrade_assurance + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/panos_upgrade_assurance/check_firewall.py b/panos_upgrade_assurance/check_firewall.py index b2f9525..69b11a0 100644 --- a/panos_upgrade_assurance/check_firewall.py +++ b/panos_upgrade_assurance/check_firewall.py @@ -949,7 +949,7 @@ def run_readiness_checks( for check in checks_list: if isinstance(check, dict): check_type, check_config = next(iter(check.items())) - if check_config == None: + if check_config is None: check_config = {} elif isinstance(check, str): check_type, check_config = check, {} diff --git a/panos_upgrade_assurance/snapshot_compare.py b/panos_upgrade_assurance/snapshot_compare.py index 648d714..85f0581 100644 --- a/panos_upgrade_assurance/snapshot_compare.py +++ b/panos_upgrade_assurance/snapshot_compare.py @@ -113,7 +113,7 @@ 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 == None: + if report_config is None: report_config = {} report_config.update({"report_type": report_type}) elif isinstance(report, str): From e87e51bb2ac778ad098a34c4358e0b73d9b66c49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pawl=C4=99ga?= Date: Mon, 7 Aug 2023 11:33:11 +0200 Subject: [PATCH 3/5] remove coverage.xml --- coverage.xml | 827 --------------------------------------------------- 1 file changed, 827 deletions(-) delete mode 100644 coverage.xml diff --git a/coverage.xml b/coverage.xml deleted file mode 100644 index 376c61f..0000000 --- a/coverage.xml +++ /dev/null @@ -1,827 +0,0 @@ - - - - - - /Users/lpawlega/Git/public_code/pan-os-upgrade-assurance/panos_upgrade_assurance - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 706ff8d2ad34662f89b8f2e42f9d3bb90bb7c2bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pawl=C4=99ga?= Date: Mon, 7 Aug 2023 12:27:42 +0200 Subject: [PATCH 4/5] added tests to cover code changes --- tests/test_check_firewall.py | 17 +++++++++++++++++ tests/test_snapshot_compare.py | 2 +- tests/test_utils.py | 13 +++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/tests/test_check_firewall.py b/tests/test_check_firewall.py index 016aa13..2915e85 100644 --- a/tests/test_check_firewall.py +++ b/tests/test_check_firewall.py @@ -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]] diff --git a/tests/test_snapshot_compare.py b/tests/test_snapshot_compare.py index 909c18f..4409180 100644 --- a/tests/test_snapshot_compare.py +++ b/tests/test_snapshot_compare.py @@ -380,7 +380,7 @@ def test_get_count_change_percentage(self, thresholds, expected_result): }, ), ( - ["routes"], + [{"routes": None}], { "routes": { "added": {"added_keys": [], "passed": True}, diff --git a/tests/test_utils.py b/tests/test_utils.py index 0e4f44d..28afeb6 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -287,6 +287,19 @@ 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"], From 3773da30fb54808344303827946e3775e0e0653a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pawl=C4=99ga?= Date: Mon, 7 Aug 2023 12:31:46 +0200 Subject: [PATCH 5/5] update makefile order --- tests/test_utils.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 28afeb6..d81083f 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -289,16 +289,8 @@ def _is_element_included_mock(*args, **kwargs): (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" }} - ], + [{"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,