support reloctable venv roots in testing framework

run_tests.sh, with_venv.sh, and the install_venv.py scripts now
support relocating the venv root to another location.

All 3 scripts now support new envinroment variables to configure
the location of the venv and the tools directory. To maintain
compatability the defaults are set to the current values.

venv_path = Location of the virtualenv directory
	Default: $(pwd)

venv_name = Name of the virtualenv directory
	Default: .venv

tools_path = Location of the tools directory
	Default: $(pwd)

Additionally the run_tests.sh script also takes these value as
arguments and will pass them along accordingly.

--virtual-env-path <path>   Location of the virtualenv directory
                             Default: $(pwd)
--virtual-env-name <name>   Name of the virtualenv directory
                             Default: .venv
--tools-path <dir>          Location of the tools directory
                             Default: $(pwd)

DocImpact

Change-Id: I1be036058227206ecca342f692cd3d6aadb24069
Fixes: bug #1116942
This commit is contained in:
Chet Burgess 2013-02-06 04:36:34 +00:00
parent 08499b9c2d
commit 4c891b9243
3 changed files with 76 additions and 38 deletions

View File

@ -6,17 +6,23 @@ function usage {
echo "Usage: $0 [OPTION]..." echo "Usage: $0 [OPTION]..."
echo "Run Nova's test suite(s)" echo "Run Nova's test suite(s)"
echo "" echo ""
echo " -V, --virtual-env Always use virtualenv. Install automatically if not present" echo " -V, --virtual-env Always use virtualenv. Install automatically if not present"
echo " -N, --no-virtual-env Don't use virtualenv. Run tests in local environment" echo " -N, --no-virtual-env Don't use virtualenv. Run tests in local environment"
echo " -s, --no-site-packages Isolate the virtualenv from the global Python environment" echo " -s, --no-site-packages Isolate the virtualenv from the global Python environment"
echo " -r, --recreate-db Recreate the test database (deprecated, as this is now the default)." echo " -r, --recreate-db Recreate the test database (deprecated, as this is now the default)."
echo " -n, --no-recreate-db Don't recreate the test database." echo " -n, --no-recreate-db Don't recreate the test database."
echo " -f, --force Force a clean re-build of the virtual environment. Useful when dependencies have been added." echo " -f, --force Force a clean re-build of the virtual environment. Useful when dependencies have been added."
echo " -p, --pep8 Just run PEP8 and HACKING compliance check" echo " -p, --pep8 Just run PEP8 and HACKING compliance check"
echo " -P, --no-pep8 Don't run static code checks" echo " -P, --no-pep8 Don't run static code checks"
echo " -c, --coverage Generate coverage report" echo " -c, --coverage Generate coverage report"
echo " -h, --help Print this usage message" echo " -h, --help Print this usage message"
echo " --hide-elapsed Don't print the elapsed time for each test along with slow test list" echo " --hide-elapsed Don't print the elapsed time for each test along with slow test list"
echo " --virtual-env-path <path> Location of the virtualenv directory"
echo " Default: \$(pwd)"
echo " --virtual-env-name <name> Name of the virtualenv directory"
echo " Default: .venv"
echo " --tools-path <dir> Location of the tools directory"
echo " Default: \$(pwd)"
echo "" echo ""
echo "Note: with no options specified, the script will try to run the tests in a virtual environment," echo "Note: with no options specified, the script will try to run the tests in a virtual environment,"
echo " If no virtualenv is found, the script will ask if you would like to create one. If you " echo " If no virtualenv is found, the script will ask if you would like to create one. If you "
@ -24,24 +30,43 @@ function usage {
exit exit
} }
function process_option { function process_options {
case "$1" in i=1
-h|--help) usage;; while [ $i -le $# ]; do
-V|--virtual-env) always_venv=1; never_venv=0;; FOO=${!i}
-N|--no-virtual-env) always_venv=0; never_venv=1;; case "${!i}" in
-s|--no-site-packages) no_site_packages=1;; -h|--help) usage;;
-r|--recreate-db) recreate_db=1;; -V|--virtual-env) always_venv=1; never_venv=0;;
-n|--no-recreate-db) recreate_db=0;; -N|--no-virtual-env) always_venv=0; never_venv=1;;
-f|--force) force=1;; -s|--no-site-packages) no_site_packages=1;;
-p|--pep8) just_pep8=1;; -r|--recreate-db) recreate_db=1;;
-P|--no-pep8) no_pep8=1;; -n|--no-recreate-db) recreate_db=0;;
-c|--coverage) coverage=1;; -f|--force) force=1;;
-*) testropts="$testropts $1";; -p|--pep8) just_pep8=1;;
*) testrargs="$testrargs $1" -P|--no-pep8) no_pep8=1;;
esac -c|--coverage) coverage=1;;
--virtual-env-path)
(( i++ ))
venv_path=${!i}
;;
--virtual-env-name)
(( i++ ))
venv_dir=${!i}
;;
--tools-path)
(( i++ ))
tools_path=${!i}
;;
-*) testropts="$testropts $1";;
*) testrargs="$testrargs $1"
esac
(( i++ ))
done
} }
venv=.venv tool_path=${tools_path:-$(pwd)}
venv_path=${venv_path:-$(pwd)}
venv_dir=${venv_name:-.venv}
with_venv=tools/with_venv.sh with_venv=tools/with_venv.sh
always_venv=0 always_venv=0
never_venv=0 never_venv=0
@ -60,9 +85,13 @@ LANG=en_US.UTF-8
LANGUAGE=en_US:en LANGUAGE=en_US:en
LC_ALL=C LC_ALL=C
for arg in "$@"; do process_options $@
process_option $arg # Make our paths available to other scripts we call
done export venv_path
export venv_dir
export venv_name
export tools_dir
export venv=${venv_path}/${venv_dir}
if [ $no_site_packages -eq 1 ]; then if [ $no_site_packages -eq 1 ]; then
installvenvopts="--no-site-packages" installvenvopts="--no-site-packages"

