Skip to content

Instantly share code, notes, and snippets.

@chmouel
Last active December 23, 2015 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chmouel/6688088 to your computer and use it in GitHub Desktop.
Save chmouel/6688088 to your computer and use it in GitHub Desktop.
show openstack job output.
#!/bin/bash
# Get console.html for some job
# without arguments list the jobs.
# Chmouel Boudjnah <chmouel@chmouel.com>
set -e
GATE=$1
function readlinkf() {
python -c 'import os,sys;print os.path.realpath(sys.argv[1])' $1
}
function get-gitreview () {
oldpwd=$PWD
curdir="./"
while [[ ${curdir} != "/" ]];do
if [[ -e .gitreview ]];then
echo $(readlinkf .gitreview)
break
fi
cd ../
curdir=$(readlinkf ./)
done
cd ${OLDPWD}
}
GIT_REVIEW_FILE=$(get-gitreview)
if [[ -z ${GIT_REVIEW_FILE} ]];then
echo "Cannot find git-review"
exit 1
fi
while read -a line;do
if [[ ${line} == host* ]];then
host=${line#*=}
elif [[ ${line} == port* ]];then
port=${line#*=}
elif [[ ${line} == project* ]];then
project=${line#*=}
project=${project/.git/}
fi
done < ${GIT_REVIEW_FILE}
if [[ -z ${host} || -z ${port} || -z ${project} ]];then
echo "Could not parse properly ${GIT_REVIEW_FILE}"
exit 1
fi
change_id=$(git log -n1|grep Change-Id|sed 's/.* I/I/')
if [[ -z ${change_id} ]];then
echo "Could not parse ChangeID"
exit 1
fi
refs_change=$(ssh -x -p ${port} ${host} "gerrit query --format=JSON --current-patch-set change:${change_id}" | grep -v '"type":"stats"' | python -c 'import json,sys;j=json.loads(sys.stdin.read().strip());print j["currentPatchSet"]["ref"]')
refs_change=${refs_change/refs\/changes\//}
if [[ -z ${refs_change} ]];then
echo "Could not find the review URL"
exit 1
fi
check_url=http://logs.openstack.org/${refs_change}/check
if [[ -z ${GATE} ]];then
curl -L -s ${check_url} | sed -n '/gate-/ { s/.*<a href="gate-\([^"]*\)".*/\1/;s/\/$//; p ;}'
exit 0
fi
latest_uuid=$(curl -L -s -f "${check_url}/gate-${GATE}?C=M;O=D" | sed -n '/folder.gif/ { s,.*a href="\([^/]*\)/.*,\1,;p; q;}')
if [[ -z ${latest_uuid} ]];then
echo "Could not find the latest UUID of the job"
exit 1
fi
full_url=${check_url}/gate-${GATE}/${latest_uuid}/console.html
curl -s ${full_url} | less
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment