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_VPP="dkms bridge-utils"
66 RPM_WANTLIST_TREX="zlib-devel unzip"
67 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"
69 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"
70 RPM_WANTLIST_JAVA="java-1.8.0-openjdk-headless java-1.8.0-openjdk-devel"
71 #RPM_WANTLIST_DOCKER="docker-engine"
73 ### For now, do not include WANTLIST_NESTED in the main list. We're installing qemu
74 ### separately because of the possible need for specific versions but the supported version seem to be ok for Centos 7.3
76 RPM_WANTLIST="$RPM_WANTLIST_INFRA $RPM_WANTLIST_CSIT $RPM_WANTLIST_VPP $RPM_WANTLIST_TREX $RPM_WANTLIST_MISC $RPM_WANTLIST_JAVA"
78 RPM_OUTPUTFILE="${OUTPUT_DIR}/rpm-packages.txt"
80 # Python requirements file. Can point to a manually crafted file
81 # here, or to the actual CSIT requirements file, or to a symlink.
83 PIP_REQUIREMENTS="../../../../requirements.txt"
84 if [ ! -f ${PIP_REQUIREMENTS} ]
86 echo "PIP requirements file ${PIP_REQUIREMENTS} not found."
90 PIP_OUTPUTFILE="${OUTPUT_DIR}/pip-requirements.txt"
92 # These will be used for SSH to the listmaker VM, and must match with what
93 # was defined in the listmaker VM's kickstart file.
98 ### Spin up simulation
100 if [ "$VIRL_USER" = "" ] || [ "$VIRL_PASSWORD" = "" ]
102 echo '$VIRL_USER and $VIRL_PASSWORD environment variables must be defined'
106 output=$(virl_std_client -u ${VIRL_USER} -p ${VIRL_PASSWORD} \
107 simengine-launch -f ${VIRL_TOPOLOGY_FILE} 2>&1)
108 id=$(echo "${output}" | grep "Simulation ID is " | cut -f 4 -d ' ')
112 echo "Did not get a simulation ID. Aborting."
120 virl_std_client -u ${VIRL_USER} -p ${VIRL_PASSWORD} simengine-stop --session ${id}
125 while [ "${ip}" = "None" ] || [ "${ip}" = "" ]
128 output=$(virl_std_client -u ${VIRL_USER} -p ${VIRL_PASSWORD} simengine-interfaces --session ${id} --nodes listmaker --interfaces management 2>&1)
129 ip=$(echo "${output}" | grep "u'ip-address" | cut -f 4 -d "'" | cut -f 1 -d '/')
135 if ping -w 60 -c 2 $ip > /dev/null
139 echo Host $ip failed to respond to ping
143 # Wait for SSH to be up
149 if [ ! -d ${OUTPUT_DIR} ]; then
154 ### SSH to the VM and perform package installation. Before each step,
155 ### dry-run and grab the URLs of the packages that would be installed.
159 # Helper function: SSH and avoid password prompt
160 sshpass -p $SSH_PASS ssh -o StrictHostKeyChecking=false -o UserKnownHostsFile=/dev/null \
161 -o LogLevel=error ${SSH_USER}@${ip} "$@"
164 RPM_TEMPFILE=$(mktemp)
165 RPM_TEMPFILE2=$(mktemp)
166 RPM_URL_TEMPFILE=$(mktemp)
168 do_ssh yum install -y @base
169 do_ssh yum install -y deltarpm
171 do_ssh yum -y install epel-release
173 do_ssh yum -y install $RPM_WANTLIST
174 for i in ${RPM_WANTLIST} ; do
175 echo $i >> $RPM_TEMPFILE
179 ### Install qemu ($RPM_WANTLIST_NESTED) separately from PPA in case specific versions are required.
181 for i in ${RPM_WANTLIST_NESTED}; do
182 echo $i http://cbs.centos.org/kojifiles/packages/qemu-kvm-ev/2.3.0/31.el7_2.21.1/x86_64/ >> $RPM_URL_TEMPFILE
185 ### Try 2 times for dependencies. Not in yum repo so it is not automatic"
187 for i in ${RPM_WANTLIST_NESTED}; do
188 do_ssh rpm -i http://cbs.centos.org/kojifiles/packages/qemu-kvm-ev/2.3.0/31.el7_2.21.1/x86_64/$i
190 for i in ${RPM_WANTLIST_NESTED}; do
191 do_ssh rpm -i http://cbs.centos.org/kojifiles/packages/qemu-kvm-ev/2.3.0/31.el7_2.21.1/x86_64/$i
195 cat $RPM_TEMPFILE | sort > $RPM_TEMPFILE2
197 cat $RPM_TEMPFILE2 > $RPM_OUTPUTFILE
198 cat $RPM_URL_TEMPFILE >> $RPM_OUTPUTFILE
200 rm -f $RPM_URL_TEMPFILE
202 ### Get Python data. We do this by installing as per our
203 ### requirements.txt file while fetching a list of all
204 ### installed modules before and after, and then comparing.
206 PIP_TEMPFILE_BEFORE=$(mktemp)
207 PIP_TEMPFILE_AFTER=$(mktemp)
208 do_ssh "cat - > /tmp/requirements.txt" < ${PIP_REQUIREMENTS}
209 do_ssh pip list | sort > $PIP_TEMPFILE_BEFORE
210 do_ssh pip install -r /tmp/requirements.txt
211 do_ssh pip list | sort > $PIP_TEMPFILE_AFTER
213 comm -1 -3 ${PIP_TEMPFILE_BEFORE} ${PIP_TEMPFILE_AFTER} | \
214 sed -e 's/\(.*\) (\(.*\))/\1==\2/' > $PIP_OUTPUTFILE
215 rm -f $PIP_TEMPFILE_BEFORE
216 rm -f $PIP_TEMPFILE_AFTER
219 ### Stop VIRL session
221 virl_std_client -u ${VIRL_USER} -p ${VIRL_PASSWORD} simengine-stop --session ${id}