View File

@ -28,7 +28,7 @@ os.sys.path.insert(0, parentdir)
import install_venv_common as install_venv import install_venv_common as install_venv
def print_help(): def print_help(venv, root):
help = """ help = """
Nova development environment setup is complete. Nova development environment setup is complete.
@ -38,21 +38,27 @@ def print_help():
To activate the Nova virtualenv for the extent of your current shell To activate the Nova virtualenv for the extent of your current shell
session you can run: session you can run:
$ source .venv/bin/activate $ source %s/bin/activate
Or, if you prefer, you can run commands in the virtualenv on a case by case Or, if you prefer, you can run commands in the virtualenv on a case by case
basis by running: basis by running:
$ tools/with_venv.sh <your command> $ %s/tools/with_venv.sh <your command>
Also, make test will automatically use the virtualenv. Also, make test will automatically use the virtualenv.
""" """
print help print help % (venv, root)
def main(argv): def main(argv):
root = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
if os.environ.get('tools_path'):
root = os.environ['tools_path']
venv = os.path.join(root, '.venv') venv = os.path.join(root, '.venv')
if os.environ.get('venv'):
venv = os.environ['venv']
pip_requires = os.path.join(root, 'tools', 'pip-requires') pip_requires = os.path.join(root, 'tools', 'pip-requires')
test_requires = os.path.join(root, 'tools', 'test-requires') test_requires = os.path.join(root, 'tools', 'test-requires')
py_version = "python%s.%s" % (sys.version_info[0], sys.version_info[1]) py_version = "python%s.%s" % (sys.version_info[0], sys.version_info[1])
@ -65,7 +71,7 @@ def main(argv):
install.create_virtualenv(no_site_packages=options.no_site_packages) install.create_virtualenv(no_site_packages=options.no_site_packages)
install.install_dependencies() install.install_dependencies()
install.post_process() install.post_process()
print_help() print_help(venv, root)
if __name__ == '__main__': if __name__ == '__main__':
main(sys.argv) main(sys.argv)

View File

@ -1,4 +1,7 @@
#!/bin/bash #!/bin/bash
TOOLS=`dirname $0` tools_path=${tools_path:-$(dirname $0)}
VENV=$TOOLS/../.venv venv_path=${venv_path:-${tools_path}}
source $VENV/bin/activate && "$@" venv_dir=${venv_name:-/../.venv}
TOOLS=${tools_path}
VENV=${venv:-${venv_path}/${venv_dir}}
source ${VENV}/bin/activate && "$@"