instack.sh 7.38 KB
Newer Older
Dan Radez's avatar
Dan Radez committed
1
#!/bin/sh
2
set -e
Dan Radez's avatar
Dan Radez committed
3
4
5
declare -i CNT

RDO_RELEASE=kilo
6
SSH_OPTIONS=(-o StrictHostKeyChecking=no -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null)
Dan Radez's avatar
Dan Radez committed
7

8
9
10
11
12
13
14
# check for dependancy packages
for i in libguestfs-tools; do
    if ! rpm -q $i > /dev/null; then
        sudo yum install -y $i
    fi
done

Dan Radez's avatar
Dan Radez committed
15
16
# RDO Manager expects a stack user to exist, this checks for one
# and creates it if you are root
17
if ! id stack > /dev/null; then
Dan Radez's avatar
Dan Radez committed
18
19
20
21
    sudo useradd stack;
    sudo echo 'stack ALL=(root) NOPASSWD:ALL' | sudo tee -a /etc/sudoers.d/stack
    sudo echo 'Defaults:stack !requiretty' | sudo tee -a /etc/sudoers.d/stack
    sudo chmod 0440 /etc/sudoers.d/stack
22
23
24
    echo 'Added user stack'
fi

Dan Radez's avatar
Dan Radez committed
25
26
27
28
29
30
31
32
33
34
35
36
# ensure that I can ssh as the stack user
if ! sudo grep "$(cat ~/.ssh/id_rsa.pub)" /home/stack/.ssh/authorized_keys; then
    if ! sudo ls -d /home/stack/.ssh/ ; then
        sudo mkdir /home/stack/.ssh
        sudo chown stack:stack /home/stack/.ssh
        sudo chmod 700 /home/stack/.ssh
    fi
    USER=$(whoami) sudo sh -c "cat ~$USER/.ssh/id_rsa.pub >> /home/stack/.ssh/authorized_keys"
    sudo chown stack:stack /home/stack/.ssh/authorized_keys
fi

# clean up stack user previously build instack disk images
37
ssh -T ${SSH_OPTIONS[@]} stack@localhost "rm -f instack*.qcow2"
Dan Radez's avatar
Dan Radez committed
38
39

# Yum repo setup for building the undercloud
40
if ! rpm -q epel-release > /dev/null; then
Dan Radez's avatar
Dan Radez committed
41
    sudo yum install http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
42
43
44
fi

if ! rpm -q rdo-release > /dev/null; then
Dan Radez's avatar
Dan Radez committed
45
    sudo yum install -y https://rdoproject.org/repos/openstack-${RDO_RELEASE}/rdo-release-${RDO_RELEASE}.rpm
46
47
fi

Dan Radez's avatar
Dan Radez committed
48
49
50
51
52
53
54
55
if ! rpm -q rdo-release > /dev/null && [ "$1" != "-master" ]; then
    sudo yum install -y https://rdoproject.org/repos/openstack-${RDO_RELEASE}/rdo-release-${RDO_RELEASE}.rpm
    sudo rm -rf /etc/yum.repos.d/delorean.repo
    sudo rm -rf /etc/yum.repos.d/delorean-current.repo
    sudo rm -rf /etc/yum.repos.d/delorean-deps.repo
elif [ "$1" == "-master" ]; then
    sudo yum -y install yum-plugin-priorities
    sudo yum-config-manager --disable openstack-${RDO_RELEASE}
56
    sudo curl -o /etc/yum.repos.d/delorean.repo http://trunk.rdoproject.org/centos7-liberty/current-passed-ci/delorean.repo
57
    sudo curl -o /etc/yum.repos.d/delorean-deps.repo http://trunk.rdoproject.org/centos7-liberty/delorean-deps.repo
58
59
    sudo rm -f /etc/yum.repos.d/delorean-current.repo

60
61
fi

Dan Radez's avatar
Dan Radez committed
62
# ensure the undercloud package is installed so we can build the undercloud
63
if ! rpm -q instack-undercloud > /dev/null; then
64
    sudo yum install -y python-tripleoclient
65
66
fi

