From dcf059af9e728ff79303937ce1c0679a8f7ef5b8 Mon Sep 17 00:00:00 2001 From: frankming Date: Mon, 29 Apr 2024 17:04:25 +0800 Subject: [PATCH] Fix iscsi url generate method for ipxe Boot from volume feature has a ipxe template render step, and it need to generate iscsi urls for booting the volume. However, it not works. In the function, lun field should be hexadecimal instead of decimal, according to SAN URIs description at https://ipxe.org/sanuri. So we need to fix it. Closes-Bug: #2055355 Change-Id: I080ca42c9ba05f2a4e0752312b79a32bef825752 Signed-off-by: frankming --- ironic/common/pxe_utils.py | 2 +- ironic/tests/unit/common/test_pxe_utils.py | 24 +++++++++++++++++++ .../notes/bug-2011053-085a8b5a36bb9b59.yaml | 8 +++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/bug-2011053-085a8b5a36bb9b59.yaml diff --git a/ironic/common/pxe_utils.py b/ironic/common/pxe_utils.py index e989542f38..2bba1bb84a 100644 --- a/ironic/common/pxe_utils.py +++ b/ironic/common/pxe_utils.py @@ -1083,7 +1083,7 @@ def get_volume_pxe_options(task): else: host = portal port = '' - return ("iscsi:%(host)s::%(port)s:%(lun)s:%(iqn)s" % + return ("iscsi:%(host)s::%(port)s:%(lun)x:%(iqn)s" % {'host': host, 'port': port, 'lun': lun, 'iqn': iqn}) def __generate_iscsi_url(properties): diff --git a/ironic/tests/unit/common/test_pxe_utils.py b/ironic/tests/unit/common/test_pxe_utils.py index 6803d27164..14b587e5f2 100644 --- a/ironic/tests/unit/common/test_pxe_utils.py +++ b/ironic/tests/unit/common/test_pxe_utils.py @@ -2428,6 +2428,30 @@ class iPXEBuildConfigOptionsTestCase(db_base.DbTestCase): options = pxe_utils.get_volume_pxe_options(task) self.assertEqual([], options['iscsi_volumes']) + def test_get_volume_pxe_options_hexadecimal_lunid(self): + vol_id = uuidutils.generate_uuid() + object_utils.create_test_volume_target( + self.context, node_id=self.node.id, volume_type='iscsi', + boot_index=0, volume_id='1234', uuid=vol_id, + properties={'target_lun': 16, + 'target_portal': 'fake_host:3260', + 'target_iqns': 'fake_iqn'}) + self.node.driver_internal_info.update({'boot_from_volume': vol_id}) + driver_internal_info = self.node.driver_internal_info + driver_internal_info['boot_from_volume'] = vol_id + self.node.driver_internal_info = driver_internal_info + self.node.save() + + expected = {'boot_from_volume': True, + 'iscsi_boot_url': 'iscsi:fake_host::3260:10:fake_iqn', + 'iscsi_initiator_iqn': None, + 'iscsi_volumes': [] + } + with task_manager.acquire(self.context, self.node.uuid, + shared=True) as task: + options = pxe_utils.get_volume_pxe_options(task) + self.assertEqual(expected, options) + def test_build_pxe_config_options_ipxe_rescue(self): self._test_build_pxe_config_options_ipxe(mode='rescue') diff --git a/releasenotes/notes/bug-2011053-085a8b5a36bb9b59.yaml b/releasenotes/notes/bug-2011053-085a8b5a36bb9b59.yaml new file mode 100644 index 0000000000..272af20d84 --- /dev/null +++ b/releasenotes/notes/bug-2011053-085a8b5a36bb9b59.yaml @@ -0,0 +1,8 @@ +--- +fixes: + - | + [`bug 2011053 `_] + Fix issue with boot from volume feature. Convert lun field from + decimal to hexadecimal when generating iscsi url so that ipxe firmware + could be able to identify the iSCSI SAN URI correctly, according to + SAN URIs description at https://ipxe.org/sanuri.