TT#81050 Add HA_CONFIG and PAIR_CONFIG support

This makes it possible to use more specific config.yml files either for
a pair of nodes, for settings that will always affect both, or for the
HA names, for settings that might affect all A or B nodes.

This matches the support in the template files.

We need to move sourcing the ha_features and carrier_features before
sourcing init, as now the ngcpcfg.cfg file can use these variables if
set.

Change-Id: Ic6b32acceb8f020f48c3afa09d9e84252b3531e7
changes/53/39853/2
Guillem Jover 6 years ago
parent 35e8e975d2
commit 354e7578c5

@ -7,6 +7,8 @@ NGCPCTL_BASE='/etc'
NGCPCTL_MAIN="${NGCPCTL_BASE}/ngcp-config"
NGCPCTL_CONFIG="${NGCPCTL_MAIN}/config.yml"
HOST_CONFIG="${NGCPCTL_MAIN}/config.$(hostname).yml"
HA_CONFIG="${HA_FILE:+${NGCPCTL_MAIN}/config${HA_FILE}.yml}"
PAIR_CONFIG="${PAIR_FILE:+${NGCPCTL_MAIN}/config${PAIR_FILE}.yml}"
LOCAL_CONFIG="${NGCPCTL_MAIN}/config.local.yml"
CONSTANTS_CONFIG="${NGCPCTL_MAIN}/constants.yml"
NETWORK_CONFIG="${NGCPCTL_MAIN}/network.yml"

