From b0487b6390b8b64e02a069157acb21e91c2d6343 Mon Sep 17 00:00:00 2001 From: Luka Peschke Date: Wed, 24 Oct 2018 17:17:04 +0200 Subject: [PATCH] Support upgrade checks This adds the ``cloudkitty-status upgrade check`` command to CloudKitty. For now, this tool checks the storage version and raises a warning in case v1 is used. Depends-On: https://review.openstack.org/#/c/615928/ Change-Id: I39dc98fb716392a22765f169e2da0d389b33b941 Story: 2003657 Task: 26124 --- cloudkitty/cli/status.py | 53 ++++++++++++ cloudkitty/tests/cli/__init__.py | 0 cloudkitty/tests/cli/test_status.py | 39 +++++++++ doc/source/admin/cli/cloudkitty-status.rst | 85 +++++++++++++++++++ doc/source/admin/cli/index.rst | 10 +++ doc/source/admin/index.rst | 1 + lower-constraints.txt | 1 + ...status-upgrade-check-fdcf054643e071d8.yaml | 5 ++ requirements.txt | 1 + setup.cfg | 1 + 10 files changed, 196 insertions(+) create mode 100644 cloudkitty/cli/status.py create mode 100644 cloudkitty/tests/cli/__init__.py create mode 100644 cloudkitty/tests/cli/test_status.py create mode 100644 doc/source/admin/cli/cloudkitty-status.rst create mode 100644 doc/source/admin/cli/index.rst create mode 100644 releasenotes/notes/status-upgrade-check-fdcf054643e071d8.yaml diff --git a/cloudkitty/cli/status.py b/cloudkitty/cli/status.py new file mode 100644 index 00000000..97248934 --- /dev/null +++ b/cloudkitty/cli/status.py @@ -0,0 +1,53 @@ +# Copyright 2018 Objectif Libre +# +# 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 cloudkitty.i18n import _ +# Import needed to register storage options +from cloudkitty import storage # noqa + + +CONF = cfg.CONF + + +class CloudkittyUpgradeChecks(upgradecheck.UpgradeCommands): + + def _storage_version(self): + if CONF.storage.version < 2: + return upgradecheck.Result( + upgradecheck.Code.WARNING, + 'Storage version is inferior to 2. Support for v1 storage ' + 'will be dropped in a future release.', + ) + return upgradecheck.Result(upgradecheck.Code.SUCCESS) + + _upgrade_checks = ( + (_('Storage version'), _storage_version), + ) + + +def main(): + return upgradecheck.main( + conf=CONF, + project='cloudkitty', + upgrade_command=CloudkittyUpgradeChecks(), + ) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/cloudkitty/tests/cli/__init__.py b/cloudkitty/tests/cli/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cloudkitty/tests/cli/test_status.py b/cloudkitty/tests/cli/test_status.py new file mode 100644 index 00000000..5f563312 --- /dev/null +++ b/cloudkitty/tests/cli/test_status.py @@ -0,0 +1,39 @@ +# Copyright 2018 Objectif Libre +# +# 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 import upgradecheck + +from cloudkitty.cli import status +from cloudkitty import tests + + +class CloudKittyStatusCheckUpgradeTest(tests.TestCase): + + def setUp(self): + super(CloudKittyStatusCheckUpgradeTest, self).setUp() + self._checks = status.CloudkittyUpgradeChecks() + + def test_storage_version_with_v1(self): + self.conf.set_override('version', 1, 'storage') + self.assertEqual( + upgradecheck.Code.WARNING, + self._checks._storage_version().code, + ) + + def test_storage_version_with_v2(self): + self.conf.set_override('version', 2, 'storage') + self.assertEqual( + upgradecheck.Code.SUCCESS, + self._checks._storage_version().code, + ) diff --git a/doc/source/admin/cli/cloudkitty-status.rst b/doc/source/admin/cli/cloudkitty-status.rst new file mode 100644 index 00000000..954b0518 --- /dev/null +++ b/doc/source/admin/cli/cloudkitty-status.rst @@ -0,0 +1,85 @@ +===================== +Cloudkitty Status CLI +===================== + +This chapter documents :command:`cloudkitty-status`. + +For help on a specific :command:`cloudkitty-status` command, enter: + +.. code-block:: console + + $ cloudkitty-status COMMAND --help + +cloudkitty-status +================= + +:program:`cloudkitty-status` is a tool that provides routines for checking the +status of a Cloudkitty deployment. + +The standard pattern for executing a :program:`cloudkitty-status` command is: + +.. code-block:: console + + cloudkitty-status [] + +Run without arguments to see a list of available command categories: + +.. code-block:: console + + cloudkitty-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: + +.. code-block:: console + + cloudkitty-status upgrade + +The following sections describe the available categories and arguments for +:program:`cloudkitty-status`. + +cloudkitty-status upgrade +========================= + +.. _cloudkitty-status-upgrade-check: + +cloudkitty-status upgrade check +------------------------------- + +``cloudkitty-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 the database. + + **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** + + **9.0.0 (Stein)** + + * Checks that the storage interface version is 2 (which is default). diff --git a/doc/source/admin/cli/index.rst b/doc/source/admin/cli/index.rst new file mode 100644 index 00000000..da3575aa --- /dev/null +++ b/doc/source/admin/cli/index.rst @@ -0,0 +1,10 @@ +Command-Line Interface Reference +================================ + +Information on the commands available through Cloudkitty's Command Line +Interface (CLI) can be found in this section. + +.. toctree:: + :maxdepth: 1 + + cloudkitty-status diff --git a/doc/source/admin/index.rst b/doc/source/admin/index.rst index 36192f8d..d41d0b5f 100644 --- a/doc/source/admin/index.rst +++ b/doc/source/admin/index.rst @@ -9,3 +9,4 @@ Administration Guide quick_deployment/index install/index configuration/index + cli/index diff --git a/lower-constraints.txt b/lower-constraints.txt index 45c5f24b..7be8c564 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -21,6 +21,7 @@ oslo.messaging==5.24.2 # Apache-2.0 oslo.middleware==3.27.0 # Apache-2.0 oslo.policy==0.5.0 # Apache-2.0 oslo.utils==3.5.0 # Apache-2.0 +oslo.upgradecheck==0.1.1 # Apache-2.0 SQLAlchemy==1.0.10 # MIT six==1.9.0 # MIT stevedore==1.5.0 # Apache-2.0 diff --git a/releasenotes/notes/status-upgrade-check-fdcf054643e071d8.yaml b/releasenotes/notes/status-upgrade-check-fdcf054643e071d8.yaml new file mode 100644 index 00000000..fcbd405b --- /dev/null +++ b/releasenotes/notes/status-upgrade-check-fdcf054643e071d8.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + A new ``cloudkitty-status upgrade check`` command has been added. It can be + used to validate a deployment before upgrading it from release N-1 to N. diff --git a/requirements.txt b/requirements.txt index b261bdd6..616826f0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,6 +23,7 @@ oslo.messaging>=5.24.2,!=9.0.0 # Apache-2.0 oslo.middleware>=3.27.0 # Apache-2.0 oslo.policy>=0.5.0 # Apache-2.0 oslo.utils>=3.5.0 # Apache-2.0 +oslo.upgradecheck>=0.1.1 # Apache-2.0 SQLAlchemy>=1.0.10,!=1.1.5,!=1.1.6,!=1.1.7,!=1.1.8 # MIT six>=1.9.0 # MIT stevedore>=1.5.0 # Apache-2.0 diff --git a/setup.cfg b/setup.cfg index 0f41e872..53c22bb8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -28,6 +28,7 @@ console_scripts = cloudkitty-processor = cloudkitty.cli.processor:main cloudkitty-storage-init = cloudkitty.cli.storage:main cloudkitty-writer = cloudkitty.cli.writer:main + cloudkitty-status = cloudkitty.cli.status:main wsgi_scripts = cloudkitty-api = cloudkitty.api.app:build_wsgi_app