diff options
| author | Zuul <zuul@review.opendev.org> | 2020-04-02 14:56:45 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2020-04-02 14:56:45 +0000 |
| commit | d71a8375fa0c96b3d8a4f32878c8e79f427ac528 (patch) | |
| tree | 8d24eedacce9cea3f4728662c4c7e73c4f67731f /ironic_python_agent/tests | |
| parent | dea6de0b2d03da3dac5584446f826ef9b3568144 (diff) | |
| parent | 34b58f60241fe331fab809b711250d0fcd306353 (diff) | |
| download | ironic-python-agent-d71a8375fa0c96b3d8a4f32878c8e79f427ac528.tar.gz | |
Merge "Only check for partitions on devices that are part of software RAID"
Diffstat (limited to 'ironic_python_agent/tests')
| -rw-r--r-- | ironic_python_agent/tests/unit/test_hardware.py | 77 |
1 files changed, 61 insertions, 16 deletions
diff --git a/ironic_python_agent/tests/unit/test_hardware.py b/ironic_python_agent/tests/unit/test_hardware.py index 80140796..c88809db 100644 --- a/ironic_python_agent/tests/unit/test_hardware.py +++ b/ironic_python_agent/tests/unit/test_hardware.py @@ -2779,8 +2779,9 @@ class TestGenericHardwareManager(base.IronicAgentTest): self.hardware.validate_configuration, self.node, []) + @mock.patch.object(disk_utils, 'list_partitions', autospec=True) @mock.patch.object(utils, 'execute', autospec=True) - def test_create_configuration(self, mocked_execute): + def test_create_configuration(self, mocked_execute, mock_list_parts): node = self.node raid_config = { "logical_disks": [ @@ -2801,6 +2802,10 @@ class TestGenericHardwareManager(base.IronicAgentTest): device2 = hardware.BlockDevice('/dev/sdb', 'sdb', 107374182400, True) self.hardware.list_block_devices = mock.Mock() self.hardware.list_block_devices.return_value = [device1, device2] + mock_list_parts.side_effect = [ + [], + processutils.ProcessExecutionError + ] mocked_execute.side_effect = [ None, # mklabel sda @@ -2843,8 +2848,16 @@ class TestGenericHardwareManager(base.IronicAgentTest): '/dev/sda2', '/dev/sdb2')]) self.assertEqual(raid_config, result) + self.assertEqual(2, mock_list_parts.call_count) + mock_list_parts.assert_has_calls([ + mock.call(x) for x in ['/dev/sda', '/dev/sdb'] + ]) + + @mock.patch.object(disk_utils, 'list_partitions', autospec=True, + return_value=[]) @mock.patch.object(utils, 'execute', autospec=True) - def test_create_configuration_raid_5(self, mocked_execute): + def test_create_configuration_raid_5(self, mocked_execute, + mock_list_parts): node = self.node raid_config = { "logical_disks": [ @@ -2922,8 +2935,11 @@ class TestGenericHardwareManager(base.IronicAgentTest): '/dev/sda2', '/dev/sdb2', '/dev/sdc2')]) self.assertEqual(raid_config, result) + @mock.patch.object(disk_utils, 'list_partitions', autospec=True, + return_value=[]) @mock.patch.object(utils, 'execute', autospec=True) - def test_create_configuration_raid_6(self, mocked_execute): + def test_create_configuration_raid_6(self, mocked_execute, + mock_list_parts): node = self.node raid_config = { "logical_disks": [ @@ -3015,8 +3031,11 @@ class TestGenericHardwareManager(base.IronicAgentTest): '/dev/sda2', '/dev/sdb2', '/dev/sdc2', '/dev/sdd2')]) self.assertEqual(raid_config, result) + @mock.patch.object(disk_utils, 'list_partitions', autospec=True, + return_value=[]) @mock.patch.object(utils, 'execute', autospec=True) - def test_create_configuration_no_max(self, mocked_execute): + def test_create_configuration_no_max(self, mocked_execute, + mock_list_parts): node = self.node raid_config = { "logical_disks": [ @@ -3078,8 +3097,11 @@ class TestGenericHardwareManager(base.IronicAgentTest): '/dev/sda2', '/dev/sdb2')]) self.assertEqual(raid_config, result) + @mock.patch.object(disk_utils, 'list_partitions', autospec=True, + return_value=[]) @mock.patch.object(utils, 'execute', autospec=True) - def test_create_configuration_max_is_first_logical(self, mocked_execute): + def test_create_configuration_max_is_first_logical(self, mocked_execute, + mock_list_parts): node = self.node raid_config = { "logical_disks": [ @@ -3141,8 +3163,11 @@ class TestGenericHardwareManager(base.IronicAgentTest): '/dev/sda2', '/dev/sdb2')]) self.assertEqual(raid_config, result) + @mock.patch.object(disk_utils, 'list_partitions', autospec=True, + return_value=[]) @mock.patch.object(utils, 'execute', autospec=True) - def test_create_configuration_with_hints(self, mocked_execute): + def test_create_configuration_with_hints(self, mocked_execute, + mock_list_parts): node = self.node raid_config = { "logical_disks": [ @@ -3216,6 +3241,11 @@ class TestGenericHardwareManager(base.IronicAgentTest): '/dev/sda2', '/dev/sdb2')]) self.assertEqual(raid_config, result) + self.assertEqual(2, mock_list_parts.call_count) + mock_list_parts.assert_has_calls([ + mock.call(x) for x in ['/dev/sda', '/dev/sdb'] + ]) + @mock.patch.object(utils, 'execute', autospec=True) def test_create_configuration_invalid_raid_config(self, mocked_execute): raid_config = { @@ -3291,8 +3321,10 @@ class TestGenericHardwareManager(base.IronicAgentTest): self.hardware.create_configuration, self.node, []) + @mock.patch.object(disk_utils, 'list_partitions', autospec=True) @mock.patch.object(utils, 'execute', autospec=True) - def test_create_configuration_partitions_detected(self, mocked_execute): + def test_create_configuration_partitions_detected(self, mocked_execute, + mock_list_parts): raid_config = { "logical_disks": [ { @@ -3307,23 +3339,28 @@ class TestGenericHardwareManager(base.IronicAgentTest): }, ] } + mock_list_parts.side_effect = [ + [], + [{'partition_name': '/dev/sdb1'}], + ] self.node['target_raid_config'] = raid_config device1 = hardware.BlockDevice('/dev/sda', 'sda', 107374182400, True) device2 = hardware.BlockDevice('/dev/sdb', 'sdb', 107374182400, True) - partition1 = hardware.BlockDevice('/dev/sdb1', 'sdb1', 268435456, True) self.hardware.list_block_devices = mock.Mock() - self.hardware.list_block_devices.side_effect = [ - [device1, device2], # pre-flight validation call - [device1, device2], - [device1, device2, partition1]] + self.hardware.list_block_devices.return_value = [ + device1, device2 + ] self.assertRaises(errors.SoftwareRAIDError, self.hardware.create_configuration, self.node, []) + @mock.patch.object(disk_utils, 'list_partitions', autospec=True, + return_value=[]) @mock.patch.object(utils, 'execute', autospec=True) def test_create_configuration_device_handling_failures(self, - mocked_execute): + mocked_execute, + mock_list_parts): raid_config = { "logical_disks": [ { @@ -3386,9 +3423,11 @@ class TestGenericHardwareManager(base.IronicAgentTest): self.hardware.create_configuration, self.node, []) + @mock.patch.object(disk_utils, 'list_partitions', autospec=True, + return_value=[]) @mock.patch.object(utils, 'execute', autospec=True) def test_create_configuration_device_handling_failures_raid5( - self, mocked_execute): + self, mocked_execute, mock_list_parts): raid_config = { "logical_disks": [ { @@ -3459,8 +3498,11 @@ class TestGenericHardwareManager(base.IronicAgentTest): result = self.hardware.create_configuration(self.node, []) self.assertEqual(result, {}) + @mock.patch.object(disk_utils, 'list_partitions', autospec=True, + return_value=[]) @mock.patch.object(utils, 'execute', autospec=True) - def test_create_configuration_with_nvme(self, mocked_execute): + def test_create_configuration_with_nvme(self, mocked_execute, + mock_list_parts): raid_config = { "logical_disks": [ { @@ -3524,8 +3566,11 @@ class TestGenericHardwareManager(base.IronicAgentTest): '/dev/nvme0n1p2', '/dev/nvme1n1p2')]) self.assertEqual(raid_config, result) + @mock.patch.object(disk_utils, 'list_partitions', autospec=True, + return_value=[]) @mock.patch.object(utils, 'execute', autospec=True) - def test_create_configuration_failure_with_nvme(self, mocked_execute): + def test_create_configuration_failure_with_nvme(self, mocked_execute, + mock_list_parts): raid_config = { "logical_disks": [ { |
