From 79e8f86aa01188d00c19584fd4fc6f954c972c24 Mon Sep 17 00:00:00 2001 From: whoami-rajat Date: Wed, 17 Oct 2018 21:14:07 +0530 Subject: [PATCH] Add cyborg-status upgrade check command framework This adds basic framework for cyborg-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: I4a180f9a1b25c75489ad3cfee30a7b55506e0bbd Story: 2003657 Task: 26126 --- cyborg/cmd/status.py | 50 ++++++++++++ cyborg/tests/unit/cmd/test_status.py | 30 +++++++ doc/source/cli/cyborg-status.rst | 78 +++++++++++++++++++ doc/source/cli/index.rst | 8 ++ doc/source/index.rst | 13 ++++ ...rade-check-framework-567f8df30b971f13.yaml | 13 ++++ requirements.txt | 1 + setup.cfg | 1 + 8 files changed, 194 insertions(+) create mode 100644 cyborg/cmd/status.py create mode 100644 cyborg/tests/unit/cmd/test_status.py create mode 100644 doc/source/cli/cyborg-status.rst create mode 100644 doc/source/cli/index.rst create mode 100644 releasenotes/notes/cyborg-status-upgrade-check-framework-567f8df30b971f13.yaml diff --git a/cyborg/cmd/status.py b/cyborg/cmd/status.py new file mode 100644 index 00000000..2f1d7b76 --- /dev/null +++ b/cyborg/cmd/status.py @@ -0,0 +1,50 @@ +# 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_config import cfg +from oslo_upgradecheck import upgradecheck + +from cyborg.common.i18n import _ + + +class Checks(upgradecheck.UpgradeCommands): + + """Various upgrade checks should be added as separate methods in this class + and added to _upgrade_checks tuple. + """ + + def _check_placeholder(self): + # TODO(whoami-rajat):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='cyborg', upgrade_command=Checks()) + +if __name__ == '__main__': + sys.exit(main()) diff --git a/cyborg/tests/unit/cmd/test_status.py b/cyborg/tests/unit/cmd/test_status.py new file mode 100644 index 00000000..0c97c94f --- /dev/null +++ b/cyborg/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 cyborg.cmd import status +from cyborg.tests 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/doc/source/cli/cyborg-status.rst b/doc/source/cli/cyborg-status.rst new file mode 100644 index 00000000..50af2c02 --- /dev/null +++ b/doc/source/cli/cyborg-status.rst @@ -0,0 +1,78 @@ +============= +cyborg-status +============= + +Synopsis +======== + +:: + + cyborg-status [] + +Description +=========== + +:program:`cyborg-status` is a tool that provides routines for checking the +status of a Cyborg deployment. + +Options +======= + +The standard pattern for executing a :program:`cyborg-status` command is:: + + cyborg-status [] + +Run without arguments to see a list of available command categories:: + + cyborg-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:: + + cyborg-status upgrade + +These sections describe the available categories and arguments for +:program:`cyborg-status`. + +Upgrade +~~~~~~~ + +.. _cyborg-status-checks: + +``cyborg-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** + + **2.0.0 (Stein)** + + * Placeholder to be filled in with checks as they are added in Stein. diff --git a/doc/source/cli/index.rst b/doc/source/cli/index.rst new file mode 100644 index 00000000..3106e7b2 --- /dev/null +++ b/doc/source/cli/index.rst @@ -0,0 +1,8 @@ +================================ +Command-Line Interface Reference +================================ + +.. toctree:: + :maxdepth: 1 + + cyborg-status diff --git a/doc/source/index.rst b/doc/source/index.rst index a9415fc7..64957472 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -41,6 +41,19 @@ API admin/api +CLI Reference +------------- + +Information on the commands available through Cyborg's Command Line +Interface (CLI) can be found in this section of documentation. + + +.. toctree:: + :maxdepth: 1 + + cli/index + + Developer Documentation ----------------------- diff --git a/releasenotes/notes/cyborg-status-upgrade-check-framework-567f8df30b971f13.yaml b/releasenotes/notes/cyborg-status-upgrade-check-framework-567f8df30b971f13.yaml new file mode 100644 index 00000000..0fcd37db --- /dev/null +++ b/releasenotes/notes/cyborg-status-upgrade-check-framework-567f8df30b971f13.yaml @@ -0,0 +1,13 @@ +--- +prelude: > + Added new tool ``cyborg-status upgrade check``. +features: + - | + New framework for ``cyborg-status upgrade check`` command is added. + This framework allows adding various checks which can be run before a + Cyborg upgrade to ensure if the upgrade can be performed safely. +upgrade: + - | + Operator can now use new CLI tool ``cyborg-status upgrade check`` + to check if Cyborg deployment can be safely upgraded from + N-1 to N release. diff --git a/requirements.txt b/requirements.txt index b03fdfd1..c61ec883 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,6 +15,7 @@ oslo.messaging>=5.29.0 # Apache-2.0 oslo.concurrency>=3.26.0 # Apache-2.0 oslo.service>=1.0.0,!=1.28.1 # Apache-2.0 oslo.db>=4.1.0 # Apache-2.0 +oslo.upgradecheck>=0.1.0 # Apache-2.0 oslo.utils>=3.33.0 # Apache-2.0 oslo.versionedobjects>=1.31.2 # Apache-2.0 oslo.policy>=0.5.0 # Apache-2.0 diff --git a/setup.cfg b/setup.cfg index 942b907a..ae54e966 100644 --- a/setup.cfg +++ b/setup.cfg @@ -38,6 +38,7 @@ console_scripts = cyborg-conductor = cyborg.cmd.conductor:main cyborg-dbsync = cyborg.cmd.dbsync:main cyborg-agent = cyborg.cmd.agent:main + cyborg-status = cyborg.cmd.status:main wsgi_scripts = cyborg-wsgi-api = cyborg.api.wsgi_app:init_application