From 2ccf639a396decdb87d0a9e02aafcb59c5cd2610 Mon Sep 17 00:00:00 2001 From: akhiljain23 Date: Thu, 18 Oct 2018 11:14:30 +0530 Subject: [PATCH] Add framework for magnum-status upgrade check This commit adds the functionality of magnum-status CLI for performing upgrade checks as part of the Stein cycle upgrade-checkers goal. It only includes a sample check which must be replaced by real checks in future. Change-Id: Ia8a74fd8bd5a804e71bb04eb0615fa114a517bc4 Story: 2003657 Task: 26138 --- doc/source/cli/index.rst | 10 ++ doc/source/cli/magnum-status.rst | 95 +++++++++++++++++++ doc/source/index.rst | 6 ++ lower-constraints.txt | 1 + magnum/cmd/status.py | 53 +++++++++++ magnum/tests/unit/cmd/test_status.py | 30 ++++++ ...rade-check-framework-5057ad67a7690a14.yaml | 8 ++ requirements.txt | 1 + setup.cfg | 1 + 9 files changed, 205 insertions(+) create mode 100644 doc/source/cli/index.rst create mode 100644 doc/source/cli/magnum-status.rst create mode 100644 magnum/cmd/status.py create mode 100644 magnum/tests/unit/cmd/test_status.py create mode 100644 releasenotes/notes/add-upgrade-check-framework-5057ad67a7690a14.yaml diff --git a/doc/source/cli/index.rst b/doc/source/cli/index.rst new file mode 100644 index 0000000000..e8fa50afd5 --- /dev/null +++ b/doc/source/cli/index.rst @@ -0,0 +1,10 @@ +Magnum CLI Documentation +======================== + +In this section you will find information on Magnum’s command line +interface. + +.. toctree:: + :maxdepth: 1 + + magnum-status diff --git a/doc/source/cli/magnum-status.rst b/doc/source/cli/magnum-status.rst new file mode 100644 index 0000000000..8ba27ed26b --- /dev/null +++ b/doc/source/cli/magnum-status.rst @@ -0,0 +1,95 @@ +============= +magnum-status +============= + +---------------------------------------- +CLI interface for Magnum status commands +---------------------------------------- + +Synopsis +======== + +:: + + magnum-status [] + +Description +=========== + +:program:`magnum-status` is a tool that provides routines for checking the +status of a Magnum deployment. + +Options +======= + +The standard pattern for executing a :program:`magnum-status` command is:: + + magnum-status [] + +Run without arguments to see a list of available command categories:: + + magnum-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:: + + magnum-status upgrade + +These sections describe the available categories and arguments for +:program:`magnum-status`. + +Upgrade +~~~~~~~ + +.. _magnum-status-checks: + +``magnum-status upgrade check`` + Performs a release-specific readiness check before restarting services with + new code. For example, missing or changed configuration options, + incompatible object states, or other conditions that could lead to + failures while upgrading. + + .. table:: **Sample Output** + + +------------------------+ + | Upgrade Check Results | + +========================+ + | Check: Sample Check | + | | + | Result: Success | + | | + | Details: Sample detail | + +------------------------+ + + **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)** + + * Sample check to be filled in with checks as they are added in Stein. diff --git a/doc/source/index.rst b/doc/source/index.rst index 8d7b42a02e..0a993b1505 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -82,6 +82,12 @@ Installation Guide install/index +CLI Guide +========= +.. toctree:: + :maxdepth: 1 + + cli/index Sample Configurations and Policies ================================== diff --git a/lower-constraints.txt b/lower-constraints.txt index 729117b8b5..f01209b2ec 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -88,6 +88,7 @@ oslo.policy==1.30.0 oslo.reports==1.18.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/magnum/cmd/status.py b/magnum/cmd/status.py new file mode 100644 index 0000000000..ca5ea68f22 --- /dev/null +++ b/magnum/cmd/status.py @@ -0,0 +1,53 @@ +# 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. + +import sys + +from oslo_upgradecheck import upgradecheck + +import magnum.conf +from magnum.i18n import _ + +CONF = magnum.conf.CONF + + +class Checks(upgradecheck.UpgradeCommands): + + """Contains upgrade checks + + Various upgrade checks should be added as separate methods in this class + and added to _upgrade_checks tuple. + """ + + def _sample_check(self): + """This is sample check added to test the upgrade check framework + + It needs to be removed after adding any real upgrade check + """ + return upgradecheck.Result(upgradecheck.Code.SUCCESS, 'Sample detail') + + _upgrade_checks = ( + # Sample check added for now. + # Whereas in future real checks must be added here in tuple + (_('Sample Check'), _sample_check), + ) + + +def main(): + return upgradecheck.main( + CONF, project='magnum', upgrade_command=Checks()) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/magnum/tests/unit/cmd/test_status.py b/magnum/tests/unit/cmd/test_status.py new file mode 100644 index 0000000000..27ebbc6f52 --- /dev/null +++ b/magnum/tests/unit/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 magnum.cmd import status +from magnum.tests import base + + +class TestUpgradeChecks(base.TestCase): + + def setUp(self): + super(TestUpgradeChecks, self).setUp() + self.cmd = status.Checks() + + def test__sample_check(self): + check_result = self.cmd._sample_check() + self.assertEqual( + Code.SUCCESS, check_result.code) diff --git a/releasenotes/notes/add-upgrade-check-framework-5057ad67a7690a14.yaml b/releasenotes/notes/add-upgrade-check-framework-5057ad67a7690a14.yaml new file mode 100644 index 0000000000..0613a51772 --- /dev/null +++ b/releasenotes/notes/add-upgrade-check-framework-5057ad67a7690a14.yaml @@ -0,0 +1,8 @@ +--- +prelude: > + Added new tool ``magnum-status upgrade check``. +features: + - | + New framework for ``magnum-status upgrade check`` command is added. + This framework allows adding various checks which can be run before a + Magnum upgrade to ensure if the upgrade can be performed safely. diff --git a/requirements.txt b/requirements.txt index cf3eff2926..a5eff15d54 100644 --- a/requirements.txt +++ b/requirements.txt @@ -34,6 +34,7 @@ oslo.middleware>=3.31.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 oslo.reports>=1.18.0 # Apache-2.0 diff --git a/setup.cfg b/setup.cfg index f5ef552d49..7cbd240d7e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -46,6 +46,7 @@ console_scripts = magnum-conductor = magnum.cmd.conductor:main magnum-db-manage = magnum.cmd.db_manage:main magnum-driver-manage = magnum.cmd.driver_manage:main + magnum-status = magnum.cmd.status:main oslo.config.opts = magnum = magnum.opts:list_opts