instack.sh 12.3 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
declare -i CNT

5 6
#rdo_images_uri=https://repos.fedorapeople.org/repos/openstack-m/rdo-images-centos-liberty-opnfv
rdo_images_uri=file:///stable-images
bobzh's avatar
bobzh committed
7
onos_artifacts_uri=file:///stable-images/onos
Dan Radez's avatar
Dan Radez committed
8

Tim Rozet's avatar
Tim Rozet committed
9
vm_index=4
Dan Radez's avatar
Dan Radez committed
10
RDO_RELEASE=liberty
11
SSH_OPTIONS=(-o StrictHostKeyChecking=no -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null)
12
OPNFV_NETWORK_TYPES="admin_network private_network public_network storage_network"
Dan Radez's avatar
Dan Radez committed
13

14
# check for dependancy packages
Dan Radez's avatar
Dan Radez committed
15
for i in rpm-build createrepo libguestfs-tools python-docutils bsdtar; do
16 17 18 19 20
    if ! rpm -q $i > /dev/null; then
        sudo yum install -y $i
    fi
done

Dan Radez's avatar
Dan Radez committed
21 22
# RDO Manager expects a stack user to exist, this checks for one
# and creates it if you are root
23
if ! id stack > /dev/null; then
Dan Radez's avatar
Dan Radez committed
24 25 26 27
    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
28 29 30
    echo 'Added user stack'
fi

Dan Radez's avatar
Dan Radez committed
31 32 33 34 35 36 37 38 39 40 41 42
# 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
43
ssh -T ${SSH_OPTIONS[@]} stack@localhost "rm -f instack*.qcow2"
Dan Radez's avatar
Dan Radez committed
44 45 46

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

62 63 64 65 66 67 68 69 70
# install the opendaylight yum repo definition
cat << 'EOF' | sudo tee /etc/yum.repos.d/opendaylight.repo
[opendaylight]
name=OpenDaylight $releasever - $basearch
baseurl=http://cbs.centos.org/repos/nfv7-opendaylight-3-candidate/$basearch/os/
enabled=1
gpgcheck=0
EOF

Dan Radez's avatar
Dan Radez committed
71
# ensure the undercloud package is installed so we can build the undercloud
72
if ! rpm -q instack-undercloud > /dev/null; then
73
    sudo yum install -y python-tripleoclient
74 75
fi

76
# ensure openvswitch is installed
Dan Radez's avatar
Dan Radez committed
77 78 79 80
if ! rpm -q openvswitch > /dev/null; then
    sudo yum install -y openvswitch
fi

81
# ensure libvirt is installed
Dan Radez's avatar
Dan Radez committed
82 83 84 85
if ! rpm -q libvirt-daemon-kvm > /dev/null; then
    sudo yum install -y libvirt-daemon-kvm
fi

Dan Radez's avatar
Dan Radez committed
86 87 88
# clean this up incase it's there
sudo rm -f /tmp/instack.answers

Dan Radez's avatar
Dan Radez committed
89
# ensure that no previous undercloud VMs are running
Dan Radez's avatar
Dan Radez committed
90
sudo ../ci/clean.sh
Dan Radez's avatar
Dan Radez committed
91
# and rebuild the bare undercloud VMs
92
ssh -T ${SSH_OPTIONS[@]} stack@localhost <<EOI
93
set -e
94
NODE_COUNT=5 NODE_CPU=2 NODE_MEM=8192 TESTENV_ARGS="--baremetal-bridge-names 'brbm brbm1 brbm2 brbm3'" instack-virt-setup
Dan Radez's avatar
Dan Radez committed
95 96 97 98 99 100 101 102 103 104
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)
Dan Radez's avatar
Dan Radez committed
105 106 107 108
if [ -z "$UNDERCLOUD" ]; then
  #if not found then dnsmasq may be using leasefile-ro
  instack_mac=$(ssh -T ${SSH_OPTIONS[@]} stack@localhost "virsh domiflist instack" | grep default | \
                grep -Eo "[0-9a-f\]+:[0-9a-f\]+:[0-9a-f\]+:[0-9a-f\]+:[0-9a-f\]+:[0-9a-f\]+")
109
  UNDERCLOUD=$(/usr/sbin/arp -e | grep ${instack_mac} | awk {'print $1'})
