blob: 6ad8c7e638c3601df2917668637683203284ee32 [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
Dean Troyer6d04fd72012-12-21 11:03:37 -060018Contributing code to DevStack follows the usual OpenStack process as described
19in `How To Contribute`__ in the OpenStack wiki. `DevStack's LaunchPad project`__
20contains the usual links for blueprints, bugs, tec.
21
22__ contribute_
23.. _contribute: http://wiki.openstack.org/HowToContribute.
24
25__ lp_
26.. _lp: https://launchpad.net/~devstack
27
Dean Troyer07c35572012-03-05 07:15:30 -060028The primary script in DevStack is ``stack.sh``, which performs the bulk of the
29work for DevStack's use cases. There is a subscript ``functions`` that contains
30generally useful shell functions and is used by a number of the scripts in
31DevStack.
32
33A number of additional scripts can be found in the ``tools`` directory that may
34be useful in setting up special-case uses of DevStack. These include: bare metal
35deployment, ramdisk deployment and Jenkins integration.
36
37
38Scripts
39-------
40
41DevStack scripts should generally begin by calling ``env(1)`` in the shebang line::
42
43 #!/usr/bin/env bash
44
45Sometimes the script needs to know the location of the DevStack install directory.
46``TOP_DIR`` should always point there, even if the script itself is located in
47a subdirectory::
48
49 # Keep track of the current devstack directory.
50 TOP_DIR=$(cd $(dirname "$0") && pwd)
51
52Many scripts will utilize shared functions from the ``functions`` file. There are
53also rc files (``stackrc`` and ``openrc``) that are often included to set the primary
54configuration of the user environment::
55
Dean Troyer51fb4542012-03-09 22:21:59 -060056 # Keep track of the current devstack directory.
57 TOP_DIR=$(cd $(dirname "$0") && pwd)
Dean Troyer07c35572012-03-05 07:15:30 -060058
59 # Import common functions
Dean Troyer51fb4542012-03-09 22:21:59 -060060 source $TOP_DIR/functions
Dean Troyer07c35572012-03-05 07:15:30 -060061
62 # Import configuration
Dean Troyer51fb4542012-03-09 22:21:59 -060063 source $TOP_DIR/openrc
Dean Troyer07c35572012-03-05 07:15:30 -060064
65``stack.sh`` is a rather large monolithic script that flows through from beginning
Dean Troyer6d04fd72012-12-21 11:03:37 -060066to end. The process of breaking it down into project-level sub-scripts is nearly
67complete and should make ``stack.sh`` easier to read and manage.
Dean Troyer05f23652012-08-29 15:20:21 -050068
69These library sub-scripts have a number of fixed entry points, some of which may
70just be stubs. These entry points will be called by ``stack.sh`` in the
71following order::
72
73 install_XXXX
74 configure_XXXX
75 init_XXXX
76 start_XXXX
77 stop_XXXX
78 cleanup_XXXX
79
80There is a sub-script template in ``lib/templates`` to be used in creating new
81service sub-scripts. The comments in ``<>`` are meta comments describing
82how to use the template and should be removed.
Dean Troyer07c35572012-03-05 07:15:30 -060083
Dean Troyer6d04fd72012-12-21 11:03:37 -060084In order to show the dependencies and conditions under which project functions
85are executed the top-level conditional testing for things like ``is_service_enabled``
86should be done in ``stack.sh``. There may be nested conditionals that need
87to be in the sub-script, such as testing for keystone being enabled in
88``configure_swift()``.
89
Dean Troyer07c35572012-03-05 07:15:30 -060090
Dean Troyer2b7ce5a2013-01-10 13:22:45 -060091stackrc
92-------
93
94``stackrc`` is the global configuration file for DevStack. It is responsible for
95calling ``localrc`` if it exists so configuration can be overridden by the user.
96
97The criteria for what belongs in ``stackrc`` can be vaguely summarized as
98follows:
99
100* All project respositories and branches (for historical reasons)
101* Global configuration that may be referenced in ``localrc``, i.e. ``DEST``, ``DATA_DIR``
102* Global service configuration like ``ENABLED_SERVICES``
103* Variables used by multiple services that do not have a clear owner, i.e.
104 ``VOLUME_BACKING_FILE_SIZE`` (nova-volumes and cinder) or ``PUBLIC_NETWORK_NAME``
105 (nova-network and quantum)
106* Variables that can not be cleanly declared in a project file due to
107 dependency ordering, i.e. the order of sourcing the project files can
108 not be changed for other reasons but the earlier file needs to dereference a
109 variable set in the later file. This should be rare.
110
111Also, variable declarations in ``stackrc`` do NOT allow overriding (the form
112``FOO=${FOO:-baz}``); if they did then they can already be changed in ``localrc``
113and can stay in the project file.
114
Dean Troyer07c35572012-03-05 07:15:30 -0600115Documentation
116-------------
117
118The official DevStack repo on GitHub does not include a gh-pages branch that
119GitHub uses to create static web sites. That branch is maintained in the
120`CloudBuilders DevStack repo`__ mirror that supports the
121http://devstack.org site. This is the primary DevStack
122documentation along with the DevStack scripts themselves.
123
124__ repo_
125.. _repo: https://github.com/cloudbuilders/devstack
126
127All of the scripts are processed with shocco_ to render them with the comments
128as text describing the script below. For this reason we tend to be a little
129verbose in the comments _ABOVE_ the code they pertain to. Shocco also supports
130Markdown formatting in the comments; use it sparingly. Specifically, ``stack.sh``
131uses Markdown headers to divide the script into logical sections.
132
133.. _shocco: http://rtomayko.github.com/shocco/
134
135
136Exercises
137---------
138
139The scripts in the exercises directory are meant to 1) perform basic operational
140checks on certain aspects of OpenStack; and b) document the use of the
141OpenStack command-line clients.
142
143In addition to the guidelines above, exercise scripts MUST follow the structure
144outlined here. ``swift.sh`` is perhaps the clearest example of these guidelines.
145These scripts are executed serially by ``exercise.sh`` in testing situations.
146
147* Begin and end with a banner that stands out in a sea of script logs to aid
148 in debugging failures, particularly in automated testing situations. If the
149 end banner is not displayed, the script ended prematurely and can be assumed
150 to have failed.
151
152 ::
153
154 echo "**************************************************"
155 echo "Begin DevStack Exercise: $0"
156 echo "**************************************************"
157 ...
158 set +o xtrace
159 echo "**************************************************"
160 echo "End DevStack Exercise: $0"
161 echo "**************************************************"
162
163* The scripts will generally have the shell ``xtrace`` attribute set to display
164 the actual commands being executed, and the ``errexit`` attribute set to exit
165 the script on non-zero exit codes::
166
167 # This script exits on an error so that errors don't compound and you see
168 # only the first error that occured.
169 set -o errexit
170
171 # Print the commands being run so that we can see the command that triggers
172 # an error. It is also useful for following allowing as the install occurs.
173 set -o xtrace
174
Dean Troyer51fb4542012-03-09 22:21:59 -0600175* Settings and configuration are stored in ``exerciserc``, which must be
176 sourced after ``openrc`` or ``stackrc``::
177
178 # Import exercise configuration
179 source $TOP_DIR/exerciserc
180
Dean Troyer07c35572012-03-05 07:15:30 -0600181* There are a couple of helper functions in the common ``functions`` sub-script
182 that will check for non-zero exit codes and unset environment variables and
183 print a message and exit the script. These should be called after most client
184 commands that are not otherwise checked to short-circuit long timeouts
185 (instance boot failure, for example)::
186
187 swift post $CONTAINER
188 die_if_error "Failure creating container $CONTAINER"
189
190 FLOATING_IP=`euca-allocate-address | cut -f2`
191 die_if_not_set FLOATING_IP "Failure allocating floating IP"
192
Chmouel Boudjnah408b0092012-03-15 23:21:55 +0000193* If you want an exercise to be skipped when for example a service wasn't
194 enabled for the exercise to be run, you can exit your exercise with the
195 special exitcode 55 and it will be detected as skipped.
196
Dean Troyer07c35572012-03-05 07:15:30 -0600197* The exercise scripts should only use the various OpenStack client binaries to
198 interact with OpenStack. This specifically excludes any ``*-manage`` tools
199 as those assume direct access to configuration and databases, as well as direct
200 database access from the exercise itself.
201
202* If specific configuration needs to be present for the exercise to complete,
203 it should be staged in ``stack.sh``, or called from ``stack.sh`` (see
204 ``files/keystone_data.sh`` for an example of this).
205
206* The ``OS_*`` environment variables should be the only ones used for all
207 authentication to OpenStack clients as documented in the CLIAuth_ wiki page.
208
209.. _CLIAuth: http://wiki.openstack.org/CLIAuth
210
211* The exercise MUST clean up after itself if successful. If it is not successful,
212 it is assumed that state will be left behind; this allows a chance for developers
213 to look around and attempt to debug the problem. The exercise SHOULD clean up
214 or graciously handle possible artifacts left over from previous runs if executed
215 again. It is acceptable to require a reboot or even a re-install of DevStack
216 to restore a clean test environment.