Ejemplo n.º 1
0
    def _detach_volume(self, context, attach_info, volume, properties,
                       force=False, remote=False):
        """Disconnect the volume from the host."""
        # Use Brick's code to do attach/detach
        connector = attach_info['connector']
        connector.disconnect_volume(attach_info['conn']['data'],
                                    attach_info['device'])

        if remote:
            # Call remote manager's terminate_connection which includes
            # driver's terminate_connection and remove export
            rpcapi = volume_rpcapi.VolumeAPI()
            rpcapi.terminate_connection(context, volume, properties,
                                        force=force)
        else:
            # Call local driver's terminate_connection and remove export.
            # NOTE(avishay) This is copied from the manager's code - need to
            # clean this up in the future.
            try:
                self.terminate_connection(volume, properties, force=force)
            except Exception as err:
                err_msg = (_('Unable to terminate volume connection: %(err)s')
                           % {'err': err})
                LOG.error(err_msg)
                raise exception.VolumeBackendAPIException(data=err_msg)

            try:
                LOG.debug(_("volume %s: removing export"), volume['id'])
                self.remove_export(context, volume)
            except Exception as ex:
                LOG.exception(_("Error detaching volume %(volume)s, "
                                "due to remove export failure."),
                              {"volume": volume['id']})
                raise exception.RemoveExportException(volume=volume['id'],
                                                      reason=ex)
Ejemplo n.º 2
0
    def test_remove_export_error(self):
        self.driver.common.is_lun_mapped = mock.Mock(return_value=True)
        self.driver.common.remove_iscsi_export = (mock.Mock(
            side_effect=exception.RemoveExportException(volume=VOLUME,
                                                        reason='dont care')))

        self.assertRaises(exception.RemoveExportException,
                          self.driver.remove_export, CONTEXT, VOLUME)
Ejemplo n.º 3
0
    def remove_export(self, context, volume):
        try:
            if not self.common.is_lun_mapped(volume['name']):
                return
        except exception.SynoLUNNotExist:
            LOG.warning("Volume not exist")
            return

        try:
            _, trg_id = (self.common.get_iqn_and_trgid(
                volume['provider_location']))
            self.common.remove_iscsi_export(volume['name'], trg_id)
        except Exception as e:
            LOG.exception('Failed to remove_export.')
            raise exception.RemoveExportException(volume=volume, reason=e.msg)