From 938caae8c4b1c8bac80ba51ec5f6b2899b667b13 Mon Sep 17 00:00:00 2001 From: Jesse S Date: Tue, 10 Oct 2023 15:38:07 -0400 Subject: [PATCH] fix: TOOLS-2541 config handler strict schema version assertion (#214) --- lib/live_cluster/client/config_handler.py | 7 ++++--- .../live_cluster/client/test_config_handler.py | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/live_cluster/client/config_handler.py b/lib/live_cluster/client/config_handler.py index 7243b162..f5cb52fd 100644 --- a/lib/live_cluster/client/config_handler.py +++ b/lib/live_cluster/client/config_handler.py @@ -327,7 +327,7 @@ def __init__(self, dir: str, as_build: str, strict=False): def _get_file_path(self, dir, as_build, file_map, strict: bool): # If the build provided is before the lowest supported version (LSV) use LSV file = list(file_map.values())[0] - key = None + used_key = list(file_map.keys())[0] # Find the closest version to the one provided. for key in file_map: @@ -335,11 +335,12 @@ def _get_file_path(self, dir, as_build, file_map, strict: bool): break file = file_map[key] + used_key = key if ( - key + used_key and strict - and version.LooseVersion(key) != version.LooseVersion(as_build) + and version.LooseVersion(used_key) != version.LooseVersion(as_build) ): raise FileNotFoundError( f"No configuration schema found for Aerospike server {as_build}. Consider upgrading asadm." diff --git a/test/unit/live_cluster/client/test_config_handler.py b/test/unit/live_cluster/client/test_config_handler.py index 4e74d849..e9501ac3 100644 --- a/test/unit/live_cluster/client/test_config_handler.py +++ b/test/unit/live_cluster/client/test_config_handler.py @@ -332,6 +332,24 @@ def test_loads_correct_file(self): patch.stopall() + def test_fails_on_strict(self): + isfile_mock = patch("os.path.isfile").start() + isfile_mock.side_effect = lambda *arg: True + pkgutil_mock = patch("pkgutil.get_data").start() + pkgutil_mock.side_effect = self.pkgutil_side_effect + + self.assertRaises( + FileNotFoundError, JsonDynamicConfigHandler, "dir", "0.0.0", strict=True + ) + self.assertRaises( + FileNotFoundError, JsonDynamicConfigHandler, "dir", "4.2.1", strict=True + ) + JsonDynamicConfigHandler("dir", "4.2.0", strict=True) + JsonDynamicConfigHandler("dir", "4.2.0.1", strict=True) + self.assertRaises( + FileNotFoundError, JsonDynamicConfigHandler, "dir", "10.2.1", strict=True + ) + def test_get_service_params(self): expected = [ "advertise-ipv6",