diff --git a/doc/source/admin/guides/upgrade.rst b/doc/source/admin/guides/upgrade.rst index f89c3bcfde..a9ea1e066f 100644 --- a/doc/source/admin/guides/upgrade.rst +++ b/doc/source/admin/guides/upgrade.rst @@ -50,6 +50,9 @@ of upgrading. In the case of the Load Balancing service, it means no downtime nor reconfiguration of service-managed resources (e.g. load balancers, listeners, pools and members). +#. Run the :ref:`octavia-status upgrade check ` + command to validate that Octavia is ready for upgrade. + #. Gracefully stop all Octavia processes. We recommend in this order: Housekeeping, Health manager, API, Worker. diff --git a/doc/source/admin/index.rst b/doc/source/admin/index.rst index 0aae97a0e2..d9b226f3d2 100644 --- a/doc/source/admin/index.rst +++ b/doc/source/admin/index.rst @@ -31,6 +31,7 @@ Operator Reference ../contributor/guides/dev-quick-start.rst guides/operator-maintenance.rst guides/upgrade.rst + octavia-status ../configuration/configref.rst ../configuration/policy.rst Anchor.rst diff --git a/doc/source/admin/octavia-status.rst b/doc/source/admin/octavia-status.rst new file mode 100644 index 0000000000..109dce4582 --- /dev/null +++ b/doc/source/admin/octavia-status.rst @@ -0,0 +1,83 @@ +============== +octavia-status +============== + +----------------------------------------- +CLI interface for Octavia status commands +----------------------------------------- + +Synopsis +======== + +:: + + octavia-status [] + +Description +=========== + +:program:`octavia-status` is a tool that provides routines for checking the +status of a Octavia deployment. + +Options +======= + +The standard pattern for executing a :program:`octavia-status` command is:: + + octavia-status [] + +Run without arguments to see a list of available command categories:: + + octavia-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:: + + octavia-status upgrade + +These sections describe the available categories and arguments for +:program:`octavia-status`. + +Upgrade +~~~~~~~ + +.. _octavia-status-checks: + +``octavia-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** + + **4.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 c13aa63e70..60c5d4282d 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -89,6 +89,7 @@ oslo.policy==1.30.0 oslo.reports==1.18.0 oslo.serialization==2.18.0 oslo.service==1.30.0 +oslo.upgradecheck==0.1.0 oslo.utils==3.33.0 oslotest==3.2.0 packaging==17.1 diff --git a/octavia/cmd/status.py b/octavia/cmd/status.py new file mode 100644 index 0000000000..72476df38e --- /dev/null +++ b/octavia/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_config import cfg +from oslo_upgradecheck import upgradecheck + +from octavia.i18n import _ + +CONF = cfg.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='octavia', upgrade_command=Checks()) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/octavia/tests/unit/cmd/test_status.py b/octavia/tests/unit/cmd/test_status.py new file mode 100644 index 0000000000..75576c73f0 --- /dev/null +++ b/octavia/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 octavia.cmd import status +from octavia.tests.unit 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) diff --git a/releasenotes/notes/add-upgrade-check-framework-cc440f3f440ba6d2.yaml b/releasenotes/notes/add-upgrade-check-framework-cc440f3f440ba6d2.yaml new file mode 100644 index 0000000000..b0922d6890 --- /dev/null +++ b/releasenotes/notes/add-upgrade-check-framework-cc440f3f440ba6d2.yaml @@ -0,0 +1,11 @@ +--- +features: + - | + Added new tool ``octavia-status upgrade check``. + This framework allows adding various checks which can be run before a + Octavia upgrade to ensure if the upgrade can be performed safely. +upgrade: + - | + Operator can now use new CLI tool ``octavia-status upgrade check`` + to check if Octavia deployment can be safely upgraded from + N-1 to N release. diff --git a/requirements.txt b/requirements.txt index a067bd05e5..f723e3ff49 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,6 +25,7 @@ oslo.messaging>=5.29.0 # Apache-2.0 oslo.middleware>=3.31.0 # Apache-2.0 oslo.policy>=1.30.0 # Apache-2.0 oslo.reports>=1.18.0 # Apache-2.0 +oslo.upgradecheck>=0.1.0 # Apache-2.0 oslo.utils>=3.33.0 # Apache-2.0 pyasn1!=0.2.3,>=0.1.8 # BSD pyasn1-modules>=0.0.6 # BSD diff --git a/setup.cfg b/setup.cfg index 4b9ee73935..4c32b700d9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -51,6 +51,7 @@ console_scripts = octavia-db-manage = octavia.db.migration.cli:main amphora-agent = octavia.cmd.agent:main haproxy-vrrp-check = octavia.cmd.haproxy_vrrp_check:main + octavia-status = octavia.cmd.status:main octavia.api.drivers = noop_driver = octavia.api.drivers.noop_driver.driver:NoopProviderDriver amphora = octavia.api.drivers.amphora_driver.driver:AmphoraProviderDriver