Fall back to PARTUUID if UUID returns nothing.
blkid does not always return a UUID when querying partitions (sda2 in my case). It does seem to return a PARTUUID though, so use that if needed. Change-Id: I6f8dbd8fb8a02f6246b7ab00801159544f3288d6 Story: 2002052 Task: 19701
This commit is contained in:
parent
9ba805d4b0
commit
ca1fe71cf9
|
@ -325,10 +325,18 @@ def populate_image(src, dst):
|
|||
|
||||
|
||||
def block_uuid(dev):
|
||||
"""Get UUID of a block device."""
|
||||
"""Get UUID of a block device.
|
||||
|
||||
Try to fetch the UUID, if that fails, try to fetch the PARTUUID.
|
||||
"""
|
||||
out, _err = utils.execute('blkid', '-s', 'UUID', '-o', 'value', dev,
|
||||
run_as_root=True,
|
||||
check_exit_code=[0])
|
||||
run_as_root=True, check_exit_code=[0])
|
||||
if not out:
|
||||
LOG.debug('Falling back to partition UUID as the block device UUID '
|
||||
'was not found while examining %(device)s',
|
||||
{'device': dev})
|
||||
out, _err = utils.execute('blkid', '-s', 'PARTUUID', '-o', 'value',
|
||||
dev, run_as_root=True, check_exit_code=[0])
|
||||
return out.strip()
|
||||
|
||||
|
||||
|
|
|
@ -807,6 +807,22 @@ class OtherFunctionTestCase(base.IronicLibTestCase):
|
|||
'/dev/fake', run_as_root=True,
|
||||
use_standard_locale=True)
|
||||
|
||||
@mock.patch.object(utils, 'execute', autospec=True)
|
||||
def test_block_uuid_fallback_to_uuid(self, mock_execute):
|
||||
mock_execute.side_effect = [('', ''),
|
||||
('value', '')]
|
||||
self.assertEqual('value',
|
||||
disk_utils.block_uuid('/dev/fake'))
|
||||
execute_calls = [
|
||||
mock.call('blkid', '-s', 'UUID', '-o', 'value',
|
||||
'/dev/fake', check_exit_code=[0],
|
||||
run_as_root=True),
|
||||
mock.call('blkid', '-s', 'PARTUUID', '-o', 'value',
|
||||
'/dev/fake', check_exit_code=[0],
|
||||
run_as_root=True)
|
||||
]
|
||||
mock_execute.assert_has_calls(execute_calls)
|
||||
|
||||
|
||||
@mock.patch.object(utils, 'execute', autospec=True)
|
||||
class WholeDiskPartitionTestCases(base.IronicLibTestCase):
|
||||
|
|
Loading…
Reference in New Issue