Chore: Update gerrit-review-action to latest v0.8
[releng/builder.git] / jjb / opendaylight-infra-apex-image-management.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2018 Red Hat, Inc. and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11
12 # Ensure we fail the job if any steps fail.
13 set -x -o pipefail -o errexit
14
15 virtualenv "/tmp/v/openstack"
16 # shellcheck source=/tmp/v/openstack/bin/activate disable=SC1091
17 source "/tmp/v/openstack/bin/activate"
18 pip install --upgrade --quiet "pip<10.0.0" setuptools
19 pip install --upgrade --quiet python-openstackclient
20 pip freeze
21
22 df -h
23
24 mkdir -p /tmp/apex_snapshots
25 pushd /tmp/apex_snapshots
26
27 wget artifacts.opnfv.org/apex/queens/noha/snapshot.properties
28 cat snapshot.properties
29 source snapshot.properties
30 SNAPSHOT_FILENAME=$(basename $OPNFV_SNAP_URL)
31
32 wget --progress=dot:giga $OPNFV_SNAP_URL
33 gunzip -c $SNAPSHOT_FILENAME > snapshots.tar
34
35 # builder VMs don't have enough disk to handle a full un-tarring, so doing one
36 # big file at a time and deleting it from the tarball as a workaround for now
37 tar -tf snapshots.tar
38
39 images=$(tar --list -f snapshots.tar | grep qcow2)
40 for image in $images; do
41   tar -xf snapshots.tar $image
42   tar --delete --file=snapshots.tar $image
43 done
44
45 # get the ssh keys and node.yaml for uploading to swift at the end
46 tar -xf snapshots.tar ./id_rsa
47 tar -xf snapshots.tar ./node.yaml
48 tar -xf snapshots.tar ./overcloudrc
49
50 ls -altr
51
52 # grab the right baremetal# for the controller(s) and compute(s)
53 CONTROLLER_NODE=$(egrep 'type|vNode-name' node.yaml | egrep -A1 controller | tail -n1 | awk '{print $2}')
54 COMPUTE_0_NODE=$(egrep 'type|vNode-name' node.yaml | egrep -A1 compute | tail -n1 | awk '{print $2}')
55 COMPUTE_1_NODE=$(egrep 'type|vNode-name' node.yaml | egrep -A1 compute | head -n2 | tail -n1 | awk '{print $2}')
56
57 # Customize images to work in ODL Vexxhost infra
58 sudo yum install -y libguestfs-tools
59 export LIBGUESTFS_BACKEND=direct
60 virt-customize -a $CONTROLLER_NODE.qcow2 \
61   --run-command "crudini --set /var/lib/config-data/puppet-generated/neutron/etc/neutron/plugins/ml2/ml2_conf.ini ml2 physical_network_mtus datacentre:1458" \
62   --run-command "crudini --set /var/lib/config-data/puppet-generated/neutron/etc/neutron/plugins/ml2/ml2_conf.ini ml2 path_mtu 1458" \
63   --run-command "crudini --set /var/lib/config-data/puppet-generated/neutron/etc/neutron/neutron.conf '' global_physnet_mtu 1458" \
64   --run-command "crudini --set /var/lib/config-data/puppet-generated/neutron/etc/neutron/dhcp_agent.ini '' debug true" \
65
66 virt-customize -a $COMPUTE_0_NODE.qcow2 \
67   --run-command "crudini --set /var/lib/config-data/puppet-generated/nova_libvirt/etc/nova/nova.conf libvirt virt_type qemu"
68
69 virt-customize -a $COMPUTE_1_NODE.qcow2 \
70   --run-command "crudini --set /var/lib/config-data/puppet-generated/nova_libvirt/etc/nova/nova.conf libvirt virt_type qemu"
71
72 for image in $CONTROLLER_NODE $COMPUTE_0_NODE $COMPUTE_1_NODE
73 do
74   # Change interface MTU to account for default network mtu of 1458
75   virt-customize -a $image.qcow2 \
76     --run-command 'sudo echo "MTU=\"1458\"" >> /etc/sysconfig/network-scripts/ifcfg-eth0' \
77     --run-command 'sudo echo "MTU=\"1458\"" >> /etc/sysconfig/network-scripts/ifcfg-br-int' \
78     --run-command 'sudo echo "MTU=\"1458\"" >> /etc/sysconfig/network-scripts/ifcfg-ovs-system' \
79     --run-command "sudo crudini --set /etc/selinux/config '' SELINUX permissive"
80 done
81
82 popd
83
84 openstack image list
85
86 # clean out any zombie OPNFV - apex images that *may* be left over from troubled jobs
87 openstack image list | egrep 'OPNFV - apex.*new ' | awk '{print "openstack image delete",$2}' | sh || true
88
89 qemu-img convert -f qcow2 -O raw /tmp/apex_snapshots/$CONTROLLER_NODE.qcow2 /tmp/apex_snapshots/$CONTROLLER_NODE.raw
90 rm /tmp/apex_snapshots/$CONTROLLER_NODE.qcow2
91 qemu-img convert -f qcow2 -O raw /tmp/apex_snapshots/$COMPUTE_0_NODE.qcow2 /tmp/apex_snapshots/$COMPUTE_0_NODE.raw
92 rm /tmp/apex_snapshots/$COMPUTE_0_NODE.qcow2
93 qemu-img convert -f qcow2 -O raw /tmp/apex_snapshots/$COMPUTE_1_NODE.qcow2 /tmp/apex_snapshots/$COMPUTE_1_NODE.raw
94 rm /tmp/apex_snapshots/$COMPUTE_1_NODE.qcow2
95
96 # create .new images first, then we can delete the existing and rename .new
97 # to existing to reduce the delta of when these images might be unavailable
98 CONTROLLER_IMAGE_NAME="ZZCI - OPNFV - apex - controller - 0"
99 COMPUTE_0_IMAGE_NAME="ZZCI - OPNFV - apex - compute - 0"
100 COMPUTE_1_IMAGE_NAME="ZZCI - OPNFV - apex - compute - 1"
101
102 openstack image create \
103   --disk-format raw --container-format bare \
104   --file /tmp/apex_snapshots/$CONTROLLER_NODE.raw "$CONTROLLER_IMAGE_NAME.new"
105 openstack image create \
106   --disk-format raw --container-format bare \
107   --file /tmp/apex_snapshots/$COMPUTE_0_NODE.raw "$COMPUTE_0_IMAGE_NAME.new"
108 openstack image create \
109   --disk-format raw --container-format bare \
110   --file /tmp/apex_snapshots/$COMPUTE_1_NODE.raw "$COMPUTE_1_IMAGE_NAME.new"
111
112 # clean out any non ".new" OPNFV - apex images. In the case of a previously failed
113 # or aborted apex management job, we can end up with multiple images with the same
114 # name so being thorough here.
115 openstack image list | egrep 'OPNFV - apex' | egrep -v 'new' | awk '{print "openstack image delete",$2}' | sh
116
117 openstack image set --name "$CONTROLLER_IMAGE_NAME" "$CONTROLLER_IMAGE_NAME.new"
118 openstack image set --tag "Date Uploaded: $(date)" "$CONTROLLER_IMAGE_NAME"
119 openstack image set --tag "Apex Archive: $(basename $OPNFV_SNAP_URL)" "$CONTROLLER_IMAGE_NAME"
120
121 openstack image set --name "$COMPUTE_0_IMAGE_NAME" "$COMPUTE_0_IMAGE_NAME.new"
122 openstack image set --tag "Date Uploaded: $(date)" "$COMPUTE_0_IMAGE_NAME"
123 openstack image set --tag "Apex Archive: $(basename $OPNFV_SNAP_URL)" "$COMPUTE_0_IMAGE_NAME"
124
125 openstack image set --name "$COMPUTE_1_IMAGE_NAME" "$COMPUTE_1_IMAGE_NAME.new"
126 openstack image set --tag "Date Uploaded: $(date)" "$COMPUTE_1_IMAGE_NAME"
127 openstack image set --tag "Apex Archive: $(basename $OPNFV_SNAP_URL)" "$COMPUTE_1_IMAGE_NAME"
128
129 # Now that the images should be up, active and ready, we can update
130 # the ssh key and node.yaml in swift
131 openstack container create OPNFV-APEX-SNAPSHOTS
132 openstack object create OPNFV-APEX-SNAPSHOTS /tmp/apex_snapshots/node.yaml --name node.yaml
133 openstack object create OPNFV-APEX-SNAPSHOTS /tmp/apex_snapshots/id_rsa --name id_rsa
134 openstack object create OPNFV-APEX-SNAPSHOTS /tmp/apex_snapshots/overcloudrc --name overcloudrc
135 openstack object list OPNFV-APEX-SNAPSHOTS
136
137 openstack image list
138
139 df -h
140