diff options
author | Zuul <zuul@review.opendev.org> | 2020-11-11 21:42:51 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2020-11-11 21:42:51 +0000 |
commit | c33b3fff66ffd648323504f923cafd7c7b12aae5 (patch) | |
tree | 674dbc7a19a888ac5c221b8dfde3558f5ba39618 | |
parent | 1f590ea3824aa112ab3a6ede78bf1e18ec368d66 (diff) | |
parent | c7858d3cc8709d95d63ff45e427f5215320bc67a (diff) | |
download | ironic-python-agent-c33b3fff66ffd648323504f923cafd7c7b12aae5.tar.gz |
Merge "Add UUID to BlockDevice object"
-rw-r--r-- | doc/source/admin/how_it_works.rst | 4 | ||||
-rw-r--r-- | ironic_python_agent/hardware.py | 7 | ||||
-rw-r--r-- | ironic_python_agent/tests/unit/test_hardware.py | 74 | ||||
-rw-r--r-- | releasenotes/notes/add-block-device-uuid-c8b38264e1688110.yaml | 5 |
4 files changed, 49 insertions, 41 deletions
diff --git a/doc/source/admin/how_it_works.rst b/doc/source/admin/how_it_works.rst index bb4b9621..726156e6 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/<rest-of-path>``). ``interfaces`` diff --git a/ironic_python_agent/hardware.py b/ironic_python_agent/hardware.py index dc7c1662..e142fdb9 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 0fce12ef..060e71b3 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() @@ -4563,7 +4563,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() @@ -4582,7 +4582,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() @@ -4595,7 +4595,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() @@ -4607,8 +4607,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 00000000..ad87aef2 --- /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. |