From dbb6195662d9fa373596888f2195ff79e1a55d14 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Mon, 13 Feb 2017 11:51:11 +0800 Subject: [PATCH] script/sepia_bt.sh: no need to pass version and sha1 anymore * try to figure out the working directory from the core dump's path * add -C directory option, so user is able to specify the directory for the downloaded packages, and extracted files. Signed-off-by: Kefu Chai --- src/script/sepia_bt.sh | 93 +++++++++++++++++++++++++++--------------- 1 file changed, 61 insertions(+), 32 deletions(-) diff --git a/src/script/sepia_bt.sh b/src/script/sepia_bt.sh index 5e07d5ee993eb..1201bd05ff8b7 100755 --- a/src/script/sepia_bt.sh +++ b/src/script/sepia_bt.sh @@ -6,28 +6,78 @@ function die() { } function usage() { - echo "bt: $0 -j job_name -c core_path -v version -d distro -s sha1" + echo "bt: $0 -c core_path [-d distro] [-C directory]" exit 1 } while getopts "j:c:v:d:s:" opt do case $opt in - j) run=$(dirname $OPTARG); - job=$(basename $OPTARG);; c) core_path=$OPTARG;; - v) release=$OPTARG;; - s) sha1=$OPTARG;; - d) distro=$OPTARG;; + C) wd=$OPTARG;; + d) codename=$OPTARG;; *) usage;; esac done -if [ -z $run ] || [ -z $core_path ] || [ -z $release ] || [ -z $distro ] || [ -z $sha1 ]; then +if [ -z $core_path ]; then usage fi -prog=`file $core_path | grep -oP "from '\K[^']+"` +sha1=$(strings $core_path | gawk 'BEGIN{ FS = "=" } /^CEPH_REF/{print $2}') + +if [ -z $distro ]; then + machine=${core_path%/coredump/*} + machine=$(basename $machine) + teuthology_log=${core_path%/remote/*}/teuthology.log + if [ ! -r ${teuthology_log} ]; then + die "missing distro, and unable to read it from ${teuthology_log}" + fi + ld=$(grep -m1 -A1 "${machine}:Running.*linux_distribution" ${teuthology_log} | tail -n1 | grep -oP "\(\K[^\)]+") + distro=$(echo $ld | gawk -F ", " '{print $1}' | sed s/\'//g) + distro=$(echo $distro | tr '[:upper:]' '[:lower:]') + distro_ver=$(echo $ld | gawk -F ", " '{print $2}' | sed s/\'//g) + codename=$(echo $ld | gawk -F ", " '{print $3}' | sed s/\'//g) +else + case $codename in + xenial) + distro=ubuntu + distro_ver=16.04 + ;; + trusty) + distro=ubuntu + distro_ver=14.04 + ;; + centos7) + distro=centos + distro_ver=7 + ;; + *) + die "unknown distro: $distro" + ;; + esac +fi + +# try to figure out a name for working directory +if [ -z $wd ]; then + run=${core_path%/remote/*} + job_id=${run#/a/} + if [ $job_id != $core_path ]; then + # use the run/job for the working dir + wd=$job_id + fi +fi + +if [ -z $wd ]; then + echo "unable to figure out the working directory, using core's basename" + wd=$(basename $core_path) + wd=${wd%.*} +fi + +mkdir -p $wd +cd $wd + +prog=$(file $core_path | grep -oP "from '\K[^']+") case $prog in ceph_test_*) pkgs="ceph-test librados2" @@ -40,6 +90,7 @@ case $prog in ;; rados) pkgs="ceph-common librados2 libradosstriper1" + ;; *) die "unknown prog: $prog" ;; @@ -48,26 +99,7 @@ esac flavor=default arch=x86_64 -case $distro in - xenial) - codename=$distro - distro=ubuntu - distro_ver=16.04 - ;; - trusty) - codename=$distro - distro=ubuntu - distro_ver=14.04 - ;; - centos7) - distro=centos - distro_ver=7 - ;; - *) - die "unknown distro: $distro" - ;; -esac - +release=$(strings $core_path | grep -m1 -oP '/build/ceph-\K[^/]+') case $distro in ubuntu) pkg_path=pool/main/c/ceph/%s_%s-1${codename}_amd64.deb @@ -91,12 +123,9 @@ query_url="https://shaman.ceph.com/api/search?status=ready&project=ceph&flavor=$ repo_url=`curl -L -s "${query_url}" | jq -r '.[0] | .url'` pkg_url=${repo_url}/${pkg_path} -mkdir -p $run/$job -cd $run/$job - for pkg in ${pkgs}; do url=`printf $pkg_url $pkg $release` - wget $url + curl -O -L -C - --silent --fail --insecure $url fname=`basename $url` case $fname in *.deb) -- 2.39.5