MT#63742 Move database actions from commit to post-build

These need to be performed after build and before service, so that
any service restart will have the correct grants and schema changes
to be able to operate correctly.

Because we usually perform these operations on the standby node where
the affected services are not running, we do not tend to notice
breaking changes, but this can happen from time to time depending on
the order of operations and the types of database changes. Doing these
operations in the commit action is in any case wrong.

While at it, improve and unify the log messages of what we are doing.

Change-Id: Ic918dc75cdfc4097dc51e2b79f82d1299588f011
mr26.0
Guillem Jover 7 months ago
parent ad0cf94b46
commit 1302daa25b

@ -8,7 +8,6 @@ set -o pipefail
# support testsuite
FUNCTIONS="${FUNCTIONS:-/usr/share/ngcp-ngcpcfg/functions/}"
HELPER="${HELPER:-/usr/share/ngcp-ngcpcfg/helper/}"
HOOKS="${HOOKS:-/usr/share/ngcp-ngcpcfg/hooks/}"
SCRIPTS="${SCRIPTS:-/usr/share/ngcp-ngcpcfg/scripts/}"
NGCP_HOSTNAME="$(ngcp-hostname)"
@ -18,7 +17,6 @@ if ! [ -r "${FUNCTIONS}"/main ] ; then
exit 1
fi
timestamp_replacementchars=''
# shellcheck source=./functions/main
. "${FUNCTIONS}"/main
@ -36,22 +34,6 @@ chown_configs
cd "$NGCPCTL_MAIN"
if [ -z "${NO_DB_SYNC:-}" ] ; then
if [ -f "${RTP_INTERFACES_CONFIG}" ] ; then
log_info "Executing sync-db: "
"${HELPER}/sync-db" "$NGCPCTL_CONFIG" "$CONSTANTS_CONFIG" "$RTP_INTERFACES_CONFIG" "$NETWORK_CONFIG" "$SITES_CONFIG" 2>&1 | \
sed "s/^/$timestamp_replacementchars/" 2>&1 | \
tee >(logger -t ngcpcfg --id="${NGCPCFG_PID}") || true
else
log_info "Executing sync-db: "
"${HELPER}/sync-db" "$NGCPCTL_CONFIG" "$CONSTANTS_CONFIG" "$NETWORK_CONFIG" "$SITES_CONFIG" 2>&1 | \
sed "s/^/$timestamp_replacementchars/" 2>&1 | \
tee >(logger -t ngcpcfg --id="${NGCPCFG_PID}") || true
fi
else
log_debug "no-db-sync: skipping 'sync-db'"
fi
if ! git config user.name >/dev/null ; then
log_debug 'git config user.name ngcp-config'
git config user.name "ngcp-config"
@ -90,23 +72,4 @@ fi
log_debug "${SCRIPTS}/etckeeper"
"${SCRIPTS}"/etckeeper "$msg" >/dev/null
if [ -z "${NO_DB_SYNC:-}" ] ; then
log_info "Synchronizing MariaDB grants/credentials"
ngcp-sync-db-grants | sed "s/^/$timestamp_replacementchars/"
ngcp-sync-db-creds | sed "s/^/$timestamp_replacementchars/"
if [ -z "${NGCP_TYPE:-}" ] ; then # SPCE
# shellcheck disable=SC1091
. /etc/default/ngcp-roles
fi
if [ "${NGCP_TYPE}" == "carrier" ] && [ "${NGCP_IS_PROXY}" == "yes" ] ; then
# shellcheck disable=SC1091
. /etc/default/ngcp-db
log_info "Synchronizing MariaDB grants/credentials for ${LOCAL_DBHOST}:${LOCAL_DBPORT}"
ngcp-sync-db-grants --db-host "${LOCAL_DBHOST}" --db-port "${LOCAL_DBPORT}" --no-warnings | sed "s/^/$timestamp_replacementchars/"
ngcp-sync-db-creds --db-host "${LOCAL_DBHOST}" --db-port "${LOCAL_DBPORT}" --no-warnings | sed "s/^/$timestamp_replacementchars/"
fi
else
log_debug "no-db-sync: skipping 'ngcp-sync-db-grants' + 'ngcp-sync-db-creds'"
fi
## END OF FILE #################################################################

@ -8,12 +8,14 @@ set -o pipefail
# support testsuite
FUNCTIONS="${FUNCTIONS:-/usr/share/ngcp-ngcpcfg/functions/}"
HELPER="${HELPER:-/usr/share/ngcp-ngcpcfg/helper/}"
if ! [ -r "${FUNCTIONS}"/main ]; then
printf "Error: %s/main could not be read. Exiting.\n" "${FUNCTIONS}" >&2
exit 1
fi
timestamp_replacementchars=''
# shellcheck source=./functions/main
. "${FUNCTIONS}"/main
@ -21,6 +23,52 @@ fi
cd "$NGCPCTL_MAIN"
# XXX: Skeleton for incremental deployment.
if [ -z "${NO_DB_SYNC:-}" ]; then
declare -a configs
configs+=("$NGCPCTL_CONFIG")
configs+=("$CONSTANTS_CONFIG")
if [ -f "${RTP_INTERFACES_CONFIG}" ]; then
configs+=("$RTP_INTERFACES_CONFIG")
fi
configs+=("$NETWORK_CONFIG")
configs+=("$SITES_CONFIG")
log_info "Synchronizing MariaDB database: "
"${HELPER}/sync-db" "${configs[@]}" 2>&1 \
| sed "s/^/$timestamp_replacementchars/" 2>&1 \
| tee >(logger -t ngcpcfg --id="${NGCPCFG_PID}") || true
else
log_debug "no-db-sync: skipping 'sync-db'"
fi
if [ -z "${NO_DB_SYNC:-}" ]; then
log_info "Synchronizing MariaDB grants/credentials"
ngcp-sync-db-grants \
| sed "s/^/$timestamp_replacementchars/"
ngcp-sync-db-creds \
| sed "s/^/$timestamp_replacementchars/"
if [ -z "${NGCP_TYPE:-}" ]; then # SPCE
# shellcheck disable=SC1091
. /etc/default/ngcp-roles
fi
if [ "${NGCP_TYPE}" == "carrier" ] && [ "${NGCP_IS_PROXY}" == "yes" ]; then
# shellcheck disable=SC1091
. /etc/default/ngcp-db
log_info "Synchronizing MariaDB grants/credentials for ${LOCAL_DBHOST}:${LOCAL_DBPORT}"
ngcp-sync-db-grants \
--db-host "${LOCAL_DBHOST}" \
--db-port "${LOCAL_DBPORT}" \
--no-warnings \
| sed "s/^/$timestamp_replacementchars/"
ngcp-sync-db-creds \
--db-host "${LOCAL_DBHOST}" \
--db-port "${LOCAL_DBPORT}" \
--no-warnings \
| sed "s/^/$timestamp_replacementchars/"
fi
else
log_debug "no-db-sync: skipping 'ngcp-sync-db-grants' + 'ngcp-sync-db-creds'"
fi
## END OF FILE #################################################################

Loading…
Cancel
Save