From a8b5afa41ec8ccda1ace6ebb85bf94c8a9ea829a Mon Sep 17 00:00:00 2001 From: Adrian Chiris Date: Mon, 18 Nov 2019 14:13:16 +0200 Subject: [PATCH] Add upgrade check for NIC Switch agent This commit adds an upgrade check for NIC switch agent alerting operators to ensure relevant hosts have kernel >= 3.13. This check is introduced due to recent cleanup in NIC switch agent code. As of U release, Supported CentOS major was updated to 8 so it is not expected that any deployment will have hosts running kernel < 3.13. This check is added as an extra precaution. This check should be removed in 1-2 cycles. A TODO was added to reflect that. Change-Id: I34003b3c2f0ac23185d036c9e47dc1c8662d6ce7 Related-bug: #1841067 --- doc/source/cli/neutron-status.rst | 8 ++++ neutron/cmd/upgrade_checks/checks.py | 48 +++++++++++++++++-- .../unit/cmd/upgrade_checks/test_checks.py | 20 ++++++++ 3 files changed, 73 insertions(+), 3 deletions(-) diff --git a/doc/source/cli/neutron-status.rst b/doc/source/cli/neutron-status.rst index 6b2c1684e8b..80561a69b9e 100644 --- a/doc/source/cli/neutron-status.rst +++ b/doc/source/cli/neutron-status.rst @@ -59,3 +59,11 @@ Command details upgrade. * - 255 - An unexpected error occurred. + + **History of Checks** + + **21.0.0 (Ussuri)** + + * A Check was added for NIC Switch agents to ensure nodes are running with + kernel 3.13 or newer. This check serves as a notification for operators + to ensure this requirement is fullfiled on relevant nodes. diff --git a/neutron/cmd/upgrade_checks/checks.py b/neutron/cmd/upgrade_checks/checks.py index 6626fb2b12c..e8c50b85bcd 100644 --- a/neutron/cmd/upgrade_checks/checks.py +++ b/neutron/cmd/upgrade_checks/checks.py @@ -30,8 +30,13 @@ LAST_NETWORKING_OVN_EXPAND_HEAD = "e55d09277410" LAST_NETWORKING_OVN_CONTRACT_HEAD = "1d271ead4eb6" -def get_l3_agents(): - filters = {'agent_type': [constants.AGENT_TYPE_L3]} +def get_agents(agt_type): + """Get agent information from Database + + :param agt_type: agent type, one of constants.AGENT_TYPE_* + :return: list of database query results + """ + filters = {'agent_type': [agt_type]} ctx = context.get_admin_context() query = model_query.get_collection_query(ctx, agent_model.Agent, @@ -39,6 +44,14 @@ def get_l3_agents(): return query.all() +def get_l3_agents(): + return get_agents(constants.AGENT_TYPE_L3) + + +def get_nic_switch_agents(): + return get_agents(constants.AGENT_TYPE_NIC_SWITCH) + + def get_networks(): ctx = context.get_admin_context() query = model_query.get_collection_query(ctx, @@ -67,7 +80,10 @@ class CoreChecks(base.BaseChecks): (_("External network bridge"), self.external_network_bridge_check), (_("Worker counts configured"), self.worker_count_check), - (_("Networking-ovn database revision"), self.ovn_db_revision_check) + (_("Networking-ovn database revision"), + self.ovn_db_revision_check), + (_("NIC Switch agent check kernel"), + self.nic_switch_agent_min_kernel_check) ] @staticmethod @@ -198,3 +214,29 @@ class CoreChecks(base.BaseChecks): return upgradecheck.Result( upgradecheck.Code.SUCCESS, _("Networking-ovn database tables are up to date.")) + + @staticmethod + def nic_switch_agent_min_kernel_check(checker): + # TODO(adrianc): This was introduced in U release, consider removing + # in 1-2 cycles. + # Background: Issue with old kernel is appernet in CentOS 7 and older. + # U release is the first release that moves from CentOS-7 to CentOS-8, + # this was added as a "heads-up" for operators to make sure min kernel + # requirement is fullfiled. + if not cfg.CONF.database.connection: + return upgradecheck.Result( + upgradecheck.Code.WARNING, + _("Database connection string is not set. " + "Check for NIC Switch agent can't be done.")) + + agents = get_nic_switch_agents() + if len(agents): + hosts = ','.join([agent.get("host") for agent in agents]) + return upgradecheck.Result( + upgradecheck.Code.WARNING, + _("NIC Switch agents detected on hosts %s, please ensure the " + "hosts run with a kernel version 3.13 or newer.") % hosts) + else: + return upgradecheck.Result( + upgradecheck.Code.SUCCESS, + _("No NIC Switch agents detected.")) diff --git a/neutron/tests/unit/cmd/upgrade_checks/test_checks.py b/neutron/tests/unit/cmd/upgrade_checks/test_checks.py index 0560e93e7f8..8c341ef9abb 100644 --- a/neutron/tests/unit/cmd/upgrade_checks/test_checks.py +++ b/neutron/tests/unit/cmd/upgrade_checks/test_checks.py @@ -158,3 +158,23 @@ class TestChecks(base.BaseTestCase): result = checks.CoreChecks.ovn_db_revision_check(mock.Mock()) self.assertEqual(Code.FAILURE, result.code) get_ovn_db_revisions.assert_called_once_with() + + def test_nic_switch_agent_min_kernel_check_no_nic_switch_agents(self): + with mock.patch.object(checks, "get_nic_switch_agents", + return_value=[]): + result = checks.CoreChecks.nic_switch_agent_min_kernel_check( + mock.Mock()) + self.assertEqual(Code.SUCCESS, result.code) + + def test_nic_switch_agent_min_kernel_check(self): + agents = [ + {'host': 'Host A'}, + {'host': 'Host B'} + ] + with mock.patch.object(checks, "get_nic_switch_agents", + return_value=agents): + result = checks.CoreChecks.nic_switch_agent_min_kernel_check( + mock.Mock()) + self.assertEqual(Code.WARNING, result.code) + self.assertIn('Host A', result.details) + self.assertIn('Host B', result.details)