diff --git a/tests/generic_config_updater/test_kubernetes_config.py b/tests/generic_config_updater/test_kubernetes_config.py index a36dfeba5ab..2093a201120 100644 --- a/tests/generic_config_updater/test_kubernetes_config.py +++ b/tests/generic_config_updater/test_kubernetes_config.py @@ -180,6 +180,10 @@ ] +def add_namespace_indentation(multiline_string, spaces=4): + return multiline_string.replace('\n', '\n' + ' ' * spaces) + + @pytest.fixture(autouse=True) def setup_env(duthosts, rand_one_dut_hostname): """ @@ -268,6 +272,13 @@ def k8s_config_update(duthost, test_data): logger.info("tmpfile {}".format(tmpfile)) json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch) + if duthost.is_multi_asic: + json_namespace = '/localhost' + for patch in json_patch: + if 'path' in patch: + patch['path'] = re.sub(r'^/', f'/{json_namespace}/', patch['path']) + target_config = [add_namespace_indentation(item) for item in target_config] + try: output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)