From 1dd84038178ec0658fdfb04939bcdbf1cfd4c6f9 Mon Sep 17 00:00:00 2001 From: Lucian Petrut Date: Tue, 5 May 2015 11:12:50 +0300 Subject: [PATCH] Windows iSCSI: remove ensure_export 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 | 22 +--------------- cinder/volume/drivers/windows/windows.py | 25 ++++++------------- .../volume/drivers/windows/windows_utils.py | 11 ++++---- 3 files changed, 13 insertions(+), 45 deletions(-) diff --git a/cinder/tests/unit/windows/test_windows.py b/cinder/tests/unit/windows/test_windows.py index 0b8eb15b5..259b7ad65 100644 --- a/cinder/tests/unit/windows/test_windows.py +++ b/cinder/tests/unit/windows/test_windows.py @@ -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 diff --git a/cinder/volume/drivers/windows/windows.py b/cinder/volume/drivers/windows/windows.py index fee2a206e..a5e33c2ff 100644 --- a/cinder/volume/drivers/windows/windows.py +++ b/cinder/volume/drivers/windows/windows.py @@ -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. diff --git a/cinder/volume/drivers/windows/windows_utils.py b/cinder/volume/drivers/windows/windows_utils.py index d4275a0eb..333905570 100644 --- a/cinder/volume/drivers/windows/windows_utils.py +++ b/cinder/volume/drivers/windows/windows_utils.py @@ -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.""" -- 2.45.2