From d75eaff065f876383ff3aedf6ef53bb26522f05c Mon Sep 17 00:00:00 2001 From: whoami-rajat Date: Tue, 23 Oct 2018 16:40:14 +0530 Subject: [PATCH] Add kuryr-status upgrade check command framework This adds basic framework for kuryr-status upgrade check commands. For now it has only "check_placeholder" check implemented. Real checks can be added to this tool in the future. Change-Id: I8af38f087672a390ec8b2b78916315b5a646fcbb Story: 2003657 Task: 26137 --- doc/source/cli/index.rst | 7 ++ doc/source/cli/kuryr-status.rst | 78 +++++++++++++++++++ doc/source/index.rst | 1 + kuryr/cmd/__init__.py | 0 kuryr/cmd/status.py | 54 +++++++++++++ kuryr/tests/unit/cmd/__init__.py | 0 kuryr/tests/unit/cmd/test_status.py | 30 +++++++ lower-constraints.txt | 1 + ...rade-check-framework-77b478d559020b92.yaml | 13 ++++ requirements.txt | 1 + setup.cfg | 3 + 11 files changed, 188 insertions(+) create mode 100644 doc/source/cli/index.rst create mode 100644 doc/source/cli/kuryr-status.rst create mode 100644 kuryr/cmd/__init__.py create mode 100644 kuryr/cmd/status.py create mode 100644 kuryr/tests/unit/cmd/__init__.py create mode 100644 kuryr/tests/unit/cmd/test_status.py create mode 100644 releasenotes/notes/kuryr-status-upgrade-check-framework-77b478d559020b92.yaml diff --git a/doc/source/cli/index.rst b/doc/source/cli/index.rst new file mode 100644 index 00000000..3365c27b --- /dev/null +++ b/doc/source/cli/index.rst @@ -0,0 +1,7 @@ +CLI Reference +============= + +.. toctree:: + :maxdepth: 1 + + kuryr-status diff --git a/doc/source/cli/kuryr-status.rst b/doc/source/cli/kuryr-status.rst new file mode 100644 index 00000000..1a5ac2f8 --- /dev/null +++ b/doc/source/cli/kuryr-status.rst @@ -0,0 +1,78 @@ +============ +kuryr-status +============ + +Synopsis +======== + +:: + + kuryr-status [] + +Description +=========== + +:program:`kuryr-status` is a tool that provides routines for checking the +status of a Kuryr deployment. + +Options +======= + +The standard pattern for executing a :program:`kuryr-status` command is:: + + kuryr-status [] + +Run without arguments to see a list of available command categories:: + + kuryr-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:: + + kuryr-status upgrade + +These sections describe the available categories and arguments for +:program:`kuryr-status`. + +Upgrade +~~~~~~~ + +.. _kuryr-status-checks: + +``kuryr-status upgrade check`` + Performs a release-specific readiness check before restarting services with + new code. This command expects to have complete configuration and access + to databases and services. + + **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.9.0 (Stein)** + + * Placeholder 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 92813f4c..c1a4d480 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -29,6 +29,7 @@ Contents: installation usage contributing + cli/index releasenotes Design and Developer Docs diff --git a/kuryr/cmd/__init__.py b/kuryr/cmd/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/kuryr/cmd/status.py b/kuryr/cmd/status.py new file mode 100644 index 00000000..be095400 --- /dev/null +++ b/kuryr/cmd/status.py @@ -0,0 +1,54 @@ +# 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 kuryr.lib._i18n import _ + + +class Checks(upgradecheck.UpgradeCommands): + + """Upgrade checks for the kuryr-status upgrade check command + + Upgrade checks should be added as separate methods in this class + and added to _upgrade_checks tuple. + """ + + def _check_placeholder(self): + # This is just a placeholder for upgrade checks, it should be + # removed when the actual checks are added + return upgradecheck.Result(upgradecheck.Code.SUCCESS) + + # The format of the check functions is to return an + # oslo_upgradecheck.upgradecheck.Result + # object with the appropriate + # oslo_upgradecheck.upgradecheck.Code and details set. + # If the check hits warnings or failures then those should be stored + # in the returned Result's "details" attribute. The + # summary will be rolled up at the end of the check() method. + _upgrade_checks = ( + # In the future there should be some real checks added here + (_('Placeholder'), _check_placeholder), + ) + + +def main(): + return upgradecheck.main( + cfg.CONF, project='kuryr', upgrade_command=Checks()) + +if __name__ == '__main__': + sys.exit(main()) diff --git a/kuryr/tests/unit/cmd/__init__.py b/kuryr/tests/unit/cmd/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/kuryr/tests/unit/cmd/test_status.py b/kuryr/tests/unit/cmd/test_status.py new file mode 100644 index 00000000..8fa4a009 --- /dev/null +++ b/kuryr/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 kuryr.cmd import status +from kuryr.tests.unit import base + + +class TestUpgradeChecks(base.TestCase): + + def setUp(self): + super(TestUpgradeChecks, self).setUp() + self.cmd = status.Checks() + + def test__check_placeholder(self): + check_result = self.cmd._check_placeholder() + self.assertEqual( + Code.SUCCESS, check_result.code) diff --git a/lower-constraints.txt b/lower-constraints.txt index 554bc4b6..d62e5722 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -62,6 +62,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.33.0 oslotest==3.2.0 Paste==2.0.2 diff --git a/releasenotes/notes/kuryr-status-upgrade-check-framework-77b478d559020b92.yaml b/releasenotes/notes/kuryr-status-upgrade-check-framework-77b478d559020b92.yaml new file mode 100644 index 00000000..6a884cbd --- /dev/null +++ b/releasenotes/notes/kuryr-status-upgrade-check-framework-77b478d559020b92.yaml @@ -0,0 +1,13 @@ +--- +prelude: > + Added new tool ``kuryr-status upgrade check``. +features: + - | + New framework for ``kuryr-status upgrade check`` command is added. + This framework allows adding various checks which can be run before a + Kuryr upgrade to ensure if the upgrade can be performed safely. +upgrade: + - | + Operator can now use new CLI tool ``kuryr-status upgrade check`` + to check if Kuryr deployment can be safely upgraded from + N-1 to N release. diff --git a/requirements.txt b/requirements.txt index d46278d0..8ae7f7b9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,6 +9,7 @@ neutron-lib>=1.13.0 # Apache-2.0 oslo.concurrency>=3.25.0 # Apache-2.0 oslo.i18n>=3.15.3 # Apache-2.0 oslo.log>=3.36.0 # Apache-2.0 +oslo.upgradecheck>=0.1.0 # Apache-2.0 oslo.utils>=3.33.0 # Apache-2.0 pbr!=2.1.0,>=2.0.0 # Apache-2.0 pyroute2>=0.4.21;sys_platform!='win32' # Apache-2.0 (+ dual licensed GPL2) diff --git a/setup.cfg b/setup.cfg index 6b4b1ffc..3f179a7c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -25,6 +25,9 @@ universal = 1 oslo.config.opts = kuryr = kuryr.lib.opts:list_kuryr_opts +console_scripts = + kuryr-status = kuryr.cmd.status:main + [files] packages = kuryr