Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
Introduce err/warn/info/tell output formatting functions in common.sh.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericzolf committed May 20, 2015
1 parent f61c816 commit 9b5a5e1
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 38 deletions.
14 changes: 9 additions & 5 deletions buildtestvms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@
# Load common parameter variables
. $(dirname "${0}")/common.sh

if [[ -z ${PUSH_USER} ]] || [[ -z ${SATELLITE} ]] || [[ -z ${RSA_ID} ]] \
|| [[ -z ${ORG} ]] || [[ -z ${TESTVM_HOSTCOLLECTION} ]]
then
err "Environment variable PUSH_USER, SATELLITE, RSA_ID, ORG " \
"or TESTVM_HOSTCOLLECTION not set or not found."
exit ${WORKSPACE_ERR}
fi

# rebuild test VMs
for I in $(ssh -l ${PUSH_USER} -i ${RSA_ID} ${SATELLITE} \
"hammer content-host list --organization \"${ORG}\" --host-collection \"$TESTVM_HOSTCOLLECTION\" \
| tail -n +4 | cut -f2 -d \"|\" | head -n -1")
do
echo "Rebuilding VM ID $I"
info "Rebuilding VM ID $I"
ssh -l ${PUSH_USER} -i ${RSA_ID} ${SATELLITE} \
"hammer host update --id $I --build yes"

Expand All @@ -29,11 +36,8 @@ do
ssh -l ${PUSH_USER} -i ${RSA_ID} ${SATELLITE} \
"hammer host start --id $I"
else
echo "Host $I is neither running nor shutoff. No action possible!"
err "Host $I is neither running nor shutoff. No action possible!"
exit 1
fi
done




17 changes: 17 additions & 0 deletions common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,22 @@ WORKSPACE_ERR=5
SRPMBUILD_ERR=6
MODBUILD_ERR=7

function tell() {
echo "${@} [$(date)]" | fold -s
}

function info() {
tell "INFO: ${@}"
}

function usage() {
tell "USAGE: ${@}"
}

function warn() {
tell "WARNING: ${@}" >&2
}

function err() {
tell "ERROR: ${@}" >&2
}
4 changes: 2 additions & 2 deletions kickstartbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

if [[ -z "$1" ]] || [[ ! -d "$1" ]]
then
echo "Usage: $0 <directory containing puppet module directories>"
usage "$0 <directory containing puppet module directories>"
exit ${NOARGS}
fi
workdir=$1

if [[ -z ${WORKSPACE} ]] || [[ ! -w ${WORKSPACE} ]]
then
echo "WORKSPACE not set or not found"
err "WORKSPACE not set or not found"
exit ${WORKSPACE_ERR}
fi

Expand Down
4 changes: 2 additions & 2 deletions kickstartpush.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

if [[ -z "$1" ]] || [[ ! -d "$1" ]]
then
echo "Usage: $0 <kickstarts directory>"
usage "$0 <kickstarts directory>"
exit ${NOARGS}
fi
workdir=$1

if [[ -z ${PUSH_USER} ]] || [[ -z ${SATELLITE} ]]
then
echo "PUSH_USER or SATELLITE not set or not found"
err "PUSH_USER or SATELLITE not set or not found"
exit ${WORKSPACE_ERR}
fi

