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 | |
Chris Dent | ebbbc05 | 2017-08-16 16:00:16 +0100 | [diff] [blame] | 15 | Prerequisites |
| 16 | ============= |
| 17 | |
| 18 | If you are planning to create a plugin that is going to host a service in the |
| 19 | service catalog (that is, your plugin will use the command |
| 20 | ``get_or_create_service``) please make sure that you apply to the `service |
| 21 | types authority`_ to reserve a valid service-type. This will help to make sure |
| 22 | that all deployments of your service use the same service-type. |
| 23 | |
Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 24 | Plugin Interface |
| 25 | ================ |
Sean M. Collins | 09e550c | 2014-10-21 11:40:08 -0400 | [diff] [blame] | 26 | |
Atsushi SAKAI | 2040143 | 2015-07-27 20:42:44 +0900 | [diff] [blame] | 27 | DevStack supports a standard mechanism for including plugins from |
Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 28 | external repositories. The plugin interface assumes the following: |
Sean Dague | 2c65e71 | 2014-12-18 09:44:56 -0500 | [diff] [blame] | 29 | |
| 30 | An external git repository that includes a ``devstack/`` top level |
Deepak C Shetty | 93e2499 | 2015-11-18 12:29:33 +0530 | [diff] [blame] | 31 | directory. Inside this directory there can be 3 files. |
| 32 | |
Jim Rollenhagen | 56632fc | 2015-12-10 05:57:19 -0800 | [diff] [blame] | 33 | - ``override-defaults`` - a file containing global variables that |
Deepak C Shetty | 93e2499 | 2015-11-18 12:29:33 +0530 | [diff] [blame] | 34 | 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 Rollenhagen | 56632fc | 2015-12-10 05:57:19 -0800 | [diff] [blame] | 38 | For example, override-defaults may export CINDER_ENABLED_BACKENDS |
Deepak C Shetty | 93e2499 | 2015-11-18 12:29:33 +0530 | [diff] [blame] | 39 | to include the plugin-specific storage backend and thus be able |
| 40 | to override the default lvm only storage backend for Cinder. |
Sean Dague | 2c65e71 | 2014-12-18 09:44:56 -0500 | [diff] [blame] | 41 | |
| 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 Dague | 33127a1 | 2015-02-09 15:17:27 -0500 | [diff] [blame] | 46 | |
| 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 Wienand | 51c48d4 | 2015-03-25 06:26:03 +1100 | [diff] [blame] | 52 | 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 | |
James E. Blair | c5853ac | 2017-11-21 09:44:42 -0800 | [diff] [blame] | 57 | The file should include a ``define_plugin`` line to indicate the |
| 58 | plugin's name, which is the name that should be used by users on |
| 59 | "enable_plugin" lines. It should generally be the last component of |
| 60 | the git repo path (e.g., if the plugin's repo is |
Riccardo Pittau | b3ee6f4 | 2018-12-18 11:19:59 +0100 | [diff] [blame] | 61 | openstack/foo, then the name here should be "foo") :: |
James E. Blair | c5853ac | 2017-11-21 09:44:42 -0800 | [diff] [blame] | 62 | |
| 63 | define_plugin <YOUR PLUGIN> |
| 64 | |
| 65 | If your plugin depends on another plugin, indicate it in this file |
| 66 | with one or more lines like the following:: |
| 67 | |
| 68 | plugin_requires <YOUR PLUGIN> <OTHER PLUGIN> |
| 69 | |
| 70 | For a complete example, if the plugin "foo" depends on "bar", the |
| 71 | ``settings`` file should include:: |
| 72 | |
| 73 | define_plugin foo |
| 74 | plugin_requires foo bar |
| 75 | |
| 76 | Devstack does not currently use this dependency information, so it's |
| 77 | important that users continue to add enable_plugin lines in the |
| 78 | correct order in ``local.conf``, however adding this information |
| 79 | allows other tools to consider dependency information when |
| 80 | automatically generating ``local.conf`` files. |
| 81 | |
Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 82 | - ``plugin.sh`` - the actual plugin. It is executed by devstack at |
| 83 | well defined points during a ``stack.sh`` run. The plugin.sh |
Deepak C Shetty | 93e2499 | 2015-11-18 12:29:33 +0530 | [diff] [blame] | 84 | internal structure is discussed below. |
Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 85 | |
Sean Dague | 2c65e71 | 2014-12-18 09:44:56 -0500 | [diff] [blame] | 86 | |
| 87 | Plugins are registered by adding the following to the localrc section |
| 88 | of ``local.conf``. |
| 89 | |
| 90 | They are added in the following format:: |
| 91 | |
Sean Dague | 33127a1 | 2015-02-09 15:17:27 -0500 | [diff] [blame] | 92 | [[local|localrc]] |
Sean Dague | 2c65e71 | 2014-12-18 09:44:56 -0500 | [diff] [blame] | 93 | enable_plugin <NAME> <GITURL> [GITREF] |
| 94 | |
Atsushi SAKAI | 2040143 | 2015-07-27 20:42:44 +0900 | [diff] [blame] | 95 | - ``name`` - an arbitrary name. (ex: glusterfs, docker, zaqar, congress) |
Sean Dague | 2c65e71 | 2014-12-18 09:44:56 -0500 | [diff] [blame] | 96 | - ``giturl`` - a valid git url that can be cloned |
| 97 | - ``gitref`` - an optional git ref (branch / ref / tag) that will be |
| 98 | cloned. Defaults to master. |
| 99 | |
| 100 | An example would be as follows:: |
| 101 | |
Matt Riedemann | 9b6d2f2 | 2019-06-18 10:43:16 -0400 | [diff] [blame] | 102 | enable_plugin ec2-api https://opendev.org/openstack/ec2-api |
Sean Dague | 2c65e71 | 2014-12-18 09:44:56 -0500 | [diff] [blame] | 103 | |
Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 104 | plugin.sh contract |
| 105 | ================== |
Ian Wienand | db1152c | 2015-01-13 10:18:49 +1100 | [diff] [blame] | 106 | |
Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 107 | ``plugin.sh`` is a bash script that will be called at specific points |
| 108 | during ``stack.sh``, ``unstack.sh``, and ``clean.sh``. It will be |
| 109 | called in the following way:: |
Ian Wienand | db1152c | 2015-01-13 10:18:49 +1100 | [diff] [blame] | 110 | |
Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 111 | source $PATH/TO/plugin.sh <mode> [phase] |
Ian Wienand | db1152c | 2015-01-13 10:18:49 +1100 | [diff] [blame] | 112 | |
Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 113 | ``mode`` can be thought of as the major mode being called, currently |
| 114 | one of: ``stack``, ``unstack``, ``clean``. ``phase`` is used by modes |
| 115 | which have multiple points during their run where it's necessary to |
| 116 | be able to execute code. All existing ``mode`` and ``phase`` points |
| 117 | are considered **strong contracts** and won't be removed without a |
| 118 | reasonable deprecation period. Additional new ``mode`` or ``phase`` |
| 119 | points may be added at any time if we discover we need them to support |
| 120 | additional kinds of plugins in devstack. |
Ian Wienand | db1152c | 2015-01-13 10:18:49 +1100 | [diff] [blame] | 121 | |
Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 122 | The current full list of ``mode`` and ``phase`` are: |
Ian Wienand | db1152c | 2015-01-13 10:18:49 +1100 | [diff] [blame] | 123 | |
Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 124 | - **stack** - Called by ``stack.sh`` four times for different phases |
| 125 | of its run: |
Sean M. Collins | 09e550c | 2014-10-21 11:40:08 -0400 | [diff] [blame] | 126 | |
Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 127 | - **pre-install** - Called after system (OS) setup is complete and |
| 128 | before project source is installed. |
| 129 | - **install** - Called after the layer 1 and 2 projects source and |
| 130 | their dependencies have been installed. |
| 131 | - **post-config** - Called after the layer 1 and 2 services have |
| 132 | been configured. All configuration files for enabled services |
| 133 | should exist at this point. |
| 134 | - **extra** - Called near the end after layer 1 and 2 services have |
| 135 | been started. |
Vasyl Saienko | 8e0fc9d | 2016-12-06 09:35:02 +0200 | [diff] [blame] | 136 | - **test-config** - Called at the end of devstack used to configure tempest |
Matthew Treinish | 655c22c | 2016-05-02 13:29:10 -0400 | [diff] [blame] | 137 | or any other test environments |
Sean M. Collins | 09e550c | 2014-10-21 11:40:08 -0400 | [diff] [blame] | 138 | |
Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 139 | - **unstack** - Called by ``unstack.sh`` before other services are shut |
| 140 | down. |
| 141 | - **clean** - Called by ``clean.sh`` before other services are cleaned, |
| 142 | but after ``unstack.sh`` has been called. |
Sean M. Collins | 09e550c | 2014-10-21 11:40:08 -0400 | [diff] [blame] | 143 | |
Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 144 | Example plugin |
| 145 | ==================== |
| 146 | |
| 147 | An example plugin would look something as follows. |
| 148 | |
| 149 | ``devstack/settings``:: |
| 150 | |
Riccardo Pittau | b3ee6f4 | 2018-12-18 11:19:59 +0100 | [diff] [blame] | 151 | # settings file for template |
Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 152 | enable_service template |
| 153 | |
| 154 | |
| 155 | ``devstack/plugin.sh``:: |
| 156 | |
| 157 | # plugin.sh - DevStack plugin.sh dispatch script template |
| 158 | |
| 159 | function install_template { |
| 160 | ... |
| 161 | } |
| 162 | |
| 163 | function init_template { |
| 164 | ... |
| 165 | } |
| 166 | |
| 167 | function configure_template { |
| 168 | ... |
| 169 | } |
| 170 | |
| 171 | # check for service enabled |
| 172 | if is_service_enabled template; then |
| 173 | |
| 174 | if [[ "$1" == "stack" && "$2" == "pre-install" ]]; then |
| 175 | # Set up system services |
| 176 | echo_summary "Configuring system services Template" |
| 177 | install_package cowsay |
| 178 | |
| 179 | elif [[ "$1" == "stack" && "$2" == "install" ]]; then |
| 180 | # Perform installation of service source |
| 181 | echo_summary "Installing Template" |
| 182 | install_template |
| 183 | |
| 184 | elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then |
| 185 | # Configure after the other layer 1 and 2 services have been configured |
| 186 | echo_summary "Configuring Template" |
| 187 | configure_template |
| 188 | |
| 189 | elif [[ "$1" == "stack" && "$2" == "extra" ]]; then |
| 190 | # Initialize and start the template service |
| 191 | echo_summary "Initializing Template" |
| 192 | init_template |
| 193 | fi |
| 194 | |
| 195 | if [[ "$1" == "unstack" ]]; then |
| 196 | # Shut down template services |
| 197 | # no-op |
| 198 | : |
| 199 | fi |
| 200 | |
| 201 | if [[ "$1" == "clean" ]]; then |
| 202 | # Remove state and transient data |
| 203 | # Remember clean.sh first calls unstack.sh |
| 204 | # no-op |
| 205 | : |
| 206 | fi |
| 207 | fi |
| 208 | |
| 209 | Plugin Execution Order |
| 210 | ====================== |
| 211 | |
| 212 | Plugins are run after in tree services at each of the stages |
| 213 | above. For example, if you need something to happen before Keystone |
| 214 | starts, you should do that at the ``post-config`` phase. |
| 215 | |
| 216 | Multiple plugins can be specified in your ``local.conf``. When that |
| 217 | happens the plugins will be executed **in order** at each phase. This |
| 218 | allows plugins to conceptually depend on each other through |
| 219 | documenting to the user the order they must be declared. A formal |
| 220 | dependency mechanism is beyond the scope of the current work. |
Adam Gandelman | 7ca90cd | 2015-03-04 17:25:07 -0800 | [diff] [blame] | 221 | |
| 222 | System Packages |
| 223 | =============== |
| 224 | |
Adam Gandelman | 7ca90cd | 2015-03-04 17:25:07 -0800 | [diff] [blame] | 225 | |
Ian Wienand | fa9aadf | 2019-01-15 18:31:05 +1100 | [diff] [blame] | 226 | |
| 227 | Devstack based |
| 228 | -------------- |
| 229 | |
| 230 | Devstack provides a custom framework for getting packages installed at |
| 231 | an early phase of its execution. These packages may be defined in a |
| 232 | plugin as files that contain new-line separated lists of packages |
| 233 | required by the plugin |
| 234 | |
Takashi Kajinami | b609c80 | 2025-01-07 10:51:03 +0900 | [diff] [blame] | 235 | Supported packaging systems include apt and dnf across multiple |
Ian Wienand | fa9aadf | 2019-01-15 18:31:05 +1100 | [diff] [blame] | 236 | distributions. To enable a plugin to hook into this and install |
| 237 | package dependencies, packages may be listed at the following |
| 238 | locations in the top-level of the plugin repository: |
Adam Gandelman | 7ca90cd | 2015-03-04 17:25:07 -0800 | [diff] [blame] | 239 | |
| 240 | - ``./devstack/files/debs/$plugin_name`` - Packages to install when running |
Martin Kopec | 90e5479 | 2022-08-16 17:29:16 +0200 | [diff] [blame] | 241 | on Ubuntu or Debian. |
Adam Gandelman | 7ca90cd | 2015-03-04 17:25:07 -0800 | [diff] [blame] | 242 | |
| 243 | - ``./devstack/files/rpms/$plugin_name`` - Packages to install when running |
Stephen Finucane | 970891a | 2021-03-02 16:45:39 +0000 | [diff] [blame] | 244 | on Red Hat, Fedora, or CentOS. |
Adam Gandelman | 7ca90cd | 2015-03-04 17:25:07 -0800 | [diff] [blame] | 245 | |
Ian Wienand | fa9aadf | 2019-01-15 18:31:05 +1100 | [diff] [blame] | 246 | Although there a no plans to remove this method of installing |
| 247 | packages, plugins should consider it deprecated for ``bindep`` support |
| 248 | described below. |
| 249 | |
| 250 | bindep |
| 251 | ------ |
| 252 | |
| 253 | The `bindep <https://docs.openstack.org/infra/bindep>`__ project has |
| 254 | become the defacto standard for OpenStack projects to specify binary |
| 255 | dependencies. |
| 256 | |
| 257 | A plugin may provide a ``./devstack/files/bindep.txt`` file, which |
| 258 | will be called with the *default* profile to install packages. For |
| 259 | details on the syntax, etc. see the bindep documentation. |
| 260 | |
| 261 | It is also possible to use the ``bindep.txt`` of projects that are |
| 262 | being installed from source with the ``-bindep`` flag available in |
| 263 | install functions. For example |
| 264 | |
| 265 | .. code-block:: bash |
| 266 | |
| 267 | if use_library_from_git "diskimage-builder"; then |
| 268 | GITREPO["diskimage-builder"]=$DISKIMAGE_BUILDER_REPO_URL |
| 269 | GITDIR["diskimage-builder"]=$DEST/diskimage-builder |
| 270 | GITBRANCH["diskimage-builder"]=$DISKIMAGE_BUILDER_REPO_REF |
| 271 | git_clone_by_name "diskimage-builder" |
| 272 | setup_dev_lib -bindep "diskimage-builder" |
| 273 | fi |
| 274 | |
| 275 | will result in any packages required by the ``bindep.txt`` of the |
| 276 | ``diskimage-builder`` project being installed. Note however that jobs |
| 277 | that switch projects between source and released/pypi installs |
| 278 | (e.g. with a ``foo-dsvm`` and a ``foo-dsvm-src`` test to cover both |
| 279 | released dependencies and master versions) will have to deal with |
| 280 | ``bindep.txt`` being unavailable without the source directory. |
| 281 | |
Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 282 | |
| 283 | Using Plugins in the OpenStack Gate |
| 284 | =================================== |
| 285 | |
| 286 | For everyday use, DevStack plugins can exist in any git tree that's |
| 287 | accessible on the internet. However, when using DevStack plugins in |
| 288 | the OpenStack gate, they must live in projects in OpenStack's |
Zhang Jinnan | 9f6b542 | 2015-10-20 01:19:06 +0800 | [diff] [blame] | 289 | gerrit. This allows testing of the plugin as well as provides network |
Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 290 | isolation against upstream git repository failures (which we see often |
| 291 | enough to be an issue). |
| 292 | |
| 293 | Ideally a plugin will be included within the ``devstack`` directory of |
Zhang Jinnan | 9f6b542 | 2015-10-20 01:19:06 +0800 | [diff] [blame] | 294 | the project they are being tested. For example, the openstack/ec2-api |
Atsushi SAKAI | 2040143 | 2015-07-27 20:42:44 +0900 | [diff] [blame] | 295 | project has its plugin support in its own tree. |
Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 296 | |
| 297 | However, some times a DevStack plugin might be used solely to |
| 298 | configure a backend service that will be used by the rest of |
| 299 | OpenStack, so there is no "project tree" per say. Good examples |
| 300 | include: integration of back end storage (e.g. ceph or glusterfs), |
| 301 | integration of SDN controllers (e.g. ovn, OpenDayLight), or |
| 302 | integration of alternate RPC systems (e.g. zmq, qpid). In these cases |
| 303 | the best practice is to build a dedicated |
Zhang Jinnan | 9f6b542 | 2015-10-20 01:19:06 +0800 | [diff] [blame] | 304 | ``openstack/devstack-plugin-FOO`` project. |
Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 305 | |
Matt Riedemann | 9b6d2f2 | 2019-06-18 10:43:16 -0400 | [diff] [blame] | 306 | Legacy project-config jobs |
| 307 | -------------------------- |
| 308 | |
Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 309 | 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] | 310 | be needed in your ``jenkins/jobs/<project>.yaml`` definition in |
Matt Riedemann | 9b6d2f2 | 2019-06-18 10:43:16 -0400 | [diff] [blame] | 311 | `project-config <https://opendev.org/openstack/project-config/>`_:: |
Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 312 | |
| 313 | # Because we are testing a non standard project, add the |
| 314 | # our project repository. This makes zuul do the right |
| 315 | # reference magic for testing changes. |
Zhang Jinnan | 9f6b542 | 2015-10-20 01:19:06 +0800 | [diff] [blame] | 316 | export PROJECTS="openstack/ec2-api $PROJECTS" |
Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 317 | |
| 318 | # note the actual url here is somewhat irrelevant because it |
| 319 | # caches in nodepool, however make it a valid url for |
| 320 | # documentation purposes. |
Matt Riedemann | 9b6d2f2 | 2019-06-18 10:43:16 -0400 | [diff] [blame] | 321 | export DEVSTACK_LOCAL_CONFIG="enable_plugin ec2-api https://opendev.org/openstack/ec2-api" |
| 322 | |
| 323 | Zuul v3 jobs |
| 324 | ------------ |
| 325 | |
| 326 | See the ``devstack_plugins`` example in :doc:`zuul_ci_jobs_migration`. |
Sean Dague | 0124e08 | 2015-06-19 08:26:45 -0400 | [diff] [blame] | 327 | |
| 328 | See Also |
| 329 | ======== |
| 330 | |
| 331 | For additional inspiration on devstack plugins you can check out the |
Andreas Jaeger | 8dd89e5 | 2019-08-11 16:00:12 +0200 | [diff] [blame] | 332 | :doc:`Plugin Registry <plugin-registry>`. |
Chris Dent | ebbbc05 | 2017-08-16 16:00:16 +0100 | [diff] [blame] | 333 | |
| 334 | .. _service types authority: https://specs.openstack.org/openstack/service-types-authority/ |