5 rdo_images_uri=https://ci.centos.org/artifacts/rdo/images/liberty/delorean/stable
9 SSH_OPTIONS=(-o StrictHostKeyChecking=no -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null)
11 # check for dependancy packages
12 for i in rpm-build createrepo libguestfs-tools python-docutils bsdtar; do
13 if ! rpm -q $i > /dev/null; then
14 sudo yum install -y $i
18 # RDO Manager expects a stack user to exist, this checks for one
19 # and creates it if you are root
20 if ! id stack > /dev/null; then
22 sudo echo 'stack ALL=(root) NOPASSWD:ALL' | sudo tee -a /etc/sudoers.d/stack
23 sudo echo 'Defaults:stack !requiretty' | sudo tee -a /etc/sudoers.d/stack
24 sudo chmod 0440 /etc/sudoers.d/stack
25 echo 'Added user stack'
28 # ensure that I can ssh as the stack user
29 if ! sudo grep "$(cat ~/.ssh/id_rsa.pub)" /home/stack/.ssh/authorized_keys; then
30 if ! sudo ls -d /home/stack/.ssh/ ; then
31 sudo mkdir /home/stack/.ssh
32 sudo chown stack:stack /home/stack/.ssh
33 sudo chmod 700 /home/stack/.ssh
35 USER=$(whoami) sudo sh -c "cat ~$USER/.ssh/id_rsa.pub >> /home/stack/.ssh/authorized_keys"
36 sudo chown stack:stack /home/stack/.ssh/authorized_keys
39 # clean up stack user previously build instack disk images
40 ssh -T ${SSH_OPTIONS[@]} stack@localhost "rm -f instack*.qcow2"
42 # Yum repo setup for building the undercloud
43 if ! rpm -q rdo-release > /dev/null && [ "$1" != "-master" ]; then
44 #pulling from current-passed-ci instead of release repos
45 #sudo yum install -y https://rdoproject.org/repos/openstack-${RDO_RELEASE}/rdo-release-${RDO_RELEASE}.rpm
46 sudo yum -y install yum-plugin-priorities
47 sudo yum-config-manager --disable openstack-${RDO_RELEASE}
48 sudo curl -o /etc/yum.repos.d/delorean.repo http://trunk.rdoproject.org/centos7-liberty/current-passed-ci/delorean.repo
49 sudo curl -o /etc/yum.repos.d/delorean-deps.repo http://trunk.rdoproject.org/centos7-liberty/delorean-deps.repo
50 sudo rm -f /etc/yum.repos.d/delorean-current.repo
51 elif [ "$1" == "-master" ]; then
52 sudo yum -y install yum-plugin-priorities
53 sudo yum-config-manager --disable openstack-${RDO_RELEASE}
54 sudo curl -o /etc/yum.repos.d/delorean.repo http://trunk.rdoproject.org/centos7/current-passed-ci/delorean.repo
55 sudo curl -o /etc/yum.repos.d/delorean-deps.repo http://trunk.rdoproject.org/centos7-liberty/delorean-deps.repo
56 sudo rm -f /etc/yum.repos.d/delorean-current.repo
59 # install the opendaylight yum repo definition
60 cat << 'EOF' | sudo tee /etc/yum.repos.d/opendaylight.repo
62 name=OpenDaylight $releasever - $basearch
63 baseurl=http://cbs.centos.org/repos/nfv7-opendaylight-3-candidate/$basearch/os/
68 # ensure the undercloud package is installed so we can build the undercloud
69 if ! rpm -q instack-undercloud > /dev/null; then
70 sudo yum install -y python-tripleoclient
73 # ensure openvswitch is installed
74 if ! rpm -q openvswitch > /dev/null; then
75 sudo yum install -y openvswitch
78 # ensure libvirt is installed
79 if ! rpm -q libvirt-daemon-kvm > /dev/null; then
80 sudo yum install -y libvirt-daemon-kvm
83 # clean this up incase it's there
84 sudo rm -f /tmp/instack.answers
86 # ensure that no previous undercloud VMs are running
88 # and rebuild the bare undercloud VMs
89 ssh -T ${SSH_OPTIONS[@]} stack@localhost <<EOI
91 NODE_COUNT=5 NODE_CPU=2 NODE_MEM=8192 TESTENV_ARGS="--baremetal-bridge-names 'brbm brbm1'" instack-virt-setup
94 # let dhcp happen so we can get the ip
95 # just wait instead of checking until we see an address
96 # because there may be a previous lease that needs
100 # get the undercloud ip address
101 UNDERCLOUD=$(grep instack /var/lib/libvirt/dnsmasq/default.leases | awk '{print $3}' | head -n 1)
102 if [ -z "$UNDERCLOUD" ]; then
103 #if not found then dnsmasq may be using leasefile-ro
104 instack_mac=$(ssh -T ${SSH_OPTIONS[@]} stack@localhost "virsh domiflist instack" | grep default | \
105 grep -Eo "[0-9a-f\]+:[0-9a-f\]+:[0-9a-f\]+:[0-9a-f\]+:[0-9a-f\]+:[0-9a-f\]+")
106 UNDERCLOUD=$(arp -e | grep ${instack_mac} | awk {'print $1'})
108 if [ -z "$UNDERCLOUD" ]; then
109 echo "\n\nNever got IP for Instack. Can Not Continue."
113 echo -e "${blue}\rInstack VM has IP $UNDERCLOUD${reset}"
117 # ensure that we can ssh to the undercloud
119 while ! ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" "echo ''" > /dev/null && [ $CNT -gt 0 ]; do
126 # yum repo, triple-o package and ssh key setup for the undercloud
127 ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" <<EOI
130 if ! rpm -q epel-release > /dev/null; then
131 yum install http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
134 yum -y install yum-plugin-priorities
135 curl -o /etc/yum.repos.d/delorean.repo http://trunk.rdoproject.org/centos7-liberty/current-passed-ci/delorean.repo
136 curl -o /etc/yum.repos.d/delorean-deps.repo http://trunk.rdoproject.org/centos7-liberty/delorean-deps.repo
138 cp /root/.ssh/authorized_keys /home/stack/.ssh/authorized_keys
139 chown stack:stack /home/stack/.ssh/authorized_keys
142 # copy instackenv file for future virt deployments
143 if [ ! -d stack ]; then mkdir stack; fi
144 scp ${SSH_OPTIONS[@]} stack@$UNDERCLOUD:instackenv.json stack/instackenv.json
146 # make a copy of instack VM's definitions, and disk image
147 # it must be stopped to make a copy of its disk image
148 ssh -T ${SSH_OPTIONS[@]} stack@localhost <<EOI
150 echo "Shutting down instack to gather configs"
151 virsh shutdown instack
153 echo "Waiting for instack VM to shutdown"
155 while virsh list | grep instack > /dev/null && [ $CNT -gt 0 ]; do
160 if virsh list | grep instack > /dev/null; then
161 echo "instack failed to shutdown for copy"
165 echo $'\nGenerating libvirt configuration'
166 for i in \$(seq 0 $vm_index); do
167 virsh dumpxml baremetalbrbm_brbm1_\$i | awk '/model type='\''virtio'\''/{c++;if(c==2){sub("model type='\''virtio'\''","model type='\''rtl8139'\''");c=0}}1' > baremetalbrbm_brbm1_\$i.xml
170 virsh dumpxml instack > instack.xml
171 virsh net-dumpxml brbm > brbm-net.xml
172 virsh net-dumpxml brbm1 > brbm1-net.xml
173 virsh pool-dumpxml default > default-pool.xml
176 # copy off the instack artifacts
177 echo "Copying instack files to build directory"
178 for i in $(seq 0 $vm_index); do
179 scp ${SSH_OPTIONS[@]} stack@localhost:baremetalbrbm_brbm1_${i}.xml .
182 scp ${SSH_OPTIONS[@]} stack@localhost:instack.xml .
183 scp ${SSH_OPTIONS[@]} stack@localhost:brbm-net.xml .
184 scp ${SSH_OPTIONS[@]} stack@localhost:brbm1-net.xml .
185 scp ${SSH_OPTIONS[@]} stack@localhost:default-pool.xml .
187 # pull down the the built images
188 echo "Copying overcloud resources"
189 IMAGES="overcloud-full.tar"
190 IMAGES+=" undercloud.qcow2"
193 # download prebuilt images from RDO Project
194 if [ "$(curl -L $rdo_images_uri/${i}.md5 | awk {'print $1'})" != "$(md5sum stack/$i | awk {'print $1'})" ] ; then
195 #if [ $i == "undercloud.qcow2" ]; then
196 ### there's a problem with the Content-Length reported by the centos artifacts
197 ### server so using wget for it until a resolution is figured out.
198 wget -nv -O stack/$i $rdo_images_uri/$i
200 # curl $rdo_images_uri/$i -o stack/$i --verbose --silent --location
203 # only untar the tar files
204 if [ "${i##*.}" == "tar" ]; then tar -xf stack/$i -C stack/; fi
207 #Adding OpenStack packages to undercloud
209 cp undercloud.qcow2 instack.qcow2
210 LIBGUESTFS_BACKEND=direct virt-customize --install yum-priorities -a instack.qcow2
211 PACKAGES="qemu-kvm-common,qemu-kvm,libvirt-daemon-kvm,libguestfs,python-libguestfs,openstack-nova-compute"
212 PACKAGES+=",openstack-swift,openstack-ceilometer-api,openstack-neutron-ml2,openstack-ceilometer-alarm"
213 PACKAGES+=",openstack-nova-conductor,openstack-ironic-inspector,openstack-ironic-api,python-openvswitch"
214 PACKAGES+=",openstack-glance,python-glance,python-troveclient,openstack-puppet-modules"
215 PACKAGES+=",openstack-neutron,openstack-neutron-openvswitch,openstack-nova-scheduler,openstack-keystone,openstack-swift-account"
216 PACKAGES+=",openstack-swift-container,openstack-swift-object,openstack-swift-plugin-swift3,openstack-swift-proxy"
217 PACKAGES+=",openstack-nova-api,openstack-nova-cert,openstack-heat-api-cfn,openstack-heat-api,"
218 PACKAGES+=",openstack-ceilometer-central,openstack-ceilometer-polling,openstack-ceilometer-collector,"
219 PACKAGES+=",openstack-heat-api-cloudwatch,openstack-heat-engine,openstack-heat-common,openstack-ceilometer-notification"
220 PACKAGES+=",hiera,puppet,memcached,keepalived,mariadb,mariadb-server,rabbitmq-server,python-pbr,python-proliantutils"
222 LIBGUESTFS_BACKEND=direct virt-customize --install $PACKAGES -a instack.qcow2
226 #Adding OpenDaylight to overcloud
228 # make a copy of the cached overcloud-full image
229 cp overcloud-full.qcow2 overcloud-full-odl.qcow2
231 # remove unnessesary packages and install nessesary packages
232 LIBGUESTFS_BACKEND=direct virt-customize --run-command "yum remove -y openstack-neutron-openvswitch" \
233 --upload /etc/yum.repos.d/opendaylight.repo:/etc/yum.repos.d/opendaylight.repo \
234 --install opendaylight,python-networking-odl -a overcloud-full-odl.qcow2
237 ## when OpenDaylight lands in upstream RDO manager this can be removed
239 # upload the opendaylight puppet module
240 rm -rf puppet-opendaylight
241 git clone https://github.com/dfarrell07/puppet-opendaylight
242 pushd puppet-opendaylight
243 git archive --format=tar.gz --prefix=opendaylight/ HEAD > ../puppet-opendaylight.tar.gz
245 LIBGUESTFS_BACKEND=direct virt-customize --upload puppet-opendaylight.tar.gz:/etc/puppet/modules/ \
246 --run-command "cd /etc/puppet/modules/ && tar xzf puppet-opendaylight.tar.gz" -a overcloud-full-odl.qcow2
248 # Patch in OpenDaylight installation and configuration
249 LIBGUESTFS_BACKEND=direct virt-customize --upload ../opendaylight-tripleo-heat-templates.patch:/tmp \
250 --run-command "cd /usr/share/openstack-tripleo-heat-templates/ && patch -Np1 < /tmp/opendaylight-tripleo-heat-templates.patch" \
252 LIBGUESTFS_BACKEND=direct virt-customize --upload ../opendaylight-puppet-neutron.patch:/tmp \
253 --run-command "cd /etc/puppet/modules/neutron && patch -Np1 < /tmp/opendaylight-puppet-neutron.patch" \
254 -a overcloud-full-odl.qcow2
258 # move and Sanitize private keys from instack.json file
259 mv stack/instackenv.json instackenv-virt.json
260 sed -i '/pm_password/c\ "pm_password": "INSERT_STACK_USER_PRIV_KEY",' instackenv-virt.json
261 sed -i '/ssh-key/c\ "ssh-key": "INSERT_STACK_USER_PRIV_KEY",' instackenv-virt.json
264 ssh -T ${SSH_OPTIONS[@]} stack@localhost <<EOI
266 virsh destroy instack 2> /dev/null || echo -n ''
267 virsh undefine instack --remove-all-storage 2> /dev/null || echo -n ''
268 for i in \$(seq 0 $vm_index); do
269 virsh destroy baremetalbrbm_brbm1_\$i 2> /dev/null || echo -n ''
270 virsh undefine baremetalbrbm_brbm1_\$i --remove-all-storage 2> /dev/null || echo -n ''