@ -11,26 +11,28 @@ if ! [ -r "${FUNCTIONS}"/logs ] ; then
fi
. "${FUNCTIONS}"/logs
if ! [ -r "${FUNCTIONS}"/init ] ; then
log_error "%s/init could not be read. Exiting." "${FUNCTIONS}"
exit 1
fi
set -o allexport
. "${FUNCTIONS}"/init
set +o allexport
## HA / carrier features {{{
if [ -r "${FUNCTIONS}"/ha_features ] ; then
. "${FUNCTIONS}"/ha_features
set_ha_file # set ${HA_FILE} for usage in generate_template_list
# Set ${HA_FILE}, used by ngcpcfg.cfg, tt2-process and encrypt.
set_ha_file
fi
if [ -r "${FUNCTIONS}"/carrier_features ] ; then
. "${FUNCTIONS}"/carrier_features
set_host_and_pair_files # set ${HOST_FILE} + ${PAIR_FILE} for usage in generate_template_list
# Set ${HOST_FILE} + ${PAIR_FILE}, used by ngcpcfg.cfg and tt2-process.
set_host_and_pair_files
fi
## }}}
if ! [ -r "${FUNCTIONS}"/init ] ; then
log_error "%s/init could not be read. Exiting." "${FUNCTIONS}"
exit 1
fi
set -o allexport
. "${FUNCTIONS}"/init
set +o allexport
## functions {{{
main_action() {
local rc=0

@ -41,7 +41,7 @@ if [ -n "${NGCP_JOBS:-}" ] ; then
ARGS+=("--jobs=${NGCP_JOBS}")
fi
for f in ${NGCPCTL_CONFIG:-} ${HOST_CONFIG:-} ${LOCAL_CONFIG:-} ${NETWORK_CONFIG:-} "${EXTRA_CONFIG_FILES[@]}" ${CONSTANTS_CONFIG:-} ; do
for f in ${NGCPCTL_CONFIG:-} ${HOST_CONFIG:-} ${HA_CONFIG:-} ${PAIR_CONFIG:-} ${LOCAL_CONFIG:-} ${NETWORK_CONFIG:-} "${EXTRA_CONFIG_FILES[@]}" ${CONSTANTS_CONFIG:-} ; do
if [ -r "$f" ] ; then
ARGS+=("-c" "$f")
fi
@ -78,9 +78,16 @@ else
fi
done
declare -a configs
for config in "${HA_CONFIG}" "${PAIR_CONFIG}"; do
if [ -n "${config}" ]; then
configs+=("-e" "$(basename "${config}")")
fi
done
if git diff-index --name-only HEAD | grep -q \
-e "$(basename "$NGCPCTL_CONFIG")" \
-e "$(basename "$HOST_CONFIG")" \
"${configs[@]}" \
-e "$(basename "$LOCAL_CONFIG")" \
-e "$(basename "$NETWORK_CONFIG")" \
-e "$(basename "$CONSTANTS_CONFIG")" ; then

@ -229,7 +229,7 @@ check_shared_storage() {
}
if [ "$*" = "" ] ; then
config_files="${NGCPCTL_CONFIG:-} ${HOST_CONFIG:-} ${LOCAL_CONFIG:-} ${NETWORK_CONFIG:-} ${EXTRA_CONFIG_FILES[*]} ${CONSTANTS_CONFIG:-}"
config_files="${NGCPCTL_CONFIG:-} ${HOST_CONFIG:-} ${HA_CONFIG:-} ${PAIR_CONFIG:-} ${LOCAL_CONFIG:-} ${NETWORK_CONFIG:-} ${EXTRA_CONFIG_FILES[*]} ${CONSTANTS_CONFIG:-}"
else
config_files="$*"
fi

@ -40,7 +40,7 @@ fi
# Get the list of configs in proper order to load.
declare -a ARGS
for f in ${NGCPCTL_CONFIG:-} ${HOST_CONFIG:-} ${LOCAL_CONFIG:-} ${NETWORK_CONFIG:-} "${EXTRA_CONFIG_FILES[@]}" ${CONSTANTS_CONFIG:-} ; do
for f in ${NGCPCTL_CONFIG:-} ${HOST_CONFIG:-} ${HA_CONFIG:-} ${PAIR_CONFIG:-} ${LOCAL_CONFIG:-} ${NETWORK_CONFIG:-} "${EXTRA_CONFIG_FILES[@]}" ${CONSTANTS_CONFIG:-} ; do
if [ -r "$f" ] ; then
ARGS+=("-c" "${f}")
fi

@ -3,6 +3,8 @@
[ -n "${NGCPCTL_MAIN:-}" ] || NGCPCTL_MAIN="${NGCPCTL_BASE}/fixtures/repos/"
[ -n "${NGCPCTL_CONFIG:-}" ] || NGCPCTL_CONFIG="${NGCPCTL_MAIN}/config.yml"
[ -n "${HOST_CONFIG:-}" ] || HOST_CONFIG="${NGCPCTL_MAIN}/config.$(hostname).yml"
[ -n "${HA_CONFIG:-}" ] || HA_CONFIG="${NGCPCTL_MAIN}/config.ha.yml"
[ -n "${PAIR_CONFIG:-}" ] || PAIR_CONFIG="${NGCPCTL_MAIN}/config.pair.yml"
[ -n "${LOCAL_CONFIG:-}" ] || LOCAL_CONFIG="${NGCPCTL_MAIN}/constants_local_carrier.yml"
[ -n "${CONSTANTS_CONFIG:-}" ] || CONSTANTS_CONFIG="${NGCPCTL_MAIN}/constants.yml"
[ -n "${NETWORK_CONFIG:-}" ] || NETWORK_CONFIG="${NGCPCTL_MAIN}/network_carrier.yml"

@ -3,6 +3,8 @@
[ -n "${NGCPCTL_MAIN:-}" ] || NGCPCTL_MAIN="${NGCPCTL_BASE}/fixtures/repos/"
[ -n "${NGCPCTL_CONFIG:-}" ] || NGCPCTL_CONFIG="${NGCPCTL_MAIN}/config.yml"
[ -n "${HOST_CONFIG:-}" ] || HOST_CONFIG="${NGCPCTL_MAIN}/config.$(hostname).yml"
[ -n "${HA_CONFIG:-}" ] || HA_CONFIG="${NGCPCTL_MAIN}/config.ha.yml"
[ -n "${PAIR_CONFIG:-}" ] || PAIR_CONFIG="${NGCPCTL_MAIN}/config.pair.yml"
[ -n "${LOCAL_CONFIG:-}" ] || LOCAL_CONFIG="${NGCPCTL_MAIN}/constants_local_pro.yml"
[ -n "${CONSTANTS_CONFIG:-}" ] || CONSTANTS_CONFIG="${NGCPCTL_MAIN}/constants.yml"
[ -n "${NETWORK_CONFIG:-}" ] || NETWORK_CONFIG="${NGCPCTL_MAIN}/network_pro.yml"

@ -0,0 +1,2 @@
ha enabled:
pair enabled:

@ -0,0 +1,2 @@
ha enabled: yes
pair enabled: yes

@ -0,0 +1,3 @@
---
ha:
enabled: yes

@ -0,0 +1,3 @@
---
pair:
enabled: yes

@ -0,0 +1,2 @@
ha enabled: [% ha.enabled %]
pair enabled: [% pair.enabled %]

@ -1,6 +1,7 @@
[pytest]
python_files=*.py
markers =
build
cmdline
get
mt_16391

@ -1,5 +1,6 @@
#!/usr/bin/env py.test-3
import filecmp
import os
import pytest
import re
@ -37,6 +38,42 @@ def test_simple_build_template_ok(ngcpcfgcli):
assert re.search(regex, out.stdout)
@pytest.mark.build
def test_simple_build_template_no_ha_no_carrier(ngcpcfgcli):
tmpdir = tempfile.mkdtemp(prefix='ngcp-', suffix='-pytest-output')
out = ngcpcfgcli("build", "--ignore-branch-check", "/etc/config_variants",
env={
'NGCP_BASE_TT2': os.getcwd(),
'OUTPUT_DIRECTORY': tmpdir,
})
regex = re.compile(r"Generating " + tmpdir + r"/etc/config_variants: OK")
assert re.search(regex, out.stdout)
output_file = os.path.join(tmpdir, "etc/config_variants")
test_file = "fixtures/output/config_variants"
assert os.path.exists(output_file)
assert os.path.exists(test_file)
assert filecmp.cmp(output_file, test_file)
@pytest.mark.build
def test_simple_build_template_pro(ngcpcfgcli):
tmpdir = tempfile.mkdtemp(prefix='ngcp-', suffix='-pytest-output')
out = ngcpcfgcli("build", "--ignore-branch-check",
"/etc/config_variants",
env={
'NGCP_BASE_TT2': os.getcwd(),
'OUTPUT_DIRECTORY': tmpdir,
'NGCPCFG': 'fixtures/ngcpcfg_pro.cfg',
})
regex = re.compile(r"Generating " + tmpdir + r"/etc/config_variants: OK")
assert re.search(regex, out.stdout)
output_file = os.path.join(tmpdir, "etc/config_variants")
test_file = "fixtures/output/config_variants_pro"
assert os.path.exists(output_file)
assert os.path.exists(test_file)
assert filecmp.cmp(output_file, test_file)
@pytest.mark.tt_17401
def test_fail_on_existing_dir_matching_output_filename(ngcpcfgcli, tmpdir):
tmpdir = tempfile.mkdtemp(prefix='ngcp-', suffix='-pytest-output')

@ -64,3 +64,25 @@ def test_get_action_missing_item(ngcpcfgcli, tmpdir):
assert "\\n" in out.stdout
assert "" in out.stderr
assert out.returncode == 0
@pytest.mark.get
def test_get_action_config_ha(ngcpcfgcli, tmpdir):
out = ngcpcfgcli("get", "ha.enabled",
env={
'NGCPCFG': 'fixtures/ngcpcfg_pro.cfg',
})
assert "yes" in out.stdout
assert "" in out.stderr
assert out.returncode == 0
@pytest.mark.get
def test_get_action_config_pair(ngcpcfgcli, tmpdir):
out = ngcpcfgcli("get", "pair.enabled",
env={
'NGCPCFG': 'fixtures/ngcpcfg_pro.cfg',
})
assert "yes" in out.stdout
assert "" in out.stderr
assert out.returncode == 0

Loading…
Cancel
Save