From 3a83fc8b9d9b2f3b0ded637f4117a510997f6de4 Mon Sep 17 00:00:00 2001 From: akhiljain23 Date: Fri, 19 Oct 2018 12:28:52 +0530 Subject: [PATCH] Add framework for vitrage-status upgrade check This commit adds the functionality of vitrage-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: Ib0c880b15a2f99a4db75654b5c41c6f10d9261af Story: 2003657 Task: 26163 --- doc/source/cli/index.rst | 11 +++ doc/source/cli/vitrage-status.rst | 83 +++++++++++++++++++ doc/source/index.rst | 7 ++ lower-constraints.txt | 1 + ...rade-check-framework-166ba1c7e266953e.yaml | 13 +++ requirements.txt | 1 + setup.cfg | 1 + vitrage/cli/status.py | 53 ++++++++++++ vitrage/tests/unit/cli/__init__.py | 0 vitrage/tests/unit/cli/test_status.py | 30 +++++++ 10 files changed, 200 insertions(+) create mode 100644 doc/source/cli/index.rst create mode 100644 doc/source/cli/vitrage-status.rst create mode 100644 releasenotes/notes/add-upgrade-check-framework-166ba1c7e266953e.yaml create mode 100644 vitrage/cli/status.py create mode 100644 vitrage/tests/unit/cli/__init__.py create mode 100644 vitrage/tests/unit/cli/test_status.py diff --git a/doc/source/cli/index.rst b/doc/source/cli/index.rst new file mode 100644 index 000000000..db506ceb6 --- /dev/null +++ b/doc/source/cli/index.rst @@ -0,0 +1,11 @@ +========================= +Vitrage CLI Documentation +========================= + +In this section you will find information on Vitrage’s command line +interface. + +.. toctree:: + :maxdepth: 1 + + vitrage-status diff --git a/doc/source/cli/vitrage-status.rst b/doc/source/cli/vitrage-status.rst new file mode 100644 index 000000000..1f05ccddf --- /dev/null +++ b/doc/source/cli/vitrage-status.rst @@ -0,0 +1,83 @@ +============== +vitrage-status +============== + +----------------------------------------- +CLI interface for Vitrage status commands +----------------------------------------- + +Synopsis +======== + +:: + + vitrage-status [] + +Description +=========== + +:program:`vitrage-status` is a tool that provides routines for checking the +status of a Vitrage deployment. + +Options +======= + +The standard pattern for executing a :program:`vitrage-status` command is:: + + vitrage-status [] + +Run without arguments to see a list of available command categories:: + + vitrage-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:: + + vitrage-status upgrade + +These sections describe the available categories and arguments for +:program:`vitrage-status`. + +Upgrade +~~~~~~~ + +.. _vitrage-status-checks: + +``vitrage-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** + + **4.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 4fbcbc4e8..e719c55a9 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -79,6 +79,13 @@ Developer Guide contributor/devstack-installation contributor/configuration +CLI Guide +--------- +.. toctree:: + :maxdepth: 1 + + cli/index + Design Documents ---------------- diff --git a/lower-constraints.txt b/lower-constraints.txt index 44f5e3937..6aac5f6df 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -67,6 +67,7 @@ oslo.middleware==3.35.0 oslo.policy==1.34.0 oslo.serialization==2.25.0 oslo.service==1.30.0 +oslo.upgradecheck==0.1.1 oslo.utils==3.36.0 oslotest==3.3.0 osprofiler==2.0.0 diff --git a/releasenotes/notes/add-upgrade-check-framework-166ba1c7e266953e.yaml b/releasenotes/notes/add-upgrade-check-framework-166ba1c7e266953e.yaml new file mode 100644 index 000000000..f8fb6ac53 --- /dev/null +++ b/releasenotes/notes/add-upgrade-check-framework-166ba1c7e266953e.yaml @@ -0,0 +1,13 @@ +--- +prelude: > + Added new tool ``vitrage-status upgrade check``. +features: + - | + New framework for ``vitrage-status upgrade check`` command is added. + This framework allows adding various checks which can be run before a + Vitrage upgrade to ensure if the upgrade can be performed safely. +upgrade: + - | + Operator can now use new CLI tool ``vitrage-status upgrade check`` + to check if Vitrage deployment can be safely upgraded from + N-1 to N release. diff --git a/requirements.txt b/requirements.txt index d1d15e770..d30bf2cff 100644 --- a/requirements.txt +++ b/requirements.txt @@ -27,6 +27,7 @@ oslo.serialization>=2.25.0 # Apache-2.0 oslo.log>=3.37.0 # Apache-2.0 oslo.policy>=1.34.0 # Apache-2.0 oslo.i18n>=3.20.0 # Apache-2.0 +oslo.upgradecheck>=0.1.1 # Apache-2.0 pecan>=1.2.1 # BSD PasteDeploy>=1.5.2 # MIT Werkzeug>=0.14.1 # BSD License diff --git a/setup.cfg b/setup.cfg index d8d9e3bc1..88b2a240c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -34,6 +34,7 @@ console_scripts = vitrage-dbsync = vitrage.cli.storage:dbsync vitrage-purge-data = vitrage.cli.storage:purge_data vitrage-snmp-parsing = vitrage.cli.snmp_parsing:main + vitrage-status = vitrage.cli.status:main vitrage.entity_graph = networkx = vitrage.graph.driver.networkx_graph:NXGraph diff --git a/vitrage/cli/status.py b/vitrage/cli/status.py new file mode 100644 index 000000000..362af912f --- /dev/null +++ b/vitrage/cli/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 vitrage.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='vitrage', upgrade_command=Checks()) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/vitrage/tests/unit/cli/__init__.py b/vitrage/tests/unit/cli/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/vitrage/tests/unit/cli/test_status.py b/vitrage/tests/unit/cli/test_status.py new file mode 100644 index 000000000..2298c9d56 --- /dev/null +++ b/vitrage/tests/unit/cli/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 vitrage.cli import status +from vitrage.tests 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)