From 1f005beb5800e518b34621bc9ad7b381e116f9fe Mon Sep 17 00:00:00 2001 From: whoami-rajat Date: Thu, 18 Oct 2018 21:11:29 +0530 Subject: [PATCH] Add manila-status upgrade check command framework This adds basic framework for manila-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: Id809535d0a01617916a8e29f151ca4e61f738fad Story: 2003657 Task: 26139 --- doc/source/cli/index.rst | 1 + doc/source/cli/manila-status.rst | 78 +++++++++++++++++++ lower-constraints.txt | 1 + manila/cmd/status.py | 53 +++++++++++++ manila/tests/cmd/test_status.py | 30 +++++++ ...rade-check-framework-aef9b5cf9d8e3bda.yaml | 13 ++++ requirements.txt | 1 + setup.cfg | 1 + 8 files changed, 178 insertions(+) create mode 100644 doc/source/cli/manila-status.rst create mode 100644 manila/cmd/status.py create mode 100644 manila/tests/cmd/test_status.py create mode 100644 releasenotes/notes/manila-status-upgrade-check-framework-aef9b5cf9d8e3bda.yaml diff --git a/doc/source/cli/index.rst b/doc/source/cli/index.rst index 89b3cd3487..003f0b7f4c 100644 --- a/doc/source/cli/index.rst +++ b/doc/source/cli/index.rst @@ -20,3 +20,4 @@ Command Line Interface manila manila-manage + manila-status diff --git a/doc/source/cli/manila-status.rst b/doc/source/cli/manila-status.rst new file mode 100644 index 0000000000..caae5bbfb1 --- /dev/null +++ b/doc/source/cli/manila-status.rst @@ -0,0 +1,78 @@ +============= +manila-status +============= + +Synopsis +======== + +:: + + manila-status [] + +Description +=========== + +:program:`manila-status` is a tool that provides routines for checking the +status of a Manila deployment. + +Options +======= + +The standard pattern for executing a :program:`manila-status` command is:: + + manila-status [] + +Run without arguments to see a list of available command categories:: + + manila-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:: + + manila-status upgrade + +These sections describe the available categories and arguments for +:program:`manila-status`. + +Upgrade +~~~~~~~ + +.. _manila-status-checks: + +``manila-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** + + **8.0.0 (Stein)** + + * Placeholder to be filled in with checks as they are added in Stein. diff --git a/lower-constraints.txt b/lower-constraints.txt index 8064269509..300322f27c 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -76,6 +76,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/manila/cmd/status.py b/manila/cmd/status.py new file mode 100644 index 0000000000..897c771604 --- /dev/null +++ b/manila/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 manila.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): + # 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='manila', upgrade_command=Checks()) + +if __name__ == '__main__': + sys.exit(main()) diff --git a/manila/tests/cmd/test_status.py b/manila/tests/cmd/test_status.py new file mode 100644 index 0000000000..215e1762fc --- /dev/null +++ b/manila/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 manila.cmd import status +from manila import test + + +class TestUpgradeChecks(test.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/releasenotes/notes/manila-status-upgrade-check-framework-aef9b5cf9d8e3bda.yaml b/releasenotes/notes/manila-status-upgrade-check-framework-aef9b5cf9d8e3bda.yaml new file mode 100644 index 0000000000..3921200e87 --- /dev/null +++ b/releasenotes/notes/manila-status-upgrade-check-framework-aef9b5cf9d8e3bda.yaml @@ -0,0 +1,13 @@ +--- +prelude: > + Added new tool ``manila-status upgrade check``. +features: + - | + New framework for ``manila-status upgrade check`` command is added. + This framework allows adding various checks which can be run before a + Manila upgrade to ensure if the upgrade can be performed safely. +upgrade: + - | + Operator can now use new CLI tool ``manila-status upgrade check`` + to check if Manila deployment can be safely upgraded from + N-1 to N release. diff --git a/requirements.txt b/requirements.txt index 3eb673fcc3..6cf7d9f213 100644 --- a/requirements.txt +++ b/requirements.txt @@ -24,6 +24,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 oslo.concurrency>=3.26.0 # Apache-2.0 paramiko>=2.0.0 # LGPLv2.1+ diff --git a/setup.cfg b/setup.cfg index 7fe710599e..6c2057b2be 100644 --- a/setup.cfg +++ b/setup.cfg @@ -39,6 +39,7 @@ console_scripts = manila-rootwrap = oslo_rootwrap.cmd:main manila-scheduler = manila.cmd.scheduler:main manila-share = manila.cmd.share:main + manila-status = manila.cmd.status:main wsgi_scripts = manila-wsgi = manila.wsgi.wsgi:initialize_application manila.scheduler.filters =