~raharper/curtin/trunk.fix-bcache-sysfs-write-failures-on-remove

« back to all changes in this revision

Viewing changes to tools/jenkins-runner

  • Committer: Scott Moser
  • Date: 2017-08-03 16:46:08 UTC
  • mfrom: (508.2.20 trunk.tgt-cleanup)
  • Revision ID: smoser@ubuntu.com-20170803164608-4de4u4wlrm34ggbc
tools/jenkins-runner: improve tgtd cleanup logic

The previous tgtd cleanup logic was hard to follow at best. It was buggy
in that it would always kill the TGT_PID process even if it didn't start it.
both cleanup lines ended with:
  <condition> || [ -n "${TGT_PID}" ] && kill -9 ${TGT_PID}
which will always run the 'kill' if TGT_PID is non-empty.

Also:
 * clean up the output of tools/jenkins-runner by redirecting
   the find-tgt.d to a file so you don't see its debug messages.
 * use modulus to get a port in the right range.
 * improve the picking of a port and then checking to see if it was used.
   I believe a race condition where tgt wasn't listening on the port when
   netstat would run lead to false positives for failures where a
   sleep would have sufficed.
 * remove the tgt socket file(s) if it was created.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
export CURTIN_VMTEST_PARALLEL=${CURTIN_VMTEST_PARALLEL:-0}
14
14
export IMAGE_DIR=${IMAGE_DIR:-/srv/images}
15
15
 
16
 
fail() { echo "$@" 1>&2; exit 1; }
 
16
# empty TGT_* variables in current env to avoid killing a pid we didn't start.
 
17
TGT_PID=""
 
18
TGT_LOG_D=""
 
19
 
 
20
error() { echo "$@" 1>&2; }
 
21
fail() { [ $# -eq 0 ] || error "$@"; exit 1; }
 
22
cleanup() {
 
23
    local ret=$?
 
24
    local keep_rules
 
25
    [ "$ret" -eq 0 ] && keep_rules="$pkeep" || keep_rules="$fkeep"
 
26
    # kill a tgtd pid that was started here.
 
27
    if [ -n "$TGT_PID" ]; then
 
28
        kill -9 ${TGT_PID};
 
29
        if [ -n "${TGT_IPC_SOCKET}" ]; then
 
30
            # var is <path>/socket but the actual socket is <path>/socket.0
 
31
            rm -f "${TGT_IPC_SOCKET}" "${TGT_IPC_SOCKET}".* ||
 
32
                error "WARN: failed removal of $TGT_IPC_SOCKET"
 
33
        fi
 
34
    fi
 
35
    if [ -n "$TGT_LOG_D" ]; then
 
36
        case ",${keep_rules}," in
 
37
            *,logs,*|*,all,*) :;;
 
38
            *) rm -Rf "${TGT_LOG_D}";;
 
39
        esac
 
40
    fi
 
41
}
17
42
 
18
43
if [ "$reuse" != "1" ]; then
19
44
    if [ -d "$topdir" ]; then
45
70
   set -- -vv --nologcapture tests/vmtests/
46
71
fi
47
72
 
48
 
# dump CURTIN* variables just for info
49
 
for v in ${!CURTIN_*} http_proxy https_proxy no_proxy; do
50
 
   echo "$v=${!v}"
51
 
done
 
73
trap cleanup EXIT
52
74
 
53
75
ntargs=( "${ntargs[@]}" "$@" )
54
76
 
57
79
    pargs=( --process-timeout=86400 "--processes=$parallel" )
58
80
fi
59
81
 
60
 
if [ -z "$TGT_IPC_SOCKET" ] && command -v "tgtd" >/dev/null 2>&1; then
 
82
if [ -n "$TGT_IPC_SOCKET" ]; then
 
83
    error "existing TGT_IPC_SOCKET=${TGT_IPC_SOCKET}"
 
84
elif command -v tgtd >/dev/null 2>&1; then
61
85
    tgtdir="$topdir/tgt.d"
62
 
    ./tools/find-tgt "$tgtdir" ||
 
86
    mkdir -p "$tgtdir" || fail "failed to create $tgtdir"
 
87
    rm -f "$tgtdir/info" || fail "failed to remove $tgtdir/info"
 
88
    ./tools/find-tgt "$tgtdir" >"${tgtdir}/find-tgt.log" 2>&1 || {
 
89
        cat "${tgtdir}/find-tgt.log" 1>&2
63
90
        fail "could not start a tgt service"
64
 
    . "$tgtdir/info"
 
91
    }
 
92
    TGT_LOG_D="$tgtdir"
 
93
    . "$tgtdir/info" >"$tgtdir/source-output.txt" 2>&1
 
94
    [ -n "$TGT_PID" ] || fail "find-tgt did not write TGT_PID"
 
95
    [ -d "/proc/${TGT_PID}" ] || fail "no tgtd process in /proc/${TGT_PID}"
 
96
else
 
97
    error "no tgtd command, iscsi tests will be skipped"
65
98
fi
66
99
 
 
100
# dump CURTIN_* and TGT_* and proxy variables just for info
 
101
for v in ${!CURTIN_*} ${!TGT_*} http_proxy https_proxy no_proxy; do
 
102
   echo "$v=${!v}"
 
103
done
 
104
 
67
105
# avoid LOG info by running python3 tests/vmtests/image_sync.py
68
106
# rather than python3 -m tests.vmtests.image_sync (LP: #1594465)
69
107
echo "Working with images in $IMAGE_DIR"
78
116
ret=$?
79
117
end_s=$(date +%s)
80
118
echo "$(date -R): vmtest end [$ret] in $(($end_s-$start_s))s"
81
 
[ $ret -eq 0 ] && [[ $pkeep == *"all"* ]] || [ -n "${TGT_PID}" ] && kill -9 ${TGT_PID}
82
 
[ $ret -ne 0 ] && [[ $pfail == *"all"* ]] || [ -n "${TGT_PID}" ] && kill -9 ${TGT_PID}
83
119
exit $ret
84
120
 
85
121
# vi: ts=4 expandtab syntax=sh