Merge "Use json for lsblk output"
This commit is contained in:
commit
a9de7f80cc
@ -540,32 +540,36 @@ def list_all_block_devices(block_type='disk',
|
||||
"Cause: %(error)s", {'path': disk_by_path_dir, 'error': e})
|
||||
|
||||
columns = utils.LSBLK_COLUMNS
|
||||
report = il_utils.execute('lsblk', '-Pbia',
|
||||
'-o{}'.format(','.join(columns)))[0]
|
||||
lines = report.splitlines()
|
||||
report = il_utils.execute('lsblk', '-bia', '--json',
|
||||
'-o{}'.format(','.join(columns)),
|
||||
check_exit_code=[0])[0]
|
||||
|
||||
try:
|
||||
report_json = json.loads(report)
|
||||
except json.decoder.JSONDecodeError as ex:
|
||||
LOG.error("Unable to decode lsblk output, invalid JSON: %s", ex)
|
||||
|
||||
context = pyudev.Context()
|
||||
devices_raw = report_json['blockdevices']
|
||||
# Convert raw json output to something useful for us
|
||||
devices = []
|
||||
for line in lines:
|
||||
device = {}
|
||||
# Split into KEY=VAL pairs
|
||||
vals = shlex.split(line)
|
||||
for key, val in (v.split('=', 1) for v in vals):
|
||||
device[key] = val.strip()
|
||||
for device_raw in devices_raw:
|
||||
# Ignore block types not specified
|
||||
devtype = device.get('TYPE')
|
||||
devtype = device_raw.get('type')
|
||||
|
||||
# We already have devices, we should ensure we don't store duplicates.
|
||||
if _is_known_device(devices, device.get('KNAME')):
|
||||
if _is_known_device(devices, device_raw.get('kname')):
|
||||
LOG.debug('Ignoring already known device %s', device_raw)
|
||||
continue
|
||||
|
||||
# If we collected the RM column, we could consult it for removable
|
||||
# media, however USB devices are also flagged as removable media.
|
||||
# we have to explicitly do this as floppy disks are type disk.
|
||||
if ignore_floppy and str(device.get('KNAME')).startswith('fd'):
|
||||
LOG.debug('Ignoring floppy disk device: %s', line)
|
||||
if ignore_floppy and str(device_raw.get('kname')).startswith('fd'):
|
||||
LOG.debug('Ignoring floppy disk device %s', device_raw)
|
||||
continue
|
||||
|
||||
dev_kname = device.get('KNAME')
|
||||
dev_kname = device_raw.get('kname')
|
||||
if check_multipath:
|
||||
# Net effect is we ignore base devices, and their base devices
|
||||
# to what would be the mapped device name which would not pass the
|
||||
@ -588,14 +592,15 @@ def list_all_block_devices(block_type='disk',
|
||||
if devtype is None or ignore_raid:
|
||||
LOG.debug(
|
||||
"TYPE did not match. Wanted: %(block_type)s but found: "
|
||||
"%(line)s (RAID devices are ignored)",
|
||||
{'block_type': block_type, 'line': line})
|
||||
"%(devtype)s (RAID devices are ignored)",
|
||||
{'block_type': block_type, 'devtype': devtype})
|
||||
continue
|
||||
elif ('raid' in devtype
|
||||
and block_type in ['raid', 'disk', 'mpath']):
|
||||
LOG.debug(
|
||||
"TYPE detected to contain 'raid', signifying a "
|
||||
"RAID volume. Found: %s", line)
|
||||
"RAID volume. Found: %(device_raw)s",
|
||||
{'device_raw': device_raw})
|
||||
elif (devtype == 'md'
|
||||
and (block_type == 'part'
|
||||
or block_type == 'md')):
|
||||
@ -605,38 +610,41 @@ def list_all_block_devices(block_type='disk',
|
||||
# more detail.
|
||||
LOG.debug(
|
||||
"TYPE detected to contain 'md', signifying a "
|
||||
"RAID partition. Found: %s", line)
|
||||
"RAID partition. Found: %(device_raw)s",
|
||||
{'device_raw': device_raw})
|
||||
elif devtype == 'mpath' and block_type == 'disk':
|
||||
LOG.debug(
|
||||
"TYPE detected to contain 'mpath', "
|
||||
"signifing a device mapper multipath device. "
|
||||
"Found: %s", line)
|
||||
"Found: %(device_raw)s",
|
||||
{'device_raw': device_raw})
|
||||
else:
|
||||
LOG.debug(
|
||||
"TYPE did not match. Wanted: %(block_type)s but found: "
|
||||
"%(line)s", {'block_type': block_type, 'line': line})
|
||||
"%(device_raw)s (RAID devices are ignored)",
|
||||
{'block_type': block_type, 'device_raw': device_raw})
|
||||
continue
|
||||
|
||||
# Ensure all required columns are at least present, even if blank
|
||||
missing = set(columns) - set(device)
|
||||
missing = set(map(str.lower, columns)) - set(device_raw)
|
||||
if missing:
|
||||
raise errors.BlockDeviceError(
|
||||
'%s must be returned by lsblk.' % ', '.join(sorted(missing)))
|
||||
|
||||
# NOTE(dtantsur): RAM disks and zRAM devices appear in the output of
|
||||
# lsblk as disks, but we cannot do anything useful with them.
|
||||
if (device['KNAME'].startswith('ram')
|
||||
or device['KNAME'].startswith('zram')):
|
||||
LOG.debug('Skipping RAM device %s', device)
|
||||
if (device_raw['kname'].startswith('ram')
|
||||
or device_raw['kname'].startswith('zram')):
|
||||
LOG.debug('Skipping RAM device %s', device_raw)
|
||||
continue
|
||||
|
||||
# NOTE(dtantsur): some hardware represents virtual floppy devices as
|
||||
# normal block devices with size 0. Filter them out.
|
||||
if ignore_empty and not int(device['SIZE'] or 0):
|
||||
LOG.debug('Skipping device %s with zero size', device)
|
||||
if ignore_empty and not int(device_raw['size'] or 0):
|
||||
LOG.debug('Skipping device %s with zero size', device_raw)
|
||||
continue
|
||||
|
||||
name = os.path.join('/dev', device['KNAME'])
|
||||
name = os.path.join('/dev', device_raw['kname'])
|
||||
|
||||
extra = {}
|
||||
try:
|
||||
@ -672,7 +680,7 @@ def list_all_block_devices(block_type='disk',
|
||||
# old distros.
|
||||
try:
|
||||
extra['hctl'] = os.listdir(
|
||||
'/sys/block/%s/device/scsi_device' % device['KNAME'])[0]
|
||||
'/sys/block/%s/device/scsi_device' % device_raw['kname'])[0]
|
||||
except (OSError, IndexError):
|
||||
LOG.warning('Could not find the SCSI address (HCTL) for '
|
||||
'device %s. Skipping', name)
|
||||
@ -681,14 +689,14 @@ def list_all_block_devices(block_type='disk',
|
||||
by_path_name = by_path_mapping.get(name)
|
||||
|
||||
devices.append(BlockDevice(name=name,
|
||||
model=device['MODEL'],
|
||||
size=int(device['SIZE'] or 0),
|
||||
rotational=bool(int(device['ROTA'])),
|
||||
vendor=_get_device_info(device['KNAME'],
|
||||
model=device_raw['model'],
|
||||
size=int(device_raw['size'] or 0),
|
||||
rotational=bool(int(device_raw['rota'])),
|
||||
vendor=_get_device_info(device_raw['kname'],
|
||||
'block', 'vendor'),
|
||||
by_path=by_path_name,
|
||||
uuid=device['UUID'],
|
||||
partuuid=device['PARTUUID'],
|
||||
uuid=device_raw['uuid'],
|
||||
partuuid=device_raw['partuuid'],
|
||||
**extra))
|
||||
return devices
|
||||
|
||||
|
@ -29,6 +29,7 @@ from ironic_python_agent import hardware
|
||||
from ironic_python_agent import partition_utils
|
||||
from ironic_python_agent import raid_utils
|
||||
from ironic_python_agent.tests.unit import base
|
||||
from ironic_python_agent.tests.unit.samples import hardware_samples as hws
|
||||
|
||||
|
||||
@mock.patch.object(hardware, 'dispatch_to_managers', autospec=True)
|
||||
@ -756,17 +757,7 @@ Boot0004* ironic1 HD(1,GPT,55db8d03-c8f6-4a5b-9155-790dddc348fa,0x800,0x640
|
||||
mock_is_md_device.return_value = False
|
||||
mock_md_get_raid_devices.return_value = {}
|
||||
mock_exists.side_effect = iter([False, True, False, True, True])
|
||||
partuuid_device = ('KNAME="sda" MODEL="DRIVE 0" SIZE="10240000" '
|
||||
'ROTA="1" TYPE="disk" UUID="987654-3210" '
|
||||
'PARTUUID=""\n'
|
||||
'KNAME="sda0" MODEL="DRIVE 0" SIZE="102400" '
|
||||
'ROTA="1" TYPE="part" '
|
||||
'UUID="' + self.fake_efi_system_part_uuid + '" '
|
||||
'PARTUUID="1234-2918"\n')
|
||||
exec_side_effect = [('', '')] * 16
|
||||
exec_side_effect.append((partuuid_device, ''))
|
||||
exec_side_effect.extend([('', '')] * 8)
|
||||
mock_execute.side_effect = exec_side_effect
|
||||
mock_execute.return_value = (hws.PARTUUID_DEVICE_TEMPLATE, '')
|
||||
|
||||
with mock.patch('builtins.open', mock.mock_open()) as mock_open:
|
||||
image._install_grub2(
|
||||
@ -823,8 +814,9 @@ Boot0004* ironic1 HD(1,GPT,55db8d03-c8f6-4a5b-9155-790dddc348fa,0x800,0x640
|
||||
'GRUB_SAVEDEFAULT': 'true'},
|
||||
use_standard_locale=True),
|
||||
mock.call('udevadm', 'settle'),
|
||||
mock.call('lsblk', '-Pbia',
|
||||
'-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID'),
|
||||
mock.call('lsblk', '-bia', '--json',
|
||||
'-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID',
|
||||
check_exit_code=[0]),
|
||||
mock.call('umount', self.fake_dir + '/boot/efi',
|
||||
attempts=3, delay_on_retry=True),
|
||||
mock.call(('chroot %s /bin/sh -c "umount -a -t vfat"' %
|
||||
@ -870,17 +862,7 @@ Boot0004* ironic1 HD(1,GPT,55db8d03-c8f6-4a5b-9155-790dddc348fa,0x800,0x640
|
||||
environ_mock.get.return_value = '/sbin'
|
||||
mock_is_md_device.return_value = False
|
||||
mock_md_get_raid_devices.return_value = {}
|
||||
partuuid_device = ('KNAME="sda" MODEL="DRIVE 0" SIZE="10240000" '
|
||||
'ROTA="1" TYPE="disk" UUID="987654-3210" '
|
||||
'PARTUUID=""\n'
|
||||
'KNAME="sda0" MODEL="DRIVE 0" SIZE="102400" '
|
||||
'ROTA="1" TYPE="part" UUID="987654-3210" '
|
||||
'PARTUUID="' + self.fake_efi_system_part_uuid
|
||||
+ '"\n')
|
||||
exec_side_effect = [('', '')] * 16
|
||||
exec_side_effect.append((partuuid_device, ''))
|
||||
exec_side_effect.extend([('', '')] * 8)
|
||||
mock_execute.side_effect = exec_side_effect
|
||||
mock_execute.return_value = (hws.PARTUUID_DEVICE_TEMPLATE, '')
|
||||
# Validates the complete opposite path *and* no-write behavior
|
||||
# occurs if the entry already exists.
|
||||
fstab_data = (
|
||||
@ -951,8 +933,9 @@ Boot0004* ironic1 HD(1,GPT,55db8d03-c8f6-4a5b-9155-790dddc348fa,0x800,0x640
|
||||
'GRUB_SAVEDEFAULT': 'true'},
|
||||
use_standard_locale=True),
|
||||
mock.call('udevadm', 'settle'),
|
||||
mock.call('lsblk', '-Pbia',
|
||||
'-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID'),
|
||||
mock.call('lsblk', '-bia', '--json',
|
||||
'-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID',
|
||||
check_exit_code=[0]),
|
||||
mock.call('umount', self.fake_dir + '/boot/efi',
|
||||
attempts=3, delay_on_retry=True),
|
||||
mock.call(('chroot %s /bin/sh -c "umount -a -t vfat"' %
|
||||
@ -1977,9 +1960,11 @@ Boot0004* ironic1 HD(1,GPT,55db8d03-c8f6-4a5b-9155-790dddc348fa,0x800,0x640
|
||||
mock_dispatch.assert_any_call('get_boot_info')
|
||||
self.assertEqual(0, mock_execute.call_count)
|
||||
|
||||
@mock.patch.object(hardware, 'list_all_block_devices', autospec=True)
|
||||
@mock.patch.object(os.path, 'exists', lambda *_: True)
|
||||
def test__append_uefi_to_fstab_handles_error(self, mock_execute,
|
||||
mock_dispatch):
|
||||
mock_dispatch,
|
||||
mock_list_blk_devs):
|
||||
with mock.patch('builtins.open', mock.mock_open()) as mock_open:
|
||||
mock_open.side_effect = OSError('boom')
|
||||
image._append_uefi_to_fstab(
|
||||
|
@ -97,43 +97,52 @@ HDPARM_INFO_TEMPLATE = (
|
||||
'Checksum: correct\n'
|
||||
)
|
||||
|
||||
BLK_DEVICE_TEMPLATE = (
|
||||
'KNAME="sda" MODEL="TinyUSB Drive" SIZE="3116853504" '
|
||||
'ROTA="0" TYPE="disk" SERIAL="123" UUID="F531-BDC3" PARTUUID=""\n'
|
||||
'KNAME="sdb" MODEL="Fastable SD131 7" SIZE="10737418240" '
|
||||
'ROTA="0" TYPE="disk" UUID="9a5e5cca-e03d-4cbd-9054-9e6ca9048222" '
|
||||
'PARTUUID=""\n'
|
||||
'KNAME="sdc" MODEL="NWD-BLP4-1600 " SIZE="1765517033472" '
|
||||
' ROTA="0" TYPE="disk" UUID="" PARTUUID=""\n'
|
||||
'KNAME="sdd" MODEL="NWD-BLP4-1600 " SIZE="1765517033472" '
|
||||
' ROTA="0" TYPE="disk" UUID="" PARTUUID=""\n'
|
||||
'KNAME="loop0" MODEL="" SIZE="109109248" ROTA="1" TYPE="loop" UUID="" '
|
||||
'PARTUUID=""\n'
|
||||
'KNAME="zram0" MODEL="" SIZE="" ROTA="0" TYPE="disk" UUID="" PARTUUID=""\n'
|
||||
'KNAME="ram0" MODEL="" SIZE="8388608" ROTA="0" TYPE="disk" UUID="" '
|
||||
'PARTUUID=""\n'
|
||||
'KNAME="ram1" MODEL="" SIZE="8388608" ROTA="0" TYPE="disk" UUID="" '
|
||||
'PARTUUID=""\n'
|
||||
'KNAME="ram2" MODEL="" SIZE="8388608" ROTA="0" TYPE="disk" UUID="" '
|
||||
'PARTUUID=""\n'
|
||||
'KNAME="ram3" MODEL="" SIZE="8388608" ROTA="0" TYPE="disk" UUID="" '
|
||||
'PARTUUID=""\n'
|
||||
'KNAME="fd1" MODEL="magic" SIZE="4096" ROTA="1" TYPE="disk" UUID="" '
|
||||
'PARTUUID=""\n'
|
||||
'KNAME="sdf" MODEL="virtual floppy" SIZE="0" ROTA="1" TYPE="disk" UUID="" '
|
||||
'PARTUUID=""\n'
|
||||
'KNAME="dm-0" MODEL="NWD-BLP4-1600 " SIZE="1765517033472" '
|
||||
' ROTA="0" TYPE="mpath" UUID="" PARTUUID=""\n'
|
||||
|
||||
)
|
||||
BLK_DEVICE_TEMPLATE = """
|
||||
{
|
||||
"blockdevices": [
|
||||
{"kname":"sda", "model":"TinyUSB Drive", "size":3116853504,
|
||||
"rota":false, "type":"disk", "serial":123, "uuid":"F531-BDC3",
|
||||
"partuuid":null},
|
||||
{"kname":"sdb", "model":"Fastable SD131 7", "size":10737418240,
|
||||
"rota":false, "type":"disk",
|
||||
"uuid":"9a5e5cca-e03d-4cbd-9054-9e6ca9048222", "partuuid":null},
|
||||
{"kname":"sdc", "model":"NWD-BLP4-1600", "size":1765517033472,
|
||||
"rota":false, "type":"disk", "uuid":null, "partuuid":null},
|
||||
{"kname":"sdd", "model":"NWD-BLP4-1600", "size":1765517033472,
|
||||
"rota":false, "type":"disk", "uuid":null, "partuuid":null},
|
||||
{"kname":"loop0", "model":null, "size":109109248, "rota":true,
|
||||
"type":"loop", "uuid":null, "partuuid": null},
|
||||
{"kname":"zram0", "model":null, "size":0, "rota":false, "type":"disk",
|
||||
"uuid":null, "partuuid":null},
|
||||
{"kname":"ram0", "model":null, "size":8388608, "rota":false,
|
||||
"type":"disk", "uuid":null, "partuuid":null},
|
||||
{"kname":"ram1", "model":null, "size":8388608, "rota":false,
|
||||
"type":"disk", "uuid":null, "partuuid":null},
|
||||
{"kname":"ram2", "model":null, "size":8388608, "rota":false,
|
||||
"type":"disk", "uuid":null, "partuuid":null},
|
||||
{"kname":"ram3", "model":null, "size":8388608, "rota":false,
|
||||
"type":"disk", "uuid":null, "partuuid":null},
|
||||
{"kname":"fd1", "model":"magic", "size":4096, "rota":true,
|
||||
"type":"disk", "uuid":null, "partuuid":null},
|
||||
{"kname":"sdf", "model":"virtual floppy", "size":0, "rota":true,
|
||||
"type":"disk", "uuid":null, "partuuid":null},
|
||||
{"kname":"dm-0", "model":"NWD-BLP4-1600", "size":"1765517033472",
|
||||
"rota":false, "type":"mpath", "uuid":null, "partuuid":null}
|
||||
]
|
||||
}
|
||||
"""
|
||||
|
||||
# NOTE(pas-ha) largest device is 1 byte smaller than 4GiB
|
||||
BLK_DEVICE_TEMPLATE_SMALL = (
|
||||
'KNAME="sda" MODEL="TinyUSB Drive" SIZE="3116853504" '
|
||||
'ROTA="0" TYPE="disk" UUID="F531-BDC3" PARTUUID=""\n'
|
||||
'KNAME="sdb" MODEL="AlmostBigEnough Drive" SIZE="4294967295" '
|
||||
'ROTA="0" TYPE="disk" UUID="" PARTUUID=""'
|
||||
)
|
||||
BLK_DEVICE_TEMPLATE_SMALL = """
|
||||
{
|
||||
"blockdevices": [
|
||||
{"kname":"sda", "model":"TinyUSB Drive", "size":3116853504, "rota":false,
|
||||
"type":"disk", "uuid":"F531-BDC", "partuuid":null},
|
||||
{"kname":"sdb", "model":"AlmostBigEnough Drive", "size":"4294967295",
|
||||
"rota":false, "type":"disk", "uuid":null, "partuuid":null}
|
||||
]
|
||||
}
|
||||
"""
|
||||
|
||||
# NOTE(TheJulia): This list intentionally contains duplicates
|
||||
# as the code filters them out by kernel device name.
|
||||
@ -142,76 +151,92 @@ BLK_DEVICE_TEMPLATE_SMALL = (
|
||||
# ROTA has been set to 0 on some software RAID devices for testing
|
||||
# purposes. In practice is appears to inherit from the underyling
|
||||
# devices, so in this example it would normally be 1.
|
||||
RAID_BLK_DEVICE_TEMPLATE = (
|
||||
'KNAME="sda" MODEL="DRIVE 0" SIZE="1765517033472" '
|
||||
'ROTA="1" TYPE="disk" UUID="" PARTUUID=""\n'
|
||||
'KNAME="sda1" MODEL="DRIVE 0" SIZE="107373133824" '
|
||||
'ROTA="1" TYPE="part" UUID="" PARTUUID=""\n'
|
||||
'KNAME="sdb" MODEL="DRIVE 1" SIZE="1765517033472" '
|
||||
'ROTA="1" TYPE="disk" UUID="" PARTUUID=""\n'
|
||||
'KNAME="sdb" MODEL="DRIVE 1" SIZE="1765517033472" '
|
||||
'ROTA="1" TYPE="disk" UUID="" PARTUUID=""\n'
|
||||
'KNAME="sdb1" MODEL="DRIVE 1" SIZE="107373133824" '
|
||||
'ROTA="1" TYPE="part" UUID="" PARTUUID=""\n'
|
||||
'KNAME="md0p1" MODEL="RAID" SIZE="107236818944" '
|
||||
'ROTA="0" TYPE="md" UUID="" PARTUUID=""\n'
|
||||
'KNAME="md0" MODEL="RAID" SIZE="1765517033470" '
|
||||
'ROTA="0" TYPE="raid1" UUID="" PARTUUID=""\n'
|
||||
'KNAME="md0" MODEL="RAID" SIZE="1765517033470" '
|
||||
'ROTA="0" TYPE="raid1" UUID="" PARTUUID=""\n'
|
||||
'KNAME="md1" MODEL="RAID" SIZE="" ROTA="0" TYPE="raid1" UUID="" '
|
||||
'PARTUUID=""'
|
||||
)
|
||||
RAID_BLK_DEVICE_TEMPLATE = ("""
|
||||
{
|
||||
"blockdevices": [
|
||||
{"kname":"sda", "model":"DRIVE 0", "size":1765517033472, "rota":true,
|
||||
"type":"disk", "uuid":null, "partuuid":null},
|
||||
{"kname":"sda1", "model":"DRIVE 0", "size":107373133824, "rota":true,
|
||||
"type":"part", "uuid":null, "partuuid":null},
|
||||
{"kname":"sdb", "model":"DRIVE 1", "size":1765517033472, "rota":true,
|
||||
"type":"disk", "uuid":null, "partuuid":null},
|
||||
{"kname":"sdb", "model":"DRIVE 1", "size":1765517033472, "rota":true,
|
||||
"type":"disk", "uuid":null, "partuuid":null},
|
||||
{"kname":"sdb1", "model":"DRIVE 1", "size":107373133824, "rota":true,
|
||||
"type":"part", "uuid":null, "partuuid":null},
|
||||
{"kname":"md0p1", "model":"RAID", "size":107236818944, "rota":false,
|
||||
"type":"md", "uuid":null, "partuuid":null},
|
||||
{"kname":"md0", "model":"RAID", "size":1765517033470, "rota":false,
|
||||
"type":"raid1", "uuid":null, "partuuid":null},
|
||||
{"kname":"md0", "model":"RAID", "size":1765517033470, "rota":false,
|
||||
"type":"raid1", "uuid":null, "partuuid":null},
|
||||
{"kname":"md1", "model":"RAID", "size":0, "rota":false, "type":"raid1",
|
||||
"uuid":null, "partuuid":null}
|
||||
]
|
||||
}
|
||||
""")
|
||||
|
||||
MULTIPATH_BLK_DEVICE_TEMPLATE = (
|
||||
'KNAME="sda" MODEL="INTEL_SSDSC2CT060A3" SIZE="60022480896" ROTA="0" '
|
||||
'TYPE="disk" UUID="" PARTUUID=""\n'
|
||||
'KNAME="sda2" MODEL="" SIZE="59162722304" ROTA="0" TYPE="part" '
|
||||
'UUID="f8b55d59-96c3-3982-b129-1b6b2ee8da86" '
|
||||
'PARTUUID="c97c8aac-7796-4433-b1fc-9b5fac43edf3"\n'
|
||||
'KNAME="sda3" MODEL="" SIZE="650002432" ROTA="0" TYPE="part" '
|
||||
'UUID="b3b03565-5f13-3c93-b2a6-6d90e25be926" '
|
||||
'PARTUUID="6c85beff-b2bd-4a1c-91b7-8abb5256459d"\n'
|
||||
'KNAME="sda1" MODEL="" SIZE="209715200" ROTA="0" TYPE="part" '
|
||||
'UUID="0a83355d-7500-3f5f-9abd-66f6fd03714c" '
|
||||
'PARTUUID="eba28b26-b76a-402c-94dd-0b66a523a485"\n'
|
||||
'KNAME="dm-0" MODEL="" SIZE="60022480896" ROTA="0" TYPE="mpath" '
|
||||
'UUID="" PARTUUID=""\n'
|
||||
'KNAME="dm-4" MODEL="" SIZE="650002432" ROTA="0" TYPE="part" '
|
||||
'UUID="b3b03565-5f13-3c93-b2a6-6d90e25be926" '
|
||||
'PARTUUID="6c85beff-b2bd-4a1c-91b7-8abb5256459d"\n'
|
||||
'KNAME="dm-2" MODEL="" SIZE="209715200" ROTA="0" TYPE="part" '
|
||||
'UUID="0a83355d-7500-3f5f-9abd-66f6fd03714c" '
|
||||
'PARTUUID="eba28b26-b76a-402c-94dd-0b66a523a485"\n'
|
||||
'KNAME="dm-3" MODEL="" SIZE="59162722304" ROTA="0" TYPE="part" '
|
||||
'UUID="f8b55d59-96c3-3982-b129-1b6b2ee8da86" '
|
||||
'PARTUUID="c97c8aac-7796-4433-b1fc-9b5fac43edf3"\n'
|
||||
'KNAME="sdb" MODEL="INTEL_SSDSC2CT060A3" SIZE="60022480896" '
|
||||
'ROTA="0" TYPE="disk" UUID="" PARTUUID=""\n'
|
||||
'KNAME="sdb2" MODEL="" SIZE="59162722304" ROTA="0" TYPE="part" '
|
||||
'UUID="f8b55d59-96c3-3982-b129-1b6b2ee8da86" '
|
||||
'PARTUUID="c97c8aac-7796-4433-b1fc-9b5fac43edf3"\n'
|
||||
'KNAME="sdb3" MODEL="" SIZE="650002432" ROTA="0" TYPE="part" '
|
||||
'UUID="b3b03565-5f13-3c93-b2a6-6d90e25be926" '
|
||||
'PARTUUID="6c85beff-b2bd-4a1c-91b7-8abb5256459d"\n'
|
||||
'KNAME="sdb1" MODEL="" SIZE="209715200" ROTA="0" TYPE="part" '
|
||||
'UUID="0a83355d-7500-3f5f-9abd-66f6fd03714c" '
|
||||
'PARTUUID="eba28b26-b76a-402c-94dd-0b66a523a485"\n'
|
||||
'KNAME="sdc" MODEL="ST1000DM003-1CH162" SIZE="1000204886016" '
|
||||
'ROTA="1" TYPE="disk" UUID="" PARTUUID=""\n'
|
||||
'KNAME="sdc1" MODEL="" SIZE="899999072256" ROTA="1" TYPE="part" '
|
||||
'UUID="457f7d3c-9376-4997-89bd-d1a7c8b04060" '
|
||||
'PARTUUID="c9433d2e-3bbc-47b4-92bf-43c1d80f06e0"\n'
|
||||
'KNAME="dm-1" MODEL="" SIZE="1000204886016" ROTA="0" TYPE="mpath" '
|
||||
'UUID="" PARTUUID=""\n'
|
||||
)
|
||||
MULTIPATH_BLK_DEVICE_TEMPLATE = ("""
|
||||
{
|
||||
"blockdevices": [
|
||||
{"kname":"sda", "model":"INTEL_SSDSC2CT060A3", "size":"60022480896",
|
||||
"rota":false, "type":"disk", "uuid":null, "partuuid":null},
|
||||
{"kname":"sda2", "model":null, "size":"59162722304", "rota":false,
|
||||
"type":"part", "uuid":"f8b55d59-96c3-3982-b129-1b6b2ee8da86",
|
||||
"partuuid":"c97c8aac-7796-4433-b1fc-9b5fac43edf3"},
|
||||
{"kname":"sda3", "model":null, "size":"650002432", "rota":false,
|
||||
"type":"part", "uuid":"b3b03565-5f13-3c93-b2a6-6d90e25be926",
|
||||
"partuuid":"6c85beff-b2bd-4a1c-91b7-8abb5256459d"},
|
||||
{"kname":"sda1", "model":null, "size":"209715200", "rota":false,
|
||||
"type":"part", "uuid":"0a83355d-7500-3f5f-9abd-66f6fd03714c",
|
||||
"partuuid":"eba28b26-b76a-402c-94dd-0b66a523a485"},
|
||||
{"kname":"dm-0", "model":null, "size":"60022480896", "rota":false,
|
||||
"type":"mpath", "uuid":null, "partuuid":null},
|
||||
{"kname":"dm-4", "model":null, "size":"650002432", "rota":false,
|
||||
"type":"part", "uuid":"b3b03565-5f13-3c93-b2a6-6d90e25be926",
|
||||
"partuuid":"6c85beff-b2bd-4a1c-91b7-8abb5256459d"},
|
||||
{"kname":"dm-2", "model":null, "size":"209715200", "rota":false,
|
||||
"type":"part", "uuid":"0a83355d-7500-3f5f-9abd-66f6fd03714c",
|
||||
"partuuid":"eba28b26-b76a-402c-94dd-0b66a523a485"},
|
||||
{"kname":"dm-3", "model":null, "size":"59162722304", "rota":false,
|
||||
"type":"part", "uuid":"f8b55d59-96c3-3982-b129-1b6b2ee8da86",
|
||||
"partuuid":"c97c8aac-7796-4433-b1fc-9b5fac43edf3"},
|
||||
{"kname":"sdb", "model":"INTEL_SSDSC2CT060A3", "size":"60022480896",
|
||||
"rota":false, "type":"disk", "uuid":null, "partuuid":null},
|
||||
{"kname":"sdb2", "model":null, "size":"59162722304",
|
||||
"rota":false, "type":"part",
|
||||
"uuid":"f8b55d59-96c3-3982-b129-1b6b2ee8da86",
|
||||
"partuuid":"c97c8aac-7796-4433-b1fc-9b5fac43edf3"},
|
||||
{"kname":"sdb3", "model":null, "size":"650002432",
|
||||
"rota":false, "type":"part",
|
||||
"uuid":"b3b03565-5f13-3c93-b2a6-6d90e25be926",
|
||||
"partuuid":"6c85beff-b2bd-4a1c-91b7-8abb5256459d"},
|
||||
{"kname":"sdb1", "model":null, "size":"209715200",
|
||||
"rota":false, "type":"part",
|
||||
"uuid":"0a83355d-7500-3f5f-9abd-66f6fd03714c",
|
||||
"partuuid":"eba28b26-b76a-402c-94dd-0b66a523a485"},
|
||||
{"kname":"sdc", "model":"ST1000DM003-1CH162", "size":"1000204886016",
|
||||
"rota":true, "type":"disk", "uuid":null, "partuuid":null},
|
||||
{"kname":"sdc1", "model":null, "size":"899999072256",
|
||||
"rota":true, "type":"part",
|
||||
"uuid":"457f7d3c-9376-4997-89bd-d1a7c8b04060",
|
||||
"partuuid":"c9433d2e-3bbc-47b4-92bf-43c1d80f06e0"},
|
||||
{"kname":"dm-1", "model":null, "size":"1000204886016", "rota":false,
|
||||
"type":"mpath", "uuid":null, "partuuid":null}
|
||||
]
|
||||
}
|
||||
""")
|
||||
|
||||
PARTUUID_DEVICE_TEMPLATE = (
|
||||
'KNAME="sda" MODEL="DRIVE 0" SIZE="1765517033472" '
|
||||
'ROTA="1" TYPE="disk" UUID="" PARTUUID=""\n'
|
||||
'KNAME="sda1" MODEL="DRIVE 0" SIZE="107373133824" '
|
||||
'ROTA="1" TYPE="part" UUID="987654-3210" PARTUUID="1234-5678"\n'
|
||||
)
|
||||
PARTUUID_DEVICE_TEMPLATE = ("""
|
||||
{
|
||||
"blockdevices": [
|
||||
{"kname":"sda", "model":"DRIVE 0", "size":1765517033472, "rota":true,
|
||||
"type":"disk", "uuid":null, "partuuid":null},
|
||||
{"kname":"sda1", "model":"DRIVE 0", "size":107373133824, "rota":true,
|
||||
"type":"part", "uuid":"987654-3210", "partuuid":"1234-5678"}
|
||||
]
|
||||
}
|
||||
""")
|
||||
|
||||
SHRED_OUTPUT_0_ITERATIONS_ZERO_FALSE = ()
|
||||
|
||||
@ -241,7 +266,6 @@ SHRED_OUTPUT_2_ITERATIONS_ZERO_FALSE = (
|
||||
'shred: /dev/sda: pass 2/2 (random)...29GiB/29GiB 100%\n'
|
||||
)
|
||||
|
||||
|
||||
LSCPU_OUTPUT = """
|
||||
Architecture: x86_64
|
||||
CPU op-mode(s): 32-bit, 64-bit
|
||||
@ -893,7 +917,6 @@ Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org
|
||||
ATA Security is: Unavailable
|
||||
""") # noqa
|
||||
|
||||
|
||||
IPMITOOL_LAN6_PRINT_DYNAMIC_ADDR = """
|
||||
IPv6 Dynamic Address 0:
|
||||
Source/Type: DHCPv6
|
||||
@ -1008,7 +1031,6 @@ Working Devices : 2
|
||||
1 259 3 1 active sync /dev/nvme1n1p1
|
||||
""")
|
||||
|
||||
|
||||
MDADM_DETAIL_OUTPUT_BROKEN_RAID0 = ("""/dev/md126:
|
||||
Version : 1.2
|
||||
Raid Level : raid0
|
||||
@ -1027,7 +1049,6 @@ MDADM_DETAIL_OUTPUT_BROKEN_RAID0 = ("""/dev/md126:
|
||||
- 8 2 - /dev/sda2
|
||||
""")
|
||||
|
||||
|
||||
MDADM_EXAMINE_OUTPUT_MEMBER = ("""/dev/sda1:
|
||||
Magic : a92b4efc
|
||||
Version : 1.2
|
||||
@ -1056,7 +1077,6 @@ MDADM_EXAMINE_OUTPUT_MEMBER = ("""/dev/sda1:
|
||||
Array State : A. ('A' == active, '.' == missing, 'R' == replacing)
|
||||
""")
|
||||
|
||||
|
||||
MDADM_EXAMINE_OUTPUT_NON_MEMBER = ("""/dev/sdz1:
|
||||
Magic : a92b4efc
|
||||
Version : 1.2
|
||||
@ -1085,7 +1105,6 @@ MDADM_EXAMINE_OUTPUT_NON_MEMBER = ("""/dev/sdz1:
|
||||
Array State : A. ('A' == active, '.' == missing, 'R' == replacing)
|
||||
""")
|
||||
|
||||
|
||||
PROC_MOUNTS_OUTPUT = ("""
|
||||
debugfs /sys/kernel/debug debugfs rw,relatime 0 0
|
||||
/dev/sda2 / ext4 rw,relatime,errors=remount-ro 0 0
|
||||
@ -1094,7 +1113,6 @@ pstore /sys/fs/pstore pstore rw,nosuid,nodev,noexec,relatime 0 0
|
||||
/dev/loop19 /snap/core/10126 squashfs ro,nodev,relatime 0 0
|
||||
""")
|
||||
|
||||
|
||||
PROC_MOUNTS_OUTPUT_NO_PSTORE = ("""
|
||||
debugfs /sys/kernel/debug debugfs rw,relatime 0 0
|
||||
/dev/sda2 / ext4 rw,relatime,errors=remount-ro 0 0
|
||||
|
@ -824,8 +824,9 @@ class TestGenericHardwareManager(base.IronicAgentTest):
|
||||
stderr='the -c option requires a path to check'), # dm-1
|
||||
]
|
||||
expected = [
|
||||
mock.call('lsblk', '-Pbia',
|
||||
'-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID'),
|
||||
mock.call('lsblk', '-bia', '--json',
|
||||
'-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID',
|
||||
check_exit_code=[0]),
|
||||
mock.call('multipath', '-c', '/dev/sda'),
|
||||
mock.call('multipath', '-ll', '/dev/sda'),
|
||||
mock.call('multipath', '-c', '/dev/sda2'),
|
||||
@ -903,8 +904,9 @@ class TestGenericHardwareManager(base.IronicAgentTest):
|
||||
stderr='the -c option requires a path to check'), # dm-1
|
||||
]
|
||||
expected = [
|
||||
mock.call('lsblk', '-Pbia',
|
||||
'-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID'),
|
||||
mock.call('lsblk', '-bia', '--json',
|
||||
'-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID',
|
||||
check_exit_code=[0]),
|
||||
mock.call('multipath', '-c', '/dev/sda'),
|
||||
mock.call('multipath', '-ll', '/dev/sda'),
|
||||
mock.call('multipath', '-c', '/dev/sda2'),
|
||||
@ -957,8 +959,9 @@ class TestGenericHardwareManager(base.IronicAgentTest):
|
||||
# should always be smaller
|
||||
self.assertEqual('/dev/md0', self.hardware.get_os_install_device())
|
||||
expected = [
|
||||
mock.call('lsblk', '-Pbia',
|
||||
'-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID'),
|
||||
mock.call('lsblk', '-bia', '--json',
|
||||
'-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID',
|
||||
check_exit_code=[0]),
|
||||
]
|
||||
|
||||
mocked_execute.assert_has_calls(expected)
|
||||
@ -982,11 +985,16 @@ class TestGenericHardwareManager(base.IronicAgentTest):
|
||||
ex = self.assertRaises(errors.DeviceNotFound,
|
||||
self.hardware.get_os_install_device)
|
||||
expected = [
|
||||
mock.call('lsblk', '-Pbia',
|
||||
'-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID'),
|
||||
mock.call('lsblk', '-bia', '--json',
|
||||
'-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID',
|
||||
check_exit_code=[0]),
|
||||
]
|
||||
|
||||
mocked_execute.assert_has_calls(expected)
|
||||
mocked_execute.assert_called_once_with(
|
||||
'lsblk', '-bia', '--json',
|
||||
'-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID',
|
||||
check_exit_code=[0])
|
||||
self.assertIn(str(4 * units.Gi), ex.details)
|
||||
mock_cached_node.assert_called_once_with()
|
||||
self.assertEqual(1, mocked_mpath.call_count)
|
||||
@ -1491,8 +1499,9 @@ class TestGenericHardwareManager(base.IronicAgentTest):
|
||||
for dev in range(3)]
|
||||
mock_readlink.assert_has_calls(expected_calls)
|
||||
expected_calls = [
|
||||
mock.call('lsblk', '-Pbia',
|
||||
'-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID'),
|
||||
mock.call('lsblk', '-bia', '--json',
|
||||
'-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID',
|
||||
check_exit_code=[0]),
|
||||
mock.call('multipath', '-c', '/dev/sda'),
|
||||
mock.call('multipath', '-c', '/dev/sdb'),
|
||||
mock.call('multipath', '-c', '/dev/sdc'),
|
||||
@ -3581,6 +3590,7 @@ class TestGenericHardwareManager(base.IronicAgentTest):
|
||||
]
|
||||
}
|
||||
self.node['target_raid_config'] = raid_config
|
||||
mocked_execute.return_value = (hws.RAID_BLK_DEVICE_TEMPLATE, '')
|
||||
self.assertRaises(errors.SoftwareRAIDError,
|
||||
self.hardware.create_configuration,
|
||||
self.node, [])
|
||||
@ -4239,6 +4249,7 @@ class TestGenericHardwareManager(base.IronicAgentTest):
|
||||
},
|
||||
]
|
||||
}
|
||||
mocked_execute.return_value = (hws.RAID_BLK_DEVICE_TEMPLATE, '')
|
||||
self.assertIsNone(self.hardware.validate_configuration(raid_config,
|
||||
self.node))
|
||||
|
||||
@ -4258,6 +4269,7 @@ class TestGenericHardwareManager(base.IronicAgentTest):
|
||||
},
|
||||
]
|
||||
}
|
||||
mocked_execute.return_value = (hws.RAID_BLK_DEVICE_TEMPLATE, '')
|
||||
self.assertRaises(errors.SoftwareRAIDError,
|
||||
self.hardware.validate_configuration,
|
||||
raid_config, self.node)
|
||||
@ -4278,6 +4290,7 @@ class TestGenericHardwareManager(base.IronicAgentTest):
|
||||
},
|
||||
]
|
||||
}
|
||||
mocked_execute.return_value = (hws.RAID_BLK_DEVICE_TEMPLATE, '')
|
||||
self.assertRaises(errors.SoftwareRAIDError,
|
||||
self.hardware.validate_configuration,
|
||||
raid_config, self.node)
|
||||
@ -4601,8 +4614,9 @@ class TestModuleFunctions(base.IronicAgentTest):
|
||||
]
|
||||
result = hardware.list_all_block_devices()
|
||||
expected_calls = [
|
||||
mock.call('lsblk', '-Pbia',
|
||||
'-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID'),
|
||||
mock.call('lsblk', '-bia', '--json',
|
||||
'-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID',
|
||||
check_exit_code=[0]),
|
||||
mock.call('multipath', '-c', '/dev/sda'),
|
||||
mock.call('multipath', '-c', '/dev/sdb')
|
||||
]
|
||||
@ -4647,8 +4661,9 @@ class TestModuleFunctions(base.IronicAgentTest):
|
||||
stderr='the -c option requires a path to check'), # md1
|
||||
]
|
||||
expected_calls = [
|
||||
mock.call('lsblk', '-Pbia',
|
||||
'-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID'),
|
||||
mock.call('lsblk', '-bia', '--json',
|
||||
'-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID',
|
||||
check_exit_code=[0]),
|
||||
mock.call('multipath', '-c', '/dev/sda'),
|
||||
mock.call('multipath', '-c', '/dev/sda1'),
|
||||
mock.call('multipath', '-c', '/dev/sdb'),
|
||||
@ -4685,8 +4700,9 @@ class TestModuleFunctions(base.IronicAgentTest):
|
||||
]
|
||||
result = hardware.list_all_block_devices(block_type='part')
|
||||
expected_calls = [
|
||||
mock.call('lsblk', '-Pbia',
|
||||
'-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID'),
|
||||
mock.call('lsblk', '-bia', '--json',
|
||||
'-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID',
|
||||
check_exit_code=[0]),
|
||||
mock.call('multipath', '-c', '/dev/sda'),
|
||||
mock.call('multipath', '-c', '/dev/sda1'),
|
||||
]
|
||||
@ -4703,10 +4719,13 @@ class TestModuleFunctions(base.IronicAgentTest):
|
||||
mock_mpath_enabled,
|
||||
mocked_execute):
|
||||
mock_mpath_enabled.return_value = False
|
||||
mocked_execute.return_value = ('TYPE="foo" MODEL="model"', '')
|
||||
mocked_execute.return_value = (
|
||||
'{"blockdevices": [{"type":"foo", "model":"model"}]}', '')
|
||||
result = hardware.list_all_block_devices()
|
||||
mocked_execute.assert_called_once_with(
|
||||
'lsblk', '-Pbia', '-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID')
|
||||
'lsblk', '-bia', '--json',
|
||||
'-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID',
|
||||
check_exit_code=[0])
|
||||
self.assertEqual([], result)
|
||||
mocked_udev.assert_called_once_with()
|
||||
|
||||
@ -4717,22 +4736,17 @@ class TestModuleFunctions(base.IronicAgentTest):
|
||||
mocked_execute):
|
||||
"""Test for missing values returned from lsblk"""
|
||||
mocked_mpath.return_value = False
|
||||
mocked_execute.side_effect = [
|
||||
('TYPE="disk" MODEL="model"', ''),
|
||||
('', ''),
|
||||
('', ''),
|
||||
('', ''),
|
||||
('', ''),
|
||||
]
|
||||
expected_calls = [
|
||||
mock.call('lsblk', '-Pbia',
|
||||
'-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID'),
|
||||
mock.call('lsblk', '-bia', '--json',
|
||||
'-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID',
|
||||
check_exit_code=[0]),
|
||||
]
|
||||
|
||||
mocked_execute.return_value = (
|
||||
'{"blockdevices": [{"type":"disk", "model":"model"}]}', '')
|
||||
self.assertRaisesRegex(
|
||||
errors.BlockDeviceError,
|
||||
r'^Block device caused unknown error: KNAME, PARTUUID, ROTA, '
|
||||
r'SIZE, UUID must be returned by lsblk.$',
|
||||
r'^Block device caused unknown error: kname, partuuid, rota, '
|
||||
r'size, uuid must be returned by lsblk.$',
|
||||
hardware.list_all_block_devices)
|
||||
mocked_udev.assert_called_once_with()
|
||||
mocked_execute.assert_has_calls(expected_calls)
|
||||
|
Loading…
x
Reference in New Issue
Block a user