From cc41e8621b5c99ecb5286f49513507eaf3ed6378 Mon Sep 17 00:00:00 2001 From: akhiljain23 Date: Fri, 19 Oct 2018 14:31:19 +0530 Subject: [PATCH] Add framework for sahara-status upgrade check This commit adds the functionality of sahara-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: Idcb8d9eaf689800812cf6087e9c5937058c89ea6 Story: 2003657 Task: 26152 --- doc/source/cli/index.rst | 11 +++ doc/source/cli/sahara-status.rst | 83 +++++++++++++++++++ doc/source/index.rst | 9 ++ lower-constraints.txt | 1 + ...rade-check-framework-9cd18dbc47b0efbd.yaml | 13 +++ requirements.txt | 1 + sahara/cli/sahara_status.py | 53 ++++++++++++ sahara/tests/unit/cli/test_sahara_status.py | 30 +++++++ setup.cfg | 1 + 9 files changed, 202 insertions(+) create mode 100644 doc/source/cli/index.rst create mode 100644 doc/source/cli/sahara-status.rst create mode 100644 releasenotes/notes/add-upgrade-check-framework-9cd18dbc47b0efbd.yaml create mode 100644 sahara/cli/sahara_status.py create mode 100644 sahara/tests/unit/cli/test_sahara_status.py diff --git a/doc/source/cli/index.rst b/doc/source/cli/index.rst new file mode 100644 index 0000000000..6c8fcf7072 --- /dev/null +++ b/doc/source/cli/index.rst @@ -0,0 +1,11 @@ +======================== +Sahara CLI Documentation +======================== + +In this section you will find information on Sahara’s command line +interface. + +.. toctree:: + :maxdepth: 1 + + sahara-status diff --git a/doc/source/cli/sahara-status.rst b/doc/source/cli/sahara-status.rst new file mode 100644 index 0000000000..a1ba218665 --- /dev/null +++ b/doc/source/cli/sahara-status.rst @@ -0,0 +1,83 @@ +============= +sahara-status +============= + +---------------------------------------- +CLI interface for Sahara status commands +---------------------------------------- + +Synopsis +======== + +:: + + sahara-status [] + +Description +=========== + +:program:`sahara-status` is a tool that provides routines for checking the +status of a Sahara deployment. + +Options +======= + +The standard pattern for executing a :program:`sahara-status` command is:: + + sahara-status [] + +Run without arguments to see a list of available command categories:: + + sahara-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:: + + sahara-status upgrade + +These sections describe the available categories and arguments for +:program:`sahara-status`. + +Upgrade +~~~~~~~ + +.. _sahara-status-checks: + +``sahara-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** + + **10.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 13db51f32d..a9b03d6f4b 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -42,6 +42,15 @@ User Guide user/index +CLI Guide +--------- + +.. toctree:: + :maxdepth: 2 + + cli/index + + Operator Documentation ---------------------- diff --git a/lower-constraints.txt b/lower-constraints.txt index bd9e81412a..8567363e5f 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -83,6 +83,7 @@ oslo.policy==1.30.0 oslo.rootwrap==5.8.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 packaging==17.1 diff --git a/releasenotes/notes/add-upgrade-check-framework-9cd18dbc47b0efbd.yaml b/releasenotes/notes/add-upgrade-check-framework-9cd18dbc47b0efbd.yaml new file mode 100644 index 0000000000..00a82e8bf9 --- /dev/null +++ b/releasenotes/notes/add-upgrade-check-framework-9cd18dbc47b0efbd.yaml @@ -0,0 +1,13 @@ +--- +prelude: > + Added new tool ``sahara-status upgrade check``. +features: + - | + New framework for ``sahara-status upgrade check`` command is added. + This framework allows adding various checks which can be run before a + Sahara upgrade to ensure if the upgrade can be performed safely. +upgrade: + - | + Operator can now use new CLI tool ``sahara-status upgrade check`` + to check if Sahara deployment can be safely upgraded from + N-1 to N release. diff --git a/requirements.txt b/requirements.txt index 6cea8b0dfd..e0522288ff 100644 --- a/requirements.txt +++ b/requirements.txt @@ -27,6 +27,7 @@ oslo.policy>=1.30.0 # Apache-2.0 oslo.rootwrap>=5.8.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.0 # Apache-2.0 oslo.utils>=3.33.0 # Apache-2.0 paramiko>=2.0.0 # LGPLv2.1+ requests>=2.14.2 # Apache-2.0 diff --git a/sahara/cli/sahara_status.py b/sahara/cli/sahara_status.py new file mode 100644 index 0000000000..ea9cdc3710 --- /dev/null +++ b/sahara/cli/sahara_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_config import cfg +from oslo_upgradecheck import upgradecheck + +from sahara.i18n import _ + +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='sahara', upgrade_command=Checks()) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/sahara/tests/unit/cli/test_sahara_status.py b/sahara/tests/unit/cli/test_sahara_status.py new file mode 100644 index 0000000000..3ac3c179e1 --- /dev/null +++ b/sahara/tests/unit/cli/test_sahara_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 sahara.cli import sahara_status +from sahara.tests.unit import base + + +class TestUpgradeChecks(base.SaharaTestCase): + + def setUp(self): + super(TestUpgradeChecks, self).setUp() + self.cmd = sahara_status.Checks() + + def test__sample_check(self): + check_result = self.cmd._sample_check() + self.assertEqual( + Code.SUCCESS, check_result.code) diff --git a/setup.cfg b/setup.cfg index 48de0d796f..fc4cc8977b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -41,6 +41,7 @@ console_scripts = _sahara-subprocess = sahara.cli.sahara_subprocess:main sahara-templates = sahara.db.templates.cli:main sahara-image-pack = sahara.cli.image_pack.cli:main + sahara-status = sahara.cli.sahara_status:main wsgi_scripts = sahara-wsgi-api = sahara.cli.sahara_api:setup_api