Skip to content

Commit 8c2ce6e

Browse files
author
Dean Troyer
committed
Virtual environment groundwork
Introduce the tooling to build virtual environments. * tools/build_venv.sh: build a venv * introduce lib/stack to house functionality extracted from stack.sh that is needed in other places, such as Grenade; start with stack_install_service to wrap the venv install mechanics * declare PROJECT_VENV array to track where project venvs should be installed * create a venv for each project defined in PROJECT_VENV in stack_install_service() Change-Id: I508588c0e2541b976dd94569d44b61dd2c35c01c
1 parent b1d8e8e commit 8c2ce6e

File tree

5 files changed

+108
-11
lines changed

5 files changed

+108
-11
lines changed

clean.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ if [[ -n "$SCREEN_LOGDIR" ]] && [[ -d "$SCREEN_LOGDIR" ]]; then
120120
fi
121121

122122
# Clean up venvs
123-
DIRS_TO_CLEAN="$WHEELHOUSE"
123+
DIRS_TO_CLEAN="$WHEELHOUSE ${PROJECT_VENV[@]}"
124124
rm -rf $DIRS_TO_CLEAN
125125

126126
# Clean up files

inc/python

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ INC_PY_TRACE=$(set +o | grep xtrace)
1515
set +o xtrace
1616

1717

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+
1825
# Python Functions
1926
# ================
2027

@@ -105,7 +112,6 @@ function pip_install {
105112
-r $test_req
106113
fi
107114
fi
108-
$xtrace
109115
}
110116

111117
# get version of a package from global requirements file

lib/stack

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
#
3+
# lib/stack
4+
#
5+
# These functions are code snippets pulled out of stack.sh for easier
6+
# re-use by Grenade. They can assume the same environment is available
7+
# as in the lower part of stack.sh, namely a valid stackrc has been sourced
8+
# as well as all of the lib/* files for the services have been sourced.
9+
#
10+
# For clarity, all functions declared here that came from ``stack.sh``
11+
# shall be named with the prefix ``stack_``.
12+
13+
14+
# Generic service install handles venv creation if confgured for service
15+
# stack_install_service service
16+
function stack_install_service {
17+
local service=$1
18+
if type install_${service} >/dev/null 2>&1; then
19+
if [[ -n ${PROJECT_VENV[$service]:-} ]]; then
20+
rm -rf ${PROJECT_VENV[$service]}
21+
source tools/build_venv.sh ${PROJECT_VENV[$service]}
22+
export PIP_VIRTUAL_ENV=${PROJECT_VENV[$service]:-}
23+
fi
24+
install_${service}
25+
if [[ -n ${PROJECT_VENV[$service]:-} ]]; then
26+
unset PIP_VIRTUAL_ENV
27+
fi
28+
fi
29+
}

stack.sh

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ source $TOP_DIR/functions
9494
# Import config functions
9595
source $TOP_DIR/lib/config
9696

97+
# Import 'public' stack.sh functions
98+
source $TOP_DIR/lib/stack
99+
97100
# Determine what system we are running on. This provides ``os_VENDOR``,
98101
# ``os_RELEASE``, ``os_UPDATE``, ``os_PACKAGE``, ``os_CODENAME``
99102
# and ``DISTRO``
@@ -742,13 +745,13 @@ fi
742745

743746
if is_service_enabled keystone; then
744747
if [ "$KEYSTONE_AUTH_HOST" == "$SERVICE_HOST" ]; then
745-
install_keystone
748+
stack_install_service keystone
746749
configure_keystone
747750
fi
748751
fi
749752

750753
if is_service_enabled s-proxy; then
751-
install_swift
754+
stack_install_service swift
752755
configure_swift
753756

754757
# swift3 middleware to provide S3 emulation to Swift
@@ -762,23 +765,23 @@ fi
762765

763766
if is_service_enabled g-api n-api; then
764767
# image catalog service
765-
install_glance
768+
stack_install_service glance
766769
configure_glance
767770
fi
768771

769772
if is_service_enabled cinder; then
770-
install_cinder
773+
stack_install_service cinder
771774
configure_cinder
772775
fi
773776

774777
if is_service_enabled neutron; then
775-
install_neutron
778+
stack_install_service neutron
776779
install_neutron_third_party
777780
fi
778781

779782
if is_service_enabled nova; then
780783
# compute service
781-
install_nova
784+
stack_install_service nova
782785
cleanup_nova
783786
configure_nova
784787
fi
@@ -787,19 +790,19 @@ if is_service_enabled horizon; then
787790
# django openstack_auth
788791
install_django_openstack_auth
789792
# dashboard
790-
install_horizon
793+
stack_install_service horizon
791794
configure_horizon
792795
fi
793796

794797
if is_service_enabled ceilometer; then
795798
install_ceilometerclient
796-
install_ceilometer
799+
stack_install_service ceilometer
797800
echo_summary "Configuring Ceilometer"
798801
configure_ceilometer
799802
fi
800803

801804
if is_service_enabled heat; then
802-
install_heat
805+
stack_install_service heat
803806
install_heat_other
804807
cleanup_heat
805808
configure_heat

tools/build_venv.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env bash
2+
#
3+
# **tools/build_venv.sh** - Build a Python Virtual Envirnment
4+
#
5+
# build_venv.sh venv-path [package [...]]
6+
#
7+
# Assumes:
8+
# - a useful pip is installed
9+
# - virtualenv will be installed by pip
10+
# - installs basic common prereq packages that require compilation
11+
# to allow quick copying of resulting venv as a baseline
12+
13+
14+
VENV_DEST=${1:-.venv}
15+
shift
16+
17+
MORE_PACKAGES="$@"
18+
19+
# If TOP_DIR is set we're being sourced rather than running stand-alone
20+
# or in a sub-shell
21+
if [[ -z "$TOP_DIR" ]]; then
22+
23+
set -o errexit
24+
set -o nounset
25+
26+
# Keep track of the devstack directory
27+
TOP_DIR=$(cd $(dirname "$0")/.. && pwd)
28+
FILES=$TOP_DIR/files
29+
30+
# Import common functions
31+
source $TOP_DIR/functions
32+
33+
GetDistro
34+
35+
source $TOP_DIR/stackrc
36+
37+
trap err_trap ERR
38+
39+
fi
40+
41+
# Exit on any errors so that errors don't compound
42+
function err_trap {
43+
local r=$?
44+
set +o xtrace
45+
46+
rm -rf $TMP_VENV_PATH
47+
48+
exit $r
49+
}
50+
51+
# Build new venv
52+
virtualenv $VENV_DEST
53+
54+
# Install modern pip
55+
$VENV_DEST/bin/pip install -U pip
56+
57+
for pkg in ${MORE_PACKAGES}; do
58+
pip_install_venv $VENV_DEST $pkg
59+
done

0 commit comments

Comments
 (0)