Use oslo.utils implementation to parse server address

... so that the address can be properly parsed even when IPv6 address
is used.

Change-Id: Ic3e043e9272518f73252ea9a8f0524ed092204b9
This commit is contained in:
Takashi Kajinami 2024-10-06 00:15:10 +09:00
parent 462f86889b
commit 1f5798bced
3 changed files with 11 additions and 14 deletions

View File

@ -26,6 +26,7 @@ from oslo_concurrency import processutils
from oslo_log import log as logging
from oslo_utils import excutils
from oslo_utils import fileutils
from oslo_utils import netutils
from ironic.common import dhcp_factory
from ironic.common import exception
@ -1089,10 +1090,8 @@ def get_volume_pxe_options(task):
return __return_item_or_first_if_list(properties.get(key + 's', ''))
def __format_portal(portal, iqn, lun):
if ':' in portal:
host, port = portal.split(':')
else:
host = portal
host, port = netutils.parse_host_port(portal)
if port is None:
port = ''
return ("iscsi:%(host)s::%(port)s:%(lun)x:%(iqn)s" %
{'host': host, 'port': port, 'lun': lun, 'iqn': iqn})

View File

@ -25,6 +25,7 @@ from ironic_lib import metrics_utils
from ironic_lib import utils as ironic_utils
from oslo_log import log as logging
from oslo_utils import importutils
from oslo_utils import netutils
from ironic.common import boot_devices
from ironic.common import exception
@ -843,12 +844,9 @@ class IRMCVolumeBootMixIn(object):
def _set_iscsi_target(self, task, viom_conf, target):
"""Set information for iSCSI boot to VIOM configuration."""
connectors = self._get_volume_connectors_by_type(task)
target_portal = target.properties['target_portal']
if ':' in target_portal:
target_host, target_port = target_portal.split(':')
else:
target_host = target_portal
target_port = None
target_host, target_port = netutils.parse_host_port(
target.properties['target_portal'])
if target.properties.get('auth_method') == 'CHAP':
chap_user = target.properties.get('auth_username')
chap_secret = target.properties.get('auth_password')

View File

@ -1719,7 +1719,7 @@ class IRMCVirtualMediaBootWithVolumeTestCase(test_common.BaseIRMCTest):
initiator_netmask=24,
target_iqn='iqn.target',
target_ip='192.168.22.22',
target_port='3260',
target_port=3260,
target_lun=1,
boot_prio=1,
chap_user=None,
@ -1753,7 +1753,7 @@ class IRMCVirtualMediaBootWithVolumeTestCase(test_common.BaseIRMCTest):
initiator_netmask=24,
target_iqn='iqn.target',
target_ip='192.168.22.22',
target_port='3260',
target_port=3260,
target_lun=1,
boot_prio=1,
chap_user=None,
@ -1779,7 +1779,7 @@ class IRMCVirtualMediaBootWithVolumeTestCase(test_common.BaseIRMCTest):
initiator_netmask=24,
target_iqn='iqn.target',
target_ip='192.168.22.22',
target_port='3260',
target_port=3260,
target_lun=1,
boot_prio=1,
chap_user=None,
@ -1836,7 +1836,7 @@ class IRMCVirtualMediaBootWithVolumeTestCase(test_common.BaseIRMCTest):
initiator_netmask=24,
target_iqn='iqn.target',
target_ip='192.168.22.22',
target_port='3260',
target_port=3260,
target_lun=1,
boot_prio=1,
chap_user='chapuser',