blob: fae1a1d8f5ee248bc5b445e0bfb4dcba230c0bbb [file] [log] [blame]
Dean Troyer0986a7b2014-10-29 22:08:13 -05001=======
2Plugins
3=======
Sean M. Collins09e550c2014-10-21 11:40:08 -04004
Sean Dague0124e082015-06-19 08:26:45 -04005The OpenStack ecosystem is wide and deep, and only growing more so
6every day. The value of DevStack is that it's simple enough to
7understand what it's doing clearly. And yet we'd like to support as
8much of the OpenStack Ecosystem as possible. We do that with plugins.
Sean M. Collins09e550c2014-10-21 11:40:08 -04009
Sean Dague0124e082015-06-19 08:26:45 -040010DevStack plugins are bits of bash code that live outside the DevStack
11tree. They are called through a strong contract, so these plugins can
12be sure that they will continue to work in the future as DevStack
13evolves.
Sean M. Collins09e550c2014-10-21 11:40:08 -040014
Chris Dentebbbc052017-08-16 16:00:16 +010015Prerequisites
16=============
17
18If you are planning to create a plugin that is going to host a service in the
19service catalog (that is, your plugin will use the command
20``get_or_create_service``) please make sure that you apply to the `service
21types authority`_ to reserve a valid service-type. This will help to make sure
22that all deployments of your service use the same service-type.
23
Sean Dague0124e082015-06-19 08:26:45 -040024Plugin Interface
25================
Sean M. Collins09e550c2014-10-21 11:40:08 -040026
Atsushi SAKAI20401432015-07-27 20:42:44 +090027DevStack supports a standard mechanism for including plugins from
Sean Dague0124e082015-06-19 08:26:45 -040028external repositories. The plugin interface assumes the following:
Sean Dague2c65e712014-12-18 09:44:56 -050029
30An external git repository that includes a ``devstack/`` top level
Deepak C Shetty93e24992015-11-18 12:29:33 +053031directory. Inside this directory there can be 3 files.
32
Jim Rollenhagen56632fc2015-12-10 05:57:19 -080033- ``override-defaults`` - a file containing global variables that
Deepak C Shetty93e24992015-11-18 12:29:33 +053034 will be sourced before the lib/* files. This allows the plugin
35 to override the defaults that are otherwise set in the lib/*
36 files.
37
Jim Rollenhagen56632fc2015-12-10 05:57:19 -080038 For example, override-defaults may export CINDER_ENABLED_BACKENDS
Deepak C Shetty93e24992015-11-18 12:29:33 +053039 to include the plugin-specific storage backend and thus be able
40 to override the default lvm only storage backend for Cinder.
Sean Dague2c65e712014-12-18 09:44:56 -050041
42- ``settings`` - a file containing global variables that will be
43 sourced very early in the process. This is helpful if other plugins
44 might depend on this one, and need access to global variables to do
45 their work.
Sean Dague33127a12015-02-09 15:17:27 -050046
47 Your settings should include any ``enable_service`` lines required
48 by your plugin. This is especially important if you are kicking off
49 services using ``run_process`` as it only works with enabled
50 services.
51
Ian Wienand51c48d42015-03-25 06:26:03 +110052 Be careful to allow users to override global-variables for
53 customizing their environment. Usually it is best to provide a
54 default value only if the variable is unset or empty; e.g. in bash
55 syntax ``FOO=${FOO:-default}``.
56
Sean Dague0124e082015-06-19 08:26:45 -040057- ``plugin.sh`` - the actual plugin. It is executed by devstack at
58 well defined points during a ``stack.sh`` run. The plugin.sh
Deepak C Shetty93e24992015-11-18 12:29:33 +053059 internal structure is discussed below.
Sean Dague0124e082015-06-19 08:26:45 -040060
Sean Dague2c65e712014-12-18 09:44:56 -050061
62Plugins are registered by adding the following to the localrc section
63of ``local.conf``.
64
65They are added in the following format::
66
Sean Dague33127a12015-02-09 15:17:27 -050067 [[local|localrc]]
Sean Dague2c65e712014-12-18 09:44:56 -050068 enable_plugin <NAME> <GITURL> [GITREF]
69
Atsushi SAKAI20401432015-07-27 20:42:44 +090070- ``name`` - an arbitrary name. (ex: glusterfs, docker, zaqar, congress)
Sean Dague2c65e712014-12-18 09:44:56 -050071- ``giturl`` - a valid git url that can be cloned
72- ``gitref`` - an optional git ref (branch / ref / tag) that will be
73 cloned. Defaults to master.
74
75An example would be as follows::
76
Zhang Jinnan9f6b5422015-10-20 01:19:06 +080077 enable_plugin ec2-api git://git.openstack.org/openstack/ec2-api
Sean Dague2c65e712014-12-18 09:44:56 -050078
Sean Dague0124e082015-06-19 08:26:45 -040079plugin.sh contract
80==================
Ian Wienanddb1152c2015-01-13 10:18:49 +110081
Sean Dague0124e082015-06-19 08:26:45 -040082``plugin.sh`` is a bash script that will be called at specific points
83during ``stack.sh``, ``unstack.sh``, and ``clean.sh``. It will be
84called in the following way::
Ian Wienanddb1152c2015-01-13 10:18:49 +110085
Sean Dague0124e082015-06-19 08:26:45 -040086 source $PATH/TO/plugin.sh <mode> [phase]
Ian Wienanddb1152c2015-01-13 10:18:49 +110087
Sean Dague0124e082015-06-19 08:26:45 -040088``mode`` can be thought of as the major mode being called, currently
89one of: ``stack``, ``unstack``, ``clean``. ``phase`` is used by modes
90which have multiple points during their run where it's necessary to
91be able to execute code. All existing ``mode`` and ``phase`` points
92are considered **strong contracts** and won't be removed without a
93reasonable deprecation period. Additional new ``mode`` or ``phase``
94points may be added at any time if we discover we need them to support
95additional kinds of plugins in devstack.
Ian Wienanddb1152c2015-01-13 10:18:49 +110096
Sean Dague0124e082015-06-19 08:26:45 -040097The current full list of ``mode`` and ``phase`` are:
Ian Wienanddb1152c2015-01-13 10:18:49 +110098
Sean Dague0124e082015-06-19 08:26:45 -040099- **stack** - Called by ``stack.sh`` four times for different phases
100 of its run:
Sean M. Collins09e550c2014-10-21 11:40:08 -0400101
Sean Dague0124e082015-06-19 08:26:45 -0400102 - **pre-install** - Called after system (OS) setup is complete and
103 before project source is installed.
104 - **install** - Called after the layer 1 and 2 projects source and
105 their dependencies have been installed.
106 - **post-config** - Called after the layer 1 and 2 services have
107 been configured. All configuration files for enabled services
108 should exist at this point.
109 - **extra** - Called near the end after layer 1 and 2 services have
110 been started.
Vasyl Saienko8e0fc9d2016-12-06 09:35:02 +0200111 - **test-config** - Called at the end of devstack used to configure tempest
Matthew Treinish655c22c2016-05-02 13:29:10 -0400112 or any other test environments
Sean M. Collins09e550c2014-10-21 11:40:08 -0400113
Sean Dague0124e082015-06-19 08:26:45 -0400114- **unstack** - Called by ``unstack.sh`` before other services are shut
115 down.
116- **clean** - Called by ``clean.sh`` before other services are cleaned,
117 but after ``unstack.sh`` has been called.
Sean M. Collins09e550c2014-10-21 11:40:08 -0400118
Sean Dague0124e082015-06-19 08:26:45 -0400119Example plugin
120====================
121
122An example plugin would look something as follows.
123
124``devstack/settings``::
125
126 # settings file for template
127 enable_service template
128
129
130``devstack/plugin.sh``::
131
132 # plugin.sh - DevStack plugin.sh dispatch script template
133
134 function install_template {
135 ...
136 }
137
138 function init_template {
139 ...
140 }
141
142 function configure_template {
143 ...
144 }
145
146 # check for service enabled
147 if is_service_enabled template; then
148
149 if [[ "$1" == "stack" && "$2" == "pre-install" ]]; then
150 # Set up system services
151 echo_summary "Configuring system services Template"
152 install_package cowsay
153
154 elif [[ "$1" == "stack" && "$2" == "install" ]]; then
155 # Perform installation of service source
156 echo_summary "Installing Template"
157 install_template
158
159 elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then
160 # Configure after the other layer 1 and 2 services have been configured
161 echo_summary "Configuring Template"
162 configure_template
163
164 elif [[ "$1" == "stack" && "$2" == "extra" ]]; then
165 # Initialize and start the template service
166 echo_summary "Initializing Template"
167 init_template
168 fi
169
170 if [[ "$1" == "unstack" ]]; then
171 # Shut down template services
172 # no-op
173 :
174 fi
175
176 if [[ "$1" == "clean" ]]; then
177 # Remove state and transient data
178 # Remember clean.sh first calls unstack.sh
179 # no-op
180 :
181 fi
182 fi
183
184Plugin Execution Order
185======================
186
187Plugins are run after in tree services at each of the stages
188above. For example, if you need something to happen before Keystone
189starts, you should do that at the ``post-config`` phase.
190
191Multiple plugins can be specified in your ``local.conf``. When that
192happens the plugins will be executed **in order** at each phase. This
193allows plugins to conceptually depend on each other through
194documenting to the user the order they must be declared. A formal
195dependency mechanism is beyond the scope of the current work.
Adam Gandelman7ca90cd2015-03-04 17:25:07 -0800196
197System Packages
198===============
199
200Devstack provides a framework for getting packages installed at an early
dieterlybf9f9a52015-09-21 13:24:00 -0600201phase of its execution. These packages may be defined in a plugin as files
Adam Gandelman7ca90cd2015-03-04 17:25:07 -0800202that contain new-line separated lists of packages required by the plugin
203
204Supported packaging systems include apt and yum across multiple distributions.
205To enable a plugin to hook into this and install package dependencies, packages
206may be listed at the following locations in the top-level of the plugin
207repository:
208
209- ``./devstack/files/debs/$plugin_name`` - Packages to install when running
210 on Ubuntu, Debian or Linux Mint.
211
212- ``./devstack/files/rpms/$plugin_name`` - Packages to install when running
213 on Red Hat, Fedora, CentOS or XenServer.
214
215- ``./devstack/files/rpms-suse/$plugin_name`` - Packages to install when
216 running on SUSE Linux or openSUSE.
Sean Dague0124e082015-06-19 08:26:45 -0400217
218
219Using Plugins in the OpenStack Gate
220===================================
221
222For everyday use, DevStack plugins can exist in any git tree that's
223accessible on the internet. However, when using DevStack plugins in
224the OpenStack gate, they must live in projects in OpenStack's
Zhang Jinnan9f6b5422015-10-20 01:19:06 +0800225gerrit. This allows testing of the plugin as well as provides network
Sean Dague0124e082015-06-19 08:26:45 -0400226isolation against upstream git repository failures (which we see often
227enough to be an issue).
228
229Ideally a plugin will be included within the ``devstack`` directory of
Zhang Jinnan9f6b5422015-10-20 01:19:06 +0800230the project they are being tested. For example, the openstack/ec2-api
Atsushi SAKAI20401432015-07-27 20:42:44 +0900231project has its plugin support in its own tree.
Sean Dague0124e082015-06-19 08:26:45 -0400232
233However, some times a DevStack plugin might be used solely to
234configure a backend service that will be used by the rest of
235OpenStack, so there is no "project tree" per say. Good examples
236include: integration of back end storage (e.g. ceph or glusterfs),
237integration of SDN controllers (e.g. ovn, OpenDayLight), or
238integration of alternate RPC systems (e.g. zmq, qpid). In these cases
239the best practice is to build a dedicated
Zhang Jinnan9f6b5422015-10-20 01:19:06 +0800240``openstack/devstack-plugin-FOO`` project.
Sean Dague0124e082015-06-19 08:26:45 -0400241
242To enable a plugin to be used in a gate job, the following lines will
Chris Dentdcc8a302015-06-27 12:45:21 +0000243be needed in your ``jenkins/jobs/<project>.yaml`` definition in
244`project-config
245<http://git.openstack.org/cgit/openstack-infra/project-config/>`_::
Sean Dague0124e082015-06-19 08:26:45 -0400246
247 # Because we are testing a non standard project, add the
248 # our project repository. This makes zuul do the right
249 # reference magic for testing changes.
Zhang Jinnan9f6b5422015-10-20 01:19:06 +0800250 export PROJECTS="openstack/ec2-api $PROJECTS"
Sean Dague0124e082015-06-19 08:26:45 -0400251
252 # note the actual url here is somewhat irrelevant because it
253 # caches in nodepool, however make it a valid url for
254 # documentation purposes.
Zhang Jinnan9f6b5422015-10-20 01:19:06 +0800255 export DEVSTACK_LOCAL_CONFIG="enable_plugin ec2-api git://git.openstack.org/openstack/ec2-api"
Sean Dague0124e082015-06-19 08:26:45 -0400256
257See Also
258========
259
260For additional inspiration on devstack plugins you can check out the
261`Plugin Registry <plugin-registry.html>`_.
Chris Dentebbbc052017-08-16 16:00:16 +0100262
263.. _service types authority: https://specs.openstack.org/openstack/service-types-authority/