From e69c8d8404a4b7806c94d020dfc0944bbd6c9c7e Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Fri, 8 Aug 2025 08:06:39 -0400 Subject: [PATCH] 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 --- scripts/apply | 17 +++++++++++------ t/test_ngcpcfg_apply.py | 8 +++----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/scripts/apply b/scripts/apply index 391ac090..e6ad06c0 100755 --- a/scripts/apply +++ b/scripts/apply @@ -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 ################################################################# diff --git a/t/test_ngcpcfg_apply.py b/t/test_ngcpcfg_apply.py index 35841ab0..b86ec480 100644 --- a/t/test_ngcpcfg_apply.py +++ b/t/test_ngcpcfg_apply.py @@ -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,