Workaround unit test failures with extra mocking

Our unit tests in IPA are leaky: we are testing implementation details
of ironic_lib. We need to factor that better over time, but for now,
ensure IPA gate is clear and can pass tests.

Change-Id: I906ffa8546c093174335268ee4e11af858fa5109
This commit is contained in:
Jay Faulkner 2024-03-11 12:53:30 -07:00
parent df7eccd7f1
commit 9e96b8b60f
1 changed files with 15 additions and 4 deletions

View File

@ -18,6 +18,7 @@ from unittest import mock
from ironic_lib import disk_partitioner
from ironic_lib import disk_utils
from ironic_lib import exception
from ironic_lib import qemu_img
from ironic_lib import utils
from oslo_concurrency import processutils
from oslo_config import cfg
@ -32,6 +33,11 @@ from ironic_python_agent.tests.unit import base
CONF = cfg.CONF
# TODO(JayF): Many tests in this file assert things that happen in ironic_lib.
# We should rework this to test IPA calls are correct and move ironic_lib
# testing into ironic_lib.
@mock.patch.object(shutil, 'copyfileobj', autospec=True)
@mock.patch.object(requests, 'get', autospec=True)
class GetConfigdriveTestCase(base.IronicAgentTest):
@ -701,6 +707,7 @@ class CreateConfigDriveTestCases(base.IronicAgentTest):
mock.call('sync'),
mock.call('udevadm', 'settle'),
mock.call('partprobe', self.dev, attempts=10, run_as_root=True),
mock.call('udevadm', 'settle'),
mock.call('sgdisk', '-v', self.dev, run_as_root=True),
mock.call('udevadm', 'settle'),
@ -762,8 +769,8 @@ class CreateConfigDriveTestCases(base.IronicAgentTest):
mock.call('sync'),
mock.call('udevadm', 'settle'),
mock.call('partprobe', self.dev, attempts=10, run_as_root=True),
mock.call('udevadm', 'settle'),
mock.call('sgdisk', '-v', self.dev, run_as_root=True),
mock.call('udevadm', 'settle'),
mock.call('test', '-e', expected_part, attempts=15,
delay_on_retry=True)
@ -827,6 +834,7 @@ class CreateConfigDriveTestCases(base.IronicAgentTest):
mock.call('sync'),
mock.call('udevadm', 'settle'),
mock.call('partprobe', self.dev, attempts=10, run_as_root=True),
mock.call('udevadm', 'settle'),
mock.call('sgdisk', '-v', self.dev, run_as_root=True),
mock.call('udevadm', 'settle'),
@ -930,6 +938,7 @@ class CreateConfigDriveTestCases(base.IronicAgentTest):
mock.call('sync'),
mock.call('udevadm', 'settle'),
mock.call('partprobe', self.dev, attempts=10, run_as_root=True),
mock.call('udevadm', 'settle'),
mock.call('sgdisk', '-v', self.dev, run_as_root=True),
mock.call('udevadm', 'settle'),
mock.call('test', '-e', expected_part, attempts=15,
@ -1029,6 +1038,7 @@ class CreateConfigDriveTestCases(base.IronicAgentTest):
mock.call('sync'),
mock.call('udevadm', 'settle'),
mock.call('partprobe', self.dev, attempts=10, run_as_root=True),
mock.call('udevadm', 'settle'),
mock.call('sgdisk', '-v', self.dev, run_as_root=True),
])
@ -1221,12 +1231,13 @@ class CreateConfigDriveTestCases(base.IronicAgentTest):
# NOTE(TheJulia): trigger_device_rescan is systemwide thus pointless
# to execute in the file test case. Also, CI unit test jobs lack sgdisk.
@mock.patch.object(qemu_img, 'image_info', autospec=True)
@mock.patch.object(disk_utils, 'trigger_device_rescan', autospec=True)
@mock.patch.object(utils, 'wait_for_disk_to_become_available', autospec=True)
@mock.patch.object(disk_utils, 'is_block_device', autospec=True)
@mock.patch.object(disk_utils, 'block_uuid', autospec=True)
@mock.patch.object(disk_utils, 'dd', autospec=True)
@mock.patch.object(disk_utils, 'convert_image', autospec=True)
@mock.patch.object(qemu_img, 'convert_image', autospec=True)
@mock.patch.object(utils, 'mkfs', autospec=True)
# NOTE(dtantsur): destroy_disk_metadata resets file size, disabling it
@mock.patch.object(disk_utils, 'destroy_disk_metadata', autospec=True)
@ -1269,7 +1280,7 @@ class RealFilePartitioningTestCase(base.IronicAgentTest):
def test_different_sizes(self, mock_destroy, mock_mkfs, mock_convert,
mock_dd, mock_block_uuid, mock_is_block,
mock_wait, mock_trigger_rescan):
mock_wait, mock_trigger_rescan, mock_qemu):
# NOTE(dtantsur): Keep this list in order with expected partitioning
fields = ['ephemeral_mb', 'swap_mb', 'root_mb']
variants = ((0, 0, 12), (4, 2, 8), (0, 4, 10), (5, 0, 10))
@ -1286,7 +1297,7 @@ class RealFilePartitioningTestCase(base.IronicAgentTest):
def test_whole_disk(self, mock_destroy, mock_mkfs, mock_convert, mock_dd,
mock_block_uuid, mock_is_block, mock_wait,
mock_trigger_rescan):
mock_trigger_rescan, mock_qemu):
# 6 MiB ephemeral + 3 MiB swap + 9 MiB root + 1 MiB for MBR
# + 1 MiB MAGIC == 20 MiB whole disk
# TODO(dtantsur): figure out why we need 'magic' 1 more MiB