Browse code

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

Dean Troyer authored on 2015/03/10 04:27:51
Showing 8 changed files
... ...
@@ -170,6 +170,30 @@ Libraries from Git
170 170
 
171 171
       LIBS_FROM_GIT=python-keystoneclient,oslo.config
172 172
 
173
+Virtual Environments
174
+--------------------
175
+
176
+  | *Default: ``USE_VENV=False``*
177
+  |   Enable the use of Python virtual environments by setting ``USE_VENV``
178
+      to ``True``.  This will enable the creation of venvs for each project
179
+      that is defined in the ``PROJECT_VENV`` array.
180
+
181
+  | *Default: ``PROJECT_VENV['<project>']='<project-dir>.venv'*
182
+  |   Each entry in the ``PROJECT_VENV`` array contains the directory name
183
+      of a venv to be used for the project.  The array index is the project
184
+      name.  Multiple projects can use the same venv if desired.
185
+
186
+  ::
187
+
188
+    PROJECT_VENV["glance"]=${GLANCE_DIR}.venv
189
+
190
+  | *Default: ``ADDITIONAL_VENV_PACKAGES=""``*
191
+  |   A comma-separated list of additional packages to be installed into each
192
+      venv.  Often projects will not have certain packages listed in its
193
+      ``requirements.txt`` file because they are 'optional' requirements,
194
+      i.e. only needed for certain configurations.  By default, the enabled
195
+      databases will have their Python bindings added when they are enabled.
196
+
173 197
 Enable Logging
174 198
 --------------
175 199
 
... ...
@@ -210,6 +210,8 @@ Tools
210 210
 -----
211 211
 
212 212
 * `tools/build\_docs.sh <tools/build_docs.sh.html>`__
213
+* `tools/build\_venv.sh <tools/build_venv.sh.html>`__
214
+* `tools/build\_wheels.sh <tools/build_wheels.sh.html>`__
213 215
 * `tools/create-stack-user.sh <tools/create-stack-user.sh.html>`__
214 216
 * `tools/create\_userrc.sh <tools/create_userrc.sh.html>`__
215 217
 * `tools/fixup\_stuff.sh <tools/fixup_stuff.sh.html>`__
... ...
@@ -109,6 +109,11 @@ function install_database {
109 109
     install_database_$DATABASE_TYPE
110 110
 }
111 111
 
112
+# Install the database Python packages
113
+function install_database_python {
114
+    install_database_python_$DATABASE_TYPE
115
+}
116
+
112 117
 # Configure and start the database
113 118
 function configure_database {
114 119
     configure_database_$DATABASE_TYPE
... ...
@@ -151,9 +151,12 @@ EOF
151 151
     else
152 152
         exit_distro_not_supported "mysql installation"
153 153
     fi
154
+}
154 155
 
156
+function install_database_python_mysql {
155 157
     # Install Python client module
156 158
     pip_install MySQL-python
159
+    ADDITIONAL_VENV_PACKAGES+=",MySQL-python"
157 160
 }
158 161
 
159 162
 function database_connection_url_mysql {
... ...
@@ -100,9 +100,12 @@ EOF
100 100
     else
101 101
         exit_distro_not_supported "postgresql installation"
102 102
     fi
103
+}
103 104
 
105
+function install_database_python_postgresql {
104 106
     # Install Python client module
105 107
     pip_install psycopg2
108
+    ADDITIONAL_VENV_PACKAGES+=",psycopg2"
106 109
 }
107 110
 
108 111
 function database_connection_url_postgresql {
... ...
@@ -16,13 +16,17 @@
16 16
 function stack_install_service {
17 17
     local service=$1
18 18
     if type install_${service} >/dev/null 2>&1; then
19
-        if [[ -n ${PROJECT_VENV[$service]:-} ]]; then
19
+        if [[ ${USE_VENV} = True && -n ${PROJECT_VENV[$service]:-} ]]; then
20 20
             rm -rf ${PROJECT_VENV[$service]}
21
-            source $TOP_DIR/tools/build_venv.sh ${PROJECT_VENV[$service]}
21
+            source $TOP_DIR/tools/build_venv.sh ${PROJECT_VENV[$service]} ${ADDITIONAL_VENV_PACKAGES//,/ }
22 22
             export PIP_VIRTUAL_ENV=${PROJECT_VENV[$service]:-}
23
+
24
+            # Install other OpenStack prereqs that might come from source repos
25
+            install_oslo
26
+            install_keystonemiddleware
23 27
         fi
24 28
         install_${service}
25
-        if [[ -n ${PROJECT_VENV[$service]:-} ]]; then
29
+        if [[ ${USE_VENV} = True && -n ${PROJECT_VENV[$service]:-} ]]; then
26 30
             unset PIP_VIRTUAL_ENV
27 31
         fi
28 32
     fi
... ...
@@ -702,6 +702,7 @@ install_rpc_backend
702 702
 
703 703
 if is_service_enabled $DATABASE_BACKENDS; then
704 704
     install_database
705
+    install_database_python
705 706
 fi
706 707
 
707 708
 if is_service_enabled neutron; then
... ...
@@ -104,6 +104,16 @@ elif [[ -f $RC_DIR/.localrc.auto ]]; then
104 104
     source $RC_DIR/.localrc.auto
105 105
 fi
106 106
 
107
+# Enable use of Python virtual environments.  Individual project use of
108
+# venvs are controlled by the PROJECT_VENV array; every project with
109
+# an entry in the array will be installed into the named venv.
110
+# By default this will put each project into its own venv.
111
+USE_VENV=$(trueorfalse False USE_VENV)
112
+
113
+# Add packages that need to be installed into a venv but are not in any
114
+# requirmenets files here, in a comma-separated list
115
+ADDITIONAL_VENV_PACKAGES=${ADITIONAL_VENV_PACKAGES:-""}
116
+
107 117
 # Configure wheel cache location
108 118
 export WHEELHOUSE=${WHEELHOUSE:-$DEST/.wheelhouse}
109 119
 export PIP_WHEEL_DIR=${PIP_WHEEL_DIR:-$WHEELHOUSE}