blob: 6a91e0a6a8ff4c89c3fa8f20d9328e68685d27d7 [file] [log] [blame]
Dean Troyer07c35572012-03-05 07:15:30 -06001Contributing to DevStack
2========================
3
4
5General
6-------
7
Dean Troyerb8dd27b2013-10-17 12:03:55 -05008DevStack is written in UNIX shell script. It uses a number of bash-isms
Dean Troyerd97ee302015-02-04 12:35:39 -06009and so is limited to Bash (version 4 and up) and compatible shells.
Dean Troyerb8dd27b2013-10-17 12:03:55 -050010Shell script was chosen because it best illustrates the steps used to
11set up and interact with OpenStack components.
Dean Troyer07c35572012-03-05 07:15:30 -060012
Jens Harbott5a304802019-08-16 09:57:59 +000013DevStack's official repository is located on opendev.org at
Matt Riedemann9b6d2f22019-06-18 10:43:16 -040014https://opendev.org/openstack/devstack. Besides the master branch that
Dean Troyer07c35572012-03-05 07:15:30 -060015tracks 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`__
Roger Luethic21cfc92014-07-22 15:35:02 +020020contains the usual links for blueprints, bugs, etc.
Dean Troyer6d04fd72012-12-21 11:03:37 -060021
22__ contribute_
zhangbailinc63d9332017-09-01 19:46:16 -070023.. _contribute: https://docs.openstack.org/infra/manual/developers.html
Dean Troyer6d04fd72012-12-21 11:03:37 -060024
25__ lp_
Jens Harbott5a304802019-08-16 09:57:59 +000026.. _lp: https://launchpad.net/devstack
Dean Troyer6d04fd72012-12-21 11:03:37 -060027
Ian Wienand6f6e2fd2015-03-20 12:16:28 +110028The `Gerrit review
Matt Riedemann9b6d2f22019-06-18 10:43:16 -040029queue <https://review.opendev.org/#/q/project:openstack/devstack>`__
Ian Wienand6f6e2fd2015-03-20 12:16:28 +110030is used for all commits.
31
Dean Troyer07c35572012-03-05 07:15:30 -060032The primary script in DevStack is ``stack.sh``, which performs the bulk of the
33work for DevStack's use cases. There is a subscript ``functions`` that contains
34generally useful shell functions and is used by a number of the scripts in
35DevStack.
36
37A number of additional scripts can be found in the ``tools`` directory that may
Dean Troyercc6b4432013-04-08 15:38:03 -050038be useful in supporting DevStack installations. Of particular note are ``info.sh``
Adam Spiersd9034762013-10-04 23:20:24 +010039to collect and report information about the installed system, and ``install_prereqs.sh``
Dean Troyercc6b4432013-04-08 15:38:03 -050040that handles installation of the prerequisite packages for DevStack. It is
41suitable, for example, to pre-load a system for making a snapshot.
Dean Troyer07c35572012-03-05 07:15:30 -060042
Ian Wienand6f6e2fd2015-03-20 12:16:28 +110043Repo Layout
44-----------
45
46The DevStack repo generally keeps all of the primary scripts at the root
47level.
48
49``doc`` - Contains the Sphinx source for the documentation.
Chang Liu2c42fd02018-08-03 16:15:20 +080050A complete doc build can be run with ``tox -edocs``.
Ian Wienand6f6e2fd2015-03-20 12:16:28 +110051
Ian Wienand6f6e2fd2015-03-20 12:16:28 +110052``extras.d`` - Contains the dispatch scripts called by the hooks in
53``stack.sh``, ``unstack.sh`` and ``clean.sh``. See :doc:`the plugins
54docs <plugins>` for more information.
55
56``files`` - Contains a variety of otherwise lost files used in
57configuring and operating DevStack. This includes templates for
58configuration files and the system dependency information. This is also
59where image files are downloaded and expanded if necessary.
60
61``lib`` - Contains the sub-scripts specific to each project. This is
62where the work of managing a project's services is located. Each
63top-level project (Keystone, Nova, etc) has a file here. Additionally
64there are some for system services and project plugins. These
65variables and functions are also used by related projects, such as
66Grenade, to manage a DevStack installation.
67
68``samples`` - Contains a sample of the local files not included in the
69DevStack repo.
70
71``tests`` - the DevStack test suite is rather sparse, mostly consisting
72of test of specific fragile functions in the ``functions`` and
73``functions-common`` files.
74
75``tools`` - Contains a collection of stand-alone scripts. While these
76may reference the top-level DevStack configuration they can generally be
Stephen Finucane970891a2021-03-02 16:45:39 +000077run alone.
Ian Wienand6f6e2fd2015-03-20 12:16:28 +110078
Dean Troyer07c35572012-03-05 07:15:30 -060079
80Scripts
81-------
82
83DevStack scripts should generally begin by calling ``env(1)`` in the shebang line::
84
85 #!/usr/bin/env bash
86
87Sometimes the script needs to know the location of the DevStack install directory.
88``TOP_DIR`` should always point there, even if the script itself is located in
89a subdirectory::
90
Dean Troyerb8dd27b2013-10-17 12:03:55 -050091 # Keep track of the current DevStack directory.
Dean Troyer07c35572012-03-05 07:15:30 -060092 TOP_DIR=$(cd $(dirname "$0") && pwd)
93
94Many scripts will utilize shared functions from the ``functions`` file. There are
95also rc files (``stackrc`` and ``openrc``) that are often included to set the primary
96configuration of the user environment::
97
Dean Troyerb8dd27b2013-10-17 12:03:55 -050098 # Keep track of the current DevStack directory.
Dean Troyer51fb4542012-03-09 22:21:59 -060099 TOP_DIR=$(cd $(dirname "$0") && pwd)
Dean Troyer07c35572012-03-05 07:15:30 -0600100
101 # Import common functions
Dean Troyer51fb4542012-03-09 22:21:59 -0600102 source $TOP_DIR/functions
Dean Troyer07c35572012-03-05 07:15:30 -0600103
104 # Import configuration
Dean Troyer51fb4542012-03-09 22:21:59 -0600105 source $TOP_DIR/openrc
Dean Troyer07c35572012-03-05 07:15:30 -0600106
107``stack.sh`` is a rather large monolithic script that flows through from beginning
Dean Troyercc6b4432013-04-08 15:38:03 -0500108to end. It has been broken down into project-specific subscripts (as noted above)
109located in ``lib`` to make ``stack.sh`` more manageable and to promote code reuse.
Dean Troyer05f23652012-08-29 15:20:21 -0500110
111These library sub-scripts have a number of fixed entry points, some of which may
112just be stubs. These entry points will be called by ``stack.sh`` in the
113following order::
114
115 install_XXXX
116 configure_XXXX
117 init_XXXX
118 start_XXXX
119 stop_XXXX
120 cleanup_XXXX
121
122There is a sub-script template in ``lib/templates`` to be used in creating new
123service sub-scripts. The comments in ``<>`` are meta comments describing
124how to use the template and should be removed.
Dean Troyer07c35572012-03-05 07:15:30 -0600125
Dean Troyer6d04fd72012-12-21 11:03:37 -0600126In order to show the dependencies and conditions under which project functions
127are executed the top-level conditional testing for things like ``is_service_enabled``
128should be done in ``stack.sh``. There may be nested conditionals that need
129to be in the sub-script, such as testing for keystone being enabled in
130``configure_swift()``.
131
Dean Troyer07c35572012-03-05 07:15:30 -0600132
Dean Troyer2b7ce5a2013-01-10 13:22:45 -0600133stackrc
134-------
135
136``stackrc`` is the global configuration file for DevStack. It is responsible for
Dean Troyerb8dd27b2013-10-17 12:03:55 -0500137calling ``local.conf`` (or ``localrc`` if it exists) so local user configuration
138is recognized.
Dean Troyer2b7ce5a2013-01-10 13:22:45 -0600139
140The criteria for what belongs in ``stackrc`` can be vaguely summarized as
141follows:
142
Dean Troyerb8dd27b2013-10-17 12:03:55 -0500143* All project repositories and branches handled directly in ``stack.sh``
144* Global configuration that may be referenced in ``local.conf``, i.e. ``DEST``, ``DATA_DIR``
Dean Troyer2b7ce5a2013-01-10 13:22:45 -0600145* Global service configuration like ``ENABLED_SERVICES``
146* Variables used by multiple services that do not have a clear owner, i.e.
Stephen Finucane4b8cba72019-05-21 14:17:11 +0100147 ``VOLUME_BACKING_FILE_SIZE`` (nova-compute and cinder) or
148 ``PUBLIC_NETWORK_NAME`` (only neutron but formerly nova-network too)
Dean Troyer2b7ce5a2013-01-10 13:22:45 -0600149* Variables that can not be cleanly declared in a project file due to
150 dependency ordering, i.e. the order of sourcing the project files can
151 not be changed for other reasons but the earlier file needs to dereference a
152 variable set in the later file. This should be rare.
153
Dean Troyerb8dd27b2013-10-17 12:03:55 -0500154Also, variable declarations in ``stackrc`` before ``local.conf`` is sourced
155do NOT allow overriding (the form
156``FOO=${FOO:-baz}``); if they did then they can already be changed in ``local.conf``
Dean Troyer2b7ce5a2013-01-10 13:22:45 -0600157and can stay in the project file.
158
Dean Troyercc6b4432013-04-08 15:38:03 -0500159
Dean Troyer07c35572012-03-05 07:15:30 -0600160Documentation
161-------------
162
Dean Troyerf5cb1ce2014-10-21 11:16:58 -0500163The DevStack repo now contains all of the static pages of devstack.org in
164the ``doc/source`` directory. The OpenStack CI system rebuilds the docs after every
Jens Harbott5a304802019-08-16 09:57:59 +0000165commit and updates devstack.org (now a redirect to https://docs.openstack.org/devstack/latest/).
Dean Troyer07c35572012-03-05 07:15:30 -0600166
167All of the scripts are processed with shocco_ to render them with the comments
168as text describing the script below. For this reason we tend to be a little
169verbose in the comments _ABOVE_ the code they pertain to. Shocco also supports
170Markdown formatting in the comments; use it sparingly. Specifically, ``stack.sh``
171uses Markdown headers to divide the script into logical sections.
172
Dean Troyerb8dd27b2013-10-17 12:03:55 -0500173.. _shocco: https://github.com/dtroyer/shocco/tree/rst_support
174
175The script used to drive <code>shocco</code> is <code>tools/build_docs.sh</code>.
Dean Troyerf5cb1ce2014-10-21 11:16:58 -0500176The complete docs build is also handled with <code>tox -edocs</code> per the
177OpenStack project standard.
Dean Troyer07c35572012-03-05 07:15:30 -0600178
179
Sean Dague6db28922013-11-22 12:16:02 -0500180Bash Style Guidelines
181~~~~~~~~~~~~~~~~~~~~~
Roger Luethi473b6282014-04-13 13:47:42 +0200182DevStack defines a bash set of best practices for maintaining large
Sean Dague6db28922013-11-22 12:16:02 -0500183collections of bash scripts. These should be considered as part of the
184review process.
185
Dean Troyerf5cb1ce2014-10-21 11:16:58 -0500186DevStack uses the bashate_ style checker
187to enforce basic guidelines, similar to pep8 and flake8 tools for Python. The
188list below is not complete for what bashate checks, nor is it all checked
189by bashate. So many lines of code, so little time.
190
Andreas Jaeger8dd89e52019-08-11 16:00:12 +0200191.. _bashate: https://pypi.org/project/bashate/
Sean Dague6db28922013-11-22 12:16:02 -0500192
193Whitespace Rules
194----------------
195
196- lines should not include trailing whitespace
197- there should be no hard tabs in the file
198- indents are 4 spaces, and all indentation should be some multiple of
199 them
200
201Control Structure Rules
202-----------------------
Ian Wienand6f6e2fd2015-03-20 12:16:28 +1100203
Sean Dague6db28922013-11-22 12:16:02 -0500204- then should be on the same line as the if
205- do should be on the same line as the for
206
207Example::
208
209 if [[ -r $TOP_DIR/local.conf ]]; then
210 LRC=$(get_meta_section_files $TOP_DIR/local.conf local)
211 for lfile in $LRC; do
212 if [[ "$lfile" == "localrc" ]]; then
213 if [[ -r $TOP_DIR/localrc ]]; then
214 warn $LINENO "localrc and local.conf:[[local]] both exist, using localrc"
215 else
216 echo "# Generated file, do not edit" >$TOP_DIR/.localrc.auto
217 get_meta_section $TOP_DIR/local.conf local $lfile >>$TOP_DIR/.localrc.auto
218 fi
219 fi
220 done
221 fi
222
223Variables and Functions
224-----------------------
Ian Wienand6f6e2fd2015-03-20 12:16:28 +1100225
Sean Dague6db28922013-11-22 12:16:02 -0500226- functions should be used whenever possible for clarity
227- functions should use ``local`` variables as much as possible to
228 ensure they are isolated from the rest of the environment
229- local variables should be lower case, global variables should be
230 upper case
231- function names should_have_underscores, NotCamelCase.
Ian Wienandaee18c72014-02-21 15:35:08 +1100232- functions should be declared as per the regex ^function foo {$
233 with code starting on the next line
Ian Wienandc7df4df2015-03-20 12:18:52 +1100234
235
236Review Criteria
Clark Boylan2a6112e2017-05-12 10:16:33 -0700237---------------
Ian Wienandc7df4df2015-03-20 12:18:52 +1100238
239There are some broad criteria that will be followed when reviewing
240your change
241
242* **Is it passing tests** -- your change will not be reviewed
Swapnil Kulkarni (coolsvap)7f0be4f2015-11-20 10:52:59 +0530243 thoroughly unless the official CI has run successfully against it.
Ian Wienandc7df4df2015-03-20 12:18:52 +1100244
245* **Does this belong in DevStack** -- DevStack reviewers have a
246 default position of "no" but are ready to be convinced by your
247 change.
248
249 For very large changes, you should consider :doc:`the plugins system
250 <plugins>` to see if your code is better abstracted from the main
251 repository.
252
253 For smaller changes, you should always consider if the change can be
254 encapsulated by per-user settings in ``local.conf``. A common example
255 is adding a simple config-option to an ``ini`` file. Specific flags
256 are not usually required for this, although adding documentation
257 about how to achieve a larger goal (which might include turning on
258 various settings, etc) is always welcome.
259
260* **Work-arounds** -- often things get broken and DevStack can be in a
261 position to fix them. Work-arounds are fine, but should be
262 presented in the context of fixing the root-cause of the problem.
263 This means it is well-commented in the code and the change-log and
264 mostly likely includes links to changes or bugs that fix the
265 underlying problem.
266
267* **Should this be upstream** -- DevStack generally does not override
268 default choices provided by projects and attempts to not
Atsushi SAKAI20401432015-07-27 20:42:44 +0900269 unexpectedly modify behavior.
Ian Wienandc7df4df2015-03-20 12:18:52 +1100270
271* **Context in commit messages** -- DevStack touches many different
272 areas and reviewers need context around changes to make good
273 decisions. We also always want it to be clear to someone -- perhaps
274 even years from now -- why we were motivated to make a change at the
275 time.
276
Clark Boylan2a6112e2017-05-12 10:16:33 -0700277
278Making Changes, Testing, and CI
279-------------------------------
280
281Changes to Devstack are tested by automated continuous integration jobs
282that run on a variety of Linux Distros using a handful of common
283configurations. What this means is that every change to Devstack is
284self testing. One major benefit of this is that developers do not
285typically need to add new non voting test jobs to add features to
286Devstack. Instead the features can be added, then if testing passes
287with the feature enabled the change is ready to merge (pending code
288review).
289
290A concrete example of this was the switch from screen based service
291management to systemd based service management. No new jobs were
292created for this. Instead the features were added to devstack, tested
293locally and in CI using a change that enabled the feature, then once
294the enabling change was passing and the new behavior communicated and
295documented it was merged.
296
297Using this process has been proven to be effective and leads to
298quicker implementation of desired features.