Skip to content

Commit

Permalink
fix: TOOLS-2541 rm configs not allowed in SC mode (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse S authored Oct 6, 2023
1 parent 341f534 commit dc10b8f
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
33 changes: 33 additions & 0 deletions lib/utils/conf_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,38 @@ async def __call__(self, context_dict: dict[str, Any]):
self._remove_default_values(build, host_config)


class RemoveConfigsConditionally(ConfigPipelineStep):
"""Some values return "null" but that is not a valid config value. You would think
that the step that removes non-defaults would handle this case but it does not.
e.g.: xdr.dc.namespace.remote-namespace
"""

async def __call__(self, context_dict: dict[str, Any]):
for host in context_dict[INTERMEDIATE]:
for top_level_config in context_dict[INTERMEDIATE][host]:
if (
isinstance(top_level_config, InterNamedSectionKey)
and top_level_config.type == "namespace"
):
# Determine if we are in SC mode.
ns_config = context_dict["namespaces"][host][top_level_config.name]

if (
"strong-consistency" in ns_config
and ns_config["strong-consistency"] == "true"
):
for config in list(
context_dict[INTERMEDIATE][host][top_level_config].keys()
):
if config in {
"read-consistency-level-override",
"write-commit-level-override",
}:
del context_dict[INTERMEDIATE][host][top_level_config][
config
]


class ConfigGenerator:
async def generate(self) -> str:
raise NotImplementedError("ConfigGenerator.generate not implemented")
Expand Down Expand Up @@ -919,6 +951,7 @@ async def _generate_intermediate(
RemoveInvalidKeysFoundInSchemas(),
ConvertCommaSeparatedToList(),
RemoveEmptyContexts(), # Should be after RemoveDefaultValues
RemoveConfigsConditionally(),
],
)

Expand Down
48 changes: 47 additions & 1 deletion test/unit/utils/test_conf_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
InterLoggingContextKey,
InterNamedSectionKey,
InterUnnamedSectionKey,
RemoveConfigsConditionally,
RemoveDefaultAndNonExistentKeys,
RemoveEmptyContexts,
RemoveNullOrEmptyOrUndefinedValues,
Expand Down Expand Up @@ -550,7 +551,11 @@ class RemoveNullValuesTest(asynctest.TestCase):
maxDiff = None

async def test_remove_null_values(self):
context_dict = {"intermediate": {"1.1.1.1": {"a": "null", "b": "1", "c": ""}}}
context_dict = {
"intermediate": {
"1.1.1.1": {"a": "null", "b": "1", "c": "", "d": "undefined"}
}
}

await RemoveNullOrEmptyOrUndefinedValues()(context_dict)

Expand Down Expand Up @@ -692,3 +697,44 @@ def __init__(self, schema_dir: str, version: str, strict: bool):
}
},
)


class RemoveConfigsConditionallyTest(asynctest.TestCase):
maxDiff = None

async def test_remove_null_values(self):
context_dict = {
"intermediate": {
"1.1.1.1": {
InterNamedSectionKey("namespace", "test"): {
"read-consistency-level-override": "all",
"write-commit-level-override": "all",
},
InterNamedSectionKey("namespace", "bar"): {
"read-consistency-level-override": "all",
"write-commit-level-override": "all",
},
}
},
"namespaces": {
"1.1.1.1": {
"test": {"strong-consistency": "true"},
"bar": {"strong-consistency": "false"},
}
},
}

await RemoveConfigsConditionally()(context_dict)

self.assertDictEqual(
context_dict["intermediate"],
{
"1.1.1.1": {
InterNamedSectionKey("namespace", "test"): {},
InterNamedSectionKey("namespace", "bar"): {
"read-consistency-level-override": "all",
"write-commit-level-override": "all",
},
}
},
)

0 comments on commit dc10b8f

Please sign in to comment.