From 64a0ccc479ca67325ffe9ccaa5496bd562c6df50 Mon Sep 17 00:00:00 2001 From: Alex Schultz Date: Thu, 27 Aug 2015 12:09:23 -0500 Subject: [PATCH] Add module reset logic for librarian This change adds the ability to do a reset or an update with the updates_modules.sh script. The reset will do a git reset on the upstream module if there are any manual changes. The update will do a librarian update which will checkout the version specified in the Puppetfile. These changes allow for better development testing as a developer can test manual changes and version changes via the update_modules.sh script. Additionally the fuel_noop_tests.rb script has been updated to support the reset flag for developer testing. Change-Id: Ib21b3ea210b554e1f58bb7a80453989ba8206104 Closes-Bug: 1489542 --- deployment/update_modules.sh | 43 +++++++++++++++++++++++++++++--- utils/jenkins/fuel_noop_tests.rb | 6 +++++ 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/deployment/update_modules.sh b/deployment/update_modules.sh index 9fa062b732..6e35293c48 100755 --- a/deployment/update_modules.sh +++ b/deployment/update_modules.sh @@ -27,9 +27,11 @@ # # Parameters: # -b - Use bundler to install librarian-puppet (optional) +# -r - Hard git reset of librarian managed modules back to specified version (optional) # -p - Puppet version to use with bundler (optional) # -h - Folder to be used as the home directory for bundler (optional) # -g - Folder to be used as the gem directory (optional) +# -u - Run librarian update (optional) # -v - Verbose printing, turns on set -x (optional) # -? - This usage information # @@ -51,13 +53,15 @@ set -e usage() { cat <] [-h ] [-g ] [-?] + Usage: $(basename $0) [-b] [-r] [-p ] [-h ] [-g ] [-u] [-?] Options: -b - Use bundler instead of assuming librarian-puppet is available + -r - Hard git reset of librarian managed modules back to specified version -p - Puppet version to use with bundler -h - Folder to be used as the home directory for bundler -g - Folder to be used as the gem directory + -u - Run librarian update -v - Verbose printing of commands -? - This usage information @@ -65,7 +69,7 @@ EOF exit 1 } -while getopts ":bp:l:h:v" opt; do +while getopts ":bp:l:h:vru" opt; do case $opt in b) USE_BUNDLER=true @@ -80,6 +84,12 @@ while getopts ":bp:l:h:v" opt; do g) GEM_HOME=$OPTARG ;; + r) + RESET_HARD=true + ;; + u) + UPDATE=true + ;; v) set -x ;; @@ -110,5 +120,32 @@ if [ "$USE_BUNDLER" = true ]; then bundle update fi -# run librarian-puppet install to populate the modules +# Check to make sure if the folder already exists, it has a .git so we can +# use git on it. If the mod folder exists, but .git doesn't then remove the mod +# folder so it can be properly installed via librarian. +for MOD in $(grep "^mod" Puppetfile | tr -d '[:punct:]' | awk '{ print $2 }'); do + MOD_DIR="${DEPLOYMENT_DIR}/puppet/${MOD}" + if [ -d $MOD_DIR ] && [ ! -d "${MOD_DIR}/.git" ]; + then + rm -rf "${MOD_DIR}" + fi +done + +# run librarian-puppet install to populate the modules if they do not already +# exist $BUNDLER_EXEC librarian-puppet install --path=puppet + +# run librarian-puppet update to ensure the modules are checked out to the +# correct version +if [ "$UPDATE" = true ]; then + $BUNDLER_EXEC librarian-puppet update --path=puppet +fi + +# do a hard reset on the librarian managed modules LP#1489542 +if [ "$RESET_HARD" = true ]; then + for MOD in $(grep "^mod " Puppetfile | tr -d '[:punct:]' | awk '{ print $2 }'); do + cd "${DEPLOYMENT_DIR}/puppet/${MOD}" + git reset --hard + done + cd $DEPLOYMENT_DIR +fi diff --git a/utils/jenkins/fuel_noop_tests.rb b/utils/jenkins/fuel_noop_tests.rb index 2e6d885185..0289d9cbba 100755 --- a/utils/jenkins/fuel_noop_tests.rb +++ b/utils/jenkins/fuel_noop_tests.rb @@ -119,6 +119,9 @@ module NoopTests opts.on('-u', '--update-librarian-puppet', 'Run librarian-puppet update in the deployment directory prior to testing') do @options[:update_librarian_puppet] = true end + opts.on('-r', '--reset-librarian-puppet', 'Reset puppet modules to librarian versions in the deployment directory prior to testing') do + @options[:reset_librarian_puppet] = true + end end optparse.parse! @@ -412,6 +415,9 @@ module NoopTests command = './update_modules.sh -v' # pass the bundle parameter to update_modules if specified for this script command = command + ' -b' if options[:bundle] + # pass the reset parameter to update_modules if specified for this script + command = command + ' -r' if options[:reset_librarian_puppet] + inside_deployment_directory do puts "-> Starting update_modules script" system command