From 5686dbc45dbdc552080592e31bed63b0f201717e Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Mon, 9 Mar 2015 14:27:51 -0500 Subject: [PATCH] Add global venv enable/disable knob Adds USE_VENV to globally enable/disable use of virtual environments. ADDITIONAL_VENV_PACKAGES is used to manually add packages that do not appear in requirements.txt or test-requirements.txt to be installed into each venv. Database Python bindings are handled this way when a dataabse service is enabled. Change-Id: I9cf298b936fd10c95e2ce5f51aab0d49d4b7f37f --- doc/source/configuration.rst | 24 ++++++++++++++++++++++++ doc/source/index.rst | 2 ++ lib/database | 5 +++++ lib/databases/mysql | 3 +++ lib/databases/postgresql | 3 +++ lib/stack | 10 +++++++--- stack.sh | 1 + stackrc | 10 ++++++++++ 8 files changed, 55 insertions(+), 3 deletions(-) diff --git a/doc/source/configuration.rst b/doc/source/configuration.rst index 7d06658ee2..05a21cde5c 100644 --- a/doc/source/configuration.rst +++ b/doc/source/configuration.rst @@ -170,6 +170,30 @@ Libraries from Git LIBS_FROM_GIT=python-keystoneclient,oslo.config +Virtual Environments +-------------------- + + | *Default: ``USE_VENV=False``* + | Enable the use of Python virtual environments by setting ``USE_VENV`` + to ``True``. This will enable the creation of venvs for each project + that is defined in the ``PROJECT_VENV`` array. + + | *Default: ``PROJECT_VENV['']='.venv'* + | Each entry in the ``PROJECT_VENV`` array contains the directory name + of a venv to be used for the project. The array index is the project + name. Multiple projects can use the same venv if desired. + + :: + + PROJECT_VENV["glance"]=${GLANCE_DIR}.venv + + | *Default: ``ADDITIONAL_VENV_PACKAGES=""``* + | A comma-separated list of additional packages to be installed into each + venv. Often projects will not have certain packages listed in its + ``requirements.txt`` file because they are 'optional' requirements, + i.e. only needed for certain configurations. By default, the enabled + databases will have their Python bindings added when they are enabled. + Enable Logging -------------- diff --git a/doc/source/index.rst b/doc/source/index.rst index bac593de03..d98e573dcc 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -210,6 +210,8 @@ Tools ----- * `tools/build\_docs.sh `__ +* `tools/build\_venv.sh `__ +* `tools/build\_wheels.sh `__ * `tools/create-stack-user.sh `__ * `tools/create\_userrc.sh `__ * `tools/fixup\_stuff.sh `__ diff --git a/lib/database b/lib/database index b114e9e4f6..ff1fafee26 100644 --- a/lib/database +++ b/lib/database @@ -109,6 +109,11 @@ function install_database { install_database_$DATABASE_TYPE } +# Install the database Python packages +function install_database_python { + install_database_python_$DATABASE_TYPE +} + # Configure and start the database function configure_database { configure_database_$DATABASE_TYPE diff --git a/lib/databases/mysql b/lib/databases/mysql index 70073c4c6f..d548db103e 100644 --- a/lib/databases/mysql +++ b/lib/databases/mysql @@ -151,9 +151,12 @@ EOF else exit_distro_not_supported "mysql installation" fi +} +function install_database_python_mysql { # Install Python client module pip_install MySQL-python + ADDITIONAL_VENV_PACKAGES+=",MySQL-python" } function database_connection_url_mysql { diff --git a/lib/databases/postgresql b/lib/databases/postgresql index e891a08754..a6bcf8c0a2 100644 --- a/lib/databases/postgresql +++ b/lib/databases/postgresql @@ -100,9 +100,12 @@ EOF else exit_distro_not_supported "postgresql installation" fi +} +function install_database_python_postgresql { # Install Python client module pip_install psycopg2 + ADDITIONAL_VENV_PACKAGES+=",psycopg2" } function database_connection_url_postgresql { diff --git a/lib/stack b/lib/stack index 9a509d8318..11dd87ca28 100644 --- a/lib/stack +++ b/lib/stack @@ -16,13 +16,17 @@ function stack_install_service { local service=$1 if type install_${service} >/dev/null 2>&1; then - if [[ -n ${PROJECT_VENV[$service]:-} ]]; then + if [[ ${USE_VENV} = True && -n ${PROJECT_VENV[$service]:-} ]]; then rm -rf ${PROJECT_VENV[$service]} - source $TOP_DIR/tools/build_venv.sh ${PROJECT_VENV[$service]} + source $TOP_DIR/tools/build_venv.sh ${PROJECT_VENV[$service]} ${ADDITIONAL_VENV_PACKAGES//,/ } export PIP_VIRTUAL_ENV=${PROJECT_VENV[$service]:-} + + # Install other OpenStack prereqs that might come from source repos + install_oslo + install_keystonemiddleware fi install_${service} - if [[ -n ${PROJECT_VENV[$service]:-} ]]; then + if [[ ${USE_VENV} = True && -n ${PROJECT_VENV[$service]:-} ]]; then unset PIP_VIRTUAL_ENV fi fi diff --git a/stack.sh b/stack.sh index d83952accc..9d4a2061ef 100755 --- a/stack.sh +++ b/stack.sh @@ -702,6 +702,7 @@ install_rpc_backend if is_service_enabled $DATABASE_BACKENDS; then install_database + install_database_python fi if is_service_enabled neutron; then diff --git a/stackrc b/stackrc index 02b12a36a0..3c4593a27f 100644 --- a/stackrc +++ b/stackrc @@ -104,6 +104,16 @@ elif [[ -f $RC_DIR/.localrc.auto ]]; then source $RC_DIR/.localrc.auto fi +# Enable use of Python virtual environments. Individual project use of +# venvs are controlled by the PROJECT_VENV array; every project with +# an entry in the array will be installed into the named venv. +# By default this will put each project into its own venv. +USE_VENV=$(trueorfalse False USE_VENV) + +# Add packages that need to be installed into a venv but are not in any +# requirmenets files here, in a comma-separated list +ADDITIONAL_VENV_PACKAGES=${ADITIONAL_VENV_PACKAGES:-""} + # Configure wheel cache location export WHEELHOUSE=${WHEELHOUSE:-$DEST/.wheelhouse} export PIP_WHEEL_DIR=${PIP_WHEEL_DIR:-$WHEELHOUSE}