]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Support Huawei driver upgrade from grizzly to havana
authorzhangchao010 <zhangchao010@huawei.com>
Wed, 9 Oct 2013 07:37:49 +0000 (15:37 +0800)
committerzhangchao010 <zhangchao010@huawei.com>
Wed, 9 Oct 2013 07:37:49 +0000 (15:37 +0800)
To make the driver upgrade from grizzly to higher versions, the patch
checks the old host name firstly when creating and deleting host in
Huawei storage system.
If the old host name exists:
*get and use it directly when adding host.
*delete it directly when deleting host.

Closes-bug 1237189

Change-Id: I82a9dbc1ef0bb0b91771afea4aadec5afe65eecf

cinder/volume/drivers/huawei/huawei_t.py
cinder/volume/drivers/huawei/ssh_common.py

index fd968cc21a5bdfb7277d029fe1fd4b2dc2a8e505..7a6f791450413fc55fa13a6b7a5a3a38e3f38292 100644 (file)
@@ -106,7 +106,8 @@ class HuaweiTISCSIDriver(driver.ISCSIDriver):
             self._get_iscsi_params(connector['initiator'])
 
         # First, add a host if not added before.
-        host_id = self.common.add_host(connector['host'])
+        host_id = self.common.add_host(connector['host'],
+                                       connector['initiator'])
 
         # Then, add the iSCSI port to the host.
         self._add_iscsi_port_to_host(host_id, connector)
@@ -324,7 +325,8 @@ class HuaweiTISCSIDriver(driver.ISCSIDriver):
 
         self.common._update_login_info()
         host_id = self.common.remove_map(volume['provider_location'],
-                                         connector['host'])
+                                         connector['host'],
+                                         connector['initiator'])
         if not self.common._get_host_map_info(host_id):
             self._remove_iscsi_port(host_id, connector)
 
index b6e85d0023387bd03bf435158b6a28f88ba88cd5..f83575053f019fdbf203f9c3a1c76e25b82e9cf7 100644 (file)
@@ -892,7 +892,7 @@ class TseriesCommon():
 
         return hostlun_id
 
-    def add_host(self, host_name):
+    def add_host(self, host_name, initiator=None):
         """Create a host and add it to hostgroup."""
         # Create an OpenStack hostgroup if not created before.
         hostgroup_name = HOST_GROUP_NAME
@@ -902,6 +902,14 @@ class TseriesCommon():
             self.hostgroup_id = self._get_hostgroup_id(hostgroup_name)
 
         # Create a host and add it to the hostgroup.
+        # Check the old host name to support the upgrade from grizzly to
+        # higher versions.
+        if initiator:
+            old_host_name = HOST_NAME_PREFIX + str(hash(initiator))
+            old_host_id = self._get_host_id(old_host_name, self.hostgroup_id)
+            if old_host_id is not None:
+                return old_host_id
+
         host_name = HOST_NAME_PREFIX + host_name
         host_id = self._get_host_id(host_name, self.hostgroup_id)
         if host_id is None:
@@ -1003,13 +1011,20 @@ class TseriesCommon():
                                      'LUN %s' % lun_id,
                                      cli_cmd, out)
 
-    def remove_map(self, volume_id, host_name):
+    def remove_map(self, volume_id, host_name, initiator=None):
         """Remove host map."""
-        host_name = HOST_NAME_PREFIX + host_name
-        host_id = self._get_host_id(host_name, self.hostgroup_id)
+        # Check the old host name to support the upgrade from grizzly to
+        # higher versions.
+        host_id = None
+        if initiator:
+            old_host_name = HOST_NAME_PREFIX + str(hash(initiator))
+            host_id = self._get_host_id(old_host_name, self.hostgroup_id)
         if host_id is None:
-            LOG.error(_('remove_map: Host %s does not exist.') % host_name)
-            raise exception.HostNotFound(host=host_name)
+            host_name = HOST_NAME_PREFIX + host_name
+            host_id = self._get_host_id(host_name, self.hostgroup_id)
+            if host_id is None:
+                LOG.error(_('remove_map: Host %s does not exist.') % host_name)
+                raise exception.HostNotFound(host=host_name)
 
         if not self._check_volume_created(volume_id):
             LOG.error(_('remove_map: Volume %s does not exist.') % volume_id)