diff --git a/main/lib/idds/tests/jsonload_test.py b/main/lib/idds/tests/jsonload_test.py index 92192ac1..aee3ae68 100644 --- a/main/lib/idds/tests/jsonload_test.py +++ b/main/lib/idds/tests/jsonload_test.py @@ -20,18 +20,30 @@ def is_string(value): def as_parse_env(dct): - print(dct) + # print(dct) for key in dct: value = dct[key] - print(value) - print(type(value)) - if is_string(value) and value.startswith('$'): - env_match = re.search('\$\{*([^\}]+)\}*', value) # noqa W605 - env_name = env_match.group(1) - if env_name not in os.environ: - print("Error: %s is defined in configmap but is not defined in environments" % env_name) - else: - dct[key] = os.environ[env_name] + # print(value) + # print(type(value)) + if is_string(value) and '$' in value: + env_matchs = re.findall('\$\{*([^\}]+)\}*', value) # noqa W605 + print("env_matchs") + print(env_matchs) + for env_name in env_matchs: + print(env_name) + if env_name not in os.environ: + print("Error: %s is defined in configmap but is not defined in environments" % env_name) + else: + # dct[key] = os.environ[env_name] + print('${%s}' % env_name) + print(os.environ.get(env_name)) + env_name1 = r'${%s}' % env_name + env_name2 = r'$%s' % env_name + print(env_name1) + print(env_name2) + print(value.replace(env_name1, os.environ.get(env_name))) + value = value.replace(env_name1, os.environ.get(env_name)).replace(env_name2, os.environ.get(env_name)) + dct[key] = value return dct @@ -49,6 +61,14 @@ def as_parse_env(dct): "pandacache_url": "${PANDACACHE_URL}", "panda_verify_host": "${PANDA_VERIFY_HOST}", "test1": {"test2": "${TEST_ENV}"} + }, + "database": + {"default": "postgresql://${IDDS_DATABASE_USER}:${IDDS_DATABASE_PASSWORD}@${IDDS_DATABASE_HOST}/${IDDS_DATABASE_NAME}", + "schema": "${IDDS_DATABASE_SCHEMA}", + "pool_size": 20, + "pool_recycle": 3600, + "echo": 0, + "pool_reset_on_return": "rollback" } } } diff --git a/main/tools/env/merge_configmap.py b/main/tools/env/merge_configmap.py index 4835f420..4f8764e2 100644 --- a/main/tools/env/merge_configmap.py +++ b/main/tools/env/merge_configmap.py @@ -36,13 +36,16 @@ def is_string(value): def as_parse_env(dct): for key in dct: value = dct[key] - if is_string(value) and value.startswith('$'): - env_match = re.search('\$\{*([^\}]+)\}*', value) # noqa W605 - env_name = env_match.group(1) - if env_name not in os.environ: - print("Error: %s is defined in configmap but is not defined in environments" % env_name) - else: - dct[key] = os.environ[env_name] + if is_string(value) and '$' in value: + env_matches = re.findall('\$\{*([^\}]+)\}*', value) # noqa W605 + for env_name in env_matches: + if env_name not in os.environ: + print("Error: %s is defined in configmap but is not defined in environments" % env_name) + else: + env_name1 = r'${%s}' % env_name + env_name2 = r'$%s' % env_name + value = value.replace(env_name1, os.environ.get(env_name)).replace(env_name2, os.environ.get(env_name)) + dct[key] = value return dct