Merge "Wrap iscsi portal in []'s if IPv6"

This commit is contained in:
Jenkins 2016-12-30 01:15:48 +00:00 committed by Gerrit Code Review
commit 4ba3429343
3 changed files with 41 additions and 4 deletions

View File

@ -26,6 +26,7 @@ from oslo_concurrency import processutils
from oslo_log import log as logging
from oslo_serialization import jsonutils
from oslo_utils import excutils
from oslo_utils import netutils
from oslo_utils import strutils
import six
@ -102,6 +103,12 @@ def _get_ironic_session():
return _IRONIC_SESSION
def _wrap_ipv6(ip):
if netutils.is_valid_ipv6(ip):
return "[%s]" % ip
return ip
def get_ironic_api_url():
"""Resolve Ironic API endpoint
@ -130,7 +137,7 @@ def discovery(portal_address, portal_port):
utils.execute('iscsiadm',
'-m', 'discovery',
'-t', 'st',
'-p', '%s:%s' % (portal_address, portal_port),
'-p', '%s:%s' % (_wrap_ipv6(portal_address), portal_port),
run_as_root=True,
check_exit_code=[0],
attempts=5,
@ -141,7 +148,7 @@ def login_iscsi(portal_address, portal_port, target_iqn):
"""Login to an iSCSI target."""
utils.execute('iscsiadm',
'-m', 'node',
'-p', '%s:%s' % (portal_address, portal_port),
'-p', '%s:%s' % (_wrap_ipv6(portal_address), portal_port),
'-T', target_iqn,
'--login',
run_as_root=True,
@ -225,7 +232,7 @@ def logout_iscsi(portal_address, portal_port, target_iqn):
"""Logout from an iSCSI target."""
utils.execute('iscsiadm',
'-m', 'node',
'-p', '%s:%s' % (portal_address, portal_port),
'-p', '%s:%s' % (_wrap_ipv6(portal_address), portal_port),
'-T', target_iqn,
'--logout',
run_as_root=True,
@ -240,7 +247,7 @@ def delete_iscsi(portal_address, portal_port, target_iqn):
# no longer a target to delete (exit code 21).
utils.execute('iscsiadm',
'-m', 'node',
'-p', '%s:%s' % (portal_address, portal_port),
'-p', '%s:%s' % (_wrap_ipv6(portal_address), portal_port),
'-T', target_iqn,
'-o', 'delete',
run_as_root=True,

View File

@ -647,6 +647,32 @@ class PhysicalWorkTestCase(tests_base.TestCase):
mock_check_dev.assert_called_once_with(address, port, iqn)
@mock.patch.object(common_utils, 'execute', autospec=True)
@mock.patch.object(utils, 'verify_iscsi_connection', autospec=True)
@mock.patch.object(utils, 'force_iscsi_lun_update', autospec=True)
@mock.patch.object(utils, 'check_file_system_for_iscsi_device',
autospec=True)
def test_ipv6_address_wrapped(self,
mock_check_dev,
mock_update,
mock_verify,
mock_exec):
address = '2001:DB8::1111'
port = 3306
iqn = 'iqn.xyz'
mock_exec.return_value = ['iqn.xyz', '']
utils.login_iscsi(address, port, iqn)
mock_exec.assert_called_once_with(
'iscsiadm',
'-m', 'node',
'-p', '[%s]:%s' % (address, port),
'-T', iqn,
'--login',
run_as_root=True,
check_exit_code=[0],
attempts=5,
delay_on_retry=True)
@mock.patch.object(disk_utils, 'is_block_device', lambda d: True)
def test_always_logout_and_delete_iscsi(self):
"""Check if logout_iscsi() and delete_iscsi() are called.

View File

@ -0,0 +1,4 @@
---
fixes:
- Can now deploy to a IPv6 iscsi portal if
instructed to do so.