From 37eccedd84d6c047f1af3011342f816228fe9070 Mon Sep 17 00:00:00 2001 From: Ilya Etingof Date: Mon, 4 Sep 2017 14:04:54 +0200 Subject: [PATCH] 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 --- ironic_lib/tests/test_utils.py | 12 +++++++++--- ironic_lib/utils.py | 4 +++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ironic_lib/tests/test_utils.py b/ironic_lib/tests/test_utils.py index 7e407f35..16af919b 100644 --- a/ironic_lib/tests/test_utils.py +++ b/ironic_lib/tests/test_utils.py @@ -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': ' /dev/sda /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'}) diff --git a/ironic_lib/utils.py b/ironic_lib/utils.py index 55dc88ce..05349ce7 100644 --- a/ironic_lib/utils.py +++ b/ironic_lib/utils.py @@ -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.