~fginther/+junk/python2or3.2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash -eu

#
# Runs an otto job with otto-run. This script must be integrated as part of a
# jenkins build step
#
# This script is part of the project Otto
#

# Copyright © 2013 Canonical Ltd.
# Author: Jean-baptiste Lallement <jean-baptiste.lallement@canonical.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

# Usual workspace cleanup
rm -Rf "$WORKSPACE"/*

show_dl_addr() {
    # Display the address to download the container used to run this test
    #
    # $1: Name of the container
    #
    if [ $# -eq 0 ]; then
        echo "E: Missing argument: <name of container>"
        return 1
    fi
    name="$1"
    ifdev=$(ip addr show |awk '$1 == "inet" && $3 == "brd" { print $7; exit 0; }')
    ipaddr=$(ip addr show dev $ifdev |awk '$1 == "inet" && $3 == "brd" { sub (/\/.*/,""); print $2 }')

    if ! nc -z $ipaddr 80; then
        echo "W: No http server running on this host"
        return 0
    fi

    containeruri="http://$ipaddr/otto/$name"
    cat <<EOF
______________________________________________________________________________

I: Archive of the container to run this test available for download from:
    $containeruri
______________________________________________________________________________
EOF
}

# Location of the testsuite on LP and locally
TS_BRANCH="${TS_BRANCH:-lp:~otto-dev/otto/testsuite_autopilot-unity}"
TS_EXPORT="$WORKSPACE/testsuite"

ARCH=$(dpkg --print-architecture )
# Find newest container
CONTAINER=$(lxc-ls "${series}-${ARCH}-*" | tail -1)

if [ -z "$CONTAINER" ] ; then
    echo "E: couldn't find containers matching '${series}-${ARCH}-*'".
    echo "E: Containers available on this system:"
    lxc-ls -1
    exit 1
fi

# Export the testsuite
bzr export $TS_EXPORT $TS_BRANCH

# Set environment for Otto and match with parameters from Jenkins
ppa="${ppa:-}"
[ -n "$ppa" ] && export TESTREPOS="ppa:$ppa"
export TESTPKGS="${testpackages:-}"
export TESTPKGSSTRICT="${packages:-}"
export TESTS="${tests:-}"
export RESULTSDIR="${WORKSPACE}/results"

# NOTE: Run otto-run with -E to preserve the environment
sudo -E $HOME/bin/otto-run $CONTAINER $TS_EXPORT || echo "E: otto-run exited with status $?"

set +e
show_dl_addr $CONTAINER
set -e