TT#63758 Move function 'action' from ngcpcfg to function/main->main_action()

We need to call action and care about SUMMARY_ONLY without calling ngcpcfg.
main_action will be used in push-parallel to call pull/build/apply actions
directly without calling ngcpcfg. Also 'ngcpcfg push' can be migrated on new
approach '--remote' (recommended by Guillem Jover, BTW, Tnx!) from the current
approach of executing commands through ngcp-ssh on remote host.

Change-Id: I927b8055a040f49d6cfb462a200ad4d4b2d660ff
changes/35/33935/3
Alexander Lutay 7 years ago
parent 6862f1834c
commit f4ac5caab2

@ -32,6 +32,33 @@ fi
## }}} ## }}}
## functions {{{ ## functions {{{
main_action() {
local rc=0
ACTION="$1"
shift
[ -z "${SUMMARY_ONLY:-}" ] && SUMMARY_ONLY=0
if [ "${SUMMARY_ONLY}" == "1" ]; then
log_debug "${SCRIPTS}/${ACTION} $* >(logger -t ngcpcfg --id=\"${NGCPCFG_PID}\") >/dev/null 2>&1"
"${SCRIPTS}/${ACTION}" "$@" >(logger -t ngcpcfg --id="${NGCPCFG_PID}") >/dev/null 2>&1 || rc=$?
else
log_debug "${SCRIPTS}/${ACTION} $*"
"${SCRIPTS}/${ACTION}" "$@" || rc=$?
fi
if [ "${rc}" == "0" ]; then
local msg="Successfully executed '${ACTION}' on '${HNAME}'"
[ "${SUMMARY_ONLY}" == "1" ] || log_only "${msg}"
[ "${SUMMARY_ONLY}" == "0" ] || log_info "${msg}"
else
local msg="Failed to call action '${ACTION}' on '${HNAME}' (see logs on '${HNAME}')"
[ "${SUMMARY_ONLY}" == "1" ] || log_only "Error: ${msg}"
[ "${SUMMARY_ONLY}" == "0" ] || log_error "${msg}"
exit "${rc}"
fi
}
hook_setup() { hook_setup() {
log_debug "hook_setup ${1:-}" log_debug "hook_setup ${1:-}"

@ -32,33 +32,6 @@ ngcpcfg_restore_perms() {
"${HELPER}"/restore-permissions "${NGCPCTL_MAIN}" "${HELPER}"/restore-permissions "${NGCPCTL_MAIN}"
} }
action() {
local rc=0
ACTION="$1"
shift
[ -z "${SUMMARY_ONLY:-}" ] && SUMMARY_ONLY=0
if [ "${SUMMARY_ONLY}" == "1" ]; then
log_debug "${SCRIPTS}/${ACTION} $* >/dev/null 2>&1"
"${SCRIPTS}/${ACTION}" "$@" >/dev/null 2>&1 || rc=$?
else
log_debug "${SCRIPTS}/${ACTION} $*"
"${SCRIPTS}/${ACTION}" "$@" || rc=$?
fi
if [ "${rc}" == "0" ]; then
local msg="Successfully executed '${ACTION}' on '${HNAME}'"
[ "${SUMMARY_ONLY}" == "1" ] || log_only "${msg}"
[ "${SUMMARY_ONLY}" == "0" ] || log_info "${msg}"
else
local msg="Failed to call action '${ACTION}' on '${HNAME}' (see logs on '${HNAME}')"
[ "${SUMMARY_ONLY}" == "1" ] || log_only "Error: ${msg}"
[ "${SUMMARY_ONLY}" == "0" ] || log_error "${msg}"
exit "${rc}"
fi
}
usage() { usage() {
# make sure to output errors on stderr # make sure to output errors on stderr
[ "${1:-}" = "1" ] && exec >&2 [ "${1:-}" = "1" ] && exec >&2
@ -163,7 +136,7 @@ case ${1:-} in
initialise|\ initialise|\
show|\ show|\
values) values)
action "$@" main_action "$@"
;; ;;
apply|\ apply|\
build|\ build|\
@ -184,7 +157,7 @@ case ${1:-} in
patch) patch)
ngcpcfg_update_perms ngcpcfg_update_perms
trap 'ngcpcfg_restore_perms' ERR EXIT trap 'ngcpcfg_restore_perms' ERR EXIT
action "$@" main_action "$@"
;; ;;
--debug) export DEBUG=1 ; shift ; "$0" "$@" ;; --debug) export DEBUG=1 ; shift ; "$0" "$@" ;;
--no-db-sync) export NO_DB_SYNC=1 ; shift ; "$0" "$@" ;; --no-db-sync) export NO_DB_SYNC=1 ; shift ; "$0" "$@" ;;

Loading…
Cancel
Save