From c7858d3cc8709d95d63ff45e427f5215320bc67a Mon Sep 17 00:00:00 2001 From: Vladyslav Drok Date: 2020年10月16日 13:03:32 +0200 Subject: [PATCH] Add UUID to BlockDevice object It'd allow for example custom ansible playbooks to use UUIDs of the introspected node's disks. In future it might also enable agent to use UUID (or by_path value) to refer to a device instead of name, as it happens currently. Change-Id: Id00437d2295c39fb12f3c25a92b30b56a58eef13 --- doc/source/admin/how_it_works.rst | 4 +- ironic_python_agent/hardware.py | 7 +- .../tests/unit/test_hardware.py | 74 +++++++++---------- ...dd-block-device-uuid-c8b38264e1688110.yaml | 5 ++ 4 files changed, 49 insertions(+), 41 deletions(-) create mode 100644 releasenotes/notes/add-block-device-uuid-c8b38264e1688110.yaml diff --git a/doc/source/admin/how_it_works.rst b/doc/source/admin/how_it_works.rst index bb4b96213..726156e6d 100644 --- a/doc/source/admin/how_it_works.rst +++ b/doc/source/admin/how_it_works.rst @@ -184,8 +184,8 @@ fields: ``disks`` list of disk block devices with fields: ``name``, ``model``, ``size`` (in bytes), ``rotational`` (boolean), ``wwn``, ``serial``, - ``vendor``, ``wwn_with_extension``, ``wwn_vendor_extension``, ``hctl`` - and ``by_path`` (the full disk path, in the form + ``uuid``, ``vendor``, ``wwn_with_extension``, ``wwn_vendor_extension``, + ``hctl`` and ``by_path`` (the full disk path, in the form ``/dev/disk/by-path/``). ``interfaces`` diff --git a/ironic_python_agent/hardware.py b/ironic_python_agent/hardware.py index a7ea9acc6..e58918a6b 100644 --- a/ironic_python_agent/hardware.py +++ b/ironic_python_agent/hardware.py @@ -416,7 +416,7 @@ def list_all_block_devices(block_type='disk', "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'] + columns = ['KNAME', 'MODEL', 'SIZE', 'ROTA', 'TYPE', 'UUID'] report = utils.execute('lsblk', '-Pbia', '-o{}'.format(','.join(columns)), check_exit_code=[0])[0] lines = report.splitlines() @@ -534,6 +534,7 @@ def list_all_block_devices(block_type='disk', vendor=_get_device_info(device['KNAME'], 'block', 'vendor'), by_path=by_path_name, + uuid=device['UUID'], **extra)) return devices @@ -600,11 +601,13 @@ class BlockDevice(encoding.SerializableComparable): def __init__(self, name, model, size, rotational, wwn=None, serial=None, vendor=None, wwn_with_extension=None, - wwn_vendor_extension=None, hctl=None, by_path=None): + wwn_vendor_extension=None, hctl=None, by_path=None, + uuid=None): self.name = name self.model = model self.size = size self.rotational = rotational + self.uuid = uuid self.wwn = wwn self.serial = serial self.vendor = vendor diff --git a/ironic_python_agent/tests/unit/test_hardware.py b/ironic_python_agent/tests/unit/test_hardware.py index afa1b96fd..7952338e5 100644 --- a/ironic_python_agent/tests/unit/test_hardware.py +++ b/ironic_python_agent/tests/unit/test_hardware.py @@ -124,37 +124,37 @@ HDPARM_INFO_TEMPLATE = ( BLK_DEVICE_TEMPLATE = ( 'KNAME="sda" MODEL="TinyUSB Drive" SIZE="3116853504" ' - 'ROTA="0" TYPE="disk" SERIAL="123"\n' + 'ROTA="0" TYPE="disk" SERIAL="123" UUID="F531-BDC3"\n' 'KNAME="sdb" MODEL="Fastable SD131 7" SIZE="10737418240" ' - 'ROTA="0" TYPE="disk"\n' + 'ROTA="0" TYPE="disk" UUID="9a5e5cca-e03d-4cbd-9054-9e6ca9048222"\n' 'KNAME="sdc" MODEL="NWD-BLP4-1600 " SIZE="1765517033472" ' - ' ROTA="0" TYPE="disk"\n' + ' ROTA="0" TYPE="disk" UUID=""\n' 'KNAME="sdd" MODEL="NWD-BLP4-1600 " SIZE="1765517033472" ' - ' ROTA="0" TYPE="disk"\n' - 'KNAME="loop0" MODEL="" SIZE="109109248" ROTA="1" TYPE="loop"\n' - 'KNAME="zram0" MODEL="" SIZE="" ROTA="0" TYPE="disk"\n' - 'KNAME="ram0" MODEL="" SIZE="8388608" ROTA="0" TYPE="disk"\n' - 'KNAME="ram1" MODEL="" SIZE="8388608" ROTA="0" TYPE="disk"\n' - 'KNAME="ram2" MODEL="" SIZE="8388608" ROTA="0" TYPE="disk"\n' - 'KNAME="ram3" MODEL="" SIZE="8388608" ROTA="0" TYPE="disk"\n' - 'KNAME="fd1" MODEL="magic" SIZE="4096" ROTA="1" TYPE="disk"\n' - 'KNAME="sdf" MODEL="virtual floppy" SIZE="0" ROTA="1" TYPE="disk"' + ' 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=""' ) # 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"\n' + 'ROTA="0" TYPE="disk" UUID="F531-BDC3"\n' 'KNAME="sdb" MODEL="AlmostBigEnough Drive" SIZE="4294967295" ' - 'ROTA="0" TYPE="disk"' + 'ROTA="0" TYPE="disk" UUID=""' ) BLK_DEVICE_TEMPLATE_SMALL_DEVICES = [ hardware.BlockDevice(name='/dev/sda', model='TinyUSB Drive', size=3116853504, rotational=False, - vendor="FooTastic"), + vendor="FooTastic", uuid="F531-BDC3"), hardware.BlockDevice(name='/dev/sdb', model='AlmostBigEnough Drive', size=4294967295, rotational=False, - vendor="FooTastic"), + vendor="FooTastic", uuid=""), ] # NOTE(TheJulia): This list intentionally contains duplicates @@ -166,36 +166,36 @@ 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"\n' + 'ROTA="1" TYPE="disk" UUID=""\n' 'KNAME="sda1" MODEL="DRIVE 0" SIZE="107373133824" ' - 'ROTA="1" TYPE="part"\n' + 'ROTA="1" TYPE="part" UUID=""\n' 'KNAME="sdb" MODEL="DRIVE 1" SIZE="1765517033472" ' - 'ROTA="1" TYPE="disk"\n' + 'ROTA="1" TYPE="disk" UUID=""\n' 'KNAME="sdb" MODEL="DRIVE 1" SIZE="1765517033472" ' - 'ROTA="1" TYPE="disk"\n' + 'ROTA="1" TYPE="disk" UUID=""\n' 'KNAME="sdb1" MODEL="DRIVE 1" SIZE="107373133824" ' - 'ROTA="1" TYPE="part"\n' + 'ROTA="1" TYPE="part" UUID=""\n' 'KNAME="md0p1" MODEL="RAID" SIZE="107236818944" ' - 'ROTA="0" TYPE="md"\n' + 'ROTA="0" TYPE="md" UUID=""\n' 'KNAME="md0" MODEL="RAID" SIZE="1765517033470" ' - 'ROTA="0" TYPE="raid1"\n' + 'ROTA="0" TYPE="raid1" UUID=""\n' 'KNAME="md0" MODEL="RAID" SIZE="1765517033470" ' - 'ROTA="0" TYPE="raid1"\n' - 'KNAME="md1" MODEL="RAID" SIZE="" ROTA="0" TYPE="raid1"' + 'ROTA="0" TYPE="raid1" UUID=""\n' + 'KNAME="md1" MODEL="RAID" SIZE="" ROTA="0" TYPE="raid1" UUID=""' ) RAID_BLK_DEVICE_TEMPLATE_DEVICES = [ hardware.BlockDevice(name='/dev/sda', model='DRIVE 0', size=1765517033472, rotational=True, - vendor="FooTastic"), + vendor="FooTastic", uuid=""), hardware.BlockDevice(name='/dev/sdb', model='DRIVE 1', size=1765517033472, rotational=True, - vendor="FooTastic"), + vendor="FooTastic", uuid=""), hardware.BlockDevice(name='/dev/md0', model='RAID', size=1765517033470, rotational=False, - vendor="FooTastic"), + vendor="FooTastic", uuid=""), hardware.BlockDevice(name='/dev/md1', model='RAID', size=0, rotational=False, - vendor="FooTastic"), + vendor="FooTastic", uuid=""), ] SHRED_OUTPUT_0_ITERATIONS_ZERO_FALSE = () @@ -1330,7 +1330,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', + 'lsblk', '-Pbia', '-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID', check_exit_code=[0]) mock_cached_node.assert_called_once_with() @@ -1352,7 +1352,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', + 'lsblk', '-Pbia', '-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID', check_exit_code=[0]) mock_cached_node.assert_called_once_with() @@ -1371,7 +1371,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', + 'lsblk', '-Pbia', '-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID', check_exit_code=[0]) self.assertIn(str(4 * units.Gi), ex.details) mock_cached_node.assert_called_once_with() @@ -4553,7 +4553,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', + 'lsblk', '-Pbia', '-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID', check_exit_code=[0]) self.assertEqual(BLK_DEVICE_TEMPLATE_SMALL_DEVICES, result) mocked_udev.assert_called_once_with() @@ -4572,7 +4572,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', + 'lsblk', '-Pbia', '-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID', check_exit_code=[0]) self.assertEqual(RAID_BLK_DEVICE_TEMPLATE_DEVICES, result) mocked_udev.assert_called_once_with() @@ -4585,7 +4585,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', + 'lsblk', '-Pbia', '-oKNAME,MODEL,SIZE,ROTA,TYPE,UUID', check_exit_code=[0]) self.assertEqual([], result) mocked_udev.assert_called_once_with() @@ -4597,8 +4597,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 must be ' - r'returned by lsblk.$', + r'^Block device caused unknown error: KNAME, ROTA, SIZE, UUID ' + r'must be returned by lsblk.$', hardware.list_all_block_devices) mocked_udev.assert_called_once_with() diff --git a/releasenotes/notes/add-block-device-uuid-c8b38264e1688110.yaml b/releasenotes/notes/add-block-device-uuid-c8b38264e1688110.yaml new file mode 100644 index 000000000..ad87aef21 --- /dev/null +++ b/releasenotes/notes/add-block-device-uuid-c8b38264e1688110.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Adds UUID of the disks to the inventory of block devices that is + collected during inspection.

AltStyle によって変換されたページ (->オリジナル) /