From fc1f2c73c665222d4a9ff32a763d4588978d9987 Mon Sep 17 00:00:00 2001 From: Riccardo Pittau Date: Wed, 3 Feb 2021 12:01:17 +0100 Subject: Use variable for lsblk columns device info Adjusted unit tests accordingly. Also removed redundant parenthesis. Change-Id: I8e2cac5172f009d5204f83bd83e1f27cfd721f09 --- ironic_python_agent/hardware.py | 5 +- ironic_python_agent/tests/unit/test_hardware.py | 71 ++++++++++++++----------- 2 files changed, 42 insertions(+), 34 deletions(-) diff --git a/ironic_python_agent/hardware.py b/ironic_python_agent/hardware.py index 1bfb2b46..8d50e354 100644 --- a/ironic_python_agent/hardware.py +++ b/ironic_python_agent/hardware.py @@ -428,8 +428,7 @@ def list_all_block_devices(block_type='disk', "version of block device name is unavailable " "Cause: %(error)s", {'path': disk_by_path_dir, 'error': e}) - # NOTE(dtantsur): keep in sync with utils.LSBLK_COLUMNS - columns = ['KNAME', 'MODEL', 'SIZE', 'ROTA', 'TYPE', 'UUID'] + columns = utils.LSBLK_COLUMNS report = utils.execute('lsblk', '-Pbia', '-o{}'.format(','.join(columns)), check_exit_code=[0])[0] lines = report.splitlines() @@ -461,7 +460,7 @@ def list_all_block_devices(block_type='disk', # Other possible type values, which we skip recording: # lvm, part, rom, loop if devtype != block_type: - if (devtype is None or ignore_raid): + if devtype is None or ignore_raid: LOG.debug("Skipping: {!r}".format(line)) continue elif ('raid' in devtype diff --git a/ironic_python_agent/tests/unit/test_hardware.py b/ironic_python_agent/tests/unit/test_hardware.py index cf27c3d7..01da31a0 100644 --- a/ironic_python_agent/tests/unit/test_hardware.py +++ b/ironic_python_agent/tests/unit/test_hardware.py @@ -125,29 +125,37 @@ HDPARM_INFO_TEMPLATE = ( BLK_DEVICE_TEMPLATE = ( 'KNAME="sda" MODEL="TinyUSB Drive" SIZE="3116853504" ' - 'ROTA="0" TYPE="disk" SERIAL="123" UUID="F531-BDC3"\n' + '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"\n' + '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=""\n' + ' ROTA="0" TYPE="disk" UUID="" PARTUUID=""\n' 'KNAME="sdd" MODEL="NWD-BLP4-1600 " SIZE="1765517033472" ' - ' ROTA="0" TYPE="disk" UUID=""\n' - 'KNAME="loop0" MODEL="" SIZE="109109248" ROTA="1" TYPE="loop" UUID=""\n' - 'KNAME="zram0" MODEL="" SIZE="" ROTA="0" TYPE="disk" UUID=""\n' - 'KNAME="ram0" MODEL="" SIZE="8388608" ROTA="0" TYPE="disk" UUID=""\n' - 'KNAME="ram1" MODEL="" SIZE="8388608" ROTA="0" TYPE="disk" UUID=""\n' - 'KNAME="ram2" MODEL="" SIZE="8388608" ROTA="0" TYPE="disk" UUID=""\n' - 'KNAME="ram3" MODEL="" SIZE="8388608" ROTA="0" TYPE="disk" UUID=""\n' - 'KNAME="fd1" MODEL="magic" SIZE="4096" ROTA="1" TYPE="disk" UUID=""\n' - 'KNAME="sdf" MODEL="virtual floppy" SIZE="0" ROTA="1" TYPE="disk" UUID=""' + ' 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=""' ) # 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"\n' + 'ROTA="0" TYPE="disk" UUID="F531-BDC3" PARTUUID=""\n' 'KNAME="sdb" MODEL="AlmostBigEnough Drive" SIZE="4294967295" ' - 'ROTA="0" TYPE="disk" UUID=""' + 'ROTA="0" TYPE="disk" UUID="" PARTUUID=""' ) BLK_DEVICE_TEMPLATE_SMALL_DEVICES = [ hardware.BlockDevice(name='/dev/sda', model='TinyUSB Drive', @@ -167,22 +175,23 @@ BLK_DEVICE_TEMPLATE_SMALL_DEVICES = [ # 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=""\n' + 'ROTA="1" TYPE="disk" UUID="" PARTUUID=""\n' 'KNAME="sda1" MODEL="DRIVE 0" SIZE="107373133824" ' - 'ROTA="1" TYPE="part" UUID=""\n' + 'ROTA="1" TYPE="part" UUID="" PARTUUID=""\n' 'KNAME="sdb" MODEL="DRIVE 1" SIZE="1765517033472" ' - 'ROTA="1" TYPE="disk" UUID=""\n' + 'ROTA="1" TYPE="disk" UUID="" PARTUUID=""\n' 'KNAME="sdb" MODEL="DRIVE 1" SIZE="1765517033472" ' - 'ROTA="1" TYPE="disk" UUID=""\n' + 'ROTA="1" TYPE="disk" UUID="" PARTUUID=""\n' 'KNAME="sdb1" MODEL="DRIVE 1" SIZE="107373133824" ' - 'ROTA="1" TYPE="part" UUID=""\n' + 'ROTA="1" TYPE="part" UUID="" PARTUUID=""\n' 'KNAME="md0p1" MODEL="RAID" SIZE="107236818944" ' - 'ROTA="0" TYPE="md" UUID=""\n' + 'ROTA="0" TYPE="md" UUID="" PARTUUID=""\n' 'KNAME="md0" MODEL="RAID" SIZE="1765517033470" ' - 'ROTA="0" TYPE="raid1" UUID=""\n' + 'ROTA="0" TYPE="raid1" UUID="" PARTUUID=""\n' 'KNAME="md0" MODEL="RAID" SIZE="1765517033470" ' - 'ROTA="0" TYPE="raid1" UUID=""\n' - 'KNAME="md1" MODEL="RAID" SIZE="" ROTA="0" TYPE="raid1" UUID=""' + 'ROTA="0" TYPE="raid1" UUID="" PARTUUID=""\n' + 'KNAME="md1" MODEL="RAID" SIZE="" ROTA="0" TYPE="raid1" UUID="" ' + 'PARTUUID=""' ) RAID_BLK_DEVICE_TEMPLATE_DEVICES = [ hardware.BlockDevice(name='/dev/sda', model='DRIVE 0', @@ -1536,7 +1545,7 @@ class TestGenericHardwareManager(base.IronicAgentTest): mocked_execute.return_value = (BLK_DEVICE_TEMPLATE, '') self.assertEqual('/dev/sdb', self.hardware.get_os_install_device()) mocked_execute.assert_called_once_with( - 'lsblk', '-Pbia', '-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID', + 'lsblk', '-Pbia', '-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID', check_exit_code=[0]) mock_cached_node.assert_called_once_with() @@ -1558,7 +1567,7 @@ class TestGenericHardwareManager(base.IronicAgentTest): # should always be smaller self.assertEqual('/dev/md0', self.hardware.get_os_install_device()) mocked_execute.assert_called_once_with( - 'lsblk', '-Pbia', '-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID', + 'lsblk', '-Pbia', '-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID', check_exit_code=[0]) mock_cached_node.assert_called_once_with() @@ -1577,7 +1586,7 @@ class TestGenericHardwareManager(base.IronicAgentTest): ex = self.assertRaises(errors.DeviceNotFound, self.hardware.get_os_install_device) mocked_execute.assert_called_once_with( - 'lsblk', '-Pbia', '-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID', + 'lsblk', '-Pbia', '-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() @@ -4815,7 +4824,7 @@ class TestModuleFunctions(base.IronicAgentTest): mocked_execute.return_value = (BLK_DEVICE_TEMPLATE_SMALL, '') result = hardware.list_all_block_devices() mocked_execute.assert_called_once_with( - 'lsblk', '-Pbia', '-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID', + 'lsblk', '-Pbia', '-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID', check_exit_code=[0]) self.assertEqual(BLK_DEVICE_TEMPLATE_SMALL_DEVICES, result) mocked_udev.assert_called_once_with() @@ -4834,7 +4843,7 @@ class TestModuleFunctions(base.IronicAgentTest): mocked_execute.return_value = (RAID_BLK_DEVICE_TEMPLATE, '') result = hardware.list_all_block_devices(ignore_empty=False) mocked_execute.assert_called_once_with( - 'lsblk', '-Pbia', '-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID', + 'lsblk', '-Pbia', '-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID', check_exit_code=[0]) self.assertEqual(RAID_BLK_DEVICE_TEMPLATE_DEVICES, result) mocked_udev.assert_called_once_with() @@ -4847,7 +4856,7 @@ class TestModuleFunctions(base.IronicAgentTest): mocked_execute.return_value = ('TYPE="foo" MODEL="model"', '') result = hardware.list_all_block_devices() mocked_execute.assert_called_once_with( - 'lsblk', '-Pbia', '-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID', + 'lsblk', '-Pbia', '-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID,PARTUUID', check_exit_code=[0]) self.assertEqual([], result) mocked_udev.assert_called_once_with() @@ -4859,8 +4868,8 @@ class TestModuleFunctions(base.IronicAgentTest): mocked_execute.return_value = ('TYPE="disk" MODEL="model"', '') self.assertRaisesRegex( errors.BlockDeviceError, - r'^Block device caused unknown error: KNAME, ROTA, SIZE, UUID ' - r'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() -- cgit v1.2.1