From 973c8a063ec9f28b7d7fceb1d603ba230079eca4 Mon Sep 17 00:00:00 2001 From: Julia Kreger Date: Thu, 3 Oct 2024 06:53:30 -0700 Subject: [PATCH] Fix actual size calculation for storage fallback logic When we were fixing the qemu-img related CVE, in our rush we didn't realize that the logic for storage sizing, which only falls back to actual size didn't match the prior interface exactly. Instead of disk_size, we have actual_size on the format inspector. This was not discovered because all of the code handling that side of the unit tests were mocked. Anyhow, easy fix. Closes-Bug: 2083520 Change-Id: Ic4390d578f564f245d7fb4013f2ba5531aee9ea9 (cherry picked from commit 90f9fa3eb0e895f6ee2a04a55013ee84b0888fb7) --- ironic/common/images.py | 2 +- ironic/tests/unit/common/test_images.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ironic/common/images.py b/ironic/common/images.py index 88daf8fb55..4fd079f870 100644 --- a/ironic/common/images.py +++ b/ironic/common/images.py @@ -492,7 +492,7 @@ def converted_size(path, estimate=False): if not estimate: return data.virtual_size growth_factor = CONF.raw_image_growth_factor - return int(min(data.disk_size * growth_factor, data.virtual_size)) + return int(min(data.actual_size * growth_factor, data.virtual_size)) def get_image_properties(context, image_href, properties="all"): diff --git a/ironic/tests/unit/common/test_images.py b/ironic/tests/unit/common/test_images.py index d8915de6b4..99b1652104 100644 --- a/ironic/tests/unit/common/test_images.py +++ b/ironic/tests/unit/common/test_images.py @@ -373,7 +373,7 @@ class IronicImagesTestCase(base.TestCase): autospec=True) def test_converted_size_estimate_default(self, image_info_mock): info = self.FakeImgInfo() - info.disk_size = 2 + info.actual_size = 2 info.virtual_size = 10 ** 10 image_info_mock.return_value = info size = images.converted_size('path', estimate=True) @@ -385,7 +385,7 @@ class IronicImagesTestCase(base.TestCase): def test_converted_size_estimate_custom(self, image_info_mock): CONF.set_override('raw_image_growth_factor', 3) info = self.FakeImgInfo() - info.disk_size = 2 + info.actual_size = 2 info.virtual_size = 10 ** 10 image_info_mock.return_value = info size = images.converted_size('path', estimate=True) @@ -397,7 +397,7 @@ class IronicImagesTestCase(base.TestCase): def test_converted_size_estimate_raw_smaller(self, image_info_mock): CONF.set_override('raw_image_growth_factor', 3) info = self.FakeImgInfo() - info.disk_size = 2 + info.actual_size = 2 info.virtual_size = 5 image_info_mock.return_value = info size = images.converted_size('path', estimate=True)