ovsdbapp/tools/debug_venv
Terry Wilson ed2184fad8 Add ability to debug OVS virtual environments
When writing tests, it is useful to be able to look at the database
being modified. Since we use OVS virtual environments and delete
them when the test ends, this is difficult to do.

This patch adds the ability to pass KEEP_ENV=1 when running tox to
keep the virtual environment around and adds tools/debug_venv to
launch an OVS sandbox using the OVS virtual environment.

Change-Id: Idbec2d544d913ffa8888a050b8a53d016c0315f2
2017-07-13 19:51:31 +00:00

64 lines
1.7 KiB
Bash
Executable File

#!/bin/sh
# Use a shell script to launch tools/debub_venv.py so that we can enter a
# virtual environment if we are not already in one
for option;do
if test -n "$prev";then
eval $prev=\$option
prev=
continue
fi
case $option in
-v)
if [ -n "$VIRTUAL_ENV" ]; then
echo "Already in a virtual environment" 1>&2
exit 1
fi
prev=venv ;;
-o)
prev=ovsvenv ;;
-h|--help)
cat << EOF
debug_venv: debug a test OVS virtual environment
usage: debug_venv [-v virtualenv] [-o ovsvenv | test_regex]"
Options:
-v The Python virtualenv to enter (defaults to 'functional')
-o The OVS virtual environment directory (precludes test_regex)
test_regex An optionsal regular expression matching the test name to debug
EOF
exit ;;
*)
if test -z "$regex";then
regex=$option
else
echo "Only one regex" 1>&2
exit 1
fi
esac
done
if [ -z "$regex" -a -z "$ovsvenv" ]; then
echo "Need regex or ovsvenv" 1>&2
exit 1
fi
if [ -z "$VIRTUAL_ENV" ]; then
. .tox/${venv:-functional}/bin/activate
trap deactivate EXIT
fi
if [ -n "$regex" -a -z "$ovsvenv" ]; then
# Just do the first match for now
lookup=$(grep $regex $VIRTUAL_ENV/ovsvenv.*|head -1)
if [ -z "$lookup" ]; then
echo "Could not match $regex" 1>&2
exit 1
fi
test_file=$(echo $lookup|cut -d: -f1)
test_match=", matched $(echo $lookup|rev|cut -d: -f1|rev)"
ovsvenv=$(head -1 $test_file)
fi
echo "Debugging OVS virtual environment: $ovsvenv$test_match"
tools/debug_venv.py $ovsvenv $VIRTUAL_ENV/src/ovs