TT#68710 Rename 'ngcpcfg values' to 'ngcpcfg get'

It was a widely popular question from users.
As the common sense pushes them to use 'get' when they use 'set/del'.
Let's follow the common logic here.
We still support old 'ngcpcfg values' syntax.

Change-Id: I40a210b7c13d21a4bff4b6988535c39091f53280
changes/37/34237/7
Alexander Lutay 6 years ago
parent 1ab8c9a1ce
commit 36a11888d6

@ -26,6 +26,7 @@ scripts/clean usr/share/ngcp-ngcpcfg/scripts/
scripts/commit usr/share/ngcp-ngcpcfg/scripts/
scripts/del usr/share/ngcp-ngcpcfg/scripts/
scripts/diff usr/share/ngcp-ngcpcfg/scripts/
scripts/get usr/share/ngcp-ngcpcfg/scripts/
scripts/etckeeper usr/share/ngcp-ngcpcfg/scripts/
scripts/initialise usr/share/ngcp-ngcpcfg/scripts/
scripts/log usr/share/ngcp-ngcpcfg/scripts/

@ -403,6 +403,10 @@ defined password and save the result as /etc/ngcp-config-crypted.tgz.gpg.
Note: This feature is only available if the ngcp-ngcpcfg-locker package is
installed.
**get** <key>::
Prints the value of <key> using ngcp config files as source.
**help**::
Display usage information and exit.
@ -548,7 +552,7 @@ system isn't available).
**values** <key>::
Prints the value of <key> using ngcp config files as source.
Obsolete synonym for 'get'.
Usage examples
--------------

@ -78,7 +78,8 @@ Actions:
fi
printf "\
values <key> print key value from YAML configuration files
values <key> obsolete synonym for 'get'
get <key> print key value from YAML configuration files
help display this help screen and exit
version display program version and exit
\n"
@ -134,8 +135,12 @@ case ${1:-} in
init-mgmt|\
init-shared|\
initialise|\
show|\
get|\
show)
main_action "$@"
;;
values)
printf "Note: 'ngcpcfg values' is obsolete, use 'ngcpcfg get'\n" >&2
main_action "$@"
;;
apply|\

@ -0,0 +1,84 @@
#!/bin/bash
# Purpose: get a value based on ngcpcfg's config
################################################################################
set -e
set -u
get_value() {
# assume safe defaults
umask 0077
input_file="$(mktemp)"
echo "[% $1 %]" > "${input_file}"
output_file="$(mktemp)"
if "$TT_WRAPPER" "${input_file}" > "${output_file}" 2>/dev/null ; then
cat "${output_file}"
else
RC=1
fi
rm -f "${input_file}" "${output_file}"
}
if [ "${#:-}" -ne 1 ] ; then
echo "Usage: ngcpcfg get <key>" >&2
echo "Example: ngcpcfg get ntp.servers" >&2
exit 1
fi
# support testsuite
FUNCTIONS="${FUNCTIONS:-/usr/share/ngcp-ngcpcfg/functions/}"
HELPER="${HELPER:-/usr/share/ngcp-ngcpcfg/helper/}"
if ! [ -r "${FUNCTIONS}"/main ] ; then
printf "Error: %s/main could not be read. Exiting.\n" "${FUNCTIONS}">&2
exit 1
fi
. "${FUNCTIONS}"/main
TT_WRAPPER="${HELPER}/tt2-wrapper"
# Kill all previous started tt2-daemon Perl processes if they were not stopped properly
killall tt2-daemon 2>/dev/null || true
if [ -n "${NGCP_SOCKETFILE:-}" ] ; then
log_debug "Using $NGCP_SOCKETFILE as tt2-daemon socket file as set via 'NGCP_SOCKETFILE'."
else
NGCP_SOCKETFILE='/var/run/ngcpcfg.socket'
fi
rm -f "${NGCP_SOCKETFILE}"
# Start new tt2-daemon Perl process
"${HELPER}"/tt2-daemon --quiet
# Load all the configs in proper order and check their avialability and valid YAML syntax
for f in ${NGCPCTL_CONFIG:-} ${HOST_CONFIG:-} ${LOCAL_CONFIG:-} ${NETWORK_CONFIG:-} "${EXTRA_CONFIG_FILES[@]}" ${CONSTANTS_CONFIG:-} ; do
if [ -r "$f" ] ; then
if ! "${HELPER}/tt2-wrapper" "/dev/null" "${f}" ; then
log_error "tt2-daemon cannot load ${f}:"
"${HELPER}/tt2-wrapper" "/dev/null" "${f}"
exit 1
fi
fi
done
# main script
RC=0
# TODO: detect HASH and try to create template to get those values?
res="$(get_value "$1")"
if [[ $res =~ ^ARRAY\(0x.+\)$ ]] ; then
get_value "$1.join(' ')"
else
echo "$res"
fi
# Kill all previous started tt2-daemon Perl processes
killall tt2-daemon 2>/dev/null || true
rm -f "${NGCP_SOCKETFILE}"
exit "$RC"
## END OF FILE #################################################################

