onos/tools/dev/p4vm/export-ova.sh
Carmelo Cascone a4dc3c12bc Update install-p4-tools.sh to use P4Runtime v1.0
Includes also various improvements to the p4vm scripts, such as:
- Choose to build VM with Ubuntu 16.04 or 18.04 (experimental)
- Allow users to specify version of protobuf and grpc to use
- Avoid building protobuf and grpc if already installed in the system
- Install Bazel 0.22

Also:
- Remove check for invalid group member weights (now PI always returns
members with weight 1)
- Re-compiled all P4 programs and fixed missing padding in controller
packet headers

Change-Id: I0e672fcebbaba63354c749f0c774af251f3cbc6c
2019-02-21 23:24:26 +00:00

64 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -xe
VM_TYPE=${P4_VM_TYPE:-dev}
function wait_vm_shutdown {
set +x
while vboxmanage showvminfo $1 | grep -c "running (since"; do
echo "Waiting for VM to shutdown..."
sleep 1
done
sleep 2
set -x
}
function wait_for_tcp_port {
set +x
while ! nc -z $1 $2; do
echo "Waiting for TCP port $2 on $1 to be open..."
sleep 1
done
sleep 2
set -x
}
# Remove references to the existing vagrant-built VM (if any).
# We want to build a new one from scratch, not start an existing one.
rm -rf .vagrant/
vagrant box update
vagrant up
SSH_PORT=`vagrant port --guest 22`
VB_UUID=`cat .vagrant/machines/default/virtualbox/id`
# Take snapshot before cleanup for local use
# e.g. to avoid re-building P4 tools from scratch
vboxmanage controlvm ${VB_UUID} acpipowerbutton
wait_vm_shutdown ${VB_UUID}
VBoxManage snapshot ${VB_UUID} take "pre-cleanup"
# Cleanup
vagrant up
# SSH port forwarding might change after vagrant up.
SSH_PORT=`vagrant port --guest 22`
wait_for_tcp_port 127.0.0.1 ${SSH_PORT}
sshpass -p 'rocks' \
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \
-p ${SSH_PORT} sdn@127.0.0.1 "bash /vagrant/pre-ova-cleanup.sh"
sleep 5
vboxmanage controlvm ${VB_UUID} acpipowerbutton
wait_vm_shutdown ${VB_UUID}
# Remove vagrant shared folder
vboxmanage sharedfolder remove ${VB_UUID} -name "vagrant"
rm -f onos-p4-${VM_TYPE}.ova
vboxmanage export ${VB_UUID} -o onos-p4-${VM_TYPE}.ova
sleep 1
vboxmanage snapshot ${VB_UUID} restore pre-cleanup
sleep 1
vboxmanage snapshot ${VB_UUID} delete pre-cleanup