MT#15973 Report in 'status' action when build/apply run is needed

If the latest git commit has a newer timestamp than
our latest "build" action then a "build" (or apply)
run is required, inform the user about it.

Change-Id: I83e2ff47ba54da733d368d78b6616d13d31a66d4
changes/90/3190/5
Michael Prokop 11 years ago
parent 9eb945734a
commit db373d3927

@ -29,6 +29,9 @@ SERVICES_POOL="${SERVICES_POOL_BASE}/etc"
# timestamp format for console output
TIME_FORMAT="+%F %T"
# directory holding files for internal state of ngcpcfg
TIMESTAMP_DIR='/var/lib/ngcpcfg/timestamps/'
# validate configs using kwalify schema
VALIDATE_SCHEMA="false"
## END OF FILE #################################################################

@ -125,6 +125,11 @@ if ! [ -d "$TEMPLATE_POOL_BASE" ] ; then
exit 1
fi
if [ -z "${TIMESTAMP_DIR:-}" ] ; then
log_error "No timestamp directory setting [TIMESTAMP_DIR] found - exiting."
exit 1
fi
if [ -d "${EXTRA_CONFIG_DIR:-}" ] && ls ${EXTRA_CONFIG_DIR}/*.yml &>/dev/null ; then
log_debug "EXTRA_CONFIG_DIR is configured and *.yml files are present, setting EXTRA_CONFIG_FILES"
EXTRA_CONFIG_FILES=${EXTRA_CONFIG_DIR}/*.yml
@ -245,6 +250,11 @@ generate_template_list() {
unset filelist_prepared filelist_final
}
timestamp_action() {
mkdir -p "${TIMESTAMP_DIR}"
touch "${TIMESTAMP_DIR}/${1}"
}
## }}}
## END OF FILE #################################################################

@ -36,66 +36,79 @@ fi
initialise() {
log_debug "${SCRIPTS}/initialise $*"
"${SCRIPTS}"/initialise $*
timestamp_action "initialise"
}
build() {
log_debug "${SCRIPTS}/build $*"
"${SCRIPTS}"/build $*
timestamp_action "build"
}
services() {
log_debug "${SCRIPTS}/services $*"
"${SCRIPTS}"/services $*
timestamp_action "services"
}
encrypt() {
log_debug "${SCRIPTS}/encrypt $*"
"${SCRIPTS}"/encrypt $*
timestamp_action "encrypt"
}
decrypt() {
log_debug "${SCRIPTS}/decrypt $*"
"${SCRIPTS}"/decrypt $*
timestamp_action "decrypt"
}
diff() {
log_debug "${SCRIPTS}/diff $*"
"${SCRIPTS}"/diff $*
timestamp_action "diff"
}
etckeeper() {
log_debug "${SCRIPTS}/etckeeper $*"
"${SCRIPTS}"/etckeeper $*
timestamp_action "etckeeper"
}
commit() {
log_debug "${SCRIPTS}/commit $*"
"${SCRIPTS}"/commit $*
timestamp_action "commit"
}
status() {
log_debug "${SCRIPTS}/status $*"
"${SCRIPTS}"/status $*
timestamp_action "status"
}
check() {
log_debug "${SCRIPTS}/check $*"
"${SCRIPTS}"/check $*
timestamp_action "check"
}
values() {
log_debug "${SCRIPTS}/values $*"
"${SCRIPTS}"/values $*
timestamp_action "values"
}
log() {
log_debug "${SCRIPTS}/log $*"
"${SCRIPTS}"/log $*
timestamp_action "log"
}
show() {
log_debug "${SCRIPTS}/show $*"
"${SCRIPTS}"/show $*
timestamp_action "show"
}
apply() {

@ -38,6 +38,19 @@ if check_for_outstanding_commits && [ -z "${1:-}" ] ; then
exit 1
fi
"${SCRIPTS}"/check && "${SCRIPTS}"/build && "${SCRIPTS}"/services && "${SCRIPTS}"/commit "$*" && "${SCRIPTS}"/etckeeper
"${SCRIPTS}"/check
timestamp_action "check"
"${SCRIPTS}"/build
timestamp_action "build"
"${SCRIPTS}"/services
timestamp_action "services"
"${SCRIPTS}"/commit "$*"
timestamp_action "commit"
"${SCRIPTS}"/etckeeper
timestamp_action "etckeeper"
## END OF FILE #################################################################

@ -116,11 +116,42 @@ check_remote() {
fi
}
check_pending_actions() {
log_debug "check_pending_actions"
log_debug "cd $NGCPCTL_MAIN"
cd "$NGCPCTL_MAIN"
log_info "Checking state of pending builds:"
local timestamp_commit=$(git log --format='%ct' -1)
log_debug "timestamp_commit = $timestamp_commit"
if ! [ -f "${TIMESTAMP_DIR}/build" ] ; then
log_debug "File ${TIMESTAMP_DIR}/build doesn't exist."
log_info "OK: no build/apply executed yet, nothing to do"
return 0
fi
local timestamp_build=$(stat --format='%Y' "${TIMESTAMP_DIR}/build")
log_debug "timestamp_build = $timestamp_build"
if [ -n "$timestamp_commit" ] && [ -n "$timestamp_build" ] ; then
local timediff=$(( timestamp_commit - timestamp_build ))
log_debug "timediff = $timediff"
if [ -n "$timediff" ] && [ "$timediff" -le 0 ] ; then
log_info "OK: nothing to build"
else
log_info "ACTION_NEEDED: commits without according build identified"
log_info "-> execute either 'ngcpcfg build' or 'ngcpcfg apply'"
fi
fi
}
if [ -z "${1:-}" ] ; then
check_local_state
check_push
check_etc_state
check_pending_actions
check_shared_storage "$@"
fi

Loading…
Cancel
Save