Dan Radez's avatar
Dan Radez committed
110 111 112 113

  if [ -z "$UNDERCLOUD" ]; then
    echo "\n\nNever got IP for Instack. Can Not Continue."
    exit 1
114 115
  else
    echo -e "${blue}\rInstack VM has IP $UNDERCLOUD${reset}"
Dan Radez's avatar
Dan Radez committed
116 117 118 119 120
  fi
else
   echo -e "${blue}\rInstack VM has IP $UNDERCLOUD${reset}"
fi

Dan Radez's avatar
Dan Radez committed
121 122
# ensure that we can ssh to the undercloud
CNT=10
123
while ! ssh -T ${SSH_OPTIONS[@]}  "root@$UNDERCLOUD" "echo ''" > /dev/null && [ $CNT -gt 0 ]; do
Dan Radez's avatar
Dan Radez committed
124 125 126 127
    echo -n "."
    sleep 3
    CNT=CNT-1
done
128
# TODO fail if CNT=0
Dan Radez's avatar
Dan Radez committed
129 130

# yum repo, triple-o package and ssh key setup for the undercloud
131
ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" <<EOI
132
set -e
133

Dan Radez's avatar
Dan Radez committed
134 135
if ! rpm -q epel-release > /dev/null; then
    yum install http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
136 137
fi

Dan Radez's avatar
Dan Radez committed
138
yum -y install yum-plugin-priorities
139
curl -o /etc/yum.repos.d/delorean.repo http://trunk.rdoproject.org/centos7-liberty/current-passed-ci/delorean.repo
140
curl -o /etc/yum.repos.d/delorean-deps.repo http://trunk.rdoproject.org/centos7-liberty/delorean-deps.repo
141

142 143 144 145
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
146 147 148 149
# 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
150 151
# make a copy of instack VM's definitions, and disk image
# it must be stopped to make a copy of its disk image
152
ssh -T ${SSH_OPTIONS[@]} stack@localhost <<EOI
153
set -e
154
echo "Shutting down instack to gather configs"
155 156 157
virsh shutdown instack

echo "Waiting for instack VM to shutdown"
Dan Radez's avatar
Dan Radez committed
158 159
CNT=20
while virsh list | grep instack > /dev/null && [ $CNT -gt 0 ]; do
160 161
    echo -n "."
    sleep 5
Dan Radez's avatar
Dan Radez committed
162
    CNT=CNT-1
163
done
Dan Radez's avatar
Dan Radez committed
164 165 166 167
if virsh list | grep instack > /dev/null; then
    echo "instack failed to shutdown for copy"
    exit 1
fi
168

169
echo $'\nGenerating libvirt configuration'
Tim Rozet's avatar
Tim Rozet committed
170
for i in \$(seq 0 $vm_index); do
171
  virsh dumpxml baremetalbrbm_brbm1_brbm2_brbm3_\$i | awk '/model type='\''virtio'\''/{c++;if(c==2){sub("model type='\''virtio'\''","model type='\''rtl8139'\''");c=0}}1' > baremetalbrbm_brbm1_brbm2_brbm3_\$i.xml
Tim Rozet's avatar
Tim Rozet committed
172 173
done

174
virsh dumpxml instack > instack.xml
175
virsh net-dumpxml brbm > brbm-net.xml
Dan Radez's avatar
Dan Radez committed
176
virsh net-dumpxml brbm1 > brbm1-net.xml
177 178
virsh net-dumpxml brbm2> brbm2-net.xml
virsh net-dumpxml brbm3 > brbm3-net.xml
179
virsh pool-dumpxml default > default-pool.xml
Dan Radez's avatar
Dan Radez committed
180 181 182 183
EOI

# copy off the instack artifacts
echo "Copying instack files to build directory"
Tim Rozet's avatar
Tim Rozet committed
184
for i in $(seq 0 $vm_index); do
185
  scp ${SSH_OPTIONS[@]} stack@localhost:baremetalbrbm_brbm1_brbm2_brbm3_${i}.xml .
Tim Rozet's avatar
Tim Rozet committed
186 187
done

