]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Parse out '@' in volume['host'] to do discovery
authorjohn-griffith <john.griffith@solidfire.com>
Wed, 27 Nov 2013 23:38:22 +0000 (16:38 -0700)
committerjohn-griffith <john.griffith@solidfire.com>
Wed, 27 Nov 2013 23:38:22 +0000 (16:38 -0700)
The backup method of getting iscsi info is to use
iscsiadm discovery, however currently that method
just uses volume['host'] which in the case of
multi-backend will use "host@backend-name".

This will cause the discovery to fail of course, so
this change just parses out the '@' symbol if it's present
and avoids the problem in the first place.

This also beefs up the error logging and exception catching
a bit.

Parsing out the '@' symbol all the time should be safe as
the accepted valid chars for hostnames are digits, a-z and
hyphens.

Change-Id: Ic45a38bf4c56a4aec6847ab0d29e3b41d35bd3d2
Closes-Bug: #1250673

cinder/volume/driver.py

index bd59f2138d55de82b28623f52af22157e30a99cc..d94b856cf5b1d53d37c2e94a404a2abaa0c2a967 100644 (file)
@@ -499,9 +499,20 @@ class ISCSIDriver(VolumeDriver):
 
         volume_name = volume['name']
 
-        (out, _err) = self._execute('iscsiadm', '-m', 'discovery',
-                                    '-t', 'sendtargets', '-p', volume['host'],
-                                    run_as_root=True)
+        try:
+            # NOTE(griff) We're doing the split straight away which should be
+            # safe since using '@' in hostname is considered invalid
+
+            (out, _err) = self._execute('iscsiadm', '-m', 'discovery',
+                                        '-t', 'sendtargets', '-p',
+                                        volume['host'].split('@')[0],
+                                        run_as_root=True)
+        except processutils.ProcessExecutionError as ex:
+            LOG.error(_("ISCSI discovery attempt failed for:%s") %
+                      volume['host'].split('@')[0])
+            LOG.debug(_("Error from iscsiadm -m discovery: %s") % ex.stderr)
+            return None
+
         for target in out.splitlines():
             if (self.configuration.iscsi_ip_address in target
                     and volume_name in target):