]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Windows iSCSI: remove ensure_export
authorLucian Petrut <lpetrut@cloudbasesolutions.com>
Tue, 5 May 2015 08:12:50 +0000 (11:12 +0300)
committerLucian Petrut <lpetrut@cloudbasesolutions.com>
Tue, 5 May 2015 12:33:47 +0000 (15:33 +0300)
The ensure_export method is called by the manager when the service
is initialized, ensuring that in-use volumes are properly exported.

iSCSI targets exported by WinTarget persist after host reboot.
For this reason, the ensure_export method can simply pass, thus
simplifying the iSCSI target creation logic.

The patch set depending on this introduces CHAP credentials support.
If the iSCSI target is accidentaly deleted, the CHAP credentials
will change, so the volume won't be accessible anyway if the target
is recreated using ensure_export.

Change-Id: I29367fc0ef0e38bb06c4a0ff5a485274cc29660e

cinder/tests/unit/windows/test_windows.py
cinder/volume/drivers/windows/windows.py
cinder/volume/drivers/windows/windows_utils.py

index 0b8eb15b573c3e486c76e0092dda42741b7fc9b8..259b7ad65f97d8d8dd4171754a41a08257992f95 100644 (file)
@@ -165,8 +165,7 @@ class TestWindowsDriver(test.TestCase):
 
         self.mox.StubOutWithMock(windows_utils.WindowsUtils,
                                  'create_iscsi_target')
-        windows_utils.WindowsUtils.create_iscsi_target(initiator_name,
-                                                       mox.IgnoreArg())
+        windows_utils.WindowsUtils.create_iscsi_target(initiator_name)
         self.mox.StubOutWithMock(windows_utils.WindowsUtils,
                                  'add_disk_to_target')
         windows_utils.WindowsUtils.add_disk_to_target(volume['name'],
@@ -216,25 +215,6 @@ class TestWindowsDriver(test.TestCase):
 
         drv.terminate_connection(volume, connector)
 
-    def test_ensure_export(self):
-        drv = self._driver
-
-        volume = db_fakes.get_fake_volume_info()
-
-        initiator_name = "%s%s" % (CONF.iscsi_target_prefix, volume['name'])
-
-        self.mox.StubOutWithMock(windows_utils.WindowsUtils,
-                                 'create_iscsi_target')
-        windows_utils.WindowsUtils.create_iscsi_target(initiator_name, True)
-        self.mox.StubOutWithMock(windows_utils.WindowsUtils,
-                                 'add_disk_to_target')
-        windows_utils.WindowsUtils.add_disk_to_target(volume['name'],
-                                                      initiator_name)
-
-        self.mox.ReplayAll()
-
-        drv.ensure_export(None, volume)
-
     def test_remove_export(self):
         drv = self._driver
 
index fee2a206ed2ea4d79eed0c8f0afdc30749818d84..a5e33c2ffa4606b2003badbef0d485355296be4c 100644 (file)
@@ -128,32 +128,21 @@ class WindowsDriver(driver.ISCSIDriver):
         snapshot_name = snapshot['name']
         self.utils.delete_snapshot(snapshot_name)
 
-    def _do_export(self, _ctx, volume, ensure=False):
-        """Do all steps to get disk exported as LUN 0 at separate target.
+    def ensure_export(self, context, volume):
+        # iSCSI targets exported by WinTarget persist after host reboot.
+        pass
 
-        :param volume: reference of volume to be exported
-        :param ensure: if True, ignore errors caused by already existing
-            resources
-        :return: iscsiadm-formatted provider location string
-        """
+    def create_export(self, context, volume):
+        """Driver entry point to get the export info for a new volume."""
         target_name = "%s%s" % (self.configuration.iscsi_target_prefix,
                                 volume['name'])
-        self.utils.create_iscsi_target(target_name, ensure)
+        self.utils.create_iscsi_target(target_name)
 
         # Get the disk to add
         vol_name = volume['name']
         self.utils.add_disk_to_target(vol_name, target_name)
 
-        return target_name
-
-    def ensure_export(self, context, volume):
-        """Driver entry point to get the export info for an existing volume."""
-        self._do_export(context, volume, ensure=True)
-
-    def create_export(self, context, volume):
-        """Driver entry point to get the export info for a new volume."""
-        loc = self._do_export(context, volume, ensure=False)
-        return {'provider_location': loc}
+        return {'provider_location': target_name}
 
     def remove_export(self, context, volume):
         """Driver entry point to remove an export for a volume.
index d4275a0eb030a29b0ccd77e76066af6a93305694..3339055701e69c757eb01fc19671b21fcc9916dd 100644 (file)
@@ -268,14 +268,13 @@ class WindowsUtils(object):
             LOG.error(err_msg)
             raise exception.VolumeBackendAPIException(data=err_msg)
 
-    def create_iscsi_target(self, target_name, ensure):
+    def create_iscsi_target(self, target_name):
         """Creates ISCSI target."""
         try:
-            cl = self._conn_wmi.__getattr__("WT_Host")
-            cl.NewHost(HostName=target_name)
+            self._conn_wmi.WT_Host.NewHost(HostName=target_name)
         except wmi.x_wmi as exc:
             excep_info = exc.com_error.excepinfo[2]
-            if not ensure or excep_info.find(u'The file exists') == -1:
+            if excep_info.find(u'The file exists') != -1:
                 err_msg = (_(
                     'create_iscsi_target: error when creating iscsi target: '
                     '%(tar_name)s . WMI exception: '
@@ -283,8 +282,8 @@ class WindowsUtils(object):
                 LOG.error(err_msg)
                 raise exception.VolumeBackendAPIException(data=err_msg)
             else:
-                LOG.info(_LI('Ignored target creation error "%s"'
-                             ' while ensuring export'), exc)
+                LOG.info(_LI('The iSCSI target %(target_name)s already '
+                             'exists.'), {'target_name': target_name})
 
     def remove_iscsi_target(self, target_name):
         """Removes ISCSI target."""