| Dean Troyer | 0986a7b | 2014-10-29 22:08:13 -0500 | [diff] [blame] | 1 | ======= | 
 | 2 | Plugins | 
 | 3 | ======= | 
| Sean M. Collins | 09e550c | 2014-10-21 11:40:08 -0400 | [diff] [blame] | 4 |  | 
| Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 5 | The OpenStack ecosystem is wide and deep, and only growing more so | 
 | 6 | every day. The value of DevStack is that it's simple enough to | 
 | 7 | understand what it's doing clearly. And yet we'd like to support as | 
 | 8 | much of the OpenStack Ecosystem as possible. We do that with plugins. | 
| Sean M. Collins | 09e550c | 2014-10-21 11:40:08 -0400 | [diff] [blame] | 9 |  | 
| Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 10 | DevStack plugins are bits of bash code that live outside the DevStack | 
 | 11 | tree. They are called through a strong contract, so these plugins can | 
 | 12 | be sure that they will continue to work in the future as DevStack | 
 | 13 | evolves. | 
| Sean M. Collins | 09e550c | 2014-10-21 11:40:08 -0400 | [diff] [blame] | 14 |  | 
| Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 15 | Plugin Interface | 
 | 16 | ================ | 
| Sean M. Collins | 09e550c | 2014-10-21 11:40:08 -0400 | [diff] [blame] | 17 |  | 
| Atsushi SAKAI | 2040143 | 2015-07-27 20:42:44 +0900 | [diff] [blame] | 18 | DevStack supports a standard mechanism for including plugins from | 
| Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 19 | external repositories. The plugin interface assumes the following: | 
| Sean Dague | 2c65e71 | 2014-12-18 09:44:56 -0500 | [diff] [blame] | 20 |  | 
 | 21 | An external git repository that includes a ``devstack/`` top level | 
| Deepak C Shetty | 93e2499 | 2015-11-18 12:29:33 +0530 | [diff] [blame] | 22 | directory. Inside this directory there can be 3 files. | 
 | 23 |  | 