188
scp ${SSH_OPTIONS[@]} stack@localhost:instack.xml .
189
scp ${SSH_OPTIONS[@]} stack@localhost:brbm-net.xml .
Dan Radez's avatar
Dan Radez committed
190
scp ${SSH_OPTIONS[@]} stack@localhost:brbm1-net.xml .
191 192
scp ${SSH_OPTIONS[@]} stack@localhost:brbm2-net.xml .
scp ${SSH_OPTIONS[@]} stack@localhost:brbm3-net.xml .
193
scp ${SSH_OPTIONS[@]} stack@localhost:default-pool.xml .
Dan Radez's avatar
Dan Radez committed
194

Dan Radez's avatar
Dan Radez committed
195 196
# pull down the the built images
echo "Copying overcloud resources"
197 198
IMAGES="overcloud-full.tar"
IMAGES+=" undercloud.qcow2"
199 200

for i in $IMAGES; do
Dan Radez's avatar
Dan Radez committed
201
  # download prebuilt images from RDO Project
Dan Radez's avatar
Dan Radez committed
202
  if [ "$(curl -L $rdo_images_uri/${i}.md5 | awk {'print $1'})" != "$(md5sum stack/$i | awk {'print $1'})" ] ; then
Dan Radez's avatar
Dan Radez committed
203 204 205
    #if [ $i == "undercloud.qcow2" ]; then
    ### there's a problem with the Content-Length reported by the centos artifacts
    ### server so using wget for it until a resolution is figured out.
206
    #wget -nv -O stack/$i $rdo_images_uri/$i
Dan Radez's avatar
Dan Radez committed
207
    #else
208
    curl $rdo_images_uri/$i -o stack/$i
Dan Radez's avatar
Dan Radez committed
209
    #fi
Dan Radez's avatar
Dan Radez committed
210
  fi
211 212
  # only untar the tar files
  if [ "${i##*.}" == "tar" ]; then tar -xf stack/$i -C stack/; fi
213 214
done

215 216 217 218 219 220 221 222
#Adding OpenStack packages to undercloud
pushd stack
cp undercloud.qcow2 instack.qcow2
LIBGUESTFS_BACKEND=direct virt-customize --install yum-priorities -a instack.qcow2
PACKAGES="qemu-kvm-common,qemu-kvm,libvirt-daemon-kvm,libguestfs,python-libguestfs,openstack-nova-compute"
PACKAGES+=",openstack-swift,openstack-ceilometer-api,openstack-neutron-ml2,openstack-ceilometer-alarm"
PACKAGES+=",openstack-nova-conductor,openstack-ironic-inspector,openstack-ironic-api,python-openvswitch"
PACKAGES+=",openstack-glance,python-glance,python-troveclient,openstack-puppet-modules"
Dan Radez's avatar
Dan Radez committed
223
PACKAGES+=",openstack-neutron,openstack-neutron-openvswitch,openstack-nova-scheduler,openstack-keystone,openstack-swift-account"
224 225 226 227
PACKAGES+=",openstack-swift-container,openstack-swift-object,openstack-swift-plugin-swift3,openstack-swift-proxy"
PACKAGES+=",openstack-nova-api,openstack-nova-cert,openstack-heat-api-cfn,openstack-heat-api,"
PACKAGES+=",openstack-ceilometer-central,openstack-ceilometer-polling,openstack-ceilometer-collector,"
PACKAGES+=",openstack-heat-api-cloudwatch,openstack-heat-engine,openstack-heat-common,openstack-ceilometer-notification"
Dan Radez's avatar
Dan Radez committed
228
PACKAGES+=",hiera,puppet,memcached,keepalived,mariadb,mariadb-server,rabbitmq-server,python-pbr,python-proliantutils"
229 230 231 232 233

LIBGUESTFS_BACKEND=direct virt-customize --install $PACKAGES -a instack.qcow2
popd


234 235
#Adding OpenDaylight to overcloud
pushd stack
Dan Radez's avatar
Dan Radez committed
236
# make a copy of the cached overcloud-full image
237
cp overcloud-full.qcow2 overcloud-full-odl.qcow2
Dan Radez's avatar
Dan Radez committed
238

bobzh's avatar
bobzh committed
239
# remove unnecessary packages and install necessary packages
240 241
LIBGUESTFS_BACKEND=direct virt-customize --run-command "yum remove -y openstack-neutron-openvswitch" \
    --upload /etc/yum.repos.d/opendaylight.repo:/etc/yum.repos.d/opendaylight.repo \
