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
This commit is contained in:
parent
3820fc19c9
commit
bb4cd9ea78
@ -82,3 +82,8 @@ Upgrade
|
|||||||
|
|
||||||
* Adds a check to validate the configured policy file is not JSON
|
* Adds a check to validate the configured policy file is not JSON
|
||||||
based as JSON based policies have been deprecated.
|
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.
|
||||||
|
@ -22,9 +22,11 @@ from oslo_upgradecheck import upgradecheck
|
|||||||
import sqlalchemy
|
import sqlalchemy
|
||||||
|
|
||||||
from ironic.cmd import dbsync
|
from ironic.cmd import dbsync
|
||||||
|
from ironic.common import driver_factory
|
||||||
from ironic.common.i18n import _
|
from ironic.common.i18n import _
|
||||||
from ironic.common import policy # noqa importing to load policy config.
|
from ironic.common import policy # noqa importing to load policy config.
|
||||||
import ironic.conf
|
import ironic.conf
|
||||||
|
from ironic.db import api as db_api
|
||||||
|
|
||||||
CONF = ironic.conf.CONF
|
CONF = ironic.conf.CONF
|
||||||
|
|
||||||
@ -131,6 +133,54 @@ class Checks(upgradecheck.UpgradeCommands):
|
|||||||
else:
|
else:
|
||||||
return upgradecheck.Result(upgradecheck.Code.SUCCESS)
|
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 (<name of check>, <check function>).
|
# A tuple of check tuples of (<name of check>, <check function>).
|
||||||
# The name of the check will be used in the output of this command.
|
# The name of the check will be used in the output of this command.
|
||||||
# The check function takes no arguments and returns an
|
# The check function takes no arguments and returns an
|
||||||
@ -147,6 +197,8 @@ class Checks(upgradecheck.UpgradeCommands):
|
|||||||
# Victoria -> Wallaby migration
|
# Victoria -> Wallaby migration
|
||||||
(_('Policy File JSON to YAML Migration'),
|
(_('Policy File JSON to YAML Migration'),
|
||||||
(common_checks.check_policy_json, {'conf': CONF})),
|
(common_checks.check_policy_json, {'conf': CONF})),
|
||||||
|
(_('Hardware Types and Interfaces Check'),
|
||||||
|
_check_hardware_types_interfaces),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -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.
|
Loading…
Reference in New Issue
Block a user