From fb06b7c96c72a61127831472fa3360e273671411 Mon Sep 17 00:00:00 2001 From: akhiljain23 Date: Fri, 19 Oct 2018 02:19:56 +0530 Subject: [PATCH] Add framework for tacker-status upgrade check This commit adds the functionality of tacker-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: I7bb127fa10dd168ab24dd8c42013576f84eadfbb Story: 2003657 Task: 26158 --- doc/source/cli/index.rst | 27 +++++ doc/source/cli/tacker-status.rst | 99 +++++++++++++++++++ doc/source/index.rst | 1 + lower-constraints.txt | 1 + ...rade-check-framework-33d6e16e24a50207.yaml | 8 ++ requirements.txt | 1 + setup.cfg | 1 + tacker/cmd/status.py | 53 ++++++++++ tacker/tests/unit/cmd/__init__.py | 0 tacker/tests/unit/cmd/test_status.py | 30 ++++++ 10 files changed, 221 insertions(+) create mode 100644 doc/source/cli/index.rst create mode 100644 doc/source/cli/tacker-status.rst create mode 100644 releasenotes/notes/add-upgrade-check-framework-33d6e16e24a50207.yaml create mode 100644 tacker/cmd/status.py create mode 100644 tacker/tests/unit/cmd/__init__.py create mode 100644 tacker/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 000000000..f291709d6 --- /dev/null +++ b/doc/source/cli/index.rst @@ -0,0 +1,27 @@ +.. + Copyright (c) 2018 NEC, Corp. + All Rights Reserved. + + 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. + +======================== +Tacker CLI Documentation +======================== + +In this section you will find information on Tacker’s command line +interface. + +.. toctree:: + :maxdepth: 1 + + tacker-status diff --git a/doc/source/cli/tacker-status.rst b/doc/source/cli/tacker-status.rst new file mode 100644 index 000000000..e97392459 --- /dev/null +++ b/doc/source/cli/tacker-status.rst @@ -0,0 +1,99 @@ +.. + Copyright (c) 2018 NEC, Corp. + All Rights Reserved. + + 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. + +============= +tacker-status +============= + +---------------------------------------- +CLI interface for Tacker status commands +---------------------------------------- + +Synopsis +======== + +:: + + tacker-status [] + +Description +=========== + +:program:`tacker-status` is a tool that provides routines for checking the +status of a Tacker deployment. + +Options +======= + +The standard pattern for executing a :program:`tacker-status` command is:: + + tacker-status [] + +Run without arguments to see a list of available command categories:: + + tacker-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:: + + tacker-status upgrade + +These sections describe the available categories and arguments for +:program:`tacker-status`. + +Upgrade +~~~~~~~ + +.. _tacker-status-checks: + +``tacker-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** + + **0.11.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 9587f29bd..4f69a94c8 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -33,6 +33,7 @@ Contents user/index admin/index configuration/index + cli/index contributor/index reference/index diff --git a/lower-constraints.txt b/lower-constraints.txt index ecc54eac9..3b21863db 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -82,6 +82,7 @@ oslo.reports==1.18.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-33d6e16e24a50207.yaml b/releasenotes/notes/add-upgrade-check-framework-33d6e16e24a50207.yaml new file mode 100644 index 000000000..4b6ea7320 --- /dev/null +++ b/releasenotes/notes/add-upgrade-check-framework-33d6e16e24a50207.yaml @@ -0,0 +1,8 @@ +--- +prelude: > + Added new tool ``tacker-status upgrade check``. +features: + - | + New framework for ``tacker-status upgrade check`` command is added. + This framework allows adding various checks which can be run before a + Tacker upgrade to ensure if the upgrade can be performed safely. diff --git a/requirements.txt b/requirements.txt index 86e36814e..76198d817 100644 --- a/requirements.txt +++ b/requirements.txt @@ -32,6 +32,7 @@ oslo.reports>=1.18.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 openstackdocstheme>=1.18.1 # Apache-2.0 python-neutronclient>=6.7.0 # Apache-2.0 diff --git a/setup.cfg b/setup.cfg index 41ded5dc3..bc27f2527 100644 --- a/setup.cfg +++ b/setup.cfg @@ -43,6 +43,7 @@ console_scripts = tacker-server = tacker.cmd.eventlet.tacker_server:main tacker-conductor = tacker.cmd.eventlet.conductor:main tacker-rootwrap = oslo.rootwrap.cmd:main + tacker-status = tacker.cmd.status:main tacker.service_plugins = dummy = tacker.tests.unit.dummy_plugin:DummyServicePlugin vnfm = tacker.vnfm.plugin:VNFMPlugin diff --git a/tacker/cmd/status.py b/tacker/cmd/status.py new file mode 100644 index 000000000..8a638a73f --- /dev/null +++ b/tacker/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_config import cfg +from oslo_upgradecheck import upgradecheck + +from tacker._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='tacker', upgrade_command=Checks()) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/tacker/tests/unit/cmd/__init__.py b/tacker/tests/unit/cmd/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tacker/tests/unit/cmd/test_status.py b/tacker/tests/unit/cmd/test_status.py new file mode 100644 index 000000000..de02361bc --- /dev/null +++ b/tacker/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 tacker.cmd import status +from tacker.tests.unit 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)