Add job to manage apex snapshot images
[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 cd /builder/openstack-hot || exit 1
25 mkdir -p /tmp/apex_snapshots
26 pushd /tmp/apex_snapshots
27
28 wget artifacts.opnfv.org/apex/queens/noha/snapshot.properties
29 cat snapshot.properties
30 source snapshot.properties
31 SNAPSHOT_FILENAME=$(basename $OPNFV_SNAP_URL)
32
33 wget --progress=dot:giga $OPNFV_SNAP_URL
34 gunzip -c $SNAPSHOT_FILENAME > snapshots.tar
35
36 # builder VMs don't have enough disk to handle a full un-tarring, so doing one
37 # big file at a time and deleting it from the tarball as a workaround for now
38 tar -tf snapshots.tar
39
40 images=$(tar --list -f snapshots.tar | grep qcow2)
41 for image in $images; do
42   tar -xf snapshots.tar $image
43   tar --delete --file=snapshots.tar $image
44 done
45
46 # get the ssh keys and node.yaml for uploading to swift at the end
47 tar -xf snapshots.tar ./id_rsa
48 tar -xf snapshots.tar ./node.yaml
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 popd
58
59 openstack image list
60
61 # clean out any zombie OPNFV - apex images that *may* be left over from troubled jobs
62 openstack image list | egrep 'OPNFV - apex.*new ' | awk '{print "openstack image delete",$2}' | sh || true
63
64 sudo yum install -y qemu-img
65
66 qemu-img convert -f qcow2 -O raw /tmp/apex_snapshots/$CONTROLLER_NODE.qcow2 /tmp/apex_snapshots/$CONTROLLER_NODE.raw
67 rm /tmp/apex_snapshots/$CONTROLLER_NODE.qcow2
68 qemu-img convert -f qcow2 -O raw /tmp/apex_snapshots/$COMPUTE_0_NODE.qcow2 /tmp/apex_snapshots/$COMPUTE_0_NODE.raw
69 rm /tmp/apex_snapshots/$COMPUTE_0_NODE.qcow2
70 qemu-img convert -f qcow2 -O raw /tmp/apex_snapshots/$COMPUTE_1_NODE.qcow2 /tmp/apex_snapshots/$COMPUTE_1_NODE.raw
71 rm /tmp/apex_snapshots/$COMPUTE_1_NODE.qcow2
72
73 # create .new images first, then we can delete the existing and rename .new
74 # to existing to reduce the delta of when these images might be unavailable
75 CONTROLLER_IMAGE_NAME="ZZCI - OPNFV - apex - controller - 0"
76 COMPUTE_0_IMAGE_NAME="ZZCI - OPNFV - apex - compute - 0"
77 COMPUTE_1_IMAGE_NAME="ZZCI - OPNFV - apex - compute - 1"
78
79 openstack image create \
80   --disk-format raw --container-format bare \
81   --file /tmp/apex_snapshots/$CONTROLLER_NODE.raw "$CONTROLLER_IMAGE_NAME.new"
82 openstack image create \
83   --disk-format raw --container-format bare \
84   --file /tmp/apex_snapshots/$COMPUTE_0_NODE.raw "$COMPUTE_0_IMAGE_NAME.new"
85 openstack image create \
86   --disk-format raw --container-format bare \
87   --file /tmp/apex_snapshots/$COMPUTE_1_NODE.raw "$COMPUTE_1_IMAGE_NAME.new"
88
89 # clean out any non ".new" OPNFV - apex images. In the case of a previously failed
90 # or aborted apex management job, we can end up with multiple images with the same
91 # name so being thorough here.
92 openstack image list | egrep 'OPNFV - apex' | egrep -v 'new' | awk '{print "openstack image delete",$2}' | sh || true
93
94 openstack image set --name "$CONTROLLER_IMAGE_NAME" "$CONTROLLER_IMAGE_NAME.new"
95 openstack image set --tag "Date Uploaded: $(date)" "$CONTROLLER_IMAGE_NAME"
96 openstack image set --tag "Apex Archive: $(basename $OPNFV_SNAP_URL)" "$CONTROLLER_IMAGE_NAME"
97
98 openstack image set --name "$COMPUTE_0_IMAGE_NAME" "$COMPUTE_0_IMAGE_NAME.new"
99 openstack image set --tag "Date Uploaded: $(date)" "$COMPUTE_0_IMAGE_NAME"
100 openstack image set --tag "Apex Archive: $(basename $OPNFV_SNAP_URL)" "$COMPUTE_0_IMAGE_NAME"
101
102 openstack image set --name "$COMPUTE_1_IMAGE_NAME" "$COMPUTE_1_IMAGE_NAME.new"
103 openstack image set --tag "Date Uploaded: $(date)" "$COMPUTE_1_IMAGE_NAME"
104 openstack image set --tag "Apex Archive: $(basename $OPNFV_SNAP_URL)" "$COMPUTE_1_IMAGE_NAME"
105
106 # Now that the images should be up, active and ready, we can update
107 # the ssh key and node.yaml in swift
108 openstack container create OPNFV-APEX-SNAPSHOTS
109 openstack object create OPNFV-APEX-SNAPSHOTS /tmp/apex_snapshots/node.yaml --name node.yaml
110 openstack object create OPNFV-APEX-SNAPSHOTS /tmp/apex_snapshots/id_rsa --name id_rsa
111 openstack object list OPNFV-APEX-SNAPSHOTS
112
113 openstack image list
114
115 df -h
116