Browse Source

Merge "Fix LVM IPv6 target portals" into stable/stein

changes/73/680473/1
Zuul 2 weeks ago
parent
commit
44cc36f418

+ 17
- 0
cinder/tests/unit/targets/test_base_iscsi_driver.py View File

@@ -158,6 +158,23 @@ class TestBaseISCSITargetDriver(tf.TargetDriverFixture):
158 158
                                                ['portal2'])
159 159
         self.assertEqual('portal:3260;portal2:3260,1 target 2', location)
160 160
 
161
+    def test_iscsi_location_IPv6(self):
162
+        ip = 'fd00:fd00:fd00:3000::12'
163
+        ip2 = 'fd00:fd00:fd00:3000::13'
164
+
165
+        location = self.target._iscsi_location(ip, 1, 'target', 2)
166
+        self.assertEqual('[%s]:3260,1 target 2' % ip, location)
167
+
168
+        location = self.target._iscsi_location(ip, 1, 'target', 2, [ip2])
169
+        self.assertEqual('[%s]:3260;[%s]:3260,1 target 2' % (ip, ip2),
170
+                         location)
171
+
172
+        # Mix of IPv6 (already with square brackets) and IPv4
173
+        ip = '[' + ip + ']'
174
+        location = self.target._iscsi_location(ip, 1, 'target', 2,
175
+                                               ['192.168.1.1'])
176
+        self.assertEqual(ip + ':3260;192.168.1.1:3260,1 target 2', location)
177
+
161 178
     def test_get_target_chap_auth(self):
162 179
         ctxt = context.get_admin_context()
163 180
         self.assertEqual(('otzL', '234Z'),

+ 13
- 0
cinder/tests/unit/targets/test_scst_driver.py View File

@@ -231,3 +231,16 @@ class TestSCSTAdmDriver(tf.TargetDriverFixture):
231 231
                 'iqn.2010-10.org.openstack:testvol',
232 232
                 'ed2c2222-5fc0-11e4-aa15-123b93f75cba',
233 233
                 0, 1, self.fake_volumes_dir, None)
234
+
235
+    def test_iscsi_location(self):
236
+        location = self.target._iscsi_location('portal', 1, 'target', 2)
237
+        self.assertEqual('portal:3260,1 target 2', location)
238
+
239
+    def test_iscsi_location_IPv6(self):
240
+        ip = 'fd00:fd00:fd00:3000::12'
241
+        location = self.target._iscsi_location(ip, 1, 'target', 2)
242
+        self.assertEqual('[%s]:3260,1 target 2' % ip, location)
243
+
244
+        ip = '[' + ip + ']'
245
+        location = self.target._iscsi_location(ip, 1, 'target', 2)
246
+        self.assertEqual(ip + ':3260,1 target 2', location)

+ 2
- 1
cinder/volume/targets/iscsi.py View File

@@ -302,7 +302,8 @@ class ISCSITarget(driver.Target):
302 302
     def _iscsi_location(self, ip, target, iqn, lun=None, ip_secondary=None):
303 303
         ip_secondary = ip_secondary or []
304 304
         port = self.configuration.target_port
305
-        portals = map(lambda x: "%s:%s" % (x, port), [ip] + ip_secondary)
305
+        portals = map(lambda x: "%s:%s" % (vutils.sanitize_host(x), port),
306
+                      [ip] + ip_secondary)
306 307
         return ("%(portals)s,%(target)s %(iqn)s %(lun)s"
307 308
                 % ({'portals': ";".join(portals),
308 309
                     'target': target, 'iqn': iqn, 'lun': lun}))

+ 2
- 1
cinder/volume/targets/scst.py View File

@@ -231,7 +231,8 @@ class SCSTAdm(iscsi.ISCSITarget):
231 231
         return tid
232 232
 
233 233
     def _iscsi_location(self, ip, target, iqn, lun=None):
234
-        return "%s:%s,%s %s %s" % (ip, self.configuration.target_port,
234
+        return "%s:%s,%s %s %s" % (vutils.sanitize_host(ip),
235
+                                   self.configuration.target_port,
235 236
                                    target, iqn, lun)
236 237
 
237 238
     def _get_iscsi_name(self, volume):

+ 8
- 0
cinder/volume/utils.py View File

@@ -38,6 +38,7 @@ from oslo_concurrency import processutils
38 38
 from oslo_config import cfg
39 39
 from oslo_log import log as logging
40 40
 from oslo_utils import excutils
41
+from oslo_utils import netutils
41 42
 from oslo_utils import strutils
42 43
 from oslo_utils import timeutils
43 44
 from oslo_utils import units
@@ -1205,3 +1206,10 @@ def check_encryption_provider(db, volume, context):
1205 1206
         raise exception.VolumeDriverException(message=msg)
1206 1207
 
1207 1208
     return encryption
1209
+
1210
+
1211
+def sanitize_host(host):
1212
+    """Ensure IPv6 addresses are enclosed in [] for iSCSI portals."""
1213
+    if netutils.is_valid_ipv6(host):
1214
+        return '[%s]' % host
1215
+    return host

+ 5
- 0
releasenotes/notes/lvm-ipv6-fix-e8d418726c92bbd5.yaml View File

@@ -0,0 +1,5 @@
1
+---
2
+fixes:
3
+  - |
4
+    LVM iSCSI driver fix for IPv6 addresses for the different targets, IET,
5
+    LIO, TGT, CXT, and SCST.

Loading…
Cancel
Save