From 20f7cfe88d7881c43658fff19a7100d2ef93e478 Mon Sep 17 00:00:00 2001 From: Rajesh Tailor Date: Wed, 23 Oct 2024 18:58:14 +0530 Subject: [PATCH] Fix case sensitive comparison As of now, if flavor has 'hw:virtio_packed_ring' extra-spec set to True and image has 'hw_virtio_packed_ring' set to 'true', if fails the comparison and throws exception. This change makes the comparison case-insensitive by adding another condition for image_value to change it from str to bool if its not None. Closes-Bug: #2085124 Change-Id: Ie1af94b216f10cad592f38037875744927c4f18a Signed-off-by: Rajesh Tailor (cherry picked from commit 8c2df0035d16df8b41e98eb4ed748ddeda9a5d62) (cherry picked from commit 749379ab43b78d69fe0884b926678395fa99a541) --- nova/tests/unit/virt/test_hardware.py | 1 + nova/virt/hardware.py | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/nova/tests/unit/virt/test_hardware.py b/nova/tests/unit/virt/test_hardware.py index 980b8703d2bf..23a3ff010d34 100644 --- a/nova/tests/unit/virt/test_hardware.py +++ b/nova/tests/unit/virt/test_hardware.py @@ -5836,6 +5836,7 @@ class VIFVirtioEnabledTest(test.NoDBTestCase): ('yes', True, True), # fail: mismatched image and flavor configuration ('no', True, exception.FlavorImageConflict), + ('yes', 'true', True), ) def test_get_vif_virtio_constraint( self, flavor_policy, image_policy, expected, diff --git a/nova/virt/hardware.py b/nova/virt/hardware.py index 6e5681ea4e02..c8c1ea1d3f12 100644 --- a/nova/virt/hardware.py +++ b/nova/virt/hardware.py @@ -1982,15 +1982,19 @@ def get_packed_virtqueue_constraint( flavor_key = ':'.join(['hw', key_value]) image_key = '_'.join(['hw', key_value]) flavor_value_str = flavor.get('extra_specs', {}).get(flavor_key, None) - image_value = image_meta.get('properties', {}).get(image_key, None) + image_value_str = image_meta.get('properties', {}).get(image_key, None) else: - flavor_value_str, image_value = _get_flavor_image_meta( + flavor_value_str, image_value_str = _get_flavor_image_meta( key_value, flavor, image_meta) flavor_value = None if flavor_value_str is not None: flavor_value = strutils.bool_from_string(flavor_value_str) + image_value = None + if image_value_str is not None: + image_value = strutils.bool_from_string(image_value_str) + if ( image_value is not None and flavor_value is not None and