diff --git a/doc/source/cli/index.rst b/doc/source/cli/index.rst index 23a9b9fae..62d93651a 100644 --- a/doc/source/cli/index.rst +++ b/doc/source/cli/index.rst @@ -2,5 +2,15 @@ Zun Command Line Guide ====================== -TODO: There is currently no command line guide for Zun. The work will be -tracked here: https://blueprints.launchpad.net/zun/+spec/zun-cli-guide +In this section you will find information on Zun’s command line +interface. + +.. toctree:: + :maxdepth: 1 + + zun-status + + +.. note:: + Other command line guide for Zun to be added. The work will be + tracked here: https://blueprints.launchpad.net/zun/+spec/zun-cli-guide diff --git a/doc/source/cli/zun-status.rst b/doc/source/cli/zun-status.rst new file mode 100644 index 000000000..406632a95 --- /dev/null +++ b/doc/source/cli/zun-status.rst @@ -0,0 +1,83 @@ +========== +Zun-status +========== + +------------------------------------- +CLI interface for zun status commands +------------------------------------- + +Synopsis +======== + +:: + + zun-status [] + +Description +=========== + +:program:`zun-status` is a tool that provides routines for checking the +status of a Zun deployment. + +Options +======= + +The standard pattern for executing a :program:`zun-status` command is:: + + zun-status [] + +Run without arguments to see a list of available command categories:: + + zun-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:: + + zun-status upgrade + +These sections describe the available categories and arguments for +:program:`zun-status`. + +Upgrade +~~~~~~~ + +.. _zun-status-checks: + +``zun-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** + + **3.0.0 (Stein)** + + * Sample check to be filled in with checks as they are added in Stein. diff --git a/lower-constraints.txt b/lower-constraints.txt index d584de212..b906af94b 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -83,6 +83,7 @@ oslo.policy==1.30.0 oslo.privsep==1.23.0 oslo.serialization==2.18.0 oslo.service==1.24.0 +oslo.upgradecheck==0.1.0 oslo.utils==3.33.0 oslo.versionedobjects==1.31.2 oslo.rootwrap==5.8.0 diff --git a/releasenotes/notes/add-upgrade-check-framework-4729fcb4ecd31221.yaml b/releasenotes/notes/add-upgrade-check-framework-4729fcb4ecd31221.yaml new file mode 100644 index 000000000..056e2e2b3 --- /dev/null +++ b/releasenotes/notes/add-upgrade-check-framework-4729fcb4ecd31221.yaml @@ -0,0 +1,14 @@ +--- +prelude: > + Added new tool ``zun-status upgrade check``. +features: + - | + New framework for ``zun-status upgrade check`` command is added. + This framework allows adding various checks which can be run before a + Zun upgrade to ensure if the upgrade can be performed safely. +upgrade: + - | + Operator can now use new CLI tool ``zun-status upgrade check`` + to check if Zun deployment can be safely upgraded from + N-1 to N release. + diff --git a/requirements.txt b/requirements.txt index 242a46265..b698377a0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -26,6 +26,7 @@ oslo.context>=2.19.2 # Apache-2.0 oslo.utils>=3.33.0 # Apache-2.0 oslo.db>=4.27.0 # Apache-2.0 oslo.rootwrap>=5.8.0 # Apache-2.0 +oslo.upgradecheck>=0.1.0 # Apache-2.0 os-brick>=2.2.0 # Apache-2.0 six>=1.10.0 # MIT SQLAlchemy!=1.1.5,!=1.1.6,!=1.1.7,!=1.1.8,>=1.0.10 # MIT diff --git a/setup.cfg b/setup.cfg index e2200bf14..2d491845e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -46,6 +46,7 @@ console_scripts = zun-db-manage = zun.cmd.db_manage:main zun-wsproxy = zun.cmd.wsproxy:main zun-rootwrap = oslo_rootwrap.cmd:main + zun-status = zun.cmd.status:main wsgi_scripts = zun-api-wsgi = zun.api.wsgi:init_application diff --git a/zun/cmd/status.py b/zun/cmd/status.py new file mode 100644 index 000000000..a12d1dd6b --- /dev/null +++ b/zun/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_upgradecheck import upgradecheck + +from zun.common.i18n import _ +import zun.conf + +CONF = zun.conf.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='zun', upgrade_command=Checks()) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/zun/tests/unit/cmd/__init__.py b/zun/tests/unit/cmd/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/zun/tests/unit/cmd/test_status.py b/zun/tests/unit/cmd/test_status.py new file mode 100644 index 000000000..e1b9fd32c --- /dev/null +++ b/zun/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 zun.cmd import status +from zun.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)