diff options
| author | Dmitry Tantsur <dtantsur@protonmail.com> | 2021-05-18 14:11:04 +0200 |
|---|---|---|
| committer | Dmitry Tantsur <dtantsur@protonmail.com> | 2021-05-18 14:45:13 +0200 |
| commit | 606e50031240e3f5bc29aa04e77e2c2f718667ee (patch) | |
| tree | b0afc62f0902172dd16222ae5f1e083022fd9622 /ironic_python_agent/tests | |
| parent | d1844c61b1a419dc39aca41c9266fb65eaff78e4 (diff) | |
| download | ironic-python-agent-606e50031240e3f5bc29aa04e77e2c2f718667ee.tar.gz | |
Rewrite write_image.sh in Python
Change-Id: I0caa65561948f4e0934943a7a0d3a209701b5a59
Diffstat (limited to 'ironic_python_agent/tests')
| -rw-r--r-- | ironic_python_agent/tests/unit/extensions/test_standby.py | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/ironic_python_agent/tests/unit/extensions/test_standby.py b/ironic_python_agent/tests/unit/extensions/test_standby.py index 1f985652..6f905a36 100644 --- a/ironic_python_agent/tests/unit/extensions/test_standby.py +++ b/ironic_python_agent/tests/unit/extensions/test_standby.py @@ -168,25 +168,45 @@ class TestStandbyExtension(base.IronicAgentTest): self.assertEqual(expected_loc, location) @mock.patch('ironic_lib.disk_utils.fix_gpt_partition', autospec=True) - @mock.patch('builtins.open', autospec=True) + @mock.patch('ironic_lib.disk_utils.trigger_device_rescan', autospec=True) @mock.patch('ironic_python_agent.utils.execute', autospec=True) - def test_write_image(self, execute_mock, open_mock, fix_gpt_mock): + @mock.patch('ironic_lib.disk_utils.udev_settle', autospec=True) + @mock.patch('ironic_lib.disk_utils.destroy_disk_metadata', autospec=True) + def test_write_image(self, wipe_mock, udev_mock, execute_mock, + rescan_mock, fix_gpt_mock): image_info = _build_fake_image_info() device = '/dev/sda' location = standby._image_location(image_info) - script = standby._path_to_script('shell/write_image.sh') - command = ['/bin/bash', script, location, device] - execute_mock.return_value = ('', '') + command = ['qemu-img', 'convert', '-t', 'directsync', + '-O', 'host_device', '-W', location, device] standby._write_image(image_info, device) - execute_mock.assert_called_once_with(*command) + + execute_mock.assert_called_once_with(*command, prlimit=mock.ANY) + wipe_mock.assert_called_once_with(device, '') + udev_mock.assert_called_once_with() + rescan_mock.assert_called_once_with(device) fix_gpt_mock.assert_called_once_with(device, node_uuid=None) + @mock.patch('ironic_lib.disk_utils.fix_gpt_partition', autospec=True) + @mock.patch('ironic_lib.disk_utils.trigger_device_rescan', autospec=True) + @mock.patch('ironic_python_agent.utils.execute', autospec=True) + @mock.patch('ironic_lib.disk_utils.udev_settle', autospec=True) + @mock.patch('ironic_lib.disk_utils.destroy_disk_metadata', autospec=True) + def test_write_image_gpt_fails(self, wipe_mock, udev_mock, execute_mock, + rescan_mock, fix_gpt_mock): + image_info = _build_fake_image_info() + device = '/dev/sda' + fix_gpt_mock.side_effect = exception.InstanceDeployFailure standby._write_image(image_info, device) - execute_mock.reset_mock() - execute_mock.return_value = ('', '') + @mock.patch('ironic_python_agent.utils.execute', autospec=True) + @mock.patch('ironic_lib.disk_utils.udev_settle', autospec=True) + @mock.patch('ironic_lib.disk_utils.destroy_disk_metadata', autospec=True) + def test_write_image_fails(self, wipe_mock, udev_mock, execute_mock): + image_info = _build_fake_image_info() + device = '/dev/sda' execute_mock.side_effect = processutils.ProcessExecutionError self.assertRaises(errors.ImageWriteError, @@ -194,8 +214,6 @@ class TestStandbyExtension(base.IronicAgentTest): image_info, device) - execute_mock.assert_called_once_with(*command) - @mock.patch.object(utils, 'get_node_boot_mode', lambda self: 'bios') @mock.patch.object(hardware, 'dispatch_to_managers', autospec=True) @mock.patch('builtins.open', autospec=True) |
