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 "apt-get update", "apt-get upgrade" 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 RELEASE="${OS}_${DATE}_${VERSION}"
42 OUTPUT_DIR="lists/${RELEASE}"
44 echo "Building release ${RELEASE}."
45 echo "Storinging data in ${OUTPUT_DIR}/."
50 APT_WANTLIST_INFRA="nfs-common cloud-init"
51 APT_WANTLIST_CSIT="python-dev python-virtualenv git"
52 APT_WANTLIST_VPP="dkms"
53 APT_WANTLIST_TREX="zlib1g-dev unzip"
54 APT_WANTLIST_NESTED="qemu-system-x86"
56 # For now, let us NOT incude WANTLIST_NESTED in the below. We're installing qemu
57 # separately from a separate source.
58 APT_WANTLIST="$APT_WANTLIST_INFRA $APT_WANTLIST_CSIT $APT_WANTLIST_VPP $WANTLIST_TREX"
60 APT_OUTPUTFILE="${OUTPUT_DIR}/apt-packages.txt"
62 # Python requirements file. Can point to a manually crafted file
63 # here, or to the actual CSIT requirements file, or to a symlink.
65 PIP_REQUIREMENTS="../../../../requirements.txt"
66 if [ ! -f ${PIP_REQUIREMENTS} ]
68 echo "PIP requirements file ${PIP_REQUIREMENTS} not found."
72 PIP_OUTPUTFILE="${OUTPUT_DIR}/pip-requirements.txt"
74 # These will be used for SSH to the listmaker VM, and must match with what
75 # was defined in the listmaker VM's kickstart file.
79 VIRL_TOPOLOGY_FILE="listmaker/virl-listmaker.yaml"
82 ### Spin up simulation
84 if [ "$VIRL_USER" = "" ] || [ "$VIRL_PASSWORD" = "" ]
86 echo '$VIRL_USER and $VIRL_PASSWORD environment variables must be defined'
90 output=$(virl_std_client -u ${VIRL_USER} -p ${VIRL_PASSWORD} \
91 simengine-launch -f ${VIRL_TOPOLOGY_FILE} 2>&1)
92 id=$(echo "${output}" | grep "Simulation ID is " | cut -f 4 -d ' ')
96 echo "Did not get a simulation ID. Aborting."
104 virl_std_client -u ${VIRL_USER} -p ${VIRL_PASSWORD} simengine-stop --session ${id}
109 while [ "${ip}" = "None" ] || [ "${ip}" = "" ]
112 output=$(virl_std_client -u ${VIRL_USER} -p ${VIRL_PASSWORD} simengine-interfaces --session ${id} --nodes listmaker --interfaces management 2>&1)
113 ip=$(echo "${output}" | grep "u'ip-address" | cut -f 4 -d "'" | cut -f 1 -d '/')
119 if ping -w 60 -c 2 $ip > /dev/null
123 echo Host $ip failed to respond to ping
127 # Wait for SSH to be up
136 ### SSH to the VM and perform package installation. Before each step,
137 ### dry-run and grab the URLs of the packages that would be installed.
141 # Helper function: SSH and avoid password prompt
142 sshpass -p $SSH_PASS ssh -o StrictHostKeyChecking=false -o UserKnownHostsFile=/dev/null \
143 -o LogLevel=error ${SSH_USER}@${ip} "$@"
146 do_ssh "cat - > /etc/apt/sources.list" <<_EOF
147 deb http://us.archive.ubuntu.com/ubuntu/ trusty main restricted
148 deb-src http://us.archive.ubuntu.com/ubuntu/ trusty main restricted
149 deb http://us.archive.ubuntu.com/ubuntu/ trusty-updates main restricted
150 deb-src http://us.archive.ubuntu.com/ubuntu/ trusty-updates main restricted
151 deb http://us.archive.ubuntu.com/ubuntu/ trusty universe
152 deb-src http://us.archive.ubuntu.com/ubuntu/ trusty universe
153 deb http://us.archive.ubuntu.com/ubuntu/ trusty-updates universe
154 deb-src http://us.archive.ubuntu.com/ubuntu/ trusty-updates universe
155 deb http://us.archive.ubuntu.com/ubuntu/ trusty multiverse
156 deb-src http://us.archive.ubuntu.com/ubuntu/ trusty multiverse
157 deb http://us.archive.ubuntu.com/ubuntu/ trusty-updates multiverse
158 deb-src http://us.archive.ubuntu.com/ubuntu/ trusty-updates multiverse
159 deb http://us.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
160 deb-src http://us.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
161 deb http://security.ubuntu.com/ubuntu trusty-security main restricted
162 deb-src http://security.ubuntu.com/ubuntu trusty-security main restricted
163 deb http://security.ubuntu.com/ubuntu trusty-security universe
164 deb-src http://security.ubuntu.com/ubuntu trusty-security universe
165 deb http://security.ubuntu.com/ubuntu trusty-security multiverse
166 deb-src http://security.ubuntu.com/ubuntu trusty-security multiverse
170 ### FIXME: Need error handling around all this
171 do_ssh apt-get update
173 APT_TEMPFILE=$(mktemp)
174 do_ssh apt-get --print-uris -y dist-upgrade >> $APT_TEMPFILE
175 do_ssh DEBIAN_FRONTEND=noninteractive apt-get -y dist-upgrade
176 do_ssh apt-get --print-uris -y install $APT_WANTLIST >> $APT_TEMPFILE
177 do_ssh DEBIAN_FRONTEND=noninteractive apt-get -y install $APT_WANTLIST
179 ### Install qemu ($APT_WANTLIST_NESTED) separately from PPA
180 do_ssh "cat - >> /etc/apt/sources.list" <<_EOF
181 # For a custom qemu build
182 deb http://ppa.launchpad.net/syseleven-platform/virtualization/ubuntu trusty main
183 deb-src http://ppa.launchpad.net/syseleven-platform/virtualization/ubuntu trusty main
185 do_ssh apt-get --allow-unauthenticated update
186 do_ssh apt-get --print-uris --allow-unauthenticated -y install $APT_WANTLIST_NESTED >> $APT_TEMPFILE
187 do_ssh DEBIAN_FRONTEND=noninteractive apt-get --allow-unauthenticated -y install $APT_WANTLIST_NESTED
189 cat $APT_TEMPFILE | grep MD5Sum | sort > $APT_OUTPUTFILE
192 ### Get Python data. We do this by installing as per our
193 ### requirements.txt file while fetching a list of all
194 ### installed modules before and after, and then comparing.
196 PIP_TEMPFILE_BEFORE=$(mktemp)
197 PIP_TEMPFILE_AFTER=$(mktemp)
198 do_ssh "cat - > /tmp/requirements.txt" < ${PIP_REQUIREMENTS}
199 do_ssh pip list | sort > $PIP_TEMPFILE_BEFORE
200 do_ssh pip install -r /tmp/requirements.txt
201 do_ssh pip list | sort > $PIP_TEMPFILE_AFTER
203 comm -1 -3 ${PIP_TEMPFILE_BEFORE} ${PIP_TEMPFILE_AFTER} | \
204 sed -e 's/\(.*\) (\(.*\))/\1==\2/' > $PIP_OUTPUTFILE
205 rm -f $PIP_TEMPFILE_BEFORE
206 rm -f $PIP_TEMPFILE_AFTER
209 ### Stop VIRL session
211 virl_std_client -u ${VIRL_USER} -p ${VIRL_PASSWORD} simengine-stop --session ${id}