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
This commit is contained in:
Luka Peschke 2018-10-24 17:17:04 +02:00
parent 2d7415a3d3
commit b0487b6390
10 changed files with 196 additions and 0 deletions

53
cloudkitty/cli/status.py Normal file
View File

@ -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())

View File

View File

@ -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,
)

View File

@ -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 <category> <command> [<args>]
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).

View File

@ -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

View File

@ -9,3 +9,4 @@ Administration Guide
quick_deployment/index
install/index
configuration/index
cli/index

View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -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