| 1 |
======= |
| 2 |
Usage |
| 3 |
======= |
| 4 |
|
| 5 |
See the module ``oslo_upgradecheck.__main__`` for an example of how to use this |
| 6 |
project. |
| 7 |
|
| 8 |
Each consuming project should create a class that inherits from |
| 9 |
:class:`oslo_upgradecheck.upgradecheck.UpgradeCommands` and implement check |
| 10 |
methods on it. Those check methods should then be added to the |
| 11 |
``_upgrade_checks`` tuple so they will be run when the |
| 12 |
:meth:`oslo_upgradecheck.upgradecheck.UpgradeCommands.check` method is |
| 13 |
called. For example:: |
| 14 |
|
| 15 |
from oslo_upgradecheck import upgradecheck |
| 16 |
|
| 17 |
class ProjectSpecificUpgradeCommands(upgradecheck.UpgradeCommands): |
| 18 |
def an_upgrade_check(self): |
| 19 |
if everything_is_awesome(): |
| 20 |
return upgradecheck.Result( |
| 21 |
upgradecheck.Code.SUCCESS, 'Success details') |
| 22 |
else: |
| 23 |
return upgradecheck.Result( |
| 24 |
upgradecheck.Code.FAILURE, 'Failure details') |
| 25 |
|
| 26 |
_upgrade_checks = (('Awesome upgrade check', an_upgrade_check)) |
| 27 |
|
| 28 |
oslo.upgradecheck also includes a basic implementation of command line argument |
| 29 |
handling that can be used to provide the minimum processing needed to implement |
| 30 |
a ``$SERVICE-status upgrade check`` command. To make use of it, write a method |
| 31 |
that creates an instance of the class created above, then pass that class's |
| 32 |
``check`` function into :func:`oslo_upgradecheck.upgradecheck.main`. The |
| 33 |
project's ConfigOpts instance must also be passed. In most projects this will |
| 34 |
just be cfg.CONF. For example:: |
| 35 |
|
| 36 |
from oslo_config import cfg |
| 37 |
|
| 38 |
def main(): |
| 39 |
return upgradecheck.main( |
| 40 |
conf=cfg.CONF, |
| 41 |
project='myprojectname', |
| 42 |
upgrade_command=ProjectSpecificUpgradeCommands(), |
| 43 |
) |
| 44 |
|
| 45 |
The entry point for the ``$SERVICE-status`` command should then point at this |
| 46 |
function. |
| 47 |
|
| 48 |
Alternatively, if a project has its own CLI code that it would prefer to reuse, |
| 49 |
it simply needs to ensure that the ``inst.check`` method is called when the |
| 50 |
``upgrade check`` parameters are passed to the ``$SERVICE-status`` command. |
| 51 |
|
| 52 |
Example |
| 53 |
------- |
| 54 |
|
| 55 |
The following is a fully functional example of implementing a check command: |
| 56 |
|
| 57 |
.. literalinclude:: main.py |