From: Walter A. Boring IV <walter.boring@hp.com>
Date: Wed, 13 Mar 2013 21:35:16 +0000 (-0700)
Subject: Fix 3PAR driver hiding existing host error
X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=f040e4d6e7d2c25ce626fa0ddd67ed0122bd22ae;p=openstack-build%2Fcinder-build.git

Fix 3PAR driver hiding existing host error

This fixes a problem with the 3par drivers where creating
a 3par host was failing but there was no message.  The driver
would fail to find the host after the creation failed and the
log entry would show that the host didn't exist.   The real
error was failing to create the host.

bug #1154700

Change-Id: I2267d958f10cc73c6c5f34d224ea3452a4402f18
---

diff --git a/cinder/exception.py b/cinder/exception.py
index c5dd7e61a..81ddac279 100644
--- a/cinder/exception.py
+++ b/cinder/exception.py
@@ -465,6 +465,10 @@ class DuplicateSfVolumeNames(Duplicate):
     message = _("Detected more than one volume with name %(vol_name)s")
 
 
+class Duplicate3PARHost(CinderException):
+    message = _("3PAR Host already exists: %(err)s.  %(info)s")
+
+
 class VolumeTypeCreateFailed(CinderException):
     message = _("Cannot create volume_type with "
                 "name %(name)s and specs %(extra_specs)s")
diff --git a/cinder/volume/drivers/san/hp/hp_3par_fc.py b/cinder/volume/drivers/san/hp/hp_3par_fc.py
index d48612fb7..f469ef03f 100644
--- a/cinder/volume/drivers/san/hp/hp_3par_fc.py
+++ b/cinder/volume/drivers/san/hp/hp_3par_fc.py
@@ -204,6 +204,11 @@ must be the same" % (cpg['domain'], self.configuration.hp3par_domain)
         out = self.common._cli_run('createhost -persona %s -domain %s %s %s'
                                    % (persona_id, domain,
                                       hostname, " ".join(wwn)), None)
+        if out and len(out) > 1:
+            if "already used by host" in out[1]:
+                err = out[1].strip()
+                info = _("The hostname must be called '%s'") % hostname
+                raise exception.Duplicate3PARHost(err=err, info=info)
 
     def _modify_3par_fibrechan_host(self, hostname, wwn):
         # when using -add, you can not send the persona or domain options
diff --git a/cinder/volume/drivers/san/hp/hp_3par_iscsi.py b/cinder/volume/drivers/san/hp/hp_3par_iscsi.py
index dea8bf1cc..b740a2f57 100644
--- a/cinder/volume/drivers/san/hp/hp_3par_iscsi.py
+++ b/cinder/volume/drivers/san/hp/hp_3par_iscsi.py
@@ -229,7 +229,12 @@ must be the same" % (cpg['domain'], self.configuration.hp3par_domain)
     def _create_3par_iscsi_host(self, hostname, iscsi_iqn, domain, persona_id):
         cmd = 'createhost -iscsi -persona %s -domain %s %s %s' % \
               (persona_id, domain, hostname, iscsi_iqn)
-        self.common._cli_run(cmd, None)
+        out = self.common._cli_run(cmd, None)
+        if out and len(out) > 1:
+            if "already used by host" in out[1]:
+                err = out[1].strip()
+                info = _("The hostname must be called '%s'") % hostname
+                raise exception.Duplicate3PARHost(err=err, info=info)
 
     def _modify_3par_iscsi_host(self, hostname, iscsi_iqn):
         # when using -add, you can not send the persona or domain options