~nskaggs/juju-ci-tools/add-essential-operations

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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
# Update the required resources on the Jenkins master and slaves.
# the --cloud-city option will also update credential and configs.
set -eux

HERE=$(pwd)
SCRIPTS=$(readlink -f $(dirname $0))
REPOSITORY_PARENT=$(dirname $SCRIPTS)

MASTER="juju-ci.vapour.ws"
SLAVES="precise-slave.vapour.ws trusty-slave.vapour.ws \
    wily-slave.vapour.ws xenial-slave.vapour.ws \
    ppc64el-slave.vapour.ws arm64-slave.vapour.ws \
    kvm-slave.vapour.ws \
    munna-maas-slave.vapour.ws  silcoon-maas-slave.vapour.ws \
    canonistack-slave.vapour.ws juju-core-slave.vapour.ws \
    cloud-health-slave.vapour.ws certification-slave.vapour.ws \
    charm-bundle-slave.vapour.ws osx-slave.vapour.ws \
    s390x-slave.vapour.ws feature-slave.vapour.ws release-slave.vapour.ws"
WIN_SLAVES="win-slave.vapour.ws"
KEY="staging-juju-rsa"
export JUJU_ENV="juju-ci3"

update_jenkins() {
    # Get the ip address which will most likely match historic ssh rules.
    hostname=$1
    if [[ $hostname == $MASTER ]]; then
        # Bypass DNS which points to the apache front-end.
        host="54.86.142.177"
    elif [[ $hostname =~ .*[.]internal$ ]]; then
        host=$hostname # resolved by /etc/hosts
    else
        host=$(host -4 -t A $hostname 8.8.8.8 | tail -1 | cut -d ' ' -f4)
    fi
    echo "updating $hostname at $host"
    if [[ "$CLOUD_CITY" == "true" ]]; then
        bzr branch lp:~juju-qa/+junk/cloud-city \
            bzr+ssh://jenkins@$host/var/lib/jenkins/cloud-city.new
    fi
    ssh jenkins@$host << EOT
#!/bin/bash
export PATH=/usr/local/bin:\$HOME/Bin:\$PATH
set -eux
if [[ "$CLOUD_CITY" == "true" ]]; then
    (cd ~/cloud-city; bzr revert; cd -)
    bzr pull -d ~/cloud-city ~/cloud-city.new
    rm -r ~/cloud-city.new
    sudo chown -R jenkins ~/cloud-city
    chmod -R go-w ~/cloud-city
    chmod 700 ~/cloud-city
    chmod 700 ~/cloud-city/gnupg
    chmod 600 ~/cloud-city/staging-juju-rsa
fi

bzr pull -d ~/juju-release-tools
bzr pull -d ~/repository
bzr pull -d ~/juju-ci-tools
if [[ ! -e ~/workspace-runner ]]; then
    bzr branch http://bazaar.launchpad.net/~juju-qa/workspace-runner/trunk/\
      ~/workspace-runner
fi
bzr pull -d ~/workspace-runner
if [[ \$(uname) == "Linux" ]]; then
    cd ~/juju-ci-tools
    make install-deps
    # The lsb_release package is broken in xenial and yakkety. The py2 module
    # is missing.
    if  [[ ! -f /usr/lib/python2.7/dist-packages/lsb_release.py ]]; then
            sudo cp /usr/lib/python3/dist-packages/lsb_release.py \
                    /usr/lib/python2.7/dist-packages/lsb_release.py
    fi
elif [[ \$(uname) == "Darwin" ]]; then
    ~/juju-ci-tools/pipdeps install
fi
if [[ -d ~/ci-director ]]; then
    bzr pull -d ~/ci-director
fi
EOT
}


update_windows() {
    hostname=$1
    scp repository.zip Administrator@$hostname:/cygdrive/c/Users/Administrator/
    ssh Administrator@$hostname << EOT
bzr pull -d ./juju-release-tools
bzr pull -d ./juju-ci-tools
/cygdrive/c/progra~2/7-Zip/7z.exe x -y repository.zip
python ./juju-ci-tools/pipdeps.py install
EOT
}


CLOUD_CITY="false"
while [[ "${1-}" != "" ]]; do
    case $1 in
        --cloud-city)
            CLOUD_CITY="true"
            ;;
    esac
    shift
done

SKIPPED=""
for hostname in $MASTER $SLAVES; do
    update_jenkins $hostname || SKIPPED="$SKIPPED $hostname"
done

# win-slaves have a different user and directory layout tan POSIX hosts.
# Also, win+bzr does not support symlinks, so we zip the local charm repo.
(cd $REPOSITORY_PARENT; zip -q -r $HERE/repository.zip repository -x *.bzr*)
for hostname in $WIN_SLAVES; do
    update_windows $hostname || update_windows $hostname
    if [[ $? -ne 0  ]]; then
        SKIPPED="$SKIPPED $hostname"
    fi
done

if [[ -n "$SKIPPED" ]]; then
    set +x
    echo
    echo "These hosts were skipped because there was an error"
    echo "$SKIPPED"
    exit 1
fi
echo "All hosts updated."