Merge "nova-status: Add hw_machine_type check for libvirt instances"

This commit is contained in:
Zuul 2021-03-06 17:22:20 +00:00 committed by Gerrit Code Review
commit 9a7d50e635
4 changed files with 54 additions and 1 deletions

View File

@ -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
========

View File

@ -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),
)

View File

@ -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
)

View File

@ -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.