TT#126250 Bypass 'apply' options into 'build' script

It is necessary to allow bypassing '--ignore-shared-storage-check':
> ngcpcfg apply --ignore-shared-storage-check

Previously 'apply' options were not passing to 'build' script.

* docs:
   - add all supported options in *apply*
   - move '--force-all-services' description to *services*
     and add it in the list of options

Change-Id: I091142d1f74b7b9e09ce94b963ff4bf9dfaa8db7
mr10.0
Victor Seva 5 years ago
parent e9f0d5227d
commit eff9d4ae07

@ -310,16 +310,15 @@ Display ngcpcfg version and exit.
Actions and action specific options
-----------------------------------
**apply** [--force-all-services] [<commit_message>]::
**apply** [--dry-run] [--force-all-services] [--ignore-branch-check] [--ignore-shared-storage-check] [--ignore-branch-check] [--ignore-shared-storage-check] [--modified-only] [<commit_message>]::
Executes the _build_, _services_ and _commit_ commands in a batch
Executes the _check_, _build_, _services_ and _commit_ commands in a batch
(assuming each command worked as expected). This option serves as a shortcut for
the most commonly executed commands. If there are any outstanding changes that
need to be committed, then the commit message needs to be provided. This is
meant so the configuration change history (accessible e.g. via 'ngcpcfg log')
provides useful information.
The *--force-all-services* option causes all services to be restarted, including
services without changes in config files.
Options for _services_, _build_ and _check_ can be used here too.
**check** [--ignore-branch-check] [--ignore-shared-storage-check] [<config_files_or_directories>|<pattern>]::
@ -520,12 +519,14 @@ All 'ngcpcfg' output is muted on STDOUT but available in the log file
Note: This option is available in High Availability setups only.
**services** [--dry-run]::
**services** [--dry-run] [--force-all-services]::
Execute any defined service actions for modified configuration files. If the
_--dry-run_ option is present the services won't be executed but you'll be
noticed which service files would be executed if being invoked without the
_--dry-run__ option.
_--force-all-services_ option causes all services to be restarted, including
services without changes in config files.
**set** [<options>] <file> <option>=<value>::

@ -31,15 +31,29 @@ check_for_outstanding_commits() {
fi
}
build_args=()
check_args=()
services_args=()
while [ -n "${1:-}" ]; do
case "$1" in
*--modified-only*) build_args+=( --modified-only ) ; shift ;;
*--ignore-branch-check*) check_args+=( --ignore-branch-check ) ; shift ;;
*--ignore-shared-storage-check*) check_args+=( --ignore-shared-storage-check ) ; shift ;;
*--dry-run*) services_args+=( --dry-run ) ; shift ;;
*--force-all-services*) services_args+=( --force-all-services ) ; shift ;;
*) break ;;
esac
done
if 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
fi
"${SCRIPTS}"/build
"${SCRIPTS}"/services "$@"
"${SCRIPTS}"/commit "$@"
"${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

@ -76,6 +76,7 @@ fi
if is_git_clean ; then
log_info "OK: nothing to commit."
else
log_debug "msg:\"$msg\""
log_debug "git add . ; git commit -a -m \"\$msg [\$(date --rfc-3339=ns)]\""
git add .
git commit -a -m "$msg [$(date --rfc-3339=ns)]" >/dev/null

