diff options
| author | Zuul <zuul@review.opendev.org> | 2020-04-16 16:22:49 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2020-04-16 16:22:49 +0000 |
| commit | 43d2b2cbe09937be8803402cb0c32ade5d172d08 (patch) | |
| tree | 0fac5ca5a80a1c2e7aab93c95e4ed9154a4e4743 /ironic_python_agent/tests | |
| parent | 6a9a9e9e1461f13e7d2478a90e2ef3bdd1f0b55f (diff) | |
| parent | ff49b04e28b74d89a5fa6334411c56628f502bee (diff) | |
| download | ironic-python-agent-43d2b2cbe09937be8803402cb0c32ade5d172d08.tar.gz | |
Merge "A boot partition on a GPT disk should be considered an EFI partition"
Diffstat (limited to 'ironic_python_agent/tests')
| -rw-r--r-- | ironic_python_agent/tests/unit/test_utils.py | 101 |
1 files changed, 43 insertions, 58 deletions
diff --git a/ironic_python_agent/tests/unit/test_utils.py b/ironic_python_agent/tests/unit/test_utils.py index 48948fc3..21407292 100644 --- a/ironic_python_agent/tests/unit/test_utils.py +++ b/ironic_python_agent/tests/unit/test_utils.py @@ -23,6 +23,7 @@ import tarfile import tempfile from unittest import mock +from ironic_lib import disk_utils from ironic_lib import utils as ironic_utils from oslo_concurrency import processutils from oslo_serialization import base64 @@ -45,30 +46,6 @@ Number Start End Size File system Name Flags 1 116MB 2361MB 2245MB ext4 ''' -PARTED_OUTPUT_UNFORMATTED_NOFS = '''Model: whatever -Disk /dev/sda: 480GB -Sector size (logical/physical): 512B/512B -Partition Table: gpt -Disk Flags: - -Number Start End Size File system Name Flags -1 1049kB 9437kB 8389kB ESP boot, esp -2 9437kB 17.8MB 8389kB BSP bios_grub -3 17.8MB 40.0GB 40.0GB -4 479GB 480GB 68.1MB -''' - -PARTED_OUTPUT_NO_EFI = '''Model: whatever -Disk /dev/sda: 450GB -Sector size (logical/physical): 512B/512B -Partition Table: gpt -Disk Flags: - -Number Start End Size File system Name Flags -14 1049kB 5243kB 4194kB bios_grub - 1 116MB 2361MB 2245MB ext4 -''' - class ExecuteTestCase(ironic_agent_base.IronicAgentTest): # This test case does call utils.execute(), so don't block access to the @@ -630,40 +607,6 @@ class TestUtils(testtools.TestCase): utils.extract_device('whatevernotmatchin12a') ) - @mock.patch.object(utils, 'execute', autospec=True) - def test_get_efi_part_on_device(self, mocked_execute): - parted_ret = PARTED_OUTPUT_UNFORMATTED.format('gpt') - mocked_execute.side_effect = [ - (parted_ret, None) - ] - ret = utils.get_efi_part_on_device('/dev/sda') - mocked_execute.assert_has_calls( - [mock.call('parted', '-s', '/dev/sda', '--', 'print')] - ) - self.assertEqual('15', ret) - - @mock.patch.object(utils, 'execute', autospec=True) - def test_get_efi_part_on_device_without_fs(self, mocked_execute): - parted_ret = PARTED_OUTPUT_UNFORMATTED_NOFS - mocked_execute.side_effect = [ - (parted_ret, None) - ] - ret = utils.get_efi_part_on_device('/dev/sda') - mocked_execute.assert_has_calls( - [mock.call('parted', '-s', '/dev/sda', '--', 'print')] - ) - self.assertEqual('1', ret) - - @mock.patch.object(utils, 'execute', autospec=True) - def test_get_efi_part_on_device_not_found(self, mocked_execute): - mocked_execute.side_effect = [ - (PARTED_OUTPUT_NO_EFI, None) - ] - self.assertIsNone(utils.get_efi_part_on_device('/dev/sda')) - mocked_execute.assert_has_calls( - [mock.call('parted', '-s', '/dev/sda', '--', 'print')] - ) - def test_extract_capability_from_dict(self): expected_dict = {"hello": "world"} root = {"capabilities": expected_dict} @@ -1040,3 +983,45 @@ class TestClockSyncUtils(ironic_agent_base.IronicAgentTest): mock_time_method.return_value = None utils.sync_clock() self.assertEqual(0, mock_execute.call_count) + + +@mock.patch.object(disk_utils, 'list_partitions', autospec=True) +@mock.patch.object(utils, 'scan_partition_table_type', autospec=True) +class TestGetEfiPart(testtools.TestCase): + + def test_get_efi_part_on_device(self, mocked_type, mocked_parts): + mocked_parts.return_value = [ + {'number': '1', 'flags': ''}, + {'number': '14', 'flags': 'bios_grub'}, + {'number': '15', 'flags': 'esp, boot'}, + ] + ret = utils.get_efi_part_on_device('/dev/sda') + self.assertEqual('15', ret) + + def test_get_efi_part_on_device_only_boot_flag_gpt(self, mocked_type, + mocked_parts): + mocked_type.return_value = 'gpt' + mocked_parts.return_value = [ + {'number': '1', 'flags': ''}, + {'number': '14', 'flags': 'bios_grub'}, + {'number': '15', 'flags': 'boot'}, + ] + ret = utils.get_efi_part_on_device('/dev/sda') + self.assertEqual('15', ret) + + def test_get_efi_part_on_device_only_boot_flag_mbr(self, mocked_type, + mocked_parts): + mocked_type.return_value = 'msdos' + mocked_parts.return_value = [ + {'number': '1', 'flags': ''}, + {'number': '14', 'flags': 'bios_grub'}, + {'number': '15', 'flags': 'boot'}, + ] + self.assertIsNone(utils.get_efi_part_on_device('/dev/sda')) + + def test_get_efi_part_on_device_not_found(self, mocked_type, mocked_parts): + mocked_parts.return_value = [ + {'number': '1', 'flags': ''}, + {'number': '14', 'flags': 'bios_grub'}, + ] + self.assertIsNone(utils.get_efi_part_on_device('/dev/sda')) |