Expand Down
18 changes: 9 additions & 9 deletions puppetbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,45 +23,45 @@ function build_puppetmodule {
modname=$(IGNORECASE=1 awk -F \' '/^name/ {print $2}' ${METADATA})
modversion=$(IGNORECASE=1 awk -F \' '/^version/ {print $2}' ${METADATA})
else
echo "Could not parse module name and/or module version using ${METADATA}"
err "Could not parse module name and/or module version using ${METADATA}"
exit 1
fi
modarchive=${modname}-${modversion}.tar.gz

if [ -f "${PUPPET_REPO}/${modarchive}" ]
then
echo "WARNING: Puppet module '${modarchive}' already in repository," >&2
echo " You might have forgotten to increase the version" >&2
echo " after doing changes. Skipping ${MODULEFILE}" >&2
warn "Puppet module '${modarchive}' already in repository," \
"You might have forgotten to increase the version" \
"after doing changes. Skipping ${MODULEFILE}."
else

# build the archive
puppet module build ${MODULEDIR}
RETVAL=$?
if [[ ${RETVAL} != 0 ]]
then
echo "Could not build puppet module ${modname} using ${METADATA}"
err "Could not build puppet module ${modname} using ${METADATA}."
exit ${MODBUILD_ERR}
fi
mv -nv ${MODULEDIR}/pkg/${modarchive} ${PUPPET_REPO} # don't overwrite
fi
echo ${git_commit} > .puppetbuild-hash
else
echo "No changes since last build - skipping ${METADATA}"
info "No changes since last build - skipping ${METADATA}"
fi
fi
}

if [[ -z "$1" ]] || [[ ! -d "$1" ]]
then
echo "Usage: $0 <directory containing puppet module directories>"
usage "$0 <directory containing puppet module directories>"
exit ${NOARGS}
fi
workdir=$1

if [[ -z ${WORKSPACE} ]] || [[ ! -w ${WORKSPACE} ]]
then
echo "WORKSPACE not set or not found"
err "Environment variable 'WORKSPACE' not set or not found"
exit ${WORKSPACE_ERR}
fi

Expand All @@ -79,7 +79,7 @@ do
then
build_puppetmodule ${METADATA}
else
echo "Could not find puppet metadata file for puppet module ${I}"
err "Could not find puppet metadata file for puppet module ${I}"
exit 1
fi
popd
Expand Down
2 changes: 1 addition & 1 deletion puppetpush.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

if [[ -z ${PUSH_USER} ]] || [[ -z ${SATELLITE} ]]
then
echo "PUSH_USER or SATELLITE not set or not found"
err "PUSH_USER or SATELLITE not set or not found"
exit ${WORKSPACE_ERR}
fi

Expand Down
18 changes: 9 additions & 9 deletions pushtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ while [[ ${#vmcopy[@]} -gt 0 ]]
do
sleep 10
((WAIT+=10))
echo "Waiting 10 seconds"
info "Waiting 10 seconds"
for I in "${vmcopy[@]}"
do
echo -n "Checking if test server $I has rebuilt... "
Expand All @@ -37,15 +37,15 @@ do
# Check if status is OK, ping reacts and SSH is there, then success!
if [[ ${status} == 3 ]] && ping -c 1 -q $I && nc -w 1 $I 22
then
echo "Success!"
tell "Success!"
unset vmcopy[$I]
else
echo "Not yet"
tell "Not yet."
fi
done
if [[ ${WAIT} -gt 6000 ]]
then
echo "Test servers still not rebuilt after 6000 seconds. Exiting."
err "Test servers still not rebuilt after 6000 seconds. Exiting."
exit 1
fi
done
Expand All @@ -59,7 +59,7 @@ export DISPLAY=nodisplay
export TEST_ROOT
for I in ${vm[@]}
do
echo "Setting up ssh keys for test server $I"
info "Setting up ssh keys for test server $I"
sed -i.bak "/^$I[, ]/d" ${KNOWN_HOSTS} # remove test server from the file

# Copy Jenkins' SSH key to the newly created server(s)
Expand All @@ -71,16 +71,16 @@ do
setsid ssh-copy-id -i ${RSA_ID} root@$I
fi

echo "Installing bats and rsync on test server $I"
info "Installing bats and rsync on test server $I"
if ssh -o StrictHostKeyChecking=no -i ${RSA_ID} root@$I \
"yum install -y bats rsync"
then
echo "copying tests to test server $I"
info "copying tests to test server $I"
rsync --delete -va -e \
"ssh -o StrictHostKeyChecking=no -i ${RSA_ID}" \
${WORKSPACE}/soe/tests root@$I:
else
echo "ERROR: Couldn't install rsync and bats on '$I'." >&2
err "Couldn't install rsync and bats on '$I'."
exit 1
fi
done
Expand All @@ -89,7 +89,7 @@ done
mkdir -p ${WORKSPACE}/test_results
for I in ${vm[@]}
do
echo "Starting TAPS tests on test server $I"
info "Starting TAPS tests on test server $I"
ssh -o StrictHostKeyChecking=no -i ${RSA_ID} root@$I \
'cd tests ; bats -t *.bats' > ${WORKSPACE}/test_results/$I.tap &
done
Expand Down
16 changes: 8 additions & 8 deletions rpmbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,41 @@ function build_srpm {
RETVAL=$?
if [[ ${RETVAL} != 0 ]]
then
echo "Could not build SRPM ${rpmname} using the specfile ${SPECFILE}"
err "Could not build SRPM ${rpmname} using the specfile ${SPECFILE}"
exit ${SRPMBUILD_ERR}
fi
srpmname=${SRPMS_DIR}/${rpmname}-*.src.rpm
/usr/bin/mock --offline --rebuild ${srpmname} -D "%debug_package %{nil}" --resultdir ${RPMS_DIR}
RETVAL=$?
if [[ ${RETVAL} != 0 ]]
then
echo "Could not build RPM ${rpmname} from ${srpmname}"
err "Could not build RPM ${rpmname} from ${srpmname}"
exit ${RPMBUILD_ERR}
fi
mv -nv ${RPMS_DIR}/*.rpm ${YUM_REPO} # don't overwrite RPMs
if [ "$(echo ${RPMS_DIR}/*.rpm)" != "${RPMS_DIR}/*.rpm" ]
then # not all RPM files could be moved, some are remaining
echo "WARNING: RPM package '${rpmname}' already in repository," >&2
echo " You might have forgotten to increase the version" >&2
echo " after doing changes. Skipping ${SPECFILE}" >&2
warn "RPM package '${rpmname}' already in repository," \
"You might have forgotten to increase the version" \
"after doing changes. Skipping ${SPECFILE}"
fi
echo ${git_commit} > .rpmbuild-hash
else
echo "No changes since last build - skipping ${SPECFILE}"
info "No changes since last build - skipping ${SPECFILE}"
fi
fi
}

if [[ -z "$1" ]] || [[ ! -d "$1" ]]
then
echo "Usage: $0 <directory containing RPM source directories>"
usage "$0 <directory containing RPM source directories>"
exit ${NOARGS}
fi
workdir=$1

if [[ -z ${WORKSPACE} ]] || [[ ! -w ${WORKSPACE} ]]
then
echo "WORKSPACE not set or not found"
err "WORKSPACE not set or not found"
exit ${WORKSPACE_ERR}
fi

Expand Down
4 changes: 2 additions & 2 deletions rpmpush.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

if [[ -z "$1" ]] || [[ ! -d "$1" ]]
then
echo "Usage: $0 <artefacts directory>"
usage "$0 <artefacts directory>"
exit ${NOARGS}
fi
workdir=$1

if [[ -z ${PUSH_USER} ]] || [[ -z ${SATELLITE} ]]
then
echo "PUSH_USER or SATELLITE not set or not found"
err "PUSH_USER or SATELLITE not set or not found"
exit ${WORKSPACE_ERR}
fi

Expand Down

0 comments on commit 9b5a5e1

Please sign in to comment.