67
# ensure openvswitch is installed
Dan Radez's avatar
Dan Radez committed
68
69
70
71
if ! rpm -q openvswitch > /dev/null; then
    sudo yum install -y openvswitch
fi

72
# ensure libvirt is installed
Dan Radez's avatar
Dan Radez committed
73
74
75
76
77
78
if ! rpm -q libvirt-daemon-kvm > /dev/null; then
    sudo yum install -y libvirt-daemon-kvm
fi

# ensure that no previous undercloud VMs are running
# and rebuild the bare undercloud VMs
79
ssh -T ${SSH_OPTIONS[@]} stack@localhost <<EOI
80
set -e
Dan Radez's avatar
Dan Radez committed
81
virsh destroy instack 2> /dev/null || echo -n ''
82
virsh undefine instack --remove-all-storage 2> /dev/null || echo -n ''
83
virsh destroy baremetalbrbm_0 2> /dev/null || echo -n ''
84
virsh undefine baremetalbrbm_0 --remove-all-storage 2> /dev/null || echo -n ''
85
virsh destroy baremetalbrbm_1 2> /dev/null || echo -n ''
86
virsh undefine baremetalbrbm_1 --remove-all-storage 2> /dev/null || echo -n ''
Dan Radez's avatar
Dan Radez committed
87
NODE_CPU=2 NODE_MEM=8192 instack-virt-setup
Dan Radez's avatar
Dan Radez committed
88
89
90
91
92
93
94
95
96
97
EOI

# let dhcp happen so we can get the ip
# just wait instead of checking until we see an address
# because there may be a previous lease that needs
# to be cleaned up
sleep 5

# get the undercloud ip address
UNDERCLOUD=$(grep instack /var/lib/libvirt/dnsmasq/default.leases | awk '{print $3}' | head -n 1)
98

Dan Radez's avatar
Dan Radez committed
99
100
# ensure that we can ssh to the undercloud
CNT=10
101
while ! ssh -T ${SSH_OPTIONS[@]}  "root@$UNDERCLOUD" "echo ''" > /dev/null && [ $CNT -gt 0 ]; do
Dan Radez's avatar
Dan Radez committed
102
103
104
105
    echo -n "."
    sleep 3
    CNT=CNT-1
done
106
# TODO fail if CNT=0
Dan Radez's avatar
Dan Radez committed
107
108

# yum repo, triple-o package and ssh key setup for the undercloud
109
ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" <<EOI
110
set -e
Dan Radez's avatar
Dan Radez committed
111
112
if ! rpm -q epel-release > /dev/null; then
    yum install http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
113
114
fi

Dan Radez's avatar
Dan Radez committed
115
yum -y install yum-plugin-priorities
116
curl -o /etc/yum.repos.d/delorean.repo http://trunk.rdoproject.org/centos7-liberty/current-passed-ci/delorean.repo
117
curl -o /etc/yum.repos.d/delorean-deps.repo http://trunk.rdoproject.org/centos7-liberty/delorean-deps.repo
Dan Radez's avatar
Dan Radez committed
118
yum install -y python-tripleoclient
119
120
121
122
cp /root/.ssh/authorized_keys /home/stack/.ssh/authorized_keys
chown stack:stack /home/stack/.ssh/authorized_keys
EOI

Dan Radez's avatar
Dan Radez committed
123
# install undercloud on Undercloud VM
124
ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "openstack undercloud install"
Dan Radez's avatar
Dan Radez committed
125

Dan Radez's avatar
Dan Radez committed
126
127
128
# Clean cache to reduce the images size
ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" "yum clean all"

Dan Radez's avatar
Dan Radez committed
129
130
131
132
# copy instackenv file for future virt deployments
if [ ! -d stack ]; then mkdir stack; fi
scp ${SSH_OPTIONS[@]} stack@$UNDERCLOUD:instackenv.json stack/instackenv.json

Dan Radez's avatar
Dan Radez committed
133
134
# make a copy of instack VM's definitions, and disk image
# it must be stopped to make a copy of its disk image
135
ssh -T ${SSH_OPTIONS[@]} stack@localhost <<EOI
136
137
set -e
echo "Shutting down instack to take snapshot"
138
139
140
virsh shutdown instack

