From b03585d2ca54f24210b46e074edc657d88c9583b Mon Sep 17 00:00:00 2001 From: akhiljain23 Date: Mon, 22 Oct 2018 11:53:05 +0530 Subject: [PATCH] Add framework for karbor-status upgrade check This commit adds the functionality of karbor-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: I8b75d516725c7cdf169d558b1c4b6f92a695ab2e Story: 2003657 Task: 26134 --- doc/source/cli/index.rst | 11 +++ doc/source/cli/karbor-status.rst | 83 +++++++++++++++++++ doc/source/index.rst | 1 + karbor/cmd/status.py | 53 ++++++++++++ karbor/tests/unit/cmd/__init__.py | 0 karbor/tests/unit/cmd/test_status.py | 30 +++++++ lower-constraints.txt | 1 + ...rade-check-framework-7e4f4c1b31f15272.yaml | 13 +++ requirements.txt | 1 + setup.cfg | 1 + 10 files changed, 194 insertions(+) create mode 100644 doc/source/cli/index.rst create mode 100644 doc/source/cli/karbor-status.rst create mode 100644 karbor/cmd/status.py create mode 100644 karbor/tests/unit/cmd/__init__.py create mode 100644 karbor/tests/unit/cmd/test_status.py create mode 100644 releasenotes/notes/add-upgrade-check-framework-7e4f4c1b31f15272.yaml diff --git a/doc/source/cli/index.rst b/doc/source/cli/index.rst new file mode 100644 index 00000000..f59c1c33 --- /dev/null +++ b/doc/source/cli/index.rst @@ -0,0 +1,11 @@ +======================== +Karbor CLI Documentation +======================== + +In this section you will find information on Karbor’s command line +interface. + +.. toctree:: + :maxdepth: 1 + + karbor-status diff --git a/doc/source/cli/karbor-status.rst b/doc/source/cli/karbor-status.rst new file mode 100644 index 00000000..0ef7946e --- /dev/null +++ b/doc/source/cli/karbor-status.rst @@ -0,0 +1,83 @@ +============= +karbor-status +============= + +---------------------------------------- +CLI interface for Karbor status commands +---------------------------------------- + +Synopsis +======== + +:: + + karbor-status [] + +Description +=========== + +:program:`karbor-status` is a tool that provides routines for checking the +status of a Karbor deployment. + +Options +======= + +The standard pattern for executing a :program:`karbor-status` command is:: + + karbor-status [] + +Run without arguments to see a list of available command categories:: + + karbor-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:: + + karbor-status upgrade + +These sections describe the available categories and arguments for +:program:`karbor-status`. + +Upgrade +~~~~~~~ + +.. _karbor-status-checks: + +``karbor-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** + + **x.x.x (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 c24ad09f..601789e5 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -27,6 +27,7 @@ Using Karbor readme install/index configuration/index + cli/index admin/index Available Plugins diff --git a/karbor/cmd/status.py b/karbor/cmd/status.py new file mode 100644 index 00000000..c1c10b98 --- /dev/null +++ b/karbor/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 karbor.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='karbor', upgrade_command=Checks()) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/karbor/tests/unit/cmd/__init__.py b/karbor/tests/unit/cmd/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/karbor/tests/unit/cmd/test_status.py b/karbor/tests/unit/cmd/test_status.py new file mode 100644 index 00000000..31deffc2 --- /dev/null +++ b/karbor/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 karbor.cmd import status +from karbor.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) diff --git a/lower-constraints.txt b/lower-constraints.txt index 76556b42..9e7e88d8 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -78,6 +78,7 @@ oslo.middleware==3.31.0 oslo.policy==1.30.0 oslo.serialization==2.18.0 oslo.service==1.24.0 +oslo.upgradecheck==0.1.0 oslo.utils==3.36.0 oslo.versionedobjects==1.31.2 oslotest==3.2.0 diff --git a/releasenotes/notes/add-upgrade-check-framework-7e4f4c1b31f15272.yaml b/releasenotes/notes/add-upgrade-check-framework-7e4f4c1b31f15272.yaml new file mode 100644 index 00000000..de82be59 --- /dev/null +++ b/releasenotes/notes/add-upgrade-check-framework-7e4f4c1b31f15272.yaml @@ -0,0 +1,13 @@ +--- +prelude: > + Added new tool ``karbor-status upgrade check``. +features: + - | + New framework for ``karbor-status upgrade check`` command is added. + This framework allows adding various checks which can be run before a + Karbor upgrade to ensure if the upgrade can be performed safely. +upgrade: + - | + Operator can now use new CLI tool ``karbor-status upgrade check`` + to check if Karbor deployment can be safely upgraded from + N-1 to N release. diff --git a/requirements.txt b/requirements.txt index 159bd162..e803e2c3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -24,6 +24,7 @@ oslo.middleware>=3.31.0 # Apache-2.0 oslo.policy>=1.30.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.versionedobjects>=1.31.2 # Apache-2.0 Paste>=2.0.2 # MIT PasteDeploy>=1.5.0 # MIT diff --git a/setup.cfg b/setup.cfg index 63fc8998..4a3e73ef 100644 --- a/setup.cfg +++ b/setup.cfg @@ -31,6 +31,7 @@ console_scripts = karbor-manage = karbor.cmd.manage:main karbor-operationengine = karbor.cmd.operationengine:main karbor-protection = karbor.cmd.protection:main + karbor-status = karbor.cmd.status:main oslo.config.opts = karbor.common.opts = karbor.common.opts:list_opts oslo.policy.enforcer =