From bb4cd9ea786a67723daba9d051f0d6dc3a8df694 Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Mon, 1 Jul 2024 15:41:30 +0200 Subject: [PATCH] Upgrade check on removed or deprecated hardware types and interfaces Issues an error on removed items still used in the configuration. Issues a warning on deprecated items or nodes that use removed drivers or interfaces. Change-Id: Iebb4cd611f7111cde20acf9ba3d4c9127925b6cf Closes-Bug: #2051954 --- doc/source/cli/ironic-status.rst | 5 ++ ironic/cmd/status.py | 52 +++++++++++++++++++ ...driver-upgrade-check-d3afaf127cafbc06.yaml | 8 +++ 3 files changed, 65 insertions(+) create mode 100644 releasenotes/notes/driver-upgrade-check-d3afaf127cafbc06.yaml diff --git a/doc/source/cli/ironic-status.rst b/doc/source/cli/ironic-status.rst index c14cd376a8..106d6f0f05 100644 --- a/doc/source/cli/ironic-status.rst +++ b/doc/source/cli/ironic-status.rst @@ -82,3 +82,8 @@ Upgrade * Adds a check to validate the configured policy file is not JSON based as JSON based policies have been deprecated. + + **2024.2** + + * Adds a check that hardware types and interfaces in the configuration exist, + and that nodes are configured with existing drivers and interfaces. diff --git a/ironic/cmd/status.py b/ironic/cmd/status.py index f3940ff5cd..63cfcc746f 100644 --- a/ironic/cmd/status.py +++ b/ironic/cmd/status.py @@ -22,9 +22,11 @@ from oslo_upgradecheck import upgradecheck import sqlalchemy from ironic.cmd import dbsync +from ironic.common import driver_factory from ironic.common.i18n import _ from ironic.common import policy # noqa importing to load policy config. import ironic.conf +from ironic.db import api as db_api CONF = ironic.conf.CONF @@ -131,6 +133,54 @@ class Checks(upgradecheck.UpgradeCommands): else: return upgradecheck.Result(upgradecheck.Code.SUCCESS) + def _check_hardware_types_interfaces(self): + try: + hw_types = driver_factory.hardware_types() + except Exception as exc: + # NOTE(dtantsur): if the hardware types failed to load, we cannot + # validate the hardware interfaces, so returning early. + msg = f"Some hardware types cannot be loaded: {exc}" + return upgradecheck.Result(upgradecheck.Code.FAILURE, details=msg) + + try: + ifaces = driver_factory.all_interfaces() + except Exception as exc: + msg = f"Some hardware interfaces cannot be loaded: {exc}" + return upgradecheck.Result(upgradecheck.Code.FAILURE, details=msg) + + warnings = [] + for name, obj in hw_types.items(): + if not obj.supported: + warnings.append(f"Hardware type {name} is deprecated or not " + "supported") + + for iface_type, iface_dict in ifaces.items(): + iface_type = iface_type.capitalize() + for name, obj in iface_dict.items(): + if not obj.supported: + warnings.append(f"{iface_type} interface {name} is " + "deprecated or not supported") + + dbapi = db_api.get_instance() + for node in dbapi.get_node_list(): + if node.driver not in hw_types: + warnings.append(f"Node {node.uuid} uses an unknown driver " + f"{node.driver}") + for iface_type, iface_dict in ifaces.items(): + value = getattr(node, f"{iface_type}_interface") + # NOTE(dtantsur): the interface value can be empty if a new + # interface type has just been added, and nodes have not been + # updated yet. + if value and value not in iface_dict: + warnings.append(f"Node {node.uuid} uses an unknown " + f"{iface_type} interface {value}") + + if warnings: + msg = ". ".join(warnings) + return upgradecheck.Result(upgradecheck.Code.WARNING, details=msg) + else: + return upgradecheck.Result(upgradecheck.Code.SUCCESS) + # A tuple of check tuples of (, ). # The name of the check will be used in the output of this command. # The check function takes no arguments and returns an @@ -147,6 +197,8 @@ class Checks(upgradecheck.UpgradeCommands): # Victoria -> Wallaby migration (_('Policy File JSON to YAML Migration'), (common_checks.check_policy_json, {'conf': CONF})), + (_('Hardware Types and Interfaces Check'), + _check_hardware_types_interfaces), ) diff --git a/releasenotes/notes/driver-upgrade-check-d3afaf127cafbc06.yaml b/releasenotes/notes/driver-upgrade-check-d3afaf127cafbc06.yaml new file mode 100644 index 0000000000..dbdf4b70c8 --- /dev/null +++ b/releasenotes/notes/driver-upgrade-check-d3afaf127cafbc06.yaml @@ -0,0 +1,8 @@ +--- +upgrade: + - | + Adds upgrade checks for the following situations: + + * Error on unknown hardware types or interfaces in the configuration. + * Warning on deprecated hardware types or interfaces in the configuration. + * Warning on unknown hardware types or interfaces used on any nodes.