From d621f727304b04f975fd815dee9fc4752ea47e1e Mon Sep 17 00:00:00 2001 From: akhiljain23 Date: Fri, 19 Oct 2018 03:19:38 +0530 Subject: [PATCH] Add framework for watcher-status upgrade check This commit adds the functionality of watcher-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: Ic3d066af439797d6f705e805334f729b52ce3aac Story: 2003657 Task: 26164 --- doc/source/man/index.rst | 3 +- doc/source/man/watcher-status.rst | 83 +++++++++++++++++++ lower-constraints.txt | 1 + ...rade-check-framework-5bb9693c8a78931c.yaml | 13 +++ requirements.txt | 1 + setup.cfg | 1 + watcher/cmd/status.py | 53 ++++++++++++ watcher/tests/cmd/test_status.py | 30 +++++++ 8 files changed, 184 insertions(+), 1 deletion(-) create mode 100644 doc/source/man/watcher-status.rst create mode 100644 releasenotes/notes/add-upgrade-check-framework-5bb9693c8a78931c.yaml create mode 100644 watcher/cmd/status.py create mode 100644 watcher/tests/cmd/test_status.py diff --git a/doc/source/man/index.rst b/doc/source/man/index.rst index 09a408d91..33c625965 100644 --- a/doc/source/man/index.rst +++ b/doc/source/man/index.rst @@ -5,4 +5,5 @@ watcher-api watcher-applier watcher-db-manage - watcher-decision-engine \ No newline at end of file + watcher-decision-engine + watcher-status diff --git a/doc/source/man/watcher-status.rst b/doc/source/man/watcher-status.rst new file mode 100644 index 000000000..8103b3e57 --- /dev/null +++ b/doc/source/man/watcher-status.rst @@ -0,0 +1,83 @@ +============== +watcher-status +============== + +----------------------------------------- +CLI interface for Watcher status commands +----------------------------------------- + +Synopsis +======== + +:: + + watcher-status [] + +Description +=========== + +:program:`watcher-status` is a tool that provides routines for checking the +status of a Watcher deployment. + +Options +======= + +The standard pattern for executing a :program:`watcher-status` command is:: + + watcher-status [] + +Run without arguments to see a list of available command categories:: + + watcher-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:: + + watcher-status upgrade + +These sections describe the available categories and arguments for +:program:`Watcher-status`. + +Upgrade +~~~~~~~ + +.. _watcher-status-checks: + +``watcher-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** + + **1.12.0 (Stein)** + + * Sample check to be filled in with checks as they are added in Stein. diff --git a/lower-constraints.txt b/lower-constraints.txt index 380d1d8f5..7f5c3474b 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -85,6 +85,7 @@ oslo.policy==1.34.0 oslo.reports==1.27.0 oslo.serialization==2.25.0 oslo.service==1.30.0 +oslo.upgradecheck==0.1.0 oslo.utils==3.36.0 oslo.versionedobjects==1.32.0 oslotest==3.3.0 diff --git a/releasenotes/notes/add-upgrade-check-framework-5bb9693c8a78931c.yaml b/releasenotes/notes/add-upgrade-check-framework-5bb9693c8a78931c.yaml new file mode 100644 index 000000000..0f99f651f --- /dev/null +++ b/releasenotes/notes/add-upgrade-check-framework-5bb9693c8a78931c.yaml @@ -0,0 +1,13 @@ +--- +prelude: > + Added new tool ``watcher-status upgrade check``. +features: + - | + New framework for ``watcher-status upgrade check`` command is added. + This framework allows adding various checks which can be run before a + Watcher upgrade to ensure if the upgrade can be performed safely. +upgrade: + - | + Operator can now use new CLI tool ``watcher-status upgrade check`` + to check if Watcher deployment can be safely upgraded from + N-1 to N release. diff --git a/requirements.txt b/requirements.txt index c6e2ce931..669ae8516 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,6 +22,7 @@ oslo.policy>=1.34.0 # Apache-2.0 oslo.reports>=1.27.0 # Apache-2.0 oslo.serialization>=2.25.0 # Apache-2.0 oslo.service>=1.30.0 # Apache-2.0 +oslo.upgradecheck>=0.1.0 # Apache-2.0 oslo.utils>=3.36.0 # Apache-2.0 oslo.versionedobjects>=1.32.0 # Apache-2.0 PasteDeploy>=1.5.2 # MIT diff --git a/setup.cfg b/setup.cfg index 9b2ee5800..298107f8b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -44,6 +44,7 @@ console_scripts = watcher-decision-engine = watcher.cmd.decisionengine:main watcher-applier = watcher.cmd.applier:main watcher-sync = watcher.cmd.sync:main + watcher-status = watcher.cmd.status:main watcher.database.migration_backend = sqlalchemy = watcher.db.sqlalchemy.migration diff --git a/watcher/cmd/status.py b/watcher/cmd/status.py new file mode 100644 index 000000000..acdd106fc --- /dev/null +++ b/watcher/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 + +from watcher._i18n import _ +from watcher import conf + +CONF = 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='watcher', upgrade_command=Checks()) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/watcher/tests/cmd/test_status.py b/watcher/tests/cmd/test_status.py new file mode 100644 index 000000000..c85f5ac36 --- /dev/null +++ b/watcher/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 watcher.cmd import status +from watcher.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)