echo "Waiting for instack VM to shutdown"
Dan Radez's avatar
Dan Radez committed
141
142
CNT=20
while virsh list | grep instack > /dev/null && [ $CNT -gt 0 ]; do
143
144
    echo -n "."
    sleep 5
Dan Radez's avatar
Dan Radez committed
145
    CNT=CNT-1
146
done
Dan Radez's avatar
Dan Radez committed
147
148
149
150
if virsh list | grep instack > /dev/null; then
    echo "instack failed to shutdown for copy"
    exit 1
fi
151

Dan Radez's avatar
Dan Radez committed
152
echo "\nCopying instack disk image and starting instack VM."
153
154
virsh dumpxml baremetalbrbm_0 > baremetalbrbm_0.xml
virsh dumpxml baremetalbrbm_1 > baremetalbrbm_1.xml
155
virsh dumpxml instack > instack.xml
Dan Radez's avatar
Dan Radez committed
156
#virsh vol-dumpxml instack.qcow2 --pool default > instack.qcow2.xml
157
virsh net-dumpxml brbm > brbm.xml
Dan Radez's avatar
Dan Radez committed
158
159
160
161
EOI

# copy off the instack artifacts
echo "Copying instack files to build directory"
162
163
164
165
scp ${SSH_OPTIONS[@]} stack@localhost:baremetalbrbm_0.xml .
scp ${SSH_OPTIONS[@]} stack@localhost:baremetalbrbm_1.xml .
scp ${SSH_OPTIONS[@]} stack@localhost:instack.xml .
scp ${SSH_OPTIONS[@]} stack@localhost:brbm.xml .
Dan Radez's avatar
Dan Radez committed
166

Dan Radez's avatar
Dan Radez committed
167
168
169
170
sudo cp /var/lib/libvirt/images/instack.qcow2 ./instack.qcow2_
sudo chown $(whoami):$(whoami) ./instack.qcow2_
virt-sparsify --check-tmpdir=fail ./instack.qcow2_ ./instack.qcow2
rm -f ./instack.qcow2_
171

Dan Radez's avatar
Dan Radez committed
172
173
# pull down the the built images
echo "Copying overcloud resources"
174
IMAGES="deploy-ramdisk-ironic.initramfs deploy-ramdisk-ironic.kernel"
Dan Radez's avatar
Dan Radez committed
175
IMAGES+=" ironic-python-agent.initramfs ironic-python-agent.kernel ironic-python-agent.vmlinuz"
176
177
178
IMAGES+=" overcloud-full.initrd overcloud-full.qcow2  overcloud-full.vmlinuz"

for i in $IMAGES; do
Dan Radez's avatar
Dan Radez committed
179
180
  # download prebuilt images from RDO Project
  curl https://repos.fedorapeople.org/repos/openstack-m/rdo-images-centos-liberty/$i -z stack/$i -o stack/$i --verbose --silent --location
181
182
183
184
done

# move and Sanitize private keys from instack.json file
mv stack/instackenv.json instackenv-virt.json
185
sed -i '/pm_password/c\      "pm_password": "INSERT_STACK_USER_PRIV_KEY",' instackenv-virt.json
186
sed -i '/ssh-key/c\  "ssh-key": "INSERT_STACK_USER_PRIV_KEY",' instackenv-virt.json
187
188

# clean up the VMs
189
ssh -T ${SSH_OPTIONS[@]} stack@localhost <<EOI
190
set -e
191
virsh destroy instack 2> /dev/null || echo -n ''
192
virsh undefine instack --remove-all-storage 2> /dev/null || echo -n ''
193
virsh destroy baremetalbrbm_0 2> /dev/null || echo -n ''
194
virsh undefine baremetalbrbm_0 --remove-all-storage 2> /dev/null || echo -n ''
195
virsh destroy baremetalbrbm_1 2> /dev/null || echo -n ''
196
virsh undefine baremetalbrbm_1 --remove-all-storage 2> /dev/null || echo -n ''
197
198
EOI