blob: 7262cff63dfcbed1ec47a0da2bf68251dbf5c9c9 [file] [log] [blame]
Dean Troyer07c35572012-03-05 07:15:30 -06001Contributing to DevStack
2========================
3
4
5General
6-------
7
8DevStack is written in POSIX shell script. This choice was made because
9it best illustrates the configuration steps that this implementation takes
10on setting up and interacting with OpenStack components. DevStack specifies
11BASH and is compatible with Bash 3.
12
13DevStack's official repository is located on GitHub at
14https://github.com/openstack-dev/devstack.git. Besides the master branch that
15tracks the OpenStack trunk branches a separate branch is maintained for all
16OpenStack releases starting with Diablo (stable/diablo).
17
18The primary script in DevStack is ``stack.sh``, which performs the bulk of the
19work for DevStack's use cases. There is a subscript ``functions`` that contains
20generally useful shell functions and is used by a number of the scripts in
21DevStack.
22
23A number of additional scripts can be found in the ``tools`` directory that may
24be useful in setting up special-case uses of DevStack. These include: bare metal
25deployment, ramdisk deployment and Jenkins integration.
26
27
28Scripts
29-------
30
31DevStack scripts should generally begin by calling ``env(1)`` in the shebang line::
32
33 #!/usr/bin/env bash
34
35Sometimes the script needs to know the location of the DevStack install directory.
36``TOP_DIR`` should always point there, even if the script itself is located in
37a subdirectory::
38
39 # Keep track of the current devstack directory.
40 TOP_DIR=$(cd $(dirname "$0") && pwd)
41
42Many scripts will utilize shared functions from the ``functions`` file. There are
43also rc files (``stackrc`` and ``openrc``) that are often included to set the primary
44configuration of the user environment::
45
Dean Troyer51fb4542012-03-09 22:21:59 -060046 # Keep track of the current devstack directory.
47 TOP_DIR=$(cd $(dirname "$0") && pwd)
Dean Troyer07c35572012-03-05 07:15:30 -060048
49 # Import common functions
Dean Troyer51fb4542012-03-09 22:21:59 -060050 source $TOP_DIR/functions
Dean Troyer07c35572012-03-05 07:15:30 -060051
52 # Import configuration
Dean Troyer51fb4542012-03-09 22:21:59 -060053 source $TOP_DIR/openrc
Dean Troyer07c35572012-03-05 07:15:30 -060054
55``stack.sh`` is a rather large monolithic script that flows through from beginning
56to end. There is a proposal to segment it to put the OpenStack projects
57into their own sub-scripts to better document the projects as a unit rather than
58have it scattered throughout ``stack.sh``. Someday.
59
60
61Documentation
62-------------
63
64The official DevStack repo on GitHub does not include a gh-pages branch that
65GitHub uses to create static web sites. That branch is maintained in the
66`CloudBuilders DevStack repo`__ mirror that supports the
67http://devstack.org site. This is the primary DevStack
68documentation along with the DevStack scripts themselves.
69
70__ repo_
71.. _repo: https://github.com/cloudbuilders/devstack
72
73All of the scripts are processed with shocco_ to render them with the comments
74as text describing the script below. For this reason we tend to be a little
75verbose in the comments _ABOVE_ the code they pertain to. Shocco also supports
76Markdown formatting in the comments; use it sparingly. Specifically, ``stack.sh``
77uses Markdown headers to divide the script into logical sections.
78
79.. _shocco: http://rtomayko.github.com/shocco/
80
81
82Exercises
83---------
84
85The scripts in the exercises directory are meant to 1) perform basic operational
86checks on certain aspects of OpenStack; and b) document the use of the
87OpenStack command-line clients.
88
89In addition to the guidelines above, exercise scripts MUST follow the structure
90outlined here. ``swift.sh`` is perhaps the clearest example of these guidelines.
91These scripts are executed serially by ``exercise.sh`` in testing situations.
92
93* Begin and end with a banner that stands out in a sea of script logs to aid
94 in debugging failures, particularly in automated testing situations. If the
95 end banner is not displayed, the script ended prematurely and can be assumed
96 to have failed.
97
98 ::
99
100 echo "**************************************************"
101 echo "Begin DevStack Exercise: $0"
102 echo "**************************************************"
103 ...
104 set +o xtrace
105 echo "**************************************************"
106 echo "End DevStack Exercise: $0"
107 echo "**************************************************"
108
109* The scripts will generally have the shell ``xtrace`` attribute set to display
110 the actual commands being executed, and the ``errexit`` attribute set to exit
111 the script on non-zero exit codes::
112
113 # This script exits on an error so that errors don't compound and you see
114 # only the first error that occured.
115 set -o errexit
116
117 # Print the commands being run so that we can see the command that triggers
118 # an error. It is also useful for following allowing as the install occurs.
119 set -o xtrace
120
Dean Troyer51fb4542012-03-09 22:21:59 -0600121* Settings and configuration are stored in ``exerciserc``, which must be
122 sourced after ``openrc`` or ``stackrc``::
123
124 # Import exercise configuration
125 source $TOP_DIR/exerciserc
126
Dean Troyer07c35572012-03-05 07:15:30 -0600127* There are a couple of helper functions in the common ``functions`` sub-script
128 that will check for non-zero exit codes and unset environment variables and
129 print a message and exit the script. These should be called after most client
130 commands that are not otherwise checked to short-circuit long timeouts
131 (instance boot failure, for example)::
132
133 swift post $CONTAINER
134 die_if_error "Failure creating container $CONTAINER"
135
136 FLOATING_IP=`euca-allocate-address | cut -f2`
137 die_if_not_set FLOATING_IP "Failure allocating floating IP"
138
Chmouel Boudjnah408b0092012-03-15 23:21:55 +0000139* If you want an exercise to be skipped when for example a service wasn't
140 enabled for the exercise to be run, you can exit your exercise with the
141 special exitcode 55 and it will be detected as skipped.
142
Dean Troyer07c35572012-03-05 07:15:30 -0600143* The exercise scripts should only use the various OpenStack client binaries to
144 interact with OpenStack. This specifically excludes any ``*-manage`` tools
145 as those assume direct access to configuration and databases, as well as direct
146 database access from the exercise itself.
147
148* If specific configuration needs to be present for the exercise to complete,
149 it should be staged in ``stack.sh``, or called from ``stack.sh`` (see
150 ``files/keystone_data.sh`` for an example of this).
151
152* The ``OS_*`` environment variables should be the only ones used for all
153 authentication to OpenStack clients as documented in the CLIAuth_ wiki page.
154
155.. _CLIAuth: http://wiki.openstack.org/CLIAuth
156
157* The exercise MUST clean up after itself if successful. If it is not successful,
158 it is assumed that state will be left behind; this allows a chance for developers
159 to look around and attempt to debug the problem. The exercise SHOULD clean up
160 or graciously handle possible artifacts left over from previous runs if executed
161 again. It is acceptable to require a reboot or even a re-install of DevStack
162 to restore a clean test environment.