Fix retrieval of config-2 existing partition
Previously it was checked using blkid -t LABEL=config-2, but this was not finding the partition, causing that images with a pre-existing config-drive partition had an extra one created by ironic. Switched to using the 'lsblk' command and parsing the output of that to get the information on the partition. Change-Id: Ic5228ce91d1a133fd846ceb7be547a227292dd38 Closes-Bug: #1654269 Depends-On: I3676cd8e5c5e61fe4e3f67ab9e121c4cd0cd599b
This commit is contained in:
parent
2a3288c69c
commit
2d8f1d91c7
|
@ -11,6 +11,7 @@
|
|||
blkid: CommandFilter, blkid, root
|
||||
blockdev: CommandFilter, blockdev, root
|
||||
hexdump: CommandFilter, hexdump, root
|
||||
lsblk: CommandFilter, lsblk, root
|
||||
qemu-img: CommandFilter, qemu-img, root
|
||||
wipefs: CommandFilter, wipefs, root
|
||||
sgdisk: CommandFilter, sgdisk, root
|
||||
|
|
|
@ -19,6 +19,7 @@ import math
|
|||
import os
|
||||
import re
|
||||
import requests
|
||||
import shlex
|
||||
import shutil
|
||||
import six
|
||||
import stat
|
||||
|
@ -605,10 +606,12 @@ def _get_labelled_partition(device, label, node_uuid):
|
|||
"""
|
||||
try:
|
||||
utils.execute('partprobe', device, run_as_root=True)
|
||||
label_arg = 'LABEL=%s' % label
|
||||
output, err = utils.execute('blkid', '-o', 'device', device,
|
||||
'-t', label_arg, check_exit_code=[0, 2],
|
||||
|
||||
# lsblk command
|
||||
output, err = utils.execute('lsblk', '-Po', 'name,label', device,
|
||||
check_exit_code=[0, 1],
|
||||
use_standard_locale=True, run_as_root=True)
|
||||
|
||||
except (processutils.UnknownArgumentError,
|
||||
processutils.ProcessExecutionError, OSError) as e:
|
||||
msg = (_('Failed to retrieve partition labels on disk %(disk)s '
|
||||
|
@ -617,14 +620,24 @@ def _get_labelled_partition(device, label, node_uuid):
|
|||
LOG.error(msg)
|
||||
raise exception.InstanceDeployFailure(msg)
|
||||
|
||||
found_part = None
|
||||
if output:
|
||||
if len(output.split()) > 1:
|
||||
raise exception.InstanceDeployFailure(
|
||||
_('More than one config drive exists on device %(device)s '
|
||||
'for node %(node)s.')
|
||||
% {'device': device, 'node': node_uuid})
|
||||
for device in output.split('\n'):
|
||||
dev = {key: value for key, value in (v.split('=', 1)
|
||||
for v in shlex.split(device))}
|
||||
if not dev:
|
||||
continue
|
||||
if dev['LABEL'] == label:
|
||||
if found_part:
|
||||
raise exception.InstanceDeployFailure(
|
||||
_('More than one partition with label '
|
||||
'%(label)s exists on device %(device)s '
|
||||
'for node %(node)s.') %
|
||||
{'label': label, 'device': device,
|
||||
'node': node_uuid})
|
||||
found_part = '/dev/%(part)s' % {'part': dev['NAME'].strip()}
|
||||
|
||||
return output.rstrip()
|
||||
return found_part
|
||||
|
||||
|
||||
def _is_disk_gpt_partitioned(device, node_uuid):
|
||||
|
|
|
@ -779,16 +779,17 @@ class WholeDiskPartitionTestCases(test_base.BaseTestCase):
|
|||
self.node_uuid = "12345678-1234-1234-1234-1234567890abcxyz"
|
||||
|
||||
def test_get_partition_present(self, mock_execute):
|
||||
blkid_output = '/dev/fake12\n'
|
||||
mock_execute.side_effect = [(None, ''), (blkid_output, '')]
|
||||
lsblk_output = 'NAME="fake12" LABEL="config-2"\n'
|
||||
part_result = '/dev/fake12'
|
||||
mock_execute.side_effect = [(None, ''), (lsblk_output, '')]
|
||||
result = disk_utils._get_labelled_partition(self.dev,
|
||||
self.config_part_label,
|
||||
self.node_uuid)
|
||||
self.assertEqual(blkid_output.rstrip(), result)
|
||||
self.assertEqual(part_result, result)
|
||||
execute_calls = [
|
||||
mock.call('partprobe', self.dev, run_as_root=True),
|
||||
mock.call('blkid', '-o', 'device', self.dev, '-t',
|
||||
'LABEL=config-2', check_exit_code=[0, 2],
|
||||
mock.call('lsblk', '-Po', 'name,label', self.dev,
|
||||
check_exit_code=[0, 1],
|
||||
use_standard_locale=True, run_as_root=True)
|
||||
]
|
||||
mock_execute.assert_has_calls(execute_calls)
|
||||
|
@ -802,22 +803,25 @@ class WholeDiskPartitionTestCases(test_base.BaseTestCase):
|
|||
self.assertIsNone(result)
|
||||
execute_calls = [
|
||||
mock.call('partprobe', self.dev, run_as_root=True),
|
||||
mock.call('blkid', '-o', 'device', self.dev, '-t',
|
||||
'LABEL=config-2', check_exit_code=[0, 2],
|
||||
mock.call('lsblk', '-Po', 'name,label', self.dev,
|
||||
check_exit_code=[0, 1],
|
||||
use_standard_locale=True, run_as_root=True)
|
||||
]
|
||||
mock_execute.assert_has_calls(execute_calls)
|
||||
|
||||
def test_get_partition_DeployFail_exc(self, mock_execute):
|
||||
blkid_output = '/dev/fake12\n/dev/fake13\n'
|
||||
mock_execute.side_effect = [(None, ''), (blkid_output, '')]
|
||||
label = 'config-2'
|
||||
lsblk_output = ('NAME="fake12" LABEL="%s"\n'
|
||||
'NAME="fake13" LABEL="%s"\n' %
|
||||
(label, label))
|
||||
mock_execute.side_effect = [(None, ''), (lsblk_output, '')]
|
||||
self.assertRaises(exception.InstanceDeployFailure,
|
||||
disk_utils._get_labelled_partition, self.dev,
|
||||
self.config_part_label, self.node_uuid)
|
||||
execute_calls = [
|
||||
mock.call('partprobe', self.dev, run_as_root=True),
|
||||
mock.call('blkid', '-o', 'device', self.dev, '-t',
|
||||
'LABEL=config-2', check_exit_code=[0, 2],
|
||||
mock.call('lsblk', '-Po', 'name,label', self.dev,
|
||||
check_exit_code=[0, 1],
|
||||
use_standard_locale=True, run_as_root=True)
|
||||
]
|
||||
mock_execute.assert_has_calls(execute_calls)
|
||||
|
|
Loading…
Reference in New Issue