From fea7f86e38b9c68b5378a3bbffd649084b5d0cdf Mon Sep 17 00:00:00 2001 From: Arne Wiebalck Date: Fri, 7 Jun 2019 14:22:38 +0200 Subject: [PATCH] Software RAID: Fix race in test for get_holder_disks The explicit creation of a mock object in one test disturbed the execution of another test (which mock'ed the same object). Use a decorator instead. Followup to Id20302537f7994982c7584af546a7e7520e9612b Change-Id: Id54d0ade7084363cb3e53752205db9a9d99d0195 --- ironic_python_agent/tests/unit/test_hardware.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ironic_python_agent/tests/unit/test_hardware.py b/ironic_python_agent/tests/unit/test_hardware.py index c15571a71..3f02eeb8b 100644 --- a/ironic_python_agent/tests/unit/test_hardware.py +++ b/ironic_python_agent/tests/unit/test_hardware.py @@ -2635,21 +2635,22 @@ class TestGenericHardwareManager(base.IronicAgentTest): holder_disks = hardware.get_holder_disks(raid_device.name) self.assertEqual(['/dev/vde', '/dev/vdf'], holder_disks) + @mock.patch.object(hardware, 'get_holder_disks', autospec=True) + @mock.patch.object(hardware, '_get_component_devices', autospec=True) @mock.patch.object(hardware, 'list_all_block_devices', autospec=True) @mock.patch.object(utils, 'execute', autospec=True) - def test_delete_configuration(self, mocked_execute, mocked_list): + def test_delete_configuration(self, mocked_execute, mocked_list, + mocked_get_component, mocked_get_holder): raid_device1 = hardware.BlockDevice('/dev/md0', 'RAID-1', 1073741824, True) raid_device2 = hardware.BlockDevice('/dev/md1', 'RAID-0', 2147483648, True) hardware.list_all_block_devices.side_effect = [ [raid_device1, raid_device2]] - hardware._get_component_devices = mock.Mock() - hardware._get_component_devices.side_effect = [ + mocked_get_component.side_effect = [ ["/dev/sda1", "/dev/sda2"], ["/dev/sdb1", "/dev/sdb2"]] - hardware.get_holder_disks = mock.Mock() - hardware.get_holder_disks.side_effect = [ + mocked_get_holder.side_effect = [ ["/dev/sda", "/dev/sdb"], ["/dev/sda", "/dev/sdb"]] mocked_execute.side_effect = [