Merge "Add module reset logic for librarian"

This commit is contained in:
Jenkins 2015-09-24 11:20:17 +00:00 committed by Gerrit Code Review
commit 92415d848a
2 changed files with 46 additions and 3 deletions

View File

@ -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> - Puppet version to use with bundler (optional)
# -h <bundle_dir> - Folder to be used as the home directory for bundler (optional)
# -g <gem_home> - 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 <<EOF
Usage: $(basename $0) [-b] [-p <puppet_version>] [-h <bundle_dir>] [-g <gem_home>] [-?]
Usage: $(basename $0) [-b] [-r] [-p <puppet_version>] [-h <bundle_dir>] [-g <gem_home>] [-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> - Puppet version to use with bundler
-h <bundle_dir> - Folder to be used as the home directory for bundler
-g <gem_home> - 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

View File

@ -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