MT#58458 skip commit actions during dry run

Don't make changes to the git repo during dry run. This also means we
don't need a commit message.

Change-Id: I62badf5326898a4aae3f657e014cae5c2e50ba58
mr13.5
Richard Fuchs 7 months ago
parent f22aff288a
commit e69c8d8404

@ -34,6 +34,7 @@ check_for_outstanding_commits() {
build_args=()
check_args=()
services_args=()
export DRYRUN='false'
export NO_DB_SYNC=${NO_DB_SYNC:-}
while [ -n "${1:-}" ]; do
case "$1" in
@ -42,6 +43,7 @@ while [ -n "${1:-}" ]; do
*--ignore-shared-storage-check*) check_args+=( --ignore-shared-storage-check ) ; shift ;;
*--dry-run*)
services_args+=( --dry-run )
DRYRUN='true'
NO_DB_SYNC=1
shift
;;
@ -50,7 +52,7 @@ while [ -n "${1:-}" ]; do
esac
done
if check_for_outstanding_commits && [ -z "${1:-}" ] ; then
if ! ${DRYRUN} && check_for_outstanding_commits && [ -z "${1:-}" ] ; then
log_error "Uncommitted configuration files found."
log_info "Please provide commit message, like: $PN apply 'summary of your changes'"
exit 1
@ -58,11 +60,14 @@ fi
"${SCRIPTS}"/build "${build_args[@]}" "${check_args[@]}"
"${SCRIPTS}"/services "${services_args[@]}"
"${SCRIPTS}"/commit "${1:-}"
# 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
if ! ${DRYRUN} ; then
"${SCRIPTS}"/commit "${1:-}"
# 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
fi
## END OF FILE #################################################################

@ -47,9 +47,10 @@ def test_apply_no_commit_msg_options(ngcpcfg, ngcpcfgcli):
env=env,
)
assert re.search(r"Please provide commit message", out.stdout)
assert re.search(r"no explicit service state changed", out.stderr)
assert re.search(r"skip restore-permissions", out.stderr)
assert re.search(r"apply --dry-run", out.stderr)
assert out.returncode != 0
assert out.returncode == 0
@pytest.mark.apply
@ -85,7 +86,6 @@ def test_apply_with_commit_msg_options(ngcpcfg, ngcpcfgcli):
out = ngcpcfgcli(
"apply",
"--ignore-branch-check",
"--dry-run",
commit_msg,
env=env,
)
@ -94,8 +94,6 @@ def test_apply_with_commit_msg_options(ngcpcfg, ngcpcfgcli):
assert re.search(r"Generating .+/etc/fake.txt: OK", out.stdout)
assert re.search(r"DEBUG: msg:\"{}\"".format(commit_msg), out.stderr)
assert re.search(r"DEBUG: DRYRUN = true", out.stderr)
assert re.search(
r"--ignore-branch-check is enabled, not checking for branch 'master'",
out.stdout,

Loading…
Cancel
Save