From 22be5aa57fae08ca5a43393a5b94af7b2e65ce17 Mon Sep 17 00:00:00 2001 From: Joseph Davis Date: Tue, 18 Sep 2018 11:18:09 -0700 Subject: [PATCH] Add "monasca-status upgrade check" for pre-upgrade Add a tool to run before upgrading a Monasca installation that will check for potential issues and report on readiness to upgrade. For Monasca, this initial version effectively does nothing, but gives a framework for future checks to be included. This is a community-wide story for Stein [1]. Story: 2003657 Task: 26142 [1] https://governance.openstack.org/tc/goals/stein/upgrade-checkers.html Change-Id: I799602caa4029d67f59307bf1ca0d1e8f254d415 --- doc/source/cli/index.rst | 49 +++++++++++++++ lower-constraints.txt | 1 + monasca_api/cmd/status.py | 61 +++++++++++++++++++ monasca_api/tests/cmd/__init__.py | 0 monasca_api/tests/cmd/test_status.py | 33 ++++++++++ ...status-upgrade-check-c37e6910c2eb0150.yaml | 12 ++++ requirements.txt | 1 + setup.cfg | 1 + 8 files changed, 158 insertions(+) create mode 100644 monasca_api/cmd/status.py create mode 100644 monasca_api/tests/cmd/__init__.py create mode 100644 monasca_api/tests/cmd/test_status.py create mode 100644 releasenotes/notes/add-monasca-status-upgrade-check-c37e6910c2eb0150.yaml diff --git a/doc/source/cli/index.rst b/doc/source/cli/index.rst index 3c592a291..37a38160b 100644 --- a/doc/source/cli/index.rst +++ b/doc/source/cli/index.rst @@ -2,3 +2,52 @@ Command Line Interface ====================== +monasca (python-monascaclient) +============================== +This is the main command line interface for working with the +Monasca services, including retrieving metrics from storage. + +See the https://docs.openstack.org/python-monascaclient/latest/ for details. + + +monasca_db +========== +CLI for Monasca database management. +:: + + usage: api [-h] [--config-dir DIR] [--config-file PATH] [--version] + {fingerprint,detect-revision,stamp,upgrade,version} ... + + +monasca-status +============== +CLI for checking the status of Monasca. + +Use the command `monasca-status upgrade check` to check +the readiness of the system for an upgrade. + +**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** + +Introduced in the Stein cycle as part of the OpenStack Community wide goal. +https://governance.openstack.org/tc/goals/stein/upgrade-checkers.html diff --git a/lower-constraints.txt b/lower-constraints.txt index 7245e5e6c..2fb5c51b2 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -66,6 +66,7 @@ oslo.middleware==3.31.0 oslo.policy==1.30.0 oslo.serialization==2.18.0 oslo.utils==3.33.0 +oslo.upgradecheck==0.1.0 # Apache-2.0 oslotest==3.2.0 paramiko==2.0.0 PasteDeploy==1.5.0 diff --git a/monasca_api/cmd/status.py b/monasca_api/cmd/status.py new file mode 100644 index 000000000..97f1a1e74 --- /dev/null +++ b/monasca_api/cmd/status.py @@ -0,0 +1,61 @@ +# Copyright (c) 2018 SUSE LLC +# +# 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. + +""" +CLI interface for monasca status commands. +https://governance.openstack.org/tc/goals/stein/upgrade-checkers.html +""" + +import sys + +from oslo_config import cfg +from oslo_upgradecheck import upgradecheck + + +def _(message): + # TODO(joadavis): simplified localization, Monasca not using oslo_i18n + return message + + +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='monasca', upgrade_command=Checks()) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/monasca_api/tests/cmd/__init__.py b/monasca_api/tests/cmd/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/monasca_api/tests/cmd/test_status.py b/monasca_api/tests/cmd/test_status.py new file mode 100644 index 000000000..23c20ede6 --- /dev/null +++ b/monasca_api/tests/cmd/test_status.py @@ -0,0 +1,33 @@ +# Copyright (c) 2018 NEC, Corp. +# Copyright (c) 2018 SUSE LLC +# +# 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 unittest + +from oslo_upgradecheck.upgradecheck import Code + +from monasca_api.cmd import status + + +class TestUpgradeChecks(unittest.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, + "Placeholder should always succeed.") diff --git a/releasenotes/notes/add-monasca-status-upgrade-check-c37e6910c2eb0150.yaml b/releasenotes/notes/add-monasca-status-upgrade-check-c37e6910c2eb0150.yaml new file mode 100644 index 000000000..f06e408e6 --- /dev/null +++ b/releasenotes/notes/add-monasca-status-upgrade-check-c37e6910c2eb0150.yaml @@ -0,0 +1,12 @@ +--- +features: + - | + Added new tool ``monasca-status upgrade check``. + New framework for ``monasca-status upgrade check`` command is added. + This framework allows adding various checks which can be run before a + Monasca upgrade to ensure if the upgrade can be performed safely. +upgrade: + - | + Operator can now use new CLI tool ``monasca-status upgrade check`` + to check if the Monasca deployment can be safely upgraded from + N-1 to N release. diff --git a/requirements.txt b/requirements.txt index c6a3a7273..1754ab40c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,6 +8,7 @@ oslo.log>=3.36.0 # Apache-2.0 oslo.middleware>=3.31.0 # Apache-2.0 oslo.policy>=1.30.0 # Apache-2.0 oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0 +oslo.upgradecheck>=0.1.0 # Apache-2.0 oslo.utils>=3.33.0 # Apache-2.0 python-keystoneclient>=3.8.0 # Apache-2.0 diff --git a/setup.cfg b/setup.cfg index 1159b9fb3..6adaa7ae6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -36,6 +36,7 @@ cassandra = console_scripts = monasca-api = monasca_api.api.server:launch monasca_db = monasca_api.cmd.monasca_db:main + monasca-status = monasca_api.cmd.status:main wsgi_scripts = monasca-api-wsgi = monasca_api.api.wsgi:main