From 34fd2a0ec7b7fdebdc3cdd3eef643921711ec1bd Mon Sep 17 00:00:00 2001 From: whoami-rajat Date: Thu, 18 Oct 2018 13:00:59 +0530 Subject: [PATCH] Add dragonflow-status upgrade check command framework This adds basic framework for dragonflow-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: I9791b3fcce65b08f92b3c5d54b529633579f795a Story: 2003657 Task: 26128 --- doc/source/cli/dragonflow-status.rst | 78 +++++++++++++++++++ doc/source/cli/index.rst | 7 ++ doc/source/index.rst | 8 ++ dragonflow/cmd/status.py | 52 +++++++++++++ dragonflow/tests/unit/cmd/test_status.py | 30 +++++++ lower-constraints.txt | 1 + ...rade-check-framework-efd2592c6decdd16.yaml | 13 ++++ requirements.txt | 1 + setup.cfg | 3 +- 9 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 doc/source/cli/dragonflow-status.rst create mode 100644 doc/source/cli/index.rst create mode 100644 dragonflow/cmd/status.py create mode 100644 dragonflow/tests/unit/cmd/test_status.py create mode 100644 releasenotes/notes/dragonflow-status-upgrade-check-framework-efd2592c6decdd16.yaml diff --git a/doc/source/cli/dragonflow-status.rst b/doc/source/cli/dragonflow-status.rst new file mode 100644 index 000000000..d3c991319 --- /dev/null +++ b/doc/source/cli/dragonflow-status.rst @@ -0,0 +1,78 @@ +================= +dragonflow-status +================= + +Synopsis +======== + +:: + + dragonflow-status [] + +Description +=========== + +:program:`dragonflow-status` is a tool that provides routines for checking the +status of a Dragonflow deployment. + +Options +======= + +The standard pattern for executing a :program:`dragonflow-status` command is:: + + dragonflow-status [] + +Run without arguments to see a list of available command categories:: + + dragonflow-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:: + + dragonflow-status upgrade + +These sections describe the available categories and arguments for +:program:`dragonflow-status`. + +Upgrade +~~~~~~~ + +.. _dragonflow-status-checks: + +``dragonflow-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** + + **4.0.0 (Stein)** + + * Placeholder to be filled in with checks as they are added in Stein. diff --git a/doc/source/cli/index.rst b/doc/source/cli/index.rst new file mode 100644 index 000000000..b755c1dbe --- /dev/null +++ b/doc/source/cli/index.rst @@ -0,0 +1,7 @@ +CLI Guide +========= + +.. toctree:: + :maxdepth: 1 + + dragonflow-status diff --git a/doc/source/index.rst b/doc/source/index.rst index 9dde9d4b6..eb4644022 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -39,6 +39,14 @@ Dragonflow Specs specs/index +CLI Reference +============= + +.. toctree:: + :maxdepth: 1 + + cli/index + Developer References ==================== diff --git a/dragonflow/cmd/status.py b/dragonflow/cmd/status.py new file mode 100644 index 000000000..4870eea78 --- /dev/null +++ b/dragonflow/cmd/status.py @@ -0,0 +1,52 @@ +# 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 dragonflow._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='dragonflow', upgrade_command=Checks()) + +if __name__ == '__main__': + sys.exit(main()) diff --git a/dragonflow/tests/unit/cmd/test_status.py b/dragonflow/tests/unit/cmd/test_status.py new file mode 100644 index 000000000..1cd82cb64 --- /dev/null +++ b/dragonflow/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 dragonflow.cmd import status +from dragonflow.tests import base as tests_base + + +class TestUpgradeChecks(tests_base.BaseTestCase): + + 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/lower-constraints.txt b/lower-constraints.txt index 9c4eb4cde..c143db4e6 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -86,6 +86,7 @@ oslo.reports==1.18.0 oslo.rootwrap==5.13.0 oslo.serialization==2.18.0 oslo.service==1.30.0 +oslo.upgradecheck==0.1.0 oslo.utils==3.36.0 oslo.versionedobjects==1.32.0 oslotest==3.2.0 diff --git a/releasenotes/notes/dragonflow-status-upgrade-check-framework-efd2592c6decdd16.yaml b/releasenotes/notes/dragonflow-status-upgrade-check-framework-efd2592c6decdd16.yaml new file mode 100644 index 000000000..76d42bb2f --- /dev/null +++ b/releasenotes/notes/dragonflow-status-upgrade-check-framework-efd2592c6decdd16.yaml @@ -0,0 +1,13 @@ +--- +prelude: > + Added new tool ``dragonflow-status upgrade check``. +features: + - | + New framework for ``dragonflow-status upgrade check`` command is added. + This framework allows adding various checks which can be run before a + Dragonflow upgrade to ensure if the upgrade can be performed safely. +upgrade: + - | + Operator can now use new CLI tool ``dragonflow-status upgrade check`` + to check if Dragonflow deployment can be safely upgraded from + N-1 to N release. diff --git a/requirements.txt b/requirements.txt index 21df8e85f..e120b386a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,6 +19,7 @@ oslo.i18n>=3.15.3 # Apache-2.0 oslo.log>=3.36.0 # Apache-2.0 oslo.reports>=1.18.0 # Apache-2.0 oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0 +oslo.upgradecheck>=0.1.0 # Apache-2.0 ovsdbapp>=0.11.0 # Apache-2.0 crc16>=0.1.1 # LGPLv3+ netaddr>=0.7.18 # BSD diff --git a/setup.cfg b/setup.cfg index 9ad22c214..7bbb64aad 100644 --- a/setup.cfg +++ b/setup.cfg @@ -58,7 +58,8 @@ console_scripts = df-l3-agent = dragonflow.cmd.eventlet.df_l3_agent:main df-metadata-service = dragonflow.cmd.eventlet.df_metadata_service:main df-bgp-service = dragonflow.cmd.eventlet.df_bgp_service:main - df-skydive-service= dragonflow.cmd.df_skydive_service:service_main + df-skydive-service = dragonflow.cmd.df_skydive_service:service_main + dragonflow-status = dragonflow.cmd.status:main dragonflow.pubsub_driver = zmq_pubsub_driver = dragonflow.db.pubsub_drivers.zmq_pubsub_driver:ZMQPubSubConnect zmq_bind_pubsub_driver = dragonflow.db.pubsub_drivers.zmq_pubsub_driver:ZMQPubSubBind