From 65b42a38966b1720cd7dd5f9828ab2a1f26b570a Mon Sep 17 00:00:00 2001 From: Derek Higgins Date: Wed, 14 Dec 2016 23:38:46 +0000 Subject: [PATCH] Wrap iscsi portal in []'s if IPv6 If deploying over a IPv6 network the portal IP address should be wrapped in square brackets. Change-Id: I350075f673a4aa88649f5b37f53175753ece0273 Fixes-Bug: #1325942 --- ironic/drivers/modules/deploy_utils.py | 15 ++++++++--- .../unit/drivers/modules/test_deploy_utils.py | 26 +++++++++++++++++++ .../ipv6-provision-67bd9c1dbcc48c97.yaml | 4 +++ 3 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/ipv6-provision-67bd9c1dbcc48c97.yaml diff --git a/ironic/drivers/modules/deploy_utils.py b/ironic/drivers/modules/deploy_utils.py index 8342e6ffbb..c8f0278559 100644 --- a/ironic/drivers/modules/deploy_utils.py +++ b/ironic/drivers/modules/deploy_utils.py @@ -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, diff --git a/ironic/tests/unit/drivers/modules/test_deploy_utils.py b/ironic/tests/unit/drivers/modules/test_deploy_utils.py index f3c5a4abdb..bf49f1519c 100644 --- a/ironic/tests/unit/drivers/modules/test_deploy_utils.py +++ b/ironic/tests/unit/drivers/modules/test_deploy_utils.py @@ -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. diff --git a/releasenotes/notes/ipv6-provision-67bd9c1dbcc48c97.yaml b/releasenotes/notes/ipv6-provision-67bd9c1dbcc48c97.yaml new file mode 100644 index 0000000000..065cb33c18 --- /dev/null +++ b/releasenotes/notes/ipv6-provision-67bd9c1dbcc48c97.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - Can now deploy to a IPv6 iscsi portal if + instructed to do so.