@ -1,84 +0,0 @@
#!/bin/bash
# Purpose: get a value based on ngcpcfg's config
################################################################################
set -e
set -u
get_value() {
# assume safe defaults
umask 0077
input_file="$(mktemp)"
echo "[% $1 %]" > "${input_file}"
output_file="$(mktemp)"
if "$TT_WRAPPER" "${input_file}" > "${output_file}" 2>/dev/null ; then
cat "${output_file}"
else
RC=1
fi
rm -f "${input_file}" "${output_file}"
}
if [ "${#:-}" -ne 1 ] ; then
echo "Usage: ngcpcfg values <key>" >&2
echo "Example: ngcpcfg values ntp.servers" >&2
exit 1
fi
# support testsuite
FUNCTIONS="${FUNCTIONS:-/usr/share/ngcp-ngcpcfg/functions/}"
HELPER="${HELPER:-/usr/share/ngcp-ngcpcfg/helper/}"
if ! [ -r "${FUNCTIONS}"/main ] ; then
printf "Error: %s/main could not be read. Exiting.\n" "${FUNCTIONS}">&2
exit 1
fi
. "${FUNCTIONS}"/main
TT_WRAPPER="${HELPER}/tt2-wrapper"
# Kill all previous started tt2-daemon Perl processes if they were not stopped properly
killall tt2-daemon 2>/dev/null || true
if [ -n "${NGCP_SOCKETFILE:-}" ] ; then
log_debug "Using $NGCP_SOCKETFILE as tt2-daemon socket file as set via 'NGCP_SOCKETFILE'."
else
NGCP_SOCKETFILE='/var/run/ngcpcfg.socket'
fi
rm -f "${NGCP_SOCKETFILE}"
# Start new tt2-daemon Perl process
"${HELPER}"/tt2-daemon --quiet
# Load all the configs in proper order and check their avialability and valid YAML syntax
for f in ${NGCPCTL_CONFIG:-} ${HOST_CONFIG:-} ${LOCAL_CONFIG:-} ${NETWORK_CONFIG:-} "${EXTRA_CONFIG_FILES[@]}" ${CONSTANTS_CONFIG:-} ; do
if [ -r "$f" ] ; then
if ! "${HELPER}/tt2-wrapper" "/dev/null" "${f}" ; then
log_error "tt2-daemon cannot load ${f}:"
"${HELPER}/tt2-wrapper" "/dev/null" "${f}"
exit 1
fi
fi
done
# main script
RC=0
# TODO: detect HASH and try to create template to get those values?
res="$(get_value "$1")"
if [[ $res =~ ^ARRAY\(0x.+\)$ ]] ; then
get_value "$1.join(' ')"
else
echo "$res"
fi
# Kill all previous started tt2-daemon Perl processes
killall tt2-daemon 2>/dev/null || true
rm -f "${NGCP_SOCKETFILE}"
exit "$RC"
## END OF FILE #################################################################

@ -48,30 +48,33 @@ else
bailout
fi
echo "Testing ngcpcfg values: database.dbhost"
value=$("$testsuite"/../sbin/ngcpcfg values database.dbhost)
if [ "${value}" != "localhost" ] ; then
echo "Error caught: database.dbhost != 'localhost'"
bailout
fi
for action in values get ; do
echo "Testing ngcpcfg ${action} database.dbhost"
value=$("$testsuite"/../sbin/ngcpcfg "${action}" database.dbhost)
if [ "${value}" != "localhost" ] ; then
echo "Error caught: database.dbhost != 'localhost' (action '${action}')"
bailout
fi
echo "Testing ngcpcfg values: ossbss.provisioning.database.user"
value=$("$testsuite"/../sbin/ngcpcfg values ossbss.provisioning.database.user)
if [ "${value}" != "soap" ] ; then
echo "Error caught: ossbss.provisioning.database.user != 'soap'"
bailout
fi
echo "Testing ngcpcfg ${action} ossbss.provisioning.database.user"
value=$("$testsuite"/../sbin/ngcpcfg "${action}" ossbss.provisioning.database.user)
if [ "${value}" != "soap" ] ; then
echo "Error caught: ossbss.provisioning.database.user != 'soap' (action '${action}')"
bailout
fi
echo "Testing ngcpcfg values: www_admin.fees_csv.element_order"
value=$("$testsuite"/../sbin/ngcpcfg values www_admin.fees_csv.element_order)
if [ "${value}" != "destination zone zone_detail onpeak_init_rate \
onpeak_init_interval onpeak_follow_rate onpeak_follow_interval \
offpeak_init_rate offpeak_init_interval offpeak_follow_rate \
offpeak_follow_interval use_free_time" ] ;
then
echo "Error caught: www_admin.fees_csv.element_order != expected value"
bailout
fi
echo "Testing ngcpcfg ${action} www_admin.fees_csv.element_order"
value=$("$testsuite"/../sbin/ngcpcfg "${action}" www_admin.fees_csv.element_order)
if [ "${value}" != "destination zone zone_detail onpeak_init_rate \
onpeak_init_interval onpeak_follow_rate onpeak_follow_interval \
offpeak_init_rate offpeak_init_interval offpeak_follow_rate \
offpeak_follow_interval use_free_time" ] ;
then
echo "Error caught: www_admin.fees_csv.element_order != expected value (action '${action}')"
bailout
fi
done
rm -rf "$TMPDIR"

Loading…
Cancel
Save