From 5cf8d51c07ecb1a2c366fef05fc87eedf4b78f39 Mon Sep 17 00:00:00 2001 From: akhiljain23 Date: Wed, 24 Oct 2018 17:32:35 +0530 Subject: [PATCH] Add framework for qinling-status upgrade check This commit adds the functionality of qinling-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: I6dd3546be2e03288654c5c3e8dad0aaabfff06a2 Story: 2003657 Task: 26151 --- doc/source/cli/index.rst | 11 ++++ doc/source/cli/qinling-status.rst | 83 +++++++++++++++++++++++++++ doc/source/index.rst | 8 +++ lower-constraints.txt | 1 + qinling/cmd/status.py | 51 ++++++++++++++++ qinling/tests/unit/cmd/__init__.py | 0 qinling/tests/unit/cmd/test_status.py | 30 ++++++++++ requirements.txt | 1 + setup.cfg | 1 + 9 files changed, 186 insertions(+) create mode 100644 doc/source/cli/index.rst create mode 100644 doc/source/cli/qinling-status.rst create mode 100644 qinling/cmd/status.py create mode 100644 qinling/tests/unit/cmd/__init__.py create mode 100644 qinling/tests/unit/cmd/test_status.py diff --git a/doc/source/cli/index.rst b/doc/source/cli/index.rst new file mode 100644 index 00000000..a05bed41 --- /dev/null +++ b/doc/source/cli/index.rst @@ -0,0 +1,11 @@ +========================= +Qinling CLI Documentation +========================= + +In this section you will find information on Qinling's command line +interface. + +.. toctree:: + :maxdepth: 1 + + qinling-status diff --git a/doc/source/cli/qinling-status.rst b/doc/source/cli/qinling-status.rst new file mode 100644 index 00000000..b237e1fa --- /dev/null +++ b/doc/source/cli/qinling-status.rst @@ -0,0 +1,83 @@ +============== +qinling-status +============== + +----------------------------------------- +CLI interface for Qinling status commands +----------------------------------------- + +Synopsis +======== + +:: + + qinling-status [] + +Description +=========== + +:program:`qinling-status` is a tool that provides routines for checking the +status of a Qinling deployment. + +Options +======= + +The standard pattern for executing a :program:`qinling-status` command is:: + + qinling-status [] + +Run without arguments to see a list of available command categories:: + + qinling-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:: + + qinling-status upgrade + +These sections describe the available categories and arguments for +:program:`qinling-status`. + +Upgrade +~~~~~~~ + +.. _qinling-status-checks: + +``qinling-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. + + **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** + + **2.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 dff1fe3d..02a31b98 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -54,6 +54,14 @@ Administration/Operation Guide admin/index +CLI Guide +--------- + +.. toctree:: + :maxdepth: 2 + + cli/index + Contributor/Developer Guide --------------------------- diff --git a/lower-constraints.txt b/lower-constraints.txt index 1815e1f1..d9be4092 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -65,6 +65,7 @@ oslo.middleware==3.35.0 oslo.policy==1.30.0 oslo.serialization==2.18.0 oslo.service==1.24.0 +oslo.upgradecheck==0.1.0 oslo.utils==3.33.0 oslotest==3.2.0 paramiko==2.4.1 diff --git a/qinling/cmd/status.py b/qinling/cmd/status.py new file mode 100644 index 00000000..80e0e6e3 --- /dev/null +++ b/qinling/cmd/status.py @@ -0,0 +1,51 @@ +# 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_config import cfg +from oslo_upgradecheck import upgradecheck + +CONF = cfg.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='qinling', upgrade_command=Checks()) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/qinling/tests/unit/cmd/__init__.py b/qinling/tests/unit/cmd/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/qinling/tests/unit/cmd/test_status.py b/qinling/tests/unit/cmd/test_status.py new file mode 100644 index 00000000..6bae39df --- /dev/null +++ b/qinling/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 qinling.cmd import status +from qinling.tests.unit import base + + +class TestUpgradeChecks(base.BaseTest): + + 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/requirements.txt b/requirements.txt index 10e34242..57f5a4a4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,6 +11,7 @@ oslo.config>=5.2.0 # Apache-2.0 oslo.db>=4.27.0 # Apache-2.0 oslo.messaging>=5.29.0 # Apache-2.0 oslo.policy>=1.30.0 # Apache-2.0 +oslo.upgradecheck>=0.1.0 # Apache-2.0 oslo.utils>=3.33.0 # Apache-2.0 oslo.log>=3.36.0 # Apache-2.0 oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0 diff --git a/setup.cfg b/setup.cfg index 1453b4a7..f182c39c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -28,6 +28,7 @@ console_scripts = qinling-api = qinling.cmd.api:main qinling-engine = qinling.cmd.engine:main qinling-db-manage = qinling.db.sqlalchemy.migration.cli:main + qinling-status = qinling.cmd.status:main qinling.storage.provider: local = qinling.storage.file_system:FileSystemStorage