nova-status: Add hw_machine_type check for libvirt instances
This change introduces a new nova-status check to ensure a machine type has been recorded for each instance within an environment. nova-status will fail with a warning when instances are found, directing the operator to use the previously added nova-manage list_unset and update commands to set a machine type for these instances. The logic for this check comes entirely from the list_unset command. It is noted in the warning output that this can be ignored if no libvirt or HyperV based computes are present in the environment as hw_machine_type is only used by these two virt drivers at present. blueprint: libvirt-default-machine-type Change-Id: Ic3ae48c57e61c4e45883fbae1328a448be025953
This commit is contained in:
parent
9a5b07d9fc
commit
8cddd243bf
@ -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
|
||||
========
|
||||
|
@ -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),
|
||||
)
|
||||
|
||||
|
||||
|
@ -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
|
||||
)
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user