From 063b139dd2e2fc82cd87765f0edd61e934fdb6e5 Mon Sep 17 00:00:00 2001 From: ngcp-config Date: Wed, 16 Mar 2022 16:18:55 +0100 Subject: [PATCH] TT#160855 patch: don't use static match for PRO/CARRIER * use ngcpcfg environment variables to match files * same approach as tt2-process Change-Id: I396dcc71a09cd6b9d51ddfcb7e3e84461c6e1667 --- scripts/patch | 25 +++++++++++++++++------ t/fixtures/ngcpcfg_carrier.cfg | 3 +++ t/fixtures/ngcpcfg_carrier_instances.cfg | 3 +++ t/fixtures/ngcpcfg_network_interfaces.cfg | 2 ++ t/fixtures/ngcpcfg_pro.cfg | 2 ++ t/fixtures/ngcpcfg_pro_instances.cfg | 2 ++ t/fixtures/read_cfg.sh | 5 +++++ t/test_ngcpcfg_patch.py | 14 ++++++++++--- 8 files changed, 47 insertions(+), 9 deletions(-) diff --git a/scripts/patch b/scripts/patch index 04ec0b4a..e0dab3e5 100755 --- a/scripts/patch +++ b/scripts/patch @@ -37,15 +37,28 @@ patch_search() { local name="$1" shift # remove the first 'patchtt/customtt' local files=("$@") - - log_debug "Searching for ${name} files (requested '${files[*]}')" - local fileslist fileslist=$(mktemp) - local a="\.sp[12]?" - local b="\.(web|db|prx|lb|slb)[0-9]+[ab]?" - local awk_regexp=".*${name}\.tt2(${a}|${b})?$" + local regexp="" + local hosts=() + if [ -n "${HOST_FILE:-}" ]; then + hosts+=("${HOST_FILE}") + fi + if [ -n "${PAIR_FILE:-}" ]; then + hosts+=("${PAIR_FILE}") + fi + if [ -n "${HA_FILE:-}" ]; then + hosts+=("${HA_FILE}") + fi + for val in "${hosts[@]}"; do + regexp="${regexp}|\\${val}" + done + local awk_regexp=".*${name}\.tt2$" + if [ -n "${regexp}" ]; then + awk_regexp=".*${name}\.tt2(${regexp#|})?$" + fi + log_debug "Searching for ${name} files (requested '${files[*]}') awk_regexp:${awk_regexp}" for dir in ${CONFIG_POOL} ; do [ -n "${dir}" ] || log_error "${dir} doesn't exist" diff --git a/t/fixtures/ngcpcfg_carrier.cfg b/t/fixtures/ngcpcfg_carrier.cfg index 73eaeba4..ab32b7ec 100644 --- a/t/fixtures/ngcpcfg_carrier.cfg +++ b/t/fixtures/ngcpcfg_carrier.cfg @@ -43,4 +43,7 @@ [ -n "${NETWORK_CONFIG_GROUP:-}" ] || NETWORK_CONFIG_GROUP="_ngcp-admin" [ -n "${NETWORK_CONFIG_CHMOD:-}" ] || NETWORK_CONFIG_CHMOD="0660" +[ -n "${HOST_FILE:-}" ] || HOST_FILE='.web01a' +[ -n "${PAIR_FILE:-}" ] || PAIR_FILE='.web01' + ## END OF FILE ################################################################# diff --git a/t/fixtures/ngcpcfg_carrier_instances.cfg b/t/fixtures/ngcpcfg_carrier_instances.cfg index bcc38b0c..12c9d32a 100644 --- a/t/fixtures/ngcpcfg_carrier_instances.cfg +++ b/t/fixtures/ngcpcfg_carrier_instances.cfg @@ -46,4 +46,7 @@ [ -n "${NETWORK_CONFIG_GROUP:-}" ] || NETWORK_CONFIG_GROUP="_ngcp-admin" [ -n "${NETWORK_CONFIG_CHMOD:-}" ] || NETWORK_CONFIG_CHMOD="0660" +[ -n "${HOST_FILE:-}" ] || HOST_FILE='.web01a' +[ -n "${PAIR_FILE:-}" ] || PAIR_FILE='.web01' + ## END OF FILE ################################################################# diff --git a/t/fixtures/ngcpcfg_network_interfaces.cfg b/t/fixtures/ngcpcfg_network_interfaces.cfg index c8b6d12d..76cda4d6 100644 --- a/t/fixtures/ngcpcfg_network_interfaces.cfg +++ b/t/fixtures/ngcpcfg_network_interfaces.cfg @@ -41,4 +41,6 @@ [ -n "${NETWORK_CONFIG_GROUP:-}" ] || NETWORK_CONFIG_GROUP="_ngcp-admin" [ -n "${NETWORK_CONFIG_CHMOD:-}" ] || NETWORK_CONFIG_CHMOD="0660" +[ -n "${HA_FILE:-}" ] || HA_FILE='.sp1' + ## END OF FILE ################################################################# diff --git a/t/fixtures/ngcpcfg_pro.cfg b/t/fixtures/ngcpcfg_pro.cfg index 55a71dc5..aca2757f 100644 --- a/t/fixtures/ngcpcfg_pro.cfg +++ b/t/fixtures/ngcpcfg_pro.cfg @@ -43,4 +43,6 @@ [ -n "${NETWORK_CONFIG_GROUP:-}" ] || NETWORK_CONFIG_GROUP="_ngcp-admin" [ -n "${NETWORK_CONFIG_CHMOD:-}" ] || NETWORK_CONFIG_CHMOD="0660" +[ -n "${HA_FILE:-}" ] || HA_FILE='.sp1' + ## END OF FILE ################################################################# diff --git a/t/fixtures/ngcpcfg_pro_instances.cfg b/t/fixtures/ngcpcfg_pro_instances.cfg index 108fd517..597ca5f5 100644 --- a/t/fixtures/ngcpcfg_pro_instances.cfg +++ b/t/fixtures/ngcpcfg_pro_instances.cfg @@ -43,4 +43,6 @@ [ -n "${NETWORK_CONFIG_GROUP:-}" ] || NETWORK_CONFIG_GROUP="_ngcp-admin" [ -n "${NETWORK_CONFIG_CHMOD:-}" ] || NETWORK_CONFIG_CHMOD="0660" +[ -n "${HA_FILE:-}" ] || HA_FILE='.sp1' + ## END OF FILE ################################################################# diff --git a/t/fixtures/read_cfg.sh b/t/fixtures/read_cfg.sh index 511f9299..66be1d82 100755 --- a/t/fixtures/read_cfg.sh +++ b/t/fixtures/read_cfg.sh @@ -50,3 +50,8 @@ echo "CONSTANTS_CONFIG_CHMOD=${CONSTANTS_CONFIG_CHMOD:-}" echo "NETWORK_CONFIG_USER=${NETWORK_CONFIG_USER:-}" echo "NETWORK_CONFIG_GROUP=${NETWORK_CONFIG_GROUP:-}" echo "NETWORK_CONFIG_CHMOD=${NETWORK_CONFIG_CHMOD:-}" + +# fake values from ngcpcfg-ha +echo "HA_FILE=${HA_FILE:-}" +echo "HOST_FILE=${HOST_FILE:-}" +echo "PAIR_FILE=${PAIR_FILE:-}" diff --git a/t/test_ngcpcfg_patch.py b/t/test_ngcpcfg_patch.py index 202e9d58..c9ad4bb6 100644 --- a/t/test_ngcpcfg_patch.py +++ b/t/test_ngcpcfg_patch.py @@ -1,7 +1,7 @@ #!/usr/bin/env py.test-3 - import shutil from pathlib import Path + import pytest from fixtures.fs import check_output @@ -376,7 +376,11 @@ def test_patch_action_build_generate_and_overwrite_customtt_file(ngcpcfg, ngcpcf # * overwrite old/available customtt files # * build proper config using new customtt files - env, cfg = ngcpcfg() + env, cfg = ngcpcfg( + env={ + "NGCPCFG": "fixtures/ngcpcfg_pro.cfg", + }, + ) template_pool = Path(cfg["TEMPLATE_POOL_BASE"]).joinpath("etc") shutil.rmtree(template_pool) apt_path = template_pool.joinpath("apt/apt.conf.d") @@ -512,7 +516,11 @@ def test_patch_action_build_generate_all_file(ngcpcfg, ngcpcfgcli): # the same as test 'test_patch_action_build_generate_and_overwrite_customtt_file' # while build all available files - env, cfg = ngcpcfg() + env, cfg = ngcpcfg( + env={ + "NGCPCFG": "fixtures/ngcpcfg_pro.cfg", + }, + ) template_pool = Path(cfg["TEMPLATE_POOL_BASE"]).joinpath("etc") shutil.rmtree(template_pool) apt_path = template_pool.joinpath("apt/apt.conf.d")