You are browsing a read-only backup copy of Wikitech. The live site can be found at wikitech.wikimedia.org

Spicerack/Cookbooks: Difference between revisions

From Wikitech-static
Jump to navigation Jump to search
imported>Jobo
No edit summary
imported>Volans
(→‎Installation: Updated documentation for multi-cookbooks dirs)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Cookbook Operations ==
== Cookbook Operations ==


To list or run a Cookbook you must be logged into one of the cumin hosts (<code>cumin[12]001</code> as of April 2020).
To list or run a Cookbook you must be logged into one of the cumin hosts ({{CuminHosts}}).


=== List available Cookbooks ===
=== List available Cookbooks ===
Line 28: Line 28:
And finally, to actually run the cookbook:
And finally, to actually run the cookbook:
   $ sudo cookbook sre.hosts.downtime [COOKBOOK_ARGS]
   $ sudo cookbook sre.hosts.downtime [COOKBOOK_ARGS]
=== Logs ===
How the cookbook store their logs is described in the [https://doc.wikimedia.org/spicerack/master/introduction.html#log-files Spicerack documentation].


== Development ==
== Development ==
Line 35: Line 38:


=== Deployment ===
=== Deployment ===
Once a patch is +2 on Gerrit, CI will take care of the actual merge and at the next Puppet run the cookbook will be updated automatically on the cluster management hosts (<code>cumin[12]001</code> as of May 2021). Forcing a Puppet run after the merge will update the cookbooks immediately.
Once a patch is +2 on Gerrit, CI will take care of the actual merge and at the next Puppet run the cookbook will be updated automatically on the cluster management hosts ({{CuminHosts}}). Forcing a Puppet run after the merge will update the cookbooks immediately.
 
==== Renaming/Deleting a cookbook ====
Due to the current way of deploying cookbooks, if a cookbook gets renamed or deleted, its compiled files (<code>.pyc</code>), if present, are not automatically deleted and needs a manual deletion.
 
Find the existing files with this command, assuming the cookbook being renamed/deleted was called <code>sre.somedir.example-action</code>, and then proceed to delete them, for example appending <code>-delete</code> to the find command.<syntaxhighlight lang="bash">
sudo cumin 'A:cumin' 'find /srv/deployment/spicerack/cookbooks/sre/somedir/ -name "example-action*.pyc"'
</syntaxhighlight>


===Creating your local environment ===
===Creating your local environment ===
Line 42: Line 52:
==== Installation ====
==== Installation ====
* Clone the required repositories from Gerrit under <tt>~/wmf/gerrit</tt> for simplicity
* Clone the required repositories from Gerrit under <tt>~/wmf/gerrit</tt> for simplicity
  $ git clone ssh://$GERRIT_USER@gerrit.wikimedia.org:29418/operations/software/spicerack
$ git clone <nowiki>ssh://$GERRIT_USER@gerrit.wikimedia.org:29418/operations/software/spicerack</nowiki>
  $ git clone ssh://$GERRIT_USER@gerrit.wikimedia.org:29418/operations/cookbooks
$ git clone <nowiki>ssh://$GERRIT_USER@gerrit.wikimedia.org:29418/operations/cookbooks</nowiki>


* Change to the  <tt>spicerack</tt> directory and run <tt>tox</tt>. It will create the proper virtualenv for us with all the dependencies required .
* Change to the  <tt>spicerack</tt> directory and run <tt>tox</tt>. It will create the proper virtualenv for us with all the dependencies required .
  $ tox -e py3N-unit  # where N is the minor version of Python installed in the system
$ tox -e py3N-unit  # where N is picked from any of environment listed with `tox -av | grep unit` for which the related Python version is available on the system
* Note: We could just run 'tox' at this point, it will be just a bit slower because it will run all the tests with all the compatible python versions that are installed in the system and configured in the tox.ini file to run the tests
* Note: We could just run 'tox' at this point, it will be just a bit slower because it will run all the tests with all the compatible python versions that are installed in the system and configured in the tox.ini file to run the tests
* There should be a <tt>.tox/py3N-tests/</tt> directory with the virtualenv created, we can source the activate script
* There should be a <tt>.tox/py3N-tests/</tt> directory with the virtualenv created, we can source the activate script
  $ source .tox/py3N-tests/bin/activate
$ source .tox/py3N-tests/bin/activate
* Create a configuration file for spicerack called <tt>config.yaml</tt>
* Create a configuration file for spicerack called <code>config.yaml</code>:
  cookbooks_base_dir: /home/$USER/wmf/gerrit/cookbooks
cookbooks_base_dirs:
  logs_base_dir: /home/$USER/wmf/gerrit/spicerack/logs
  - ~/wmf/gerrit/cookbooks
logs_base_dir: ~/wmf/gerrit/spicerack/logs


* The cookbook entry point script should be available, and you should be able to see the list of available cookbooks
* The cookbook entry point script should be available, and you should be able to see the list of available cookbooks
  $ cookbook -c config.yaml -l
$ cookbook -c config.yaml -l
 
===== Additional steps for WMCS cookbooks =====
 
* Clone the additional repository for WMCS-specific cookbooks:
 
<code>$ git clone <nowiki>ssh://$GERRIT_USER@gerrit.wikimedia.org:29418/cloud/wmcs-cookbooks</nowiki></code>
 
* Add the new checked out repository to the list of available cookbooks in the <code>config.yaml</code> file:
 
cookbooks_base_dirs:
  - ~/wmf/gerrit/cookbooks
  - ~/wmf/gerrit/wmcs-cookbooks
logs_base_dir: ~/wmf/gerrit/spicerack/logs


== Also see ==
== Also see ==

Latest revision as of 12:24, 3 January 2023

Cookbook Operations

To list or run a Cookbook you must be logged into one of the cumin hosts (cumin1001.eqiad.wmnet, cumin2002.codfw.wmnet).

List available Cookbooks

To show a tree of the available cookbooks run:

 $ cookbook -l

To include a brief one-line description of each cookbook in the tree use:

 $ cookbook -lv

Run a single Cookbook

The generic way of running a cookbook is:

 $ sudo cookbook [-d] [-v] COOKBOOK [COOKBOOK_ARGS]

The full dotted name as shown in the tree of the available cookbooks (e.g. sre.hosts.downtime) must be used. To see the global options of the cookbook executable:

 $ cookbook -h

To see the specific options of a given cookbook:

 $ sudo cookbook sre.hosts.downtime -h

To run the cookbook in dry-run mode (it will not !log and will not execute any RW operation in the infrastructure):

 $ sudo cookbook -d sre.hosts.downtime [COOKBOOK_ARGS]

And finally, to actually run the cookbook:

 $ sudo cookbook sre.hosts.downtime [COOKBOOK_ARGS]

Logs

How the cookbook store their logs is described in the Spicerack documentation.

Development

Documentation

See the Cookbooks API section of the Spicerack documentation.

Deployment

Once a patch is +2 on Gerrit, CI will take care of the actual merge and at the next Puppet run the cookbook will be updated automatically on the cluster management hosts (cumin1001.eqiad.wmnet, cumin2002.codfw.wmnet). Forcing a Puppet run after the merge will update the cookbooks immediately.

Renaming/Deleting a cookbook

Due to the current way of deploying cookbooks, if a cookbook gets renamed or deleted, its compiled files (.pyc), if present, are not automatically deleted and needs a manual deletion.

Find the existing files with this command, assuming the cookbook being renamed/deleted was called sre.somedir.example-action, and then proceed to delete them, for example appending -delete to the find command.

sudo cumin 'A:cumin' 'find /srv/deployment/spicerack/cookbooks/sre/somedir/ -name "example-action*.pyc"'

Creating your local environment

Pre-requisites

  • tox

Installation

  • Clone the required repositories from Gerrit under ~/wmf/gerrit for simplicity
$ git clone ssh://$GERRIT_USER@gerrit.wikimedia.org:29418/operations/software/spicerack
$ git clone ssh://$GERRIT_USER@gerrit.wikimedia.org:29418/operations/cookbooks
  • Change to the spicerack directory and run tox. It will create the proper virtualenv for us with all the dependencies required .
$ tox -e py3N-unit  # where N is picked from any of environment listed with `tox -av | grep unit` for which the related Python version is available on the system
  • Note: We could just run 'tox' at this point, it will be just a bit slower because it will run all the tests with all the compatible python versions that are installed in the system and configured in the tox.ini file to run the tests
  • There should be a .tox/py3N-tests/ directory with the virtualenv created, we can source the activate script
$ source .tox/py3N-tests/bin/activate
  • Create a configuration file for spicerack called config.yaml:
cookbooks_base_dirs:
  - ~/wmf/gerrit/cookbooks
logs_base_dir: ~/wmf/gerrit/spicerack/logs
  • The cookbook entry point script should be available, and you should be able to see the list of available cookbooks
$ cookbook -c config.yaml -l
Additional steps for WMCS cookbooks
  • Clone the additional repository for WMCS-specific cookbooks:

$ git clone ssh://$GERRIT_USER@gerrit.wikimedia.org:29418/cloud/wmcs-cookbooks

  • Add the new checked out repository to the list of available cookbooks in the config.yaml file:
cookbooks_base_dirs:
  - ~/wmf/gerrit/cookbooks
  - ~/wmf/gerrit/wmcs-cookbooks
logs_base_dir: ~/wmf/gerrit/spicerack/logs

Also see