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 bridge-utils"
53 APT_WANTLIST_TREX="zlib1g-dev unzip"
54 APT_WANTLIST_NESTED="qemu-system-x86"
55 APT_WANTLIST_JAVA="openjdk-8-jdk-headless"
56 APT_WANTLIST_DOCKER="docker-engine"
58 # For now, let us NOT incude WANTLIST_NESTED in the below. We're installing qemu
59 # separately from a separate source.
60 APT_WANTLIST="$APT_WANTLIST_INFRA $APT_WANTLIST_CSIT $APT_WANTLIST_VPP $WANTLIST_TREX"
62 APT_OUTPUTFILE="${OUTPUT_DIR}/apt-packages.txt"
64 # Python requirements file. Can point to a manually crafted file
65 # here, or to the actual CSIT requirements file, or to a symlink.
67 PIP_REQUIREMENTS="../../../../requirements.txt"
68 if [ ! -f ${PIP_REQUIREMENTS} ]
70 echo "PIP requirements file ${PIP_REQUIREMENTS} not found."
74 PIP_OUTPUTFILE="${OUTPUT_DIR}/pip-requirements.txt"
76 # These will be used for SSH to the listmaker VM, and must match with what
77 # was defined in the listmaker VM's kickstart file.
81 VIRL_TOPOLOGY_FILE="listmaker/virl-listmaker.yaml"
84 ### Spin up simulation
86 if [ "$VIRL_USER" = "" ] || [ "$VIRL_PASSWORD" = "" ]
88 echo '$VIRL_USER and $VIRL_PASSWORD environment variables must be defined'
92 output=$(virl_std_client -u ${VIRL_USER} -p ${VIRL_PASSWORD} \
93 simengine-launch -f ${VIRL_TOPOLOGY_FILE} 2>&1)
94 id=$(echo "${output}" | grep "Simulation ID is " | cut -f 4 -d ' ')
98 echo "Did not get a simulation ID. Aborting."
106 virl_std_client -u ${VIRL_USER} -p ${VIRL_PASSWORD} simengine-stop --session ${id}
111 while [ "${ip}" = "None" ] || [ "${ip}" = "" ]
114 output=$(virl_std_client -u ${VIRL_USER} -p ${VIRL_PASSWORD} simengine-interfaces --session ${id} --nodes listmaker --interfaces management 2>&1)
115 ip=$(echo "${output}" | grep "u'ip-address" | cut -f 4 -d "'" | cut -f 1 -d '/')
121 if ping -w 60 -c 2 $ip > /dev/null
125 echo Host $ip failed to respond to ping
129 # Wait for SSH to be up
138 ### SSH to the VM and perform package installation. Before each step,
139 ### dry-run and grab the URLs of the packages that would be installed.
143 # Helper function: SSH and avoid password prompt
144 sshpass -p $SSH_PASS ssh -o StrictHostKeyChecking=false -o UserKnownHostsFile=/dev/null \
145 -o LogLevel=error ${SSH_USER}@${ip} "$@"
148 do_ssh "cat - > /etc/apt/sources.list" <<_EOF
149 deb http://us.archive.ubuntu.com/ubuntu/ trusty main restricted
150 deb-src http://us.archive.ubuntu.com/ubuntu/ trusty main restricted
151 deb http://us.archive.ubuntu.com/ubuntu/ trusty-updates main restricted
152 deb-src http://us.archive.ubuntu.com/ubuntu/ trusty-updates main restricted
153 deb http://us.archive.ubuntu.com/ubuntu/ trusty universe
154 deb-src http://us.archive.ubuntu.com/ubuntu/ trusty universe
155 deb http://us.archive.ubuntu.com/ubuntu/ trusty-updates universe
156 deb-src http://us.archive.ubuntu.com/ubuntu/ trusty-updates universe
157 deb http://us.archive.ubuntu.com/ubuntu/ trusty multiverse
158 deb-src http://us.archive.ubuntu.com/ubuntu/ trusty multiverse
159 deb http://us.archive.ubuntu.com/ubuntu/ trusty-updates multiverse
160 deb-src http://us.archive.ubuntu.com/ubuntu/ trusty-updates multiverse
161 deb http://us.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
162 deb-src http://us.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
163 deb http://security.ubuntu.com/ubuntu trusty-security main restricted
164 deb-src http://security.ubuntu.com/ubuntu trusty-security main restricted
165 deb http://security.ubuntu.com/ubuntu trusty-security universe
166 deb-src http://security.ubuntu.com/ubuntu trusty-security universe
167 deb http://security.ubuntu.com/ubuntu trusty-security multiverse
168 deb-src http://security.ubuntu.com/ubuntu trusty-security multiverse
172 ### FIXME: Need error handling around all this
173 do_ssh apt-get update
175 APT_TEMPFILE=$(mktemp)
176 do_ssh apt-get --print-uris -y dist-upgrade >> $APT_TEMPFILE
177 do_ssh DEBIAN_FRONTEND=noninteractive apt-get -y dist-upgrade
178 do_ssh apt-get --print-uris -y install $APT_WANTLIST >> $APT_TEMPFILE
179 do_ssh DEBIAN_FRONTEND=noninteractive apt-get -y install $APT_WANTLIST
181 ### Install qemu ($APT_WANTLIST_NESTED) separately from PPA
182 do_ssh "cat - >> /etc/apt/sources.list" <<_EOF
183 # For a custom qemu build
184 deb http://ppa.launchpad.net/syseleven-platform/virtualization/ubuntu trusty main
185 deb-src http://ppa.launchpad.net/syseleven-platform/virtualization/ubuntu trusty main
187 do_ssh apt-get --allow-unauthenticated update
188 do_ssh apt-get --print-uris --allow-unauthenticated -y install $APT_WANTLIST_NESTED >> $APT_TEMPFILE
189 do_ssh DEBIAN_FRONTEND=noninteractive apt-get --allow-unauthenticated -y install $APT_WANTLIST_NESTED
191 ### Install Java ($APT_WANTLIST_JAVA) separately from PPA
192 do_ssh "cat - >> /etc/apt/sources.list" <<_EOF
194 deb http://ppa.launchpad.net/openjdk-r/ppa/ubuntu trusty main
196 do_ssh apt-get --allow-unauthenticated update
197 do_ssh apt-get --print-uris --allow-unauthenticated -y install $APT_WANTLIST_JAVA >> $APT_TEMPFILE
198 do_ssh DEBIAN_FRONTEND=noninteractive apt-get --allow-unauthenticated -y install $APT_WANTLIST_JAVA
200 ### Install Docker ($APT_WANTLIST_DOCKER) separately from PPA
201 do_ssh "cat - >> /etc/apt/sources.list" <<_EOF
203 deb https://apt.dockerproject.org/repo ubuntu-trusty main
205 do_ssh apt-get --allow-unauthenticated update
206 do_ssh apt-get --print-uris --allow-unauthenticated -y install $APT_WANTLIST_DOCKER >> $APT_TEMPFILE
207 do_ssh DEBIAN_FRONTEND=noninteractive apt-get --allow-unauthenticated -y install $APT_WANTLIST_DOCKER
209 cat $APT_TEMPFILE | grep MD5Sum | sort > $APT_OUTPUTFILE
212 ### Get Python data. We do this by installing as per our
213 ### requirements.txt file while fetching a list of all
214 ### installed modules before and after, and then comparing.
216 PIP_TEMPFILE_BEFORE=$(mktemp)
217 PIP_TEMPFILE_AFTER=$(mktemp)
218 do_ssh "cat - > /tmp/requirements.txt" < ${PIP_REQUIREMENTS}
219 do_ssh pip list | sort > $PIP_TEMPFILE_BEFORE
220 do_ssh pip install -r /tmp/requirements.txt
221 do_ssh pip list | sort > $PIP_TEMPFILE_AFTER
223 comm -1 -3 ${PIP_TEMPFILE_BEFORE} ${PIP_TEMPFILE_AFTER} | \
224 sed -e 's/\(.*\) (\(.*\))/\1==\2/' > $PIP_OUTPUTFILE
225 rm -f $PIP_TEMPFILE_BEFORE
226 rm -f $PIP_TEMPFILE_AFTER
229 ### Stop VIRL session
231 virl_std_client -u ${VIRL_USER} -p ${VIRL_PASSWORD} simengine-stop --session ${id}