From e8f7ce894ed44e93e5f7c256f097e0283078c62e Mon Sep 17 00:00:00 2001 From: Alexander Lutay Date: Tue, 20 Oct 2015 17:30:25 +0200 Subject: [PATCH] MT#15803 Add ngcpcfg log/show scripts to improve usability Change-Id: I56f3c6d6cb5187ac471e0ae05ff313f24803fc1c --- debian/ngcp-ngcpcfg.install | 2 ++ docs/ngcpcfg.txt | 10 +++++++++- sbin/ngcpcfg | 13 +++++++++++++ scripts/log | 38 +++++++++++++++++++++++++++++++++++++ scripts/show | 31 ++++++++++++++++++++++++++++++ 5 files changed, 93 insertions(+), 1 deletion(-) create mode 100755 scripts/log create mode 100755 scripts/show diff --git a/debian/ngcp-ngcpcfg.install b/debian/ngcp-ngcpcfg.install index 402cc5a6..968f2ee5 100644 --- a/debian/ngcp-ngcpcfg.install +++ b/debian/ngcp-ngcpcfg.install @@ -18,6 +18,8 @@ scripts/commit usr/share/ngcp-ngcpcfg/scripts/ scripts/diff 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/ scripts/services usr/share/ngcp-ngcpcfg/scripts/ +scripts/show usr/share/ngcp-ngcpcfg/scripts/ scripts/status usr/share/ngcp-ngcpcfg/scripts/ scripts/values usr/share/ngcp-ngcpcfg/scripts/ diff --git a/docs/ngcpcfg.txt b/docs/ngcpcfg.txt index eca9a037..2bdcc66e 100644 --- a/docs/ngcpcfg.txt +++ b/docs/ngcpcfg.txt @@ -284,6 +284,10 @@ sip:carrier environment. Further details about the details of the setup are available in the <> section. Note: This feature is only available if the ngcp-ngcpcfg-carrier package is installed. + **log** [-p]:: + +Prints the log of local changes. Expand all changes if '-p' option is specified. + **pull**:: Retrieve modifications from shared repository. @@ -311,6 +315,11 @@ _--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. + **show** []:: + +Display the change details for specified . Show the latest change if +no is specified. + **status** [--local-only]:: Display the current state of the configuration system, like modified @@ -319,7 +328,6 @@ Note: The _--local-only_ option is available in the High Availability setup only and disables checking any remote systems (useful when the remote system isn't available). - **values** :: Prints the value of using ngcp config files as source. diff --git a/sbin/ngcpcfg b/sbin/ngcpcfg index b545a44f..0139c49d 100755 --- a/sbin/ngcpcfg +++ b/sbin/ngcpcfg @@ -88,6 +88,15 @@ values() { "${SCRIPTS}"/values $* } +log() { + log_debug "${SCRIPTS}/log $*" + "${SCRIPTS}"/log $* +} + +show() { + log_debug "${SCRIPTS}/show $*" + "${SCRIPTS}"/show $* +} usage() { # make sure to output errors on stderr @@ -104,6 +113,8 @@ usage() { $PN initialise - initialise setup (to be executed only once on setup) $PN check - validate YAML configuration files $PN values - print key value from YAML configuration files + $PN log [opt] - show log of config changes + $PN show [id] - show latest config change (if id is specified show specified id instead) " # display only if ngcp-ngcpcfg-ha is available @@ -151,6 +162,8 @@ case ${1:-} in diff) shift ; diff "$*" ;; init-mgmt) shift ; init-mgmt "$*" ;; values) shift ; values "$*" ;; + log) shift ; log "$*" ;; + show) shift ; show "$*" ;; --debug) export DEBUG=1 ; shift ; $0 $* ;; --no-db-sync) export NO_DB_SYNC=1 ; shift ; $0 $* ;; --no-validate) export NO_VALIDATE=1; shift ; $0 $* ;; diff --git a/scripts/log b/scripts/log new file mode 100755 index 00000000..ff7e0158 --- /dev/null +++ b/scripts/log @@ -0,0 +1,38 @@ +#!/bin/bash +# Purpose: show ngcpcfg log (git log) in human readable format +################################################################################ + +set -e +set -u + +# 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 + +cd "$NGCPCTL_MAIN" + +if [ -f "${FUNCTIONS}/ha_features" ] ; then + + if ! git remote update origin >/dev/null 2>&1 ; then + log_error "Failed to fetch changes from shared repository" + exit 1 + fi + + git log $* --oneline --date-order --graph --date=rfc --format=format:"%h (%ar) %s %d" master origin/master + +else + + git log $* --oneline --date-order --graph --date=rfc --format=format:"%h (%ar) %s %d" master + +fi + +exit 0 + +## END OF FILE ################################################################# diff --git a/scripts/show b/scripts/show new file mode 100755 index 00000000..31483fd2 --- /dev/null +++ b/scripts/show @@ -0,0 +1,31 @@ +#!/bin/bash +# Purpose: show ngcpcfg changes (git show) as part of ngcpcfg framework +################################################################################ + +set -e +set -u + +# 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 + +if [ "$*" = "" ] ; then + git_commit="HEAD" +else + git_commit="$*" +fi + + +cd "$NGCPCTL_MAIN" +git show ${git_commit} + +exit 0 + +## END OF FILE #################################################################