diff --git a/doc/source/cli/nova-status.rst b/doc/source/cli/nova-status.rst index 680937cd6d2a..6341bf0e9927 100644 --- a/doc/source/cli/nova-status.rst +++ b/doc/source/cli/nova-status.rst @@ -146,6 +146,7 @@ Upgrade **23.0.0 (Wallaby)** * Checks for computes older than the previous major release + * Checks for any instances without ``hw_machine_type`` set. See Also ======== diff --git a/nova/cmd/status.py b/nova/cmd/status.py index 569e78b509ed..1974feb58b0b 100644 --- a/nova/cmd/status.py +++ b/nova/cmd/status.py @@ -36,9 +36,14 @@ from nova.db.sqlalchemy import api as db_session from nova import exception from nova.i18n import _ from nova.objects import cell_mapping as cell_mapping_obj +# NOTE(lyarwood): The following are imported as machine_type_utils expects them +# to be registered under nova.objects when called via _check_machine_type_set +from nova.objects import image_meta as image_meta_obj # noqa: F401 +from nova.objects import instance as instance_obj # noqa: F401 from nova import policy from nova import utils from nova import version +from nova.virt.libvirt import machine_type_utils from nova.volume import cinder CONF = nova.conf.CONF @@ -307,6 +312,19 @@ class UpgradeCommands(upgradecheck.UpgradeCommands): return upgradecheck.Result(upgradecheck.Code.SUCCESS) + def _check_machine_type_set(self): + ctxt = nova_context.get_admin_context() + if machine_type_utils.get_instances_without_type(ctxt): + msg = (_(""" +Instances found without hw_machine_type set. This warning can be ignored if +your environment does not contain libvirt based compute hosts. +Use the `nova-manage machine_type list_unset` command to list these instances. +For more details see the following: +https://docs.openstack.org/latest/nova/admin/hw_machine_type.html""")) + return upgradecheck.Result(upgradecheck.Code.WARNING, msg) + + return upgradecheck.Result(upgradecheck.Code.SUCCESS) + # The format of the check functions is to return an upgradecheck.Result # object with the appropriate upgradecheck.Code and details set. If the # check hits warnings or failures then those should be stored in the @@ -329,7 +347,9 @@ class UpgradeCommands(upgradecheck.UpgradeCommands): (common_checks.check_policy_json, {'conf': CONF}) ), # Added in Wallaby - (_('Older than N-1 computes'), _check_old_computes) + (_('Older than N-1 computes'), _check_old_computes), + # Added in Wallaby + (_('hw_machine_type unset'), _check_machine_type_set), ) diff --git a/nova/tests/unit/cmd/test_status.py b/nova/tests/unit/cmd/test_status.py index e51fdb98f3ec..f27e7ce88dfe 100644 --- a/nova/tests/unit/cmd/test_status.py +++ b/nova/tests/unit/cmd/test_status.py @@ -476,3 +476,30 @@ class TestUpgradeCheckOldCompute(test.NoDBTestCase): return_value=too_old): result = self.cmd._check_old_computes() self.assertEqual(upgradecheck.Code.WARNING, result.code) + + +class TestCheckMachineTypeUnset(test.NoDBTestCase): + + def setUp(self): + super().setUp() + self.cmd = status.UpgradeCommands() + + @mock.patch( + 'nova.virt.libvirt.machine_type_utils.get_instances_without_type', + new=mock.Mock(return_value=[mock.Mock(spec=objects.Instance)])) + def test_instances_found_without_hw_machine_type(self): + result = self.cmd._check_machine_type_set() + self.assertEqual( + upgradecheck.Code.WARNING, + result.code + ) + + @mock.patch( + 'nova.virt.libvirt.machine_type_utils.get_instances_without_type', + new=mock.Mock(return_value=[])) + def test_instances_not_found_without_hw_machine_type(self): + result = self.cmd._check_machine_type_set() + self.assertEqual( + upgradecheck.Code.SUCCESS, + result.code + ) diff --git a/releasenotes/notes/libvirt-store-and-change-default-machine-type-bf86b4973c4dee4c.yaml b/releasenotes/notes/libvirt-store-and-change-default-machine-type-bf86b4973c4dee4c.yaml index 9bd952994625..e1f1caa97923 100644 --- a/releasenotes/notes/libvirt-store-and-change-default-machine-type-bf86b4973c4dee4c.yaml +++ b/releasenotes/notes/libvirt-store-and-change-default-machine-type-bf86b4973c4dee4c.yaml @@ -46,3 +46,8 @@ upgrade: This command will list instance UUIDs that do not have a machine type recorded. An optional cell UUID can be provided to list on instances without a machine type from that cell. + + A new ``nova-status`` check has been introduced to help operators + identify if any instances within their environment have ``hw_machine_type`` + unset before they attempt to change the ``[libvirt]hw_machine_type`` + configurable.