blob: 96500f2e155b6acaaedb15e89f76aa1ed4c7c1f7 [file] [log] [blame]
Carmelo Casconed6615072017-12-15 00:53:43 -08001#!/usr/bin/env bash
2
3set -xe
4
Carmelo Casconeada7b5b2019-04-23 13:50:03 -07005VM_TYPE=${1:-dev}
6USE_STRATUM=${USE_STRATUM:-false}
7STRATUM_BMV2_TAR=${STRATUM_BMV2_TAR-unknown}
8
9DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
Carmelo Casconec5569c22018-04-18 10:09:15 +090010
Carmelo Cascone57defd32018-05-11 14:34:01 -070011function wait_vm_shutdown {
12 set +x
Carmelo Casconeef715492018-05-14 19:48:46 -070013 while vboxmanage showvminfo $1 | grep -c "running (since"; do
Carmelo Cascone57defd32018-05-11 14:34:01 -070014 echo "Waiting for VM to shutdown..."
15 sleep 1
16 done
17 sleep 2
18 set -x
19}
20
Carmelo Casconeef715492018-05-14 19:48:46 -070021function wait_for_tcp_port {
22 set +x
23 while ! nc -z $1 $2; do
24 echo "Waiting for TCP port $2 on $1 to be open..."
25 sleep 1
26 done
27 sleep 2
28 set -x
29}
30
Carmelo Casconeada7b5b2019-04-23 13:50:03 -070031rm -rf ./tmp
32if [[ ${VM_TYPE} = "tutorial" ]]
33then
34 bazel build //:onos
35 bazel build //:onos-package-admin
36 rm -rf ~/.m2/repository/org/onosproject
37 cd ${ONOS_ROOT}
38 onos-publish -l
39 cd ${DIR}
40 mkdir -p ./tmp
41 cp ../../../bazel-bin/onos.tar.gz ./tmp/onos.tar.gz
42 cp ../../../bazel-bin/onos-admin.tar.gz ./tmp/onos-admin.tar.gz
43 cp ../mininet/bmv2.py ./tmp/bmv2.py
44 mv ~/.m2/repository/org/onosproject ./tmp/artifacts
45 if [[ ${USE_STRATUM} = true ]]
46 then
47 cp ${STRATUM_BMV2_TAR} ./tmp/stratum_bmv2.tar.gz
48 fi
49fi
Carmelo Casconed6615072017-12-15 00:53:43 -080050
Carmelo Casconeada7b5b2019-04-23 13:50:03 -070051# Initial provisioning if necessary.
52USE_STRATUM=${USE_STRATUM} vagrant up ${VM_TYPE}
Carmelo Casconed6615072017-12-15 00:53:43 -080053
Carmelo Casconeada7b5b2019-04-23 13:50:03 -070054rm -rf ./tmp
55
56SSH_PORT=`vagrant port --guest 22 ${VM_TYPE}`
57VB_UUID=`cat .vagrant/machines/${VM_TYPE}/virtualbox/id`
58
59if [[ ${VM_TYPE} = "dev" ]]
60then
61 # Take snapshot before cleanup for local use
62 # e.g. to avoid re-building P4 tools from scratch
63 vboxmanage controlvm ${VB_UUID} acpipowerbutton
64 wait_vm_shutdown ${VB_UUID}
65 VBoxManage snapshot ${VB_UUID} take "pre-cleanup"
66 vagrant up ${VM_TYPE}
67 # SSH port forwarding might change after vagrant up.
68 SSH_PORT=`vagrant port --guest 22 ${VM_TYPE}`
69 wait_for_tcp_port 127.0.0.1 ${SSH_PORT}
70fi
Carmelo Cascone57defd32018-05-11 14:34:01 -070071
72# Cleanup
cmo4ab984b2019-06-14 16:06:12 +080073vagrant ssh -c 'bash /vagrant/ova-cleanup.sh' ${VM_TYPE}
Carmelo Casconed6615072017-12-15 00:53:43 -080074sleep 5
Carmelo Cascone4f985cd2018-02-11 17:36:42 -080075vboxmanage controlvm ${VB_UUID} acpipowerbutton
Carmelo Cascone57defd32018-05-11 14:34:01 -070076wait_vm_shutdown ${VB_UUID}
Carmelo Casconed6615072017-12-15 00:53:43 -080077
78# Remove vagrant shared folder
79vboxmanage sharedfolder remove ${VB_UUID} -name "vagrant"
80
Carmelo Cascone57defd32018-05-11 14:34:01 -070081rm -f onos-p4-${VM_TYPE}.ova
Carmelo Casconec5569c22018-04-18 10:09:15 +090082vboxmanage export ${VB_UUID} -o onos-p4-${VM_TYPE}.ova
Carmelo Cascone57defd32018-05-11 14:34:01 -070083
Carmelo Casconeada7b5b2019-04-23 13:50:03 -070084if [[ ${VM_TYPE} = "dev" ]]
85then
86 sleep 1
87 vboxmanage snapshot ${VB_UUID} restore pre-cleanup
88 sleep 1
89 vboxmanage snapshot ${VB_UUID} delete pre-cleanup
90fi