Dan Radez's avatar
Dan Radez committed
242 243 244 245 246 247
    --install opendaylight,python-networking-odl -a overcloud-full-odl.qcow2

## WORK AROUND
## when OpenDaylight lands in upstream RDO manager this can be removed

# upload the opendaylight puppet module
248 249 250 251 252
rm -rf puppet-opendaylight
git clone https://github.com/dfarrell07/puppet-opendaylight
pushd puppet-opendaylight
git archive --format=tar.gz --prefix=opendaylight/ HEAD > ../puppet-opendaylight.tar.gz
popd
253 254
LIBGUESTFS_BACKEND=direct virt-customize --upload puppet-opendaylight.tar.gz:/etc/puppet/modules/ \
                                         --run-command "cd /etc/puppet/modules/ && tar xzf puppet-opendaylight.tar.gz" -a overcloud-full-odl.qcow2
Dan Radez's avatar
Dan Radez committed
255 256

# Patch in OpenDaylight installation and configuration
bobzh's avatar
bobzh committed
257 258
LIBGUESTFS_BACKEND=direct virt-customize --upload ../opnfv-tripleo-heat-templates.patch:/tmp \
                                         --run-command "cd /usr/share/openstack-tripleo-heat-templates/ && patch -Np1 < /tmp/opnfv-tripleo-heat-templates.patch" \
Dan Radez's avatar
Dan Radez committed
259 260 261 262 263
                                         -a instack.qcow2
LIBGUESTFS_BACKEND=direct virt-customize --upload ../opendaylight-puppet-neutron.patch:/tmp \
                                         --run-command "cd /etc/puppet/modules/neutron && patch -Np1 < /tmp/opendaylight-puppet-neutron.patch" \
                                         -a overcloud-full-odl.qcow2
## END WORK AROUND
264 265
popd

bobzh's avatar
bobzh committed
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
## WORK AROUND
## when ONOS lands in upstream OPNFV artifacts this can be removed

# upload the onos puppet module
pushd stack

rm -rf puppet-onos
git clone https://github.com/bobzhouHW/puppet-onos.git
pushd puppet-onos
# download jdk, onos and maven dependancy packages.
pushd files
curl ${onos_artifacts_uri}/jdk-8u51-linux-x64.tar.gz -o ./jdk-8u51-linux-x64.tar.gz
curl ${onos_artifacts_uri}/onos-1.3.0.tar.gz -o ./onos-1.3.0.tar.gz
curl ${onos_artifacts_uri}/repository.tar -o ./repository.tar
popd
git archive --format=tar.gz --prefix=onos/ HEAD > ../puppet-onos.tar.gz
popd
LIBGUESTFS_BACKEND=direct virt-customize --upload puppet-onos.tar.gz:/etc/puppet/modules/ \
                                         --run-command "cd /etc/puppet/modules/ && tar xzf puppet-onos.tar.gz" -a overcloud-full-odl.qcow2

## END WORK AROUND
popd

289 290
# move and Sanitize private keys from instack.json file
mv stack/instackenv.json instackenv-virt.json
291
sed -i '/pm_password/c\      "pm_password": "INSERT_STACK_USER_PRIV_KEY",' instackenv-virt.json
292
sed -i '/ssh-key/c\  "ssh-key": "INSERT_STACK_USER_PRIV_KEY",' instackenv-virt.json
293 294

# clean up the VMs
295
ssh -T ${SSH_OPTIONS[@]} stack@localhost <<EOI
296
set -e
297
virsh destroy instack 2> /dev/null || echo -n ''
298
virsh undefine instack --remove-all-storage 2> /dev/null || echo -n ''
Tim Rozet's avatar
Tim Rozet committed
299
for i in \$(seq 0 $vm_index); do
300 301
  virsh destroy baremetalbrbm_brbm1_brbm2_brbm3_\$i 2> /dev/null || echo -n ''
  virsh undefine baremetalbrbm_brbm1_brbm2_brbm3_\$i --remove-all-storage 2> /dev/null || echo -n ''
Tim Rozet's avatar
Tim Rozet committed
302
done
303 304
EOI