Dean Troyer | 07c3557 | 2012-03-05 07:15:30 -0600 | [diff] [blame] | 1 | Contributing to DevStack |
| 2 | ======================== |
| 3 | |
| 4 | |
| 5 | General |
| 6 | ------- |
| 7 | |
| 8 | DevStack is written in POSIX shell script. This choice was made because |
| 9 | it best illustrates the configuration steps that this implementation takes |
| 10 | on setting up and interacting with OpenStack components. DevStack specifies |
| 11 | BASH and is compatible with Bash 3. |
| 12 | |
| 13 | DevStack's official repository is located on GitHub at |
| 14 | https://github.com/openstack-dev/devstack.git. Besides the master branch that |
| 15 | tracks the OpenStack trunk branches a separate branch is maintained for all |
| 16 | OpenStack releases starting with Diablo (stable/diablo). |
| 17 | |
Dean Troyer | 6d04fd7 | 2012-12-21 11:03:37 -0600 | [diff] [blame^] | 18 | Contributing code to DevStack follows the usual OpenStack process as described |
| 19 | in `How To Contribute`__ in the OpenStack wiki. `DevStack's LaunchPad project`__ |
| 20 | contains 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 Troyer | 07c3557 | 2012-03-05 07:15:30 -0600 | [diff] [blame] | 28 | The primary script in DevStack is ``stack.sh``, which performs the bulk of the |
| 29 | work for DevStack's use cases. There is a subscript ``functions`` that contains |
| 30 | generally useful shell functions and is used by a number of the scripts in |
| 31 | DevStack. |
| 32 | |
| 33 | A number of additional scripts can be found in the ``tools`` directory that may |
| 34 | be useful in setting up special-case uses of DevStack. These include: bare metal |
| 35 | deployment, ramdisk deployment and Jenkins integration. |
| 36 | |
| 37 | |
| 38 | Scripts |
| 39 | ------- |
| 40 | |
| 41 | DevStack scripts should generally begin by calling ``env(1)`` in the shebang line:: |
| 42 | |
| 43 | #!/usr/bin/env bash |
| 44 | |
| 45 | Sometimes 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 |
| 47 | a subdirectory:: |
| 48 | |
| 49 | # Keep track of the current devstack directory. |
| 50 | TOP_DIR=$(cd $(dirname "$0") && pwd) |
| 51 | |
| 52 | Many scripts will utilize shared functions from the ``functions`` file. There are |
| 53 | also rc files (``stackrc`` and ``openrc``) that are often included to set the primary |
| 54 | configuration of the user environment:: |
| 55 | |
Dean Troyer | 51fb454 | 2012-03-09 22:21:59 -0600 | [diff] [blame] | 56 | # Keep track of the current devstack directory. |
| 57 | TOP_DIR=$(cd $(dirname "$0") && pwd) |
Dean Troyer | 07c3557 | 2012-03-05 07:15:30 -0600 | [diff] [blame] | 58 | |
| 59 | # Import common functions |
Dean Troyer | 51fb454 | 2012-03-09 22:21:59 -0600 | [diff] [blame] | 60 | source $TOP_DIR/functions |
Dean Troyer | 07c3557 | 2012-03-05 07:15:30 -0600 | [diff] [blame] | 61 | |
| 62 | # Import configuration |
Dean Troyer | 51fb454 | 2012-03-09 22:21:59 -0600 | [diff] [blame] | 63 | source $TOP_DIR/openrc |
Dean Troyer | 07c3557 | 2012-03-05 07:15:30 -0600 | [diff] [blame] | 64 | |
| 65 | ``stack.sh`` is a rather large monolithic script that flows through from beginning |
Dean Troyer | 6d04fd7 | 2012-12-21 11:03:37 -0600 | [diff] [blame^] | 66 | to end. The process of breaking it down into project-level sub-scripts is nearly |
| 67 | complete and should make ``stack.sh`` easier to read and manage. |
Dean Troyer | 05f2365 | 2012-08-29 15:20:21 -0500 | [diff] [blame] | 68 | |
| 69 | These library sub-scripts have a number of fixed entry points, some of which may |
| 70 | just be stubs. These entry points will be called by ``stack.sh`` in the |
| 71 | following order:: |
| 72 | |
| 73 | install_XXXX |
| 74 | configure_XXXX |
| 75 | init_XXXX |
| 76 | start_XXXX |
| 77 | stop_XXXX |
| 78 | cleanup_XXXX |
| 79 | |
| 80 | There is a sub-script template in ``lib/templates`` to be used in creating new |
| 81 | service sub-scripts. The comments in ``<>`` are meta comments describing |
| 82 | how to use the template and should be removed. |
Dean Troyer | 07c3557 | 2012-03-05 07:15:30 -0600 | [diff] [blame] | 83 | |
Dean Troyer | 6d04fd7 | 2012-12-21 11:03:37 -0600 | [diff] [blame^] | 84 | In order to show the dependencies and conditions under which project functions |
| 85 | are executed the top-level conditional testing for things like ``is_service_enabled`` |
| 86 | should be done in ``stack.sh``. There may be nested conditionals that need |
| 87 | to be in the sub-script, such as testing for keystone being enabled in |
| 88 | ``configure_swift()``. |
| 89 | |
Dean Troyer | 07c3557 | 2012-03-05 07:15:30 -0600 | [diff] [blame] | 90 | |
| 91 | Documentation |
| 92 | ------------- |
| 93 | |
| 94 | The official DevStack repo on GitHub does not include a gh-pages branch that |
| 95 | GitHub uses to create static web sites. That branch is maintained in the |
| 96 | `CloudBuilders DevStack repo`__ mirror that supports the |
| 97 | http://devstack.org site. This is the primary DevStack |
| 98 | documentation along with the DevStack scripts themselves. |
| 99 | |
| 100 | __ repo_ |
| 101 | .. _repo: https://github.com/cloudbuilders/devstack |
| 102 | |
| 103 | All of the scripts are processed with shocco_ to render them with the comments |
| 104 | as text describing the script below. For this reason we tend to be a little |
| 105 | verbose in the comments _ABOVE_ the code they pertain to. Shocco also supports |
| 106 | Markdown formatting in the comments; use it sparingly. Specifically, ``stack.sh`` |
| 107 | uses Markdown headers to divide the script into logical sections. |
| 108 | |
| 109 | .. _shocco: http://rtomayko.github.com/shocco/ |
| 110 | |
| 111 | |
| 112 | Exercises |
| 113 | --------- |
| 114 | |
| 115 | The scripts in the exercises directory are meant to 1) perform basic operational |
| 116 | checks on certain aspects of OpenStack; and b) document the use of the |
| 117 | OpenStack command-line clients. |
| 118 | |
| 119 | In addition to the guidelines above, exercise scripts MUST follow the structure |
| 120 | outlined here. ``swift.sh`` is perhaps the clearest example of these guidelines. |
| 121 | These scripts are executed serially by ``exercise.sh`` in testing situations. |
| 122 | |
| 123 | * Begin and end with a banner that stands out in a sea of script logs to aid |
| 124 | in debugging failures, particularly in automated testing situations. If the |
| 125 | end banner is not displayed, the script ended prematurely and can be assumed |
| 126 | to have failed. |
| 127 | |
| 128 | :: |
| 129 | |
| 130 | echo "**************************************************" |
| 131 | echo "Begin DevStack Exercise: $0" |
| 132 | echo "**************************************************" |
| 133 | ... |
| 134 | set +o xtrace |
| 135 | echo "**************************************************" |
| 136 | echo "End DevStack Exercise: $0" |
| 137 | echo "**************************************************" |
| 138 | |
| 139 | * The scripts will generally have the shell ``xtrace`` attribute set to display |
| 140 | the actual commands being executed, and the ``errexit`` attribute set to exit |
| 141 | the script on non-zero exit codes:: |
| 142 | |
| 143 | # This script exits on an error so that errors don't compound and you see |
| 144 | # only the first error that occured. |
| 145 | set -o errexit |
| 146 | |
| 147 | # Print the commands being run so that we can see the command that triggers |
| 148 | # an error. It is also useful for following allowing as the install occurs. |
| 149 | set -o xtrace |
| 150 | |
Dean Troyer | 51fb454 | 2012-03-09 22:21:59 -0600 | [diff] [blame] | 151 | * Settings and configuration are stored in ``exerciserc``, which must be |
| 152 | sourced after ``openrc`` or ``stackrc``:: |
| 153 | |
| 154 | # Import exercise configuration |
| 155 | source $TOP_DIR/exerciserc |
| 156 | |
Dean Troyer | 07c3557 | 2012-03-05 07:15:30 -0600 | [diff] [blame] | 157 | * There are a couple of helper functions in the common ``functions`` sub-script |
| 158 | that will check for non-zero exit codes and unset environment variables and |
| 159 | print a message and exit the script. These should be called after most client |
| 160 | commands that are not otherwise checked to short-circuit long timeouts |
| 161 | (instance boot failure, for example):: |
| 162 | |
| 163 | swift post $CONTAINER |
| 164 | die_if_error "Failure creating container $CONTAINER" |
| 165 | |
| 166 | FLOATING_IP=`euca-allocate-address | cut -f2` |
| 167 | die_if_not_set FLOATING_IP "Failure allocating floating IP" |
| 168 | |
Chmouel Boudjnah | 408b009 | 2012-03-15 23:21:55 +0000 | [diff] [blame] | 169 | * If you want an exercise to be skipped when for example a service wasn't |
| 170 | enabled for the exercise to be run, you can exit your exercise with the |
| 171 | special exitcode 55 and it will be detected as skipped. |
| 172 | |
Dean Troyer | 07c3557 | 2012-03-05 07:15:30 -0600 | [diff] [blame] | 173 | * The exercise scripts should only use the various OpenStack client binaries to |
| 174 | interact with OpenStack. This specifically excludes any ``*-manage`` tools |
| 175 | as those assume direct access to configuration and databases, as well as direct |
| 176 | database access from the exercise itself. |
| 177 | |
| 178 | * If specific configuration needs to be present for the exercise to complete, |
| 179 | it should be staged in ``stack.sh``, or called from ``stack.sh`` (see |
| 180 | ``files/keystone_data.sh`` for an example of this). |
| 181 | |
| 182 | * The ``OS_*`` environment variables should be the only ones used for all |
| 183 | authentication to OpenStack clients as documented in the CLIAuth_ wiki page. |
| 184 | |
| 185 | .. _CLIAuth: http://wiki.openstack.org/CLIAuth |
| 186 | |
| 187 | * The exercise MUST clean up after itself if successful. If it is not successful, |
| 188 | it is assumed that state will be left behind; this allows a chance for developers |
| 189 | to look around and attempt to debug the problem. The exercise SHOULD clean up |
| 190 | or graciously handle possible artifacts left over from previous runs if executed |
| 191 | again. It is acceptable to require a reboot or even a re-install of DevStack |
| 192 | to restore a clean test environment. |