forked from cloud-bulldozer/stockpile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
infrared.sh
161 lines (130 loc) · 3.64 KB
/
infrared.sh
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
HOST=$1
TOPOLOGY_NODES=undercloud:1,controller:1,compute:1
BASEDIR="/home/stockpile/ospci"
VENVDIR="$BASEDIR/venv"
SSH_DIR=~/.ssh
SSHKEY="$SSH_DIR/id_rsa"
VERSION=13
BUILD=passed_phase2
LOGFILE="$BASEDIR/run.log"
PACKAGES=(git gcc libffi-devel openssl-devel python-virtualenv libselinux-python ansible)
set -ex
if [ "$#" -ne 2 ]; then
echo "Pass host and action as parameters" 2>&1
echo "./$0 $1 cleanup|vms|uc|oc|full" 2>&1
exit 1
fi
# cleanup previous vms
function cleanup_host() {
if [ -f $VENVDIR/bin/activate ]; then
source $VENVDIR/bin/activate
infrared virsh --host-address ${HOST} \
--host-key ${SSHKEY} \
--topology-nodes ${TOPOLOGY_NODES} \
--host-memory-overcommit True \
--cleanup yes
rm -rf $BASEDIR
fi
}
# installs the required packages and generates a ssh key
function prep_env() {
for PACKAGE in ${PACKAGES[@]}
do
yum install -y $PACKAGE
done
if [ -f "$SSHKEY" ]; then
echo "ssh key exist"
else
ssh-keygen -q -N "" -f ${SSH_DIR}/id_rsa
cat "$SSH_DIR/id_rsa.pub" >> "$SSH_DIR/authorized_keys"
fi
}
# [provision new vms - same command without '--cleanup']
function create_vms() {
mkdir -p $BASEDIR
cd $BASEDIR
git clone https://github.com/redhat-openstack/infrared.git
virtualenv $VENVDIR
source $VENVDIR/bin/activate
pip install --upgrade pip
pip install --upgrade setuptools
cd $BASEDIR/infrared
pip install . 2>&1 | tee $LOGFILE
infrared virsh --host-address ${HOST} \
--host-key ${SSHKEY} \
--topology-nodes ${TOPOLOGY_NODES} \
--host-memory-overcommit True
}
# installs undercloud
function undercloud_install() {
source $VENVDIR/bin/activate
cd $BASEDIR/infrared
infrared tripleo-undercloud \
--version ${VERSION} \
--build ${BUILD} \
--images-task rpm \
--images-update no
}
# deploys overcloud
function overcloud_deploy() {
source $VENVDIR/bin/activate
cd $BASEDIR/infrared
infrared tripleo-overcloud -v \
--introspect yes \
--tagging yes \
--deploy yes \
--version $VERSION \
--deployment-files virt \
}
#installs browbeat and generates host file
function browbeat_install() {
yum install -y ansible
source $VENVDIR/bin/activate
cd $BASEDIR/infrared
ssh -T -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa stack@undercloud-0 <<'EOSSH'
source ~/stackrc
git clone https://github.com/cloud-bulldozer/browbeat.git
pushd ~/browbeat/ansible
grep "8.8.8.8" ~/browbeat/ansible/install/group_vars/all.yml | sed 's/8.8.8.8/10.11.5.19/'
./generate_tripleo_hostfile.sh -l
popd
EOSSH
#run browbeat
# need separate SSH session since Jenkins job seems to exit after running ansible host generation
ssh -T -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@undercloud-0 <<EOSSH
pwd
su - stack
pushd ~/browbeat/ansible
install browbeat
ansible-playbook -i hosts install/browbeat.yml
popd
EOSSH
}
case $2 in
cleanup)
cleanup_host
;;
vms)
cleanup_host
prep_env
create_vms
;;
uc)
undercloud_install
;;
oc)
overcloud_deploy
;;
full)
cleanup_host
prep_env
create_vms
undercloud_install
overcloud_deploy
browbeat_install
;;
*)
echo "please choose between cleanup|vms|uc|oc|full"
;;
esac