Skip to content

Commit

Permalink
fix: TOOLS-2541 config handler strict schema version assertion (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdogmcsteezy committed Oct 10, 2023
1 parent 9d6edc5 commit 938caae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/live_cluster/client/config_handler.py
Expand Up @@ -327,19 +327,20 @@ 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:
if version.LooseVersion(key) > version.LooseVersion(as_build):
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."
Expand Down
18 changes: 18 additions & 0 deletions test/unit/live_cluster/client/test_config_handler.py
Expand Up @@ -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",
Expand Down

0 comments on commit 938caae

Please sign in to comment.