Browse code

Merge "Virtual environment groundwork"

Jenkins authored on 2015/02/20 15:45:09
Showing 5 changed files
... ...
@@ -120,7 +120,7 @@ if [[ -n "$SCREEN_LOGDIR" ]] && [[ -d "$SCREEN_LOGDIR" ]]; then
120 120
 fi
121 121
 
122 122
 # Clean up venvs
123
-DIRS_TO_CLEAN="$WHEELHOUSE"
123
+DIRS_TO_CLEAN="$WHEELHOUSE ${PROJECT_VENV[@]}"
124 124
 rm -rf $DIRS_TO_CLEAN
125 125
 
126 126
 # Clean up files
... ...
@@ -15,6 +15,13 @@ INC_PY_TRACE=$(set +o | grep xtrace)
15 15
 set +o xtrace
16 16
 
17 17
 
18
+# Global Config Variables
19
+
20
+# PROJECT_VENV contains the name of the virtual enviromnet for each
21
+# project.  A null value installs to the system Python directories.
22
+declare -A PROJECT_VENV
23
+
24
+
18 25
 # Python Functions
19 26
 # ================
20 27
 
... ...
@@ -105,7 +112,6 @@ function pip_install {
105 105
                 -r $test_req
106 106
         fi
107 107
     fi
108
-    $xtrace
109 108
 }
110 109
 
111 110
 # get version of a package from global requirements file
112 111
new file mode 100644
... ...
@@ -0,0 +1,29 @@
0
+#!/bin/bash
1
+#
2
+# lib/stack
3
+#
4
+# These functions are code snippets pulled out of stack.sh for easier
5
+# re-use by Grenade.  They can assume the same environment is available
6
+# as in the lower part of stack.sh, namely a valid stackrc has been sourced
7
+# as well as all of the lib/* files for the services have been sourced.
8
+#
9
+# For clarity, all functions declared here that came from ``stack.sh``
10
+# shall be named with the prefix ``stack_``.
11
+
12
+
13
+# Generic service install handles venv creation if confgured for service
14
+# stack_install_service service
15
+function stack_install_service {
16
+    local service=$1
17
+    if type install_${service} >/dev/null 2>&1; then
18
+        if [[ -n ${PROJECT_VENV[$service]:-} ]]; then
19
+            rm -rf ${PROJECT_VENV[$service]}
20
+            source tools/build_venv.sh ${PROJECT_VENV[$service]}
21
+            export PIP_VIRTUAL_ENV=${PROJECT_VENV[$service]:-}
22
+        fi
23
+        install_${service}
24
+        if [[ -n ${PROJECT_VENV[$service]:-} ]]; then
25
+            unset PIP_VIRTUAL_ENV
26
+        fi
27
+    fi
28
+}
... ...
@@ -94,6 +94,9 @@ source $TOP_DIR/functions
94 94
 # Import config functions
95 95
 source $TOP_DIR/lib/config
96 96
 
97
+# Import 'public' stack.sh functions
98
+source $TOP_DIR/lib/stack
99
+
97 100
 # Determine what system we are running on.  This provides ``os_VENDOR``,
98 101
 # ``os_RELEASE``, ``os_UPDATE``, ``os_PACKAGE``, ``os_CODENAME``
99 102
 # and ``DISTRO``
... ...
@@ -742,13 +745,13 @@ fi
742 742
 
743 743
 if is_service_enabled keystone; then
744 744
     if [ "$KEYSTONE_AUTH_HOST" == "$SERVICE_HOST" ]; then
745
-        install_keystone
745
+        stack_install_service keystone
746 746
         configure_keystone
747 747
     fi
748 748
 fi
749 749
 
750 750
 if is_service_enabled s-proxy; then
751
-    install_swift
751
+    stack_install_service swift
752 752
     configure_swift
753 753
 
754 754
     # swift3 middleware to provide S3 emulation to Swift
... ...
@@ -762,23 +765,23 @@ fi
762 762
 
763 763
 if is_service_enabled g-api n-api; then
764 764
     # image catalog service
765
-    install_glance
765
+    stack_install_service glance
766 766
     configure_glance
767 767
 fi
768 768
 
769 769
 if is_service_enabled cinder; then
770
-    install_cinder
770
+    stack_install_service cinder
771 771
     configure_cinder
772 772
 fi
773 773
 
774 774
 if is_service_enabled neutron; then
775
-    install_neutron
775
+    stack_install_service neutron
776 776
     install_neutron_third_party
777 777
 fi
778 778
 
779 779
 if is_service_enabled nova; then
780 780
     # compute service
781
-    install_nova
781
+    stack_install_service nova
782 782
     cleanup_nova
783 783
     configure_nova
784 784
 fi
... ...
@@ -787,19 +790,19 @@ if is_service_enabled horizon; then
787 787
     # django openstack_auth
788 788
     install_django_openstack_auth
789 789
     # dashboard
790
-    install_horizon
790
+    stack_install_service horizon
791 791
     configure_horizon
792 792
 fi
793 793
 
794 794
 if is_service_enabled ceilometer; then
795 795
     install_ceilometerclient
796
-    install_ceilometer
796
+    stack_install_service ceilometer
797 797
     echo_summary "Configuring Ceilometer"
798 798
     configure_ceilometer
799 799
 fi
800 800
 
801 801
 if is_service_enabled heat; then
802
-    install_heat
802
+    stack_install_service heat
803 803
     install_heat_other
804 804
     cleanup_heat
805 805
     configure_heat
806 806
new file mode 100755
... ...
@@ -0,0 +1,59 @@
0
+#!/usr/bin/env bash
1
+#
2
+# **tools/build_venv.sh** - Build a Python Virtual Envirnment
3
+#
4
+# build_venv.sh venv-path [package [...]]
5
+#
6
+# Assumes:
7
+# - a useful pip is installed
8
+# - virtualenv will be installed by pip
9
+# - installs basic common prereq packages that require compilation
10
+#   to allow quick copying of resulting venv as a baseline
11
+
12
+
13
+VENV_DEST=${1:-.venv}
14
+shift
15
+
16
+MORE_PACKAGES="$@"
17
+
18
+# If TOP_DIR is set we're being sourced rather than running stand-alone
19
+# or in a sub-shell
20
+if [[ -z "$TOP_DIR" ]]; then
21
+
22
+    set -o errexit
23
+    set -o nounset
24
+
25
+    # Keep track of the devstack directory
26
+    TOP_DIR=$(cd $(dirname "$0")/.. && pwd)
27
+    FILES=$TOP_DIR/files
28
+
29
+    # Import common functions
30
+    source $TOP_DIR/functions
31
+
32
+    GetDistro
33
+
34
+    source $TOP_DIR/stackrc
35
+
36
+    trap err_trap ERR
37
+
38
+fi
39
+
40
+# Exit on any errors so that errors don't compound
41
+function err_trap {
42
+    local r=$?
43
+    set +o xtrace
44
+
45
+    rm -rf $TMP_VENV_PATH
46
+
47
+    exit $r
48
+}
49
+
50
+# Build new venv
51
+virtualenv $VENV_DEST
52
+
53
+# Install modern pip
54
+$VENV_DEST/bin/pip install -U pip
55
+
56
+for pkg in ${MORE_PACKAGES}; do
57
+    pip_install_venv $VENV_DEST $pkg
58
+done