@ -46,15 +46,58 @@ def test_apply_no_commit_msg(ngcpcfgcli, tmpdir, gitrepo):
assert out.returncode != 0
@pytest.mark.apply
def test_apply_no_commit_msg_options(ngcpcfgcli, tmpdir, gitrepo):
outdir = tmpdir.mkdir("ngcp-pytest-output")
src = "basic-ngcp-config.tar.gz"
with gitrepo.from_archive(src):
cfg_dir = os.path.join(gitrepo.localpath, "ngcp-config")
tt2_dir = os.path.join(os.getcwd(), "fixtures", "apply_templates")
env = {
"DEBUG": "true",
"RUN_DIR": tmpdir.mkdir("ngcp-pytest-rundir"),
"OUTPUT_DIRECTORY": outdir,
"TEMPLATE_POOL_BASE": tt2_dir,
# don't mess with perms
"SKIP_RESTORE_PERMS": "true",
"NGCPCTL_MAIN": cfg_dir,
# we just need a clean git repo
"NGCPCTL_BASE": cfg_dir,
"STATE_FILES_DIR": outdir + "/var/lib/ngcpcfg/state/",
}
# create a change in repo
Path(os.path.join(cfg_dir, "config.yml")).touch()
print("env:{}".format(env))
out = ngcpcfgcli(
"apply",
"--ignore-branch-check",
"--dry-run",
env=env,
)
# debug, only printed in logs in case of error
print("stdout:")
print(out.stdout.replace("\\n", "\n"))
print("stderr:")
print(out.stderr.replace("\\n", "\n"))
msg = r"Please provide commit message"
regex = re.compile(msg)
assert re.search(regex, out.stdout)
assert out.returncode != 0
@pytest.mark.apply
def test_apply_with_commit_msg(ngcpcfgcli, tmpdir, gitrepo):
outdir = tmpdir.mkdir("ngcp-pytest-output")
src = "basic-ngcp-config.tar.gz"
commit_msg = "whatever commit message"
with gitrepo.from_archive(src):
cfg_dir = os.path.join(gitrepo.localpath, "ngcp-config")
tt2_dir = os.path.join(os.getcwd(), "fixtures", "apply_templates")
env = {
# "DEBUG": "true",
"DEBUG": "true",
"RUN_DIR": tmpdir.mkdir("ngcp-pytest-rundir"),
"OUTPUT_DIRECTORY": outdir,
"TEMPLATE_POOL_BASE": tt2_dir,
@ -68,7 +111,7 @@ def test_apply_with_commit_msg(ngcpcfgcli, tmpdir, gitrepo):
print("env:{}".format(env))
out = ngcpcfgcli(
"apply",
"whatever commit message",
commit_msg,
env=env,
)
@ -81,5 +124,63 @@ def test_apply_with_commit_msg(ngcpcfgcli, tmpdir, gitrepo):
print("stderr:")
print(out.stderr.replace("\\n", "\n"))
assert out.returncode == 0
assert re.search(regex, out.stdout)
msg = r"DEBUG: msg:\"{}\"".format(commit_msg)
regex = re.compile(msg)
assert re.search(regex, out.stderr)
@pytest.mark.apply
def test_apply_with_commit_msg_options(ngcpcfgcli, tmpdir, gitrepo):
outdir = tmpdir.mkdir("ngcp-pytest-output")
src = "basic-ngcp-config.tar.gz"
commit_msg = "whatever commit message"
with gitrepo.from_archive(src):
cfg_dir = os.path.join(gitrepo.localpath, "ngcp-config")
tt2_dir = os.path.join(os.getcwd(), "fixtures", "apply_templates")
env = {
"DEBUG": "true",
"RUN_DIR": tmpdir.mkdir("ngcp-pytest-rundir"),
"OUTPUT_DIRECTORY": outdir,
"TEMPLATE_POOL_BASE": tt2_dir,
# don't mess with perms
"SKIP_RESTORE_PERMS": "true",
"NGCPCTL_MAIN": cfg_dir,
# we just need a clean git repo
"NGCPCTL_BASE": cfg_dir,
"STATE_FILES_DIR": outdir + "/var/lib/ngcpcfg/state/",
}
print("env:{}".format(env))
out = ngcpcfgcli(
"apply",
"--dry-run",
"--ignore-branch-check",
commit_msg,
env=env,
)
msg = r"Generating .+/etc/fake.txt: OK"
regex = re.compile(msg)
# debug, only printed in logs in case of error
print("stdout:")
print(out.stdout.replace("\\n", "\n"))
print("stderr:")
print(out.stderr.replace("\\n", "\n"))
assert out.returncode == 0
assert re.search(regex, out.stdout)
msg = r"DEBUG: DRYRUN = true"
regex = re.compile(msg)
assert re.search(regex, out.stderr)
msg = r"--ignore-branch-check is enabled, not checking for branch 'master'"
regex = re.compile(msg)
assert re.search(regex, out.stdout)
msg = r"DEBUG: msg:\"{}\"".format(commit_msg)
regex = re.compile(msg)
assert re.search(regex, out.stderr)

Loading…
Cancel
Save