Added `by_path` root device hint

With the introduction of the `by_path` introspection
attribute at the IPA [1], it is now possible to leverage
the stable block device names for root device hinting.

This patch adds the `by_path` attribute to the collection
of valid root device hints.

1. https://review.openstack.org/#/c/498489/

Change-Id: I6f1c6b5ec5face7180aeb2d1aeebe50a6eb33f24
This commit is contained in:
Ilya Etingof 2017-09-04 14:04:54 +02:00
parent b3e1b9be94
commit 37eccedd84
2 changed files with 12 additions and 4 deletions

View File

@ -198,7 +198,7 @@ class ParseRootDeviceTestCase(base.IronicLibTestCase):
'serial': 'foo-serial', 'vendor': 'foo VENDOR with space',
'name': '/dev/sda', 'wwn_with_extension': '123456111',
'wwn_vendor_extension': '111', 'rotational': True,
'hctl': '1:0:0:0'}
'hctl': '1:0:0:0', 'by_path': '/dev/disk/by-path/1:0:0:0'}
result = utils.parse_root_device_hints(root_device)
expected = {
'wwn': 's== 123456', 'model': 's== foo%20model',
@ -206,7 +206,8 @@ class ParseRootDeviceTestCase(base.IronicLibTestCase):
'vendor': 's== foo%20vendor%20with%20space',
'name': 's== /dev/sda', 'wwn_with_extension': 's== 123456111',
'wwn_vendor_extension': 's== 111', 'rotational': True,
'hctl': 's== 1%3A0%3A0%3A0'}
'hctl': 's== 1%3A0%3A0%3A0',
'by_path': 's== /dev/disk/by-path/1%3A0%3A0%3A0'}
self.assertEqual(expected, result)
def test_parse_root_device_hints_with_operators(self):
@ -216,13 +217,14 @@ class ParseRootDeviceTestCase(base.IronicLibTestCase):
'name': '<or> /dev/sda <or> /dev/sdb',
'wwn_with_extension': 's!= 123456111',
'wwn_vendor_extension': 's== 111', 'rotational': True,
'hctl': 's== 1:0:0:0'}
'hctl': 's== 1:0:0:0', 'by_path': 's== /dev/disk/by-path/1:0:0:0'}
# Validate strings being normalized
expected = copy.deepcopy(root_device)
expected['model'] = 's== foo%20model'
expected['vendor'] = 's== foo%20vendor%20with%20space'
expected['hctl'] = 's== 1%3A0%3A0%3A0'
expected['by_path'] = 's== /dev/disk/by-path/1%3A0%3A0%3A0'
result = utils.parse_root_device_hints(root_device)
# The hints already contain the operators, make sure we keep it
@ -307,6 +309,10 @@ class ParseRootDeviceTestCase(base.IronicLibTestCase):
self.assertRaises(ValueError, utils.parse_root_device_hints,
{'hctl': 123})
def test_parse_root_device_hints_invalid_by_path(self):
self.assertRaises(ValueError, utils.parse_root_device_hints,
{'by_path': 123})
def test_parse_root_device_hints_non_existent_hint(self):
self.assertRaises(ValueError, utils.parse_root_device_hints,
{'non-existent': 'foo'})

View File

@ -52,7 +52,7 @@ LOG = logging.getLogger(__name__)
VALID_ROOT_DEVICE_HINTS = {
'size': int, 'model': str, 'wwn': str, 'serial': str, 'vendor': str,
'wwn_with_extension': str, 'wwn_vendor_extension': str, 'name': str,
'rotational': bool, 'hctl': str,
'rotational': bool, 'hctl': str, 'by_path': str,
}
@ -348,6 +348,8 @@ def match_root_device_hints(devices, root_device_hints):
(not rotational).
:hctl: (String): The SCSI address: Host, channel, target and lun.
For example: '1:0:0:0'.
:by_path: (String): The alternative device name,
e.g. /dev/disk/by-path/pci-0000:00
:param root_device_hints: A dictionary with the root device hints.
:raises: ValueError, if some information is invalid.