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'],
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
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.
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: '
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."""