From: zhangchao010 <zhangchao010@huawei.com>
Date: Mon, 14 Oct 2013 05:08:02 +0000 (+0800)
Subject: Fix Huawei HVS driver AttributeError
X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=7aa0c1d9a4a02add6b00aeb764e9ba86a3c460ff;p=openstack-build%2Fcinder-build.git

Fix Huawei HVS driver AttributeError

This patch checks the iSCSI port info and raises an exception
if it can not get the port info from the configuration.

Closes-bug: #1237185
Change-Id: I341ccbe77abd25421e5ee0b2d07ace3759fbccef
---

diff --git a/cinder/volume/drivers/huawei/rest_common.py b/cinder/volume/drivers/huawei/rest_common.py
index edb468986..daeb054c0 100644
--- a/cinder/volume/drivers/huawei/rest_common.py
+++ b/cinder/volume/drivers/huawei/rest_common.py
@@ -1054,6 +1054,13 @@ class HVSCommon():
                 iscsi_port_info = item['LOCATION']
                 break
 
+        if not iscsi_port_info:
+            msg = (_('_get_iscsi_port_info: Failed to get iscsi port info '
+                     'through config IP %(ip)s, please check config file.')
+                   % {'ip': ip})
+            LOG.error(msg)
+            raise exception.InvalidInput(reason=msg)
+
         return iscsi_port_info
 
     def _get_iscsi_conf(self):
@@ -1078,28 +1085,23 @@ class HVSCommon():
         LOG.debug(_('_get_tgt_iqn: iSCSI IP is %s.') % iscsiip)
         ip_info = self._get_iscsi_port_info(iscsiip)
         iqn_prefix = self._get_iscsi_tgt_port()
-        LOG.debug(_('request ip info is %s.') % ip_info)
+
         split_list = ip_info.split(".")
         newstr = split_list[1] + split_list[2]
-        LOG.debug(_('new str info is %s.') % newstr)
-
-        if ip_info:
-            if newstr[0] == 'A':
-                ctr = "0"
-            elif newstr[0] == 'B':
-                ctr = "1"
-            interface = '0' + newstr[1]
-            port = '0' + newstr[3]
-            iqn_suffix = ctr + '02' + interface + port
-            for i in range(0, len(iqn_suffix)):
-                if iqn_suffix[i] != '0':
-                    iqn_suffix = iqn_suffix[i:]
-                    break
-            iqn = iqn_prefix + ':' + iqn_suffix + ':' + iscsiip
-            LOG.debug(_('_get_tgt_iqn: iSCSI target iqn is %s') % iqn)
-            return iqn
-        else:
-            return None
+        if newstr[0] == 'A':
+            ctr = "0"
+        elif newstr[0] == 'B':
+            ctr = "1"
+        interface = '0' + newstr[1]
+        port = '0' + newstr[3]
+        iqn_suffix = ctr + '02' + interface + port
+        for i in range(0, len(iqn_suffix)):
+            if iqn_suffix[i] != '0':
+                iqn_suffix = iqn_suffix[i:]
+                break
+        iqn = iqn_prefix + ':' + iqn_suffix + ':' + iscsiip
+        LOG.debug(_('_get_tgt_iqn: iSCSI target iqn is %s') % iqn)
+        return iqn
 
     def _get_fc_target_wwpns(self, wwn):
         url = (self.url +