3 # Copyright (c) 2016 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # This script is to spin up a simulation in VIRL, and fetch the URLs for all packages
17 # that the user would obtain if they did an "yum update" today.
19 # This entire step is neither secure nor portable. The assumption --for now-- is that
20 # this will only ever be run in LF CSIT VIRL lab. Should the requirement arise to
21 # run this elsewhere, then additional work may be required to make this more
24 # This script requires that the following two environment variables be defined-
29 VERSION=$(cat $(dirname $0)/CHANGELOG | grep '^## ' | head -1 | sed -e 's/.*\[\(.*\)\].*/\1/')
30 if [ "${VERSION}" = "" ]
32 echo "Unable to determine build version from CHANGELOG file. Make sure"
33 echo "that there is an entry for the most recent version in CHANGELOG,"
34 echo "and that the entry is formated like"
36 echo "## [1.0] - 2016-05-20"
39 DATE=$(date +%Y-%m-%d)
41 if [ "$1" == "centos-7-1511" ]
44 VIRL_TOPOLOGY_FILE="listmaker/virl-listmaker-centos-7-1511.yaml"
45 elif [ "$1" == "centos-7.3-1611" ]
48 VIRL_TOPOLOGY_FILE="listmaker/virl-listmaker-centos-7.3-1611.yaml"
50 echo specify argument -- probably centos-7-1511 or centos-7.3-1611
54 RELEASE="${OS}_${DATE}_${VERSION}"
55 OUTPUT_DIR="lists/${RELEASE}"
57 echo "Building release ${RELEASE}."
58 echo "Storing data in ${OUTPUT_DIR}/."
63 RPM_WANTLIST_INFRA="nfs-utils cloud-init pkgconfig yum-utils"
64 RPM_WANTLIST_CSIT="python-devel python-pip python-virtualenv python-setuptools python-pip openssl-devel git strongswan"
65 RPM_WANTLIST_TLDK="tcpdump"
66 RPM_WANTLIST_VPP="dkms bridge-utils libmbedcrypto0 libmbedtls10 libmbedx509-0"
67 RPM_WANTLIST_TREX="zlib-devel unzip"
68 RPM_WANTLIST_MISC="socat psmisc gperftools glusterfs glusterfs-api libiscsi libibverbs libpcap libpcap-devel pixman libpng pulseaudio-libs librados2 librbd1 librdmacm libseccomp spice-server libusb usbredir glusterfs-devel seavgabios-bin sgabios-bin ipxe-roms-qemu nss-devel seabios-bin"
70 RPM_WANTLIST_NESTED="qemu-img-ev-2.3.0-31.el7_2.21.1.x86_64.rpm libcacard-ev-2.3.0-31.el7_2.21.1.x86_64.rpm libcacard-devel-ev-2.3.0-31.el7_2.21.1.x86_64.rpm qemu-kvm-ev-debuginfo-2.3.0-31.el7_2.21.1.x86_64.rpm qemu-kvm-tools-ev-2.3.0-31.el7_2.21.1.x86_64.rpm qemu-kvm-common-ev-2.3.0-31.el7_2.21.1.x86_64.rpm qemu-kvm-ev-2.3.0-31.el7_2.21.1.x86_64.rpm libcacard-tools-ev-2.3.0-31.el7_2.21.1.x86_64.rpm"
71 RPM_WANTLIST_JAVA="java-1.8.0-openjdk-headless java-1.8.0-openjdk-devel"
72 #RPM_WANTLIST_DOCKER="docker-engine"
74 ### For now, do not include WANTLIST_NESTED in the main list. We're installing qemu
75 ### separately because of the possible need for specific versions but the supported version seem to be ok for Centos 7.3
77 RPM_WANTLIST="$RPM_WANTLIST_INFRA $RPM_WANTLIST_CSIT $RPM_WANTLIST_VPP $RPM_WANTLIST_TREX $RPM_WANTLIST_MISC $RPM_WANTLIST_JAVA $RPM_WANTLIST_TLDK"
79 RPM_OUTPUTFILE="${OUTPUT_DIR}/rpm-packages.txt"
81 # Python requirements file. Can point to a manually crafted file
82 # here, or to the actual CSIT requirements file, or to a symlink.
84 PIP_REQUIREMENTS="../../../../requirements.txt"
85 if [ ! -f ${PIP_REQUIREMENTS} ]
87 echo "PIP requirements file ${PIP_REQUIREMENTS} not found."
91 PIP_OUTPUTFILE="${OUTPUT_DIR}/pip-requirements.txt"
93 # These will be used for SSH to the listmaker VM, and must match with what
94 # was defined in the listmaker VM's kickstart file.
99 ### Spin up simulation
101 if [ "$VIRL_USER" = "" ] || [ "$VIRL_PASSWORD" = "" ]
103 echo '$VIRL_USER and $VIRL_PASSWORD environment variables must be defined'
107 output=$(virl_std_client -u ${VIRL_USER} -p ${VIRL_PASSWORD} \
108 simengine-launch -f ${VIRL_TOPOLOGY_FILE} 2>&1)
109 id=$(echo "${output}" | grep "Simulation ID is " | cut -f 4 -d ' ')
113 echo "Did not get a simulation ID. Aborting."
121 virl_std_client -u ${VIRL_USER} -p ${VIRL_PASSWORD} simengine-stop --session ${id}
126 while [ "${ip}" = "None" ] || [ "${ip}" = "" ]
129 output=$(virl_std_client -u ${VIRL_USER} -p ${VIRL_PASSWORD} simengine-interfaces --session ${id} --nodes listmaker --interfaces management 2>&1)
130 ip=$(echo "${output}" | grep "u'ip-address" | cut -f 4 -d "'" | cut -f 1 -d '/')
136 if ping -w 60 -c 2 $ip > /dev/null
140 echo Host $ip failed to respond to ping
144 # Wait for SSH to be up
150 if [ ! -d ${OUTPUT_DIR} ]; then
155 ### SSH to the VM and perform package installation. Before each step,
156 ### dry-run and grab the URLs of the packages that would be installed.
160 # Helper function: SSH and avoid password prompt
161 sshpass -p $SSH_PASS ssh -o StrictHostKeyChecking=false -o UserKnownHostsFile=/dev/null \
162 -o LogLevel=error ${SSH_USER}@${ip} "$@"
165 RPM_TEMPFILE=$(mktemp)
166 RPM_TEMPFILE2=$(mktemp)
167 RPM_URL_TEMPFILE=$(mktemp)
169 do_ssh yum install -y @base
170 do_ssh yum install -y deltarpm
172 do_ssh yum -y install epel-release
174 do_ssh yum -y install $RPM_WANTLIST
175 for i in ${RPM_WANTLIST} ; do
176 echo $i >> $RPM_TEMPFILE
180 ### Install qemu ($RPM_WANTLIST_NESTED) separately from PPA in case specific versions are required.
182 for i in ${RPM_WANTLIST_NESTED}; do
183 echo $i http://cbs.centos.org/kojifiles/packages/qemu-kvm-ev/2.3.0/31.el7_2.21.1/x86_64/ >> $RPM_URL_TEMPFILE
186 ### Try 2 times for dependencies. Not in yum repo so it is not automatic"
188 for i in ${RPM_WANTLIST_NESTED}; do
189 do_ssh rpm -i http://cbs.centos.org/kojifiles/packages/qemu-kvm-ev/2.3.0/31.el7_2.21.1/x86_64/$i
191 for i in ${RPM_WANTLIST_NESTED}; do
192 do_ssh rpm -i http://cbs.centos.org/kojifiles/packages/qemu-kvm-ev/2.3.0/31.el7_2.21.1/x86_64/$i
196 cat $RPM_TEMPFILE | sort > $RPM_TEMPFILE2
198 cat $RPM_TEMPFILE2 > $RPM_OUTPUTFILE
199 cat $RPM_URL_TEMPFILE >> $RPM_OUTPUTFILE
201 rm -f $RPM_URL_TEMPFILE
203 ### Get Python data. We do this by installing as per our
204 ### requirements.txt file while fetching a list of all
205 ### installed modules before and after, and then comparing.
207 PIP_TEMPFILE_BEFORE=$(mktemp)
208 PIP_TEMPFILE_AFTER=$(mktemp)
209 do_ssh "cat - > /tmp/requirements.txt" < ${PIP_REQUIREMENTS}
210 do_ssh pip list | sort > $PIP_TEMPFILE_BEFORE
211 do_ssh pip install -r /tmp/requirements.txt
212 do_ssh pip list | sort > $PIP_TEMPFILE_AFTER
214 comm -1 -3 ${PIP_TEMPFILE_BEFORE} ${PIP_TEMPFILE_AFTER} | \
215 sed -e 's/\(.*\) (\(.*\))/\1==\2/' > $PIP_OUTPUTFILE
216 rm -f $PIP_TEMPFILE_BEFORE
217 rm -f $PIP_TEMPFILE_AFTER
220 ### Stop VIRL session
222 virl_std_client -u ${VIRL_USER} -p ${VIRL_PASSWORD} simengine-stop --session ${id}