diff --git a/barbican/cmd/status.py b/barbican/cmd/status.py new file mode 100644 index 000000000..daab75589 --- /dev/null +++ b/barbican/cmd/status.py @@ -0,0 +1,49 @@ +# Copyright (c) 2018 NEC, Corp. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from oslo_config import cfg +from oslo_upgradecheck import upgradecheck + +from barbican.i18n import _ + + +class Checks(upgradecheck.UpgradeCommands): + + """Upgrade checks for the barbican-status upgrade check command + + Upgrade checks should be added as separate methods in this class + and added to _upgrade_checks tuple. + """ + + def _check_placeholder(self): + # This is just a placeholder for upgrade checks, it should be + # removed when the actual checks are added + return upgradecheck.Result(upgradecheck.Code.SUCCESS) + + # The format of the check functions is to return an + # oslo_upgradecheck.upgradecheck.Result + # object with the appropriate + # oslo_upgradecheck.upgradecheck.Code and details set. + # If the check hits warnings or failures then those should be stored + # in the returned Result's "details" attribute. The + # summary will be rolled up at the end of the check() method. + _upgrade_checks = ( + # In the future there should be some real checks added here + (_('Placeholder'), _check_placeholder), + ) + + +def main(): + return upgradecheck.main( + cfg.CONF, project='barbican', upgrade_command=Checks()) diff --git a/barbican/tests/cmd/test-status.py b/barbican/tests/cmd/test-status.py new file mode 100644 index 000000000..37bf3bd76 --- /dev/null +++ b/barbican/tests/cmd/test-status.py @@ -0,0 +1,30 @@ +# Copyright (c) 2018 NEC, Corp. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from oslo_upgradecheck.upgradecheck import Code + +from barbican.cmd import status +from barbican.tests import utils + + +class TestUpgradeChecks(utils.BaseTestCase): + + def setUp(self): + super(TestUpgradeChecks, self).setUp() + self.cmd = status.Checks() + + def test__check_placeholder(self): + check_result = self.cmd._check_placeholder() + self.assertEqual( + Code.SUCCESS, check_result.code) diff --git a/doc/source/cli/barbican-status.rst b/doc/source/cli/barbican-status.rst new file mode 100644 index 000000000..1c818fbef --- /dev/null +++ b/doc/source/cli/barbican-status.rst @@ -0,0 +1,78 @@ +=============== +barbican-status +=============== + +Synopsis +======== + +:: + + barbican-status [] + +Description +=========== + +:program:`barbican-status` is a tool that provides routines for checking the +status of a Barbican deployment. + +Options +======= + +The standard pattern for executing a :program:`barbican-status` command is:: + + barbican-status [] + +Run without arguments to see a list of available command categories:: + + barbican-status + +Categories are: + +* ``upgrade`` + +Detailed descriptions are below. + +You can also run with a category argument such as ``upgrade`` to see a list of +all commands in that category:: + + barbican-status upgrade + +These sections describe the available categories and arguments for +:program:`barbican-status`. + +Upgrade +~~~~~~~ + +.. _barbican-status-checks: + +``barbican-status upgrade check`` + Performs a release-specific readiness check before restarting services with + new code. This command expects to have complete configuration and access + to databases and services. + + **Return Codes** + + .. list-table:: + :widths: 20 80 + :header-rows: 1 + + * - Return code + - Description + * - 0 + - All upgrade readiness checks passed successfully and there is nothing + to do. + * - 1 + - At least one check encountered an issue and requires further + investigation. This is considered a warning but the upgrade may be OK. + * - 2 + - There was an upgrade status check failure that needs to be + investigated. This should be considered something that stops an + upgrade. + * - 255 + - An unexpected error occurred. + + **History of Checks** + + **8.0.0 (Stein)** + + * Placeholder to be filled in with checks as they are added in Stein. diff --git a/doc/source/cli/index.rst b/doc/source/cli/index.rst new file mode 100644 index 000000000..fe8ae2251 --- /dev/null +++ b/doc/source/cli/index.rst @@ -0,0 +1,7 @@ +CLI Reference +============= + +.. toctree:: + :maxdepth: 1 + + barbican-status diff --git a/doc/source/index.rst b/doc/source/index.rst index 194870aab..e812a5069 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -9,6 +9,7 @@ such as Symmetric Keys, Asymmetric Keys, Certificates and raw binary data. :maxdepth: 2 admin/index + cli/index install/index configuration/index contributor/index diff --git a/lower-constraints.txt b/lower-constraints.txt index 51a568a2b..67418c1c7 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -73,6 +73,7 @@ oslo.middleware==3.31.0 oslo.policy==1.30.0 oslo.serialization==2.18.0 oslo.service==1.24.0 +oslo.upgradecheck==0.1.1 oslo.utils==3.33.0 oslo.versionedobjects==1.31.2 oslotest==3.2.0 diff --git a/releasenotes/notes/barbican-status-upgrade-check-framework-9df56289b1d91ba4.yaml b/releasenotes/notes/barbican-status-upgrade-check-framework-9df56289b1d91ba4.yaml new file mode 100644 index 000000000..5325dfa62 --- /dev/null +++ b/releasenotes/notes/barbican-status-upgrade-check-framework-9df56289b1d91ba4.yaml @@ -0,0 +1,13 @@ +--- +prelude: > + Added new tool ``barbican-status upgrade check``. +features: + - | + New framework for ``barbican-status upgrade check`` command is added. + This framework allows adding various checks which can be run before a + Barbican upgrade to ensure if the upgrade can be performed safely. +upgrade: + - | + Operator can now use new CLI tool ``barbican-status upgrade check`` + to check if Barbican deployment can be safely upgraded from + N-1 to N release. diff --git a/requirements.txt b/requirements.txt index 86ded330a..8aae045f6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,6 +17,7 @@ oslo.log>=3.36.0 # Apache-2.0 oslo.policy>=1.30.0 # Apache-2.0 oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0 oslo.service!=1.28.1,>=1.24.0 # Apache-2.0 +oslo.upgradecheck>=0.1.1 # Apache-2.0 oslo.utils>=3.33.0 # Apache-2.0 oslo.versionedobjects>=1.31.2 # Apache-2.0 Paste>=2.0.2 # MIT diff --git a/setup.cfg b/setup.cfg index 7217b9874..6906a5e73 100644 --- a/setup.cfg +++ b/setup.cfg @@ -45,6 +45,7 @@ console_scripts = pkcs11-kek-rewrap = barbican.cmd.pkcs11_kek_rewrap:main pkcs11-key-generation = barbican.cmd.pkcs11_key_generation:main barbican-retry = barbican.cmd.retry_scheduler:main + barbican-status = barbican.cmd.status:main wsgi_scripts = barbican-wsgi-api = barbican.api.app:get_api_wsgi_script