| Jim Rollenhagen | 56632fc | 2015-12-10 05:57:19 -0800 | [diff] [blame] | 24 | - ``override-defaults`` - a file containing global variables that | 
| Deepak C Shetty | 93e2499 | 2015-11-18 12:29:33 +0530 | [diff] [blame] | 25 |   will be sourced before the lib/* files. This allows the plugin | 
 | 26 |   to override the defaults that are otherwise set in the lib/* | 
 | 27 |   files. | 
 | 28 |  | 
| Jim Rollenhagen | 56632fc | 2015-12-10 05:57:19 -0800 | [diff] [blame] | 29 |   For example, override-defaults may export CINDER_ENABLED_BACKENDS | 
| Deepak C Shetty | 93e2499 | 2015-11-18 12:29:33 +0530 | [diff] [blame] | 30 |   to include the plugin-specific storage backend and thus be able | 
 | 31 |   to override the default lvm only storage backend for Cinder. | 
| Sean Dague | 2c65e71 | 2014-12-18 09:44:56 -0500 | [diff] [blame] | 32 |  | 
 | 33 | - ``settings`` - a file containing global variables that will be | 
 | 34 |   sourced very early in the process. This is helpful if other plugins | 
 | 35 |   might depend on this one, and need access to global variables to do | 
 | 36 |   their work. | 
| Sean Dague | 33127a1 | 2015-02-09 15:17:27 -0500 | [diff] [blame] | 37 |  | 
 | 38 |   Your settings should include any ``enable_service`` lines required | 
 | 39 |   by your plugin. This is especially important if you are kicking off | 
 | 40 |   services using ``run_process`` as it only works with enabled | 
 | 41 |   services. | 
 | 42 |  | 
| Ian Wienand | 51c48d4 | 2015-03-25 06:26:03 +1100 | [diff] [blame] | 43 |   Be careful to allow users to override global-variables for | 
 | 44 |   customizing their environment.  Usually it is best to provide a | 
 | 45 |   default value only if the variable is unset or empty; e.g. in bash | 
 | 46 |   syntax ``FOO=${FOO:-default}``. | 
 | 47 |  | 
| Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 48 | - ``plugin.sh`` - the actual plugin. It is executed by devstack at | 
 | 49 |   well defined points during a ``stack.sh`` run. The plugin.sh | 
| Deepak C Shetty | 93e2499 | 2015-11-18 12:29:33 +0530 | [diff] [blame] | 50 |   internal structure is discussed below. | 
| Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 51 |  | 
| Sean Dague | 2c65e71 | 2014-12-18 09:44:56 -0500 | [diff] [blame] | 52 |  | 
 | 53 | Plugins are registered by adding the following to the localrc section | 
 | 54 | of ``local.conf``. | 
 | 55 |  | 
 | 56 | They are added in the following format:: | 
 | 57 |  | 
| Sean Dague | 33127a1 | 2015-02-09 15:17:27 -0500 | [diff] [blame] | 58 |   [[local|localrc]] | 
| Sean Dague | 2c65e71 | 2014-12-18 09:44:56 -0500 | [diff] [blame] | 59 |   enable_plugin <NAME> <GITURL> [GITREF] | 
 | 60 |  | 
| Atsushi SAKAI | 2040143 | 2015-07-27 20:42:44 +0900 | [diff] [blame] | 61 | - ``name`` - an arbitrary name. (ex: glusterfs, docker, zaqar, congress) | 
| Sean Dague | 2c65e71 | 2014-12-18 09:44:56 -0500 | [diff] [blame] | 62 | - ``giturl`` - a valid git url that can be cloned | 
 | 63 | - ``gitref`` - an optional git ref (branch / ref / tag) that will be | 
 | 64 |   cloned. Defaults to master. | 
 | 65 |  | 
 | 66 | An example would be as follows:: | 
 | 67 |  | 
| Zhang Jinnan | 9f6b542 | 2015-10-20 01:19:06 +0800 | [diff] [blame] | 68 |   enable_plugin ec2-api git://git.openstack.org/openstack/ec2-api | 
| Sean Dague | 2c65e71 | 2014-12-18 09:44:56 -0500 | [diff] [blame] | 69 |  | 
| Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 70 | plugin.sh contract | 
 | 71 | ================== | 
| Ian Wienand | db1152c | 2015-01-13 10:18:49 +1100 | [diff] [blame] | 72 |  | 
| Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 73 | ``plugin.sh`` is a bash script that will be called at specific points | 
 | 74 | during ``stack.sh``, ``unstack.sh``, and ``clean.sh``. It will be | 
 | 75 | called in the following way:: | 
| Ian Wienand | db1152c | 2015-01-13 10:18:49 +1100 | [diff] [blame] | 76 |  | 
| Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 77 |   source $PATH/TO/plugin.sh <mode> [phase] | 
| Ian Wienand | db1152c | 2015-01-13 10:18:49 +1100 | [diff] [blame] | 78 |  | 
| Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 79 | ``mode`` can be thought of as the major mode being called, currently | 
 | 80 | one of: ``stack``, ``unstack``, ``clean``. ``phase`` is used by modes | 
 | 81 | which have multiple points during their run where it's necessary to | 
 | 82 | be able to execute code. All existing ``mode`` and ``phase`` points | 
 | 83 | are considered **strong contracts** and won't be removed without a | 
 | 84 | reasonable deprecation period. Additional new ``mode`` or ``phase`` | 
 | 85 | points may be added at any time if we discover we need them to support | 
 | 86 | additional kinds of plugins in devstack. | 
| Ian Wienand | db1152c | 2015-01-13 10:18:49 +1100 | [diff] [blame] | 87 |  | 
| Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 88 | The current full list of ``mode`` and ``phase`` are: | 
| Ian Wienand | db1152c | 2015-01-13 10:18:49 +1100 | [diff] [blame] | 89 |  | 
| Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 90 | -  **stack** - Called by ``stack.sh`` four times for different phases | 
 | 91 |    of its run: | 
| Sean M. Collins | 09e550c | 2014-10-21 11:40:08 -0400 | [diff] [blame] | 92 |  | 
| Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 93 |    -  **pre-install** - Called after system (OS) setup is complete and | 
 | 94 |       before project source is installed. | 
 | 95 |    -  **install** - Called after the layer 1 and 2 projects source and | 
 | 96 |       their dependencies have been installed. | 
 | 97 |    -  **post-config** - Called after the layer 1 and 2 services have | 
 | 98 |       been configured. All configuration files for enabled services | 
 | 99 |       should exist at this point. | 
 | 100 |    -  **extra** - Called near the end after layer 1 and 2 services have | 
 | 101 |       been started. | 
| Vasyl Saienko | 04d51e4 | 2016-08-05 13:48:23 +0300 | [diff] [blame] | 102 |    - **test-config** - Called at the end of devstack used to configure tempest | 
| Matthew Treinish | 655c22c | 2016-05-02 13:29:10 -0400 | [diff] [blame] | 103 |       or any other test environments | 
| Sean M. Collins | 09e550c | 2014-10-21 11:40:08 -0400 | [diff] [blame] | 104 |  | 
| Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 105 | -  **unstack** - Called by ``unstack.sh`` before other services are shut | 
 | 106 |    down. | 
 | 107 | -  **clean** - Called by ``clean.sh`` before other services are cleaned, | 
 | 108 |    but after ``unstack.sh`` has been called. | 
| Sean M. Collins | 09e550c | 2014-10-21 11:40:08 -0400 | [diff] [blame] | 109 |  | 
| Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 110 | Example plugin | 
 | 111 | ==================== | 
 | 112 |  | 
 | 113 | An example plugin would look something as follows. | 
 | 114 |  | 
 | 115 | ``devstack/settings``:: | 
 | 116 |  | 
 | 117 |     # settings file for template | 
 | 118 |   enable_service template | 
 | 119 |  | 
 | 120 |  | 
 | 121 | ``devstack/plugin.sh``:: | 
 | 122 |  | 
 | 123 |     # plugin.sh - DevStack plugin.sh dispatch script template | 
 | 124 |  | 
 | 125 |     function install_template { | 
 | 126 |         ... | 
 | 127 |     } | 
 | 128 |  | 
 | 129 |     function init_template { | 
 | 130 |         ... | 
 | 131 |     } | 
 | 132 |  | 
 | 133 |     function configure_template { | 
 | 134 |         ... | 
 | 135 |     } | 
 | 136 |  | 
 | 137 |     # check for service enabled | 
 | 138 |     if is_service_enabled template; then | 
 | 139 |  | 
 | 140 |         if [[ "$1" == "stack" && "$2" == "pre-install" ]]; then | 
 | 141 |             # Set up system services | 
 | 142 |             echo_summary "Configuring system services Template" | 
 | 143 |             install_package cowsay | 
 | 144 |  | 
 | 145 |         elif [[ "$1" == "stack" && "$2" == "install" ]]; then | 
 | 146 |             # Perform installation of service source | 
 | 147 |             echo_summary "Installing Template" | 
 | 148 |             install_template | 
 | 149 |  | 
 | 150 |         elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then | 
 | 151 |             # Configure after the other layer 1 and 2 services have been configured | 
 | 152 |             echo_summary "Configuring Template" | 
 | 153 |             configure_template | 
 | 154 |  | 
 | 155 |         elif [[ "$1" == "stack" && "$2" == "extra" ]]; then | 
 | 156 |             # Initialize and start the template service | 
 | 157 |             echo_summary "Initializing Template" | 
 | 158 |             init_template | 
 | 159 |         fi | 
 | 160 |  | 
 | 161 |         if [[ "$1" == "unstack" ]]; then | 
 | 162 |             # Shut down template services | 
 | 163 |             # no-op | 
 | 164 |             : | 
 | 165 |         fi | 
 | 166 |  | 
 | 167 |         if [[ "$1" == "clean" ]]; then | 
 | 168 |             # Remove state and transient data | 
 | 169 |             # Remember clean.sh first calls unstack.sh | 
 | 170 |             # no-op | 
 | 171 |             : | 
 | 172 |         fi | 
 | 173 |     fi | 
 | 174 |  | 
 | 175 | Plugin Execution Order | 
 | 176 | ====================== | 
 | 177 |  | 
 | 178 | Plugins are run after in tree services at each of the stages | 
 | 179 | above. For example, if you need something to happen before Keystone | 
 | 180 | starts, you should do that at the ``post-config`` phase. | 
 | 181 |  | 
 | 182 | Multiple plugins can be specified in your ``local.conf``. When that | 
 | 183 | happens the plugins will be executed **in order** at each phase. This | 
 | 184 | allows plugins to conceptually depend on each other through | 
 | 185 | documenting to the user the order they must be declared. A formal | 
 | 186 | dependency mechanism is beyond the scope of the current work. | 
| Adam Gandelman | 7ca90cd | 2015-03-04 17:25:07 -0800 | [diff] [blame] | 187 |  | 
 | 188 | System Packages | 
 | 189 | =============== | 
 | 190 |  | 
 | 191 | Devstack provides a framework for getting packages installed at an early | 
| dieterly | bf9f9a5 | 2015-09-21 13:24:00 -0600 | [diff] [blame] | 192 | phase of its execution. These packages may be defined in a plugin as files | 
| Adam Gandelman | 7ca90cd | 2015-03-04 17:25:07 -0800 | [diff] [blame] | 193 | that contain new-line separated lists of packages required by the plugin | 
 | 194 |  | 
 | 195 | Supported packaging systems include apt and yum across multiple distributions. | 
 | 196 | To enable a plugin to hook into this and install package dependencies, packages | 
 | 197 | may be listed at the following locations in the top-level of the plugin | 
 | 198 | repository: | 
 | 199 |  | 
 | 200 | - ``./devstack/files/debs/$plugin_name`` - Packages to install when running | 
 | 201 |   on Ubuntu, Debian or Linux Mint. | 
 | 202 |  | 
 | 203 | - ``./devstack/files/rpms/$plugin_name`` - Packages to install when running | 
 | 204 |   on Red Hat, Fedora, CentOS or XenServer. | 
 | 205 |  | 
 | 206 | - ``./devstack/files/rpms-suse/$plugin_name`` - Packages to install when | 
 | 207 |   running on SUSE Linux or openSUSE. | 
| Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 208 |  | 
 | 209 |  | 
 | 210 | Using Plugins in the OpenStack Gate | 
 | 211 | =================================== | 
 | 212 |  | 
 | 213 | For everyday use, DevStack plugins can exist in any git tree that's | 
 | 214 | accessible on the internet. However, when using DevStack plugins in | 
 | 215 | the OpenStack gate, they must live in projects in OpenStack's | 
| Zhang Jinnan | 9f6b542 | 2015-10-20 01:19:06 +0800 | [diff] [blame] | 216 | gerrit. This allows testing of the plugin as well as provides network | 
| Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 217 | isolation against upstream git repository failures (which we see often | 
 | 218 | enough to be an issue). | 
 | 219 |  | 
 | 220 | Ideally a plugin will be included within the ``devstack`` directory of | 
| Zhang Jinnan | 9f6b542 | 2015-10-20 01:19:06 +0800 | [diff] [blame] | 221 | the project they are being tested. For example, the openstack/ec2-api | 
| Atsushi SAKAI | 2040143 | 2015-07-27 20:42:44 +0900 | [diff] [blame] | 222 | project has its plugin support in its own tree. | 
| Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 223 |  | 
 | 224 | However, some times a DevStack plugin might be used solely to | 
 | 225 | configure a backend service that will be used by the rest of | 
 | 226 | OpenStack, so there is no "project tree" per say. Good examples | 
 | 227 | include: integration of back end storage (e.g. ceph or glusterfs), | 
 | 228 | integration of SDN controllers (e.g. ovn, OpenDayLight), or | 
 | 229 | integration of alternate RPC systems (e.g. zmq, qpid). In these cases | 
 | 230 | the best practice is to build a dedicated | 
| Zhang Jinnan | 9f6b542 | 2015-10-20 01:19:06 +0800 | [diff] [blame] | 231 | ``openstack/devstack-plugin-FOO`` project. | 
| Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 232 |  | 
 | 233 | To enable a plugin to be used in a gate job, the following lines will | 
| Chris Dent | dcc8a30 | 2015-06-27 12:45:21 +0000 | [diff] [blame] | 234 | be needed in your ``jenkins/jobs/<project>.yaml`` definition in | 
 | 235 | `project-config | 
 | 236 | <http://git.openstack.org/cgit/openstack-infra/project-config/>`_:: | 
| Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 237 |  | 
 | 238 |   # Because we are testing a non standard project, add the | 
 | 239 |   # our project repository. This makes zuul do the right | 
 | 240 |   # reference magic for testing changes. | 
| Zhang Jinnan | 9f6b542 | 2015-10-20 01:19:06 +0800 | [diff] [blame] | 241 |   export PROJECTS="openstack/ec2-api $PROJECTS" | 
| Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 242 |  | 
 | 243 |   # note the actual url here is somewhat irrelevant because it | 
 | 244 |   # caches in nodepool, however make it a valid url for | 
 | 245 |   # documentation purposes. | 
| Zhang Jinnan | 9f6b542 | 2015-10-20 01:19:06 +0800 | [diff] [blame] | 246 |   export DEVSTACK_LOCAL_CONFIG="enable_plugin ec2-api git://git.openstack.org/openstack/ec2-api" | 
| Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 247 |  | 
 | 248 | See Also | 
 | 249 | ======== | 
 | 250 |  | 
 | 251 | For additional inspiration on devstack plugins you can check out the | 
 | 252 | `Plugin Registry <plugin-registry.html>`_. |