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

In a previous implementation using timestamps we ran into timing
problems on slower systems. So instead lets record the git commit
ID of the latest ngcpcfg commit and check whether we have a match
between this commit and an according ngcpcfg build.

If the "ngcpcfg build" was executed without an "ngcpcfg commit"
before then we mark it as dirty since we don't have an according
git commit available for testing against. Since that's a common
workflow we don't report it as a real problem though, instead we
inform the user using:

| OK:     nothing to build (latest build newer than latest commit)

As we commit AFTER the build in the apply action we can use a
workaround for this situation, so build and commit state match
with each other in that case then.

Change-Id: I48e32db6f42b53fe97a0b88805e7ddbee8576133
changes/97/3797/6
Michael Prokop 11 years ago
parent a8823269d1
commit c9b62658a1

@ -32,6 +32,9 @@ TIME_FORMAT="+%F %T"
# Run-time state directory
RUN_DIR='/var/run'
# directory holding files for internal state of ngcpcfg
STATE_FILES_DIR='/var/lib/ngcpcfg/state/'
# validate configs using kwalify schema
VALIDATE_SCHEMA="false"
## END OF FILE #################################################################

@ -245,6 +245,23 @@ generate_template_list() {
unset filelist_prepared filelist_final
}
record_commit_id() {
log_debug "cd $NGCPCTL_MAIN"
cd "$NGCPCTL_MAIN"
log_debug "mkdir -p ${STATE_FILES_DIR}"
mkdir -p "${STATE_FILES_DIR}"
# if there are uncommited changes then record it as such
if git status --porcelain | grep -q . ; then
echo "dirty" > "${STATE_FILES_DIR}/build"
else
local latest_commit=$(git log -1 --format="%H")
log_debug "echo $latest_commit > ${STATE_FILES_DIR}/build"
echo "$latest_commit" > "${STATE_FILES_DIR}/build"
fi
}
## }}}
## END OF FILE #################################################################

@ -38,6 +38,17 @@ if check_for_outstanding_commits && [ -z "${1:-}" ] ; then
exit 1
fi
"${SCRIPTS}"/check && "${SCRIPTS}"/build && "${SCRIPTS}"/services && "${SCRIPTS}"/commit "$*" && "${SCRIPTS}"/etckeeper
"${SCRIPTS}"/check
"${SCRIPTS}"/build
"${SCRIPTS}"/services
"${SCRIPTS}"/commit "$*"
# We "commit" AFTER we "build", therefore the state information is out of date
# and would be marked as "dirty". As we have full control over this during the
# "apply" run let's ensure it's not marked as dirty.
record_commit_id
"${SCRIPTS}"/etckeeper
## END OF FILE #################################################################

@ -48,6 +48,8 @@ build_config_files() {
"${HELPER}/build_config" "${file}"
RC=$(($RC + $?))
done
record_commit_id
}
# main script

@ -130,10 +130,43 @@ check_reboot_requests() {
fi
}
check_pending_build() {
log_debug "$FUNCNAME"
log_debug "cd $NGCPCTL_MAIN"
cd "$NGCPCTL_MAIN"
log_info "Checking state of pending builds:"
local latest_commit=$(git log -1 --format="%H")
log_debug "latest_commit = $latest_commit"
if ! [ -f "${STATE_FILES_DIR}/build" ] ; then
log_debug "File ${STATE_FILES_DIR}/build doesn't exist."
log_info "OK: no build/apply executed yet, nothing to do"
return 0
fi
local latest_build_commit=$(cat "${STATE_FILES_DIR}/build")
log_debug "latest_build_commit = $latest_build_commit"
if [ -n "$latest_commit" ] && [ -n "$latest_build_commit" ] ; then
if [ "$latest_build_commit" = "dirty" ] ; then
log_info "OK: nothing to build (latest build newer than latest commit)"
elif [ "$latest_commit" = "$latest_build_commit" ] ; 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_build
check_shared_storage "$@"
check_reboot_requests
fi

Loading…
Cancel
Save