Ejemplo n.º 1
0
    def setUp(self):
        super(CoraidDriverImageTestCases, self).setUp()

        self.fake_dev_path = '/dev/ether/fake_dev'

        self.fake_connection = {
            'driver_volume_type': 'aoe',
            'data': {
                'target_shelf': fake_shelf,
                'target_lun': fake_lun
            }
        }

        self.fake_volume_info = {
            'shelf': self.fake_connection['data']['target_shelf'],
            'lun': self.fake_connection['data']['target_lun']
        }

        self.mox.StubOutWithMock(self.driver, 'initialize_connection')
        self.driver.initialize_connection(fake_volume, {})\
            .AndReturn(self.fake_connection)

        self.mox.StubOutWithMock(self.driver, 'terminate_connection')
        self.driver.terminate_connection(fake_volume,
                                         mox.IgnoreArg(),
                                         force=False).AndReturn(None)

        root_helper = 'sudo cinder-rootwrap /etc/cinder/rootwrap.conf'

        self.mox.StubOutWithMock(connector, 'get_connector_properties')
        connector.get_connector_properties(root_helper,
                                           CONF.my_ip).\
            AndReturn({})

        self.mox.StubOutWithMock(utils, 'brick_get_connector')

        aoe_initiator = self.mox.CreateMockAnything()

        utils.brick_get_connector('aoe',
                                  device_scan_attempts=3,
                                  use_multipath=False,
                                  conn=mox.IgnoreArg()).\
            AndReturn(aoe_initiator)

        aoe_initiator\
            .connect_volume(self.fake_connection['data'])\
            .AndReturn({'path': self.fake_dev_path})

        aoe_initiator.check_valid_device(self.fake_dev_path)\
            .AndReturn(True)

        aoe_initiator.disconnect_volume(
            {
                'target_shelf': self.fake_volume_info['shelf'],
                'target_lun': self.fake_volume_info['lun']
            }, mox.IgnoreArg())
Ejemplo n.º 2
0
    def setUp(self):
        super(CoraidDriverImageTestCases, self).setUp()

        self.fake_dev_path = '/dev/ether/fake_dev'

        self.fake_connection = {'driver_volume_type': 'aoe',
                                'data': {'target_shelf': fake_shelf,
                                         'target_lun': fake_lun}}

        self.fake_volume_info = {
            'shelf': self.fake_connection['data']['target_shelf'],
            'lun': self.fake_connection['data']['target_lun']}

        self.mox.StubOutWithMock(self.driver, 'initialize_connection')
        self.driver.initialize_connection(fake_volume, {})\
            .AndReturn(self.fake_connection)

        self.mox.StubOutWithMock(self.driver, 'terminate_connection')
        self.driver.terminate_connection(fake_volume, mox.IgnoreArg(),
                                         force=False).AndReturn(None)

        root_helper = 'sudo cinder-rootwrap /etc/cinder/rootwrap.conf'

        self.mox.StubOutWithMock(connector, 'get_connector_properties')
        connector.get_connector_properties(root_helper,
                                           CONF.my_ip).\
            AndReturn({})

        self.mox.StubOutWithMock(utils, 'brick_get_connector')

        aoe_initiator = self.mox.CreateMockAnything()

        utils.brick_get_connector('aoe',
                                  device_scan_attempts=3,
                                  use_multipath=False,
                                  conn=mox.IgnoreArg()).\
            AndReturn(aoe_initiator)

        aoe_initiator\
            .connect_volume(self.fake_connection['data'])\
            .AndReturn({'path': self.fake_dev_path})

        aoe_initiator.check_valid_device(self.fake_dev_path)\
            .AndReturn(True)

        aoe_initiator.disconnect_volume(
            {'target_shelf': self.fake_volume_info['shelf'],
             'target_lun': self.fake_volume_info['lun']}, mox.IgnoreArg())
Ejemplo n.º 3
0
def brick_get_connector_properties():
    """wrapper for the brick calls to automatically set
    the root_helper needed for cinder.
    """

    root_helper = get_root_helper()
    return connector.get_connector_properties(root_helper)
Ejemplo n.º 4
0
def brick_get_connector_properties():
    """wrapper for the brick calls to automatically set
    the root_helper needed for cinder.
    """

    root_helper = get_root_helper()
    return connector.get_connector_properties(root_helper, CONF.my_ip)
Ejemplo n.º 5
0
    def setUp(self):
        super(CoraidDriverImageTestCases, self).setUp()

        self.fake_dev_path = "/dev/ether/fake_dev"

        self.fake_connection = {
            "driver_volume_type": "aoe",
            "data": {"target_shelf": fake_shelf, "target_lun": fake_lun},
        }

        self.fake_volume_info = {
            "shelf": self.fake_connection["data"]["target_shelf"],
            "lun": self.fake_connection["data"]["target_lun"],
        }

        self.mox.StubOutWithMock(self.driver, "initialize_connection")
        self.driver.initialize_connection(fake_volume, {}).AndReturn(self.fake_connection)

        self.mox.StubOutWithMock(self.driver, "terminate_connection")
        self.driver.terminate_connection(fake_volume, mox.IgnoreArg(), force=False).AndReturn(None)

        root_helper = "sudo cinder-rootwrap /etc/cinder/rootwrap.conf"

        self.mox.StubOutWithMock(connector, "get_connector_properties")
        connector.get_connector_properties(root_helper, CONF.my_ip).AndReturn({})

        self.mox.StubOutWithMock(utils, "brick_get_connector")

        aoe_initiator = self.mox.CreateMockAnything()

        utils.brick_get_connector("aoe", device_scan_attempts=3, use_multipath=False, conn=mox.IgnoreArg()).AndReturn(
            aoe_initiator
        )

        aoe_initiator.connect_volume(self.fake_connection["data"]).AndReturn({"path": self.fake_dev_path})

        aoe_initiator.check_valid_device(self.fake_dev_path).AndReturn(True)

        aoe_initiator.disconnect_volume(
            {"target_shelf": self.fake_volume_info["shelf"], "target_lun": self.fake_volume_info["lun"]},
            mox.IgnoreArg(),
        )
Ejemplo n.º 6
0
    def copy_volume_data(self, context, src_vol, dest_vol, remote=None):
        """Copy data from src_vol to dest_vol."""
        LOG.debug(_('copy_data_between_volumes %(src)s -> %(dest)s.')
                  % {'src': src_vol['name'], 'dest': dest_vol['name']})

        properties = initiator.get_connector_properties()
        dest_remote = True if remote in ['dest', 'both'] else False
        dest_orig_status = dest_vol['status']
        try:
            dest_attach_info = self._attach_volume(context,
                                                   dest_vol,
                                                   properties,
                                                   remote=dest_remote)
        except Exception:
            with excutils.save_and_reraise_exception():
                msg = _("Failed to attach volume %(vol)s")
                LOG.error(msg % {'vol': dest_vol['id']})
                self.db.volume_update(context, dest_vol['id'],
                                      {'status': dest_orig_status})

        src_remote = True if remote in ['src', 'both'] else False
        src_orig_status = src_vol['status']
        try:
            src_attach_info = self._attach_volume(context,
                                                  src_vol,
                                                  properties,
                                                  remote=src_remote)
        except Exception:
            with excutils.save_and_reraise_exception():
                msg = _("Failed to attach volume %(vol)s")
                LOG.error(msg % {'vol': src_vol['id']})
                self.db.volume_update(context, src_vol['id'],
                                      {'status': src_orig_status})
                self._copy_volume_data_cleanup(context, dest_vol, properties,
                                               dest_attach_info, dest_remote,
                                               force=True)

        try:
            volume_utils.copy_volume(src_attach_info['device']['path'],
                                     dest_attach_info['device']['path'],
                                     src_vol['size'])
            copy_error = False
        except Exception:
            with excutils.save_and_reraise_exception():
                msg = _("Failed to copy volume %(src)s to %(dest)d")
                LOG.error(msg % {'src': src_vol['id'], 'dest': dest_vol['id']})
                copy_error = True
        finally:
            self._copy_volume_data_cleanup(context, dest_vol, properties,
                                           dest_attach_info, dest_remote,
                                           force=copy_error)
            self._copy_volume_data_cleanup(context, src_vol, properties,
                                           src_attach_info, src_remote,
                                           force=copy_error)
Ejemplo n.º 7
0
    def setUp(self):
        super(CoraidDriverImageTestCases, self).setUp()

        self.fake_dev_path = '/dev/ether/fake_dev'

        self.fake_connection = {'driver_volume_type': 'aoe',
                                'data': {'target_shelf': fake_shelf,
                                         'target_lun': fake_lun}}

        self.fake_volume_info = {
            'shelf': self.fake_connection['data']['target_shelf'],
            'lun': self.fake_connection['data']['target_lun']}

        self.mox.StubOutWithMock(self.driver, 'initialize_connection')
        self.driver.initialize_connection(fake_volume, {})\
            .AndReturn(self.fake_connection)

        self.mox.StubOutWithMock(self.driver, 'terminate_connection')
        self.driver.terminate_connection(fake_volume, mox.IgnoreArg())\
            .AndReturn(None)

        self.mox.StubOutWithMock(connector, 'get_connector_properties')
        connector.get_connector_properties().AndReturn({})

        self.mox.StubOutWithMock(connector.InitiatorConnector, 'factory')

        aoe_initiator = self.mox.CreateMockAnything()

        connector.InitiatorConnector.factory('aoe', use_multipath=False)\
            .AndReturn(aoe_initiator)

        aoe_initiator\
            .connect_volume(self.fake_connection['data'])\
            .AndReturn({'path': self.fake_dev_path})

        aoe_initiator.check_valid_device(self.fake_dev_path)\
            .AndReturn(True)

        aoe_initiator.disconnect_volume(
            {'target_shelf': self.fake_volume_info['shelf'],
             'target_lun': self.fake_volume_info['lun']}, mox.IgnoreArg())
Ejemplo n.º 8
0
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        """Fetch the image from image_service and write it to the volume."""
        LOG.debug(_("copy_image_to_volume %s.") % volume["name"])

        properties = initiator.get_connector_properties()
        attach_info = self._attach_volume(context, volume, properties)

        try:
            image_utils.fetch_to_raw(context, image_service, image_id, attach_info["device"]["path"])
        finally:
            self._detach_volume(attach_info)
            self.terminate_connection(volume, properties)
Ejemplo n.º 9
0
    def copy_volume_to_image(self, context, volume, image_service, image_meta):
        """Copy the volume to the specified image."""
        LOG.debug(_("copy_volume_to_image %s.") % volume["name"])

        properties = initiator.get_connector_properties()
        attach_info = self._attach_volume(context, volume, properties)

        try:
            image_utils.upload_volume(context, image_service, image_meta, attach_info["device"]["path"])
        finally:
            self._detach_volume(attach_info)
            self.terminate_connection(volume, properties)
Ejemplo n.º 10
0
    def copy_volume_to_image(self, context, volume, image_service, image_meta):
        """Copy the volume to the specified image."""
        LOG.debug(_('copy_volume_to_image %s.') % volume['name'])

        properties = initiator.get_connector_properties()
        attach_info = self._attach_volume(context, volume, properties)

        try:
            image_utils.upload_volume(context, image_service, image_meta,
                                      attach_info['device']['path'])
        finally:
            self._detach_volume(attach_info)
            self.terminate_connection(volume, properties)
Ejemplo n.º 11
0
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        """Fetch the image from image_service and write it to the volume."""
        LOG.debug(_('copy_image_to_volume %s.') % volume['name'])

        properties = initiator.get_connector_properties()
        attach_info = self._attach_volume(context, volume, properties)

        try:
            image_utils.fetch_to_raw(context, image_service, image_id,
                                     attach_info['device']['path'])
        finally:
            self._detach_volume(attach_info)
            self.terminate_connection(volume, properties)
Ejemplo n.º 12
0
 def _test_brick_get_connector_properties(self, multipath,
                                          enforce_multipath,
                                          multipath_result, mock_wwnns,
                                          mock_wwpns, mock_initiator,
                                          mock_gethostname):
     props_actual = connector.get_connector_properties(
         'sudo', CONF.my_ip, multipath, enforce_multipath)
     props = {
         'initiator': 'fakeinitiator',
         'host': 'fakehost',
         'ip': CONF.my_ip,
         'multipath': multipath_result
     }
     self.assertEqual(props, props_actual)
Ejemplo n.º 13
0
 def _test_brick_get_connector_properties(self, multipath,
                                          enforce_multipath,
                                          multipath_result,
                                          mock_wwnns, mock_wwpns,
                                          mock_initiator, mock_gethostname):
     props_actual = connector.get_connector_properties('sudo',
                                                       CONF.my_ip,
                                                       multipath,
                                                       enforce_multipath)
     props = {'initiator': 'fakeinitiator',
              'host': 'fakehost',
              'ip': CONF.my_ip,
              'multipath': multipath_result}
     self.assertEqual(props, props_actual)
Ejemplo n.º 14
0
def brick_get_connector_properties(multipath=False, enforce_multipath=False):
    """wrapper for the brick calls to automatically set
    the root_helper needed for cinder.

    :param multipath:         A boolean indicating whether the connector can
                              support multipath.
    :param enforce_multipath: If True, it raises exception when multipath=True
                              is specified but multipathd is not running.
                              If False, it falls back to multipath=False
                              when multipathd is not running.
    """

    root_helper = get_root_helper()
    return connector.get_connector_properties(root_helper, CONF.my_ip,
                                              multipath, enforce_multipath)
Ejemplo n.º 15
0
    def copy_volume_to_image(self, context, volume, image_service, image_meta):
        """Copy the volume to the specified image."""
        LOG.debug(_('copy_volume_to_image %s.') % volume['name'])

        properties = initiator.get_connector_properties()
        connection, device, connector = self._attach_volume(context, volume,
                                                            properties)

        try:
            image_utils.upload_volume(context,
                                      image_service,
                                      image_meta,
                                      device['path'])
        finally:
            self._detach_volume(connection, device, connector)
            self.terminate_connection(volume, properties)
Ejemplo n.º 16
0
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        """Fetch the image from image_service and write it to the volume."""
        LOG.debug(_('copy_image_to_volume %s.') % volume['name'])

        properties = initiator.get_connector_properties()
        connection, device, connector = self._attach_volume(context, volume,
                                                            properties)

        try:
            image_utils.fetch_to_raw(context,
                                     image_service,
                                     image_id,
                                     device['path'])
        finally:
            self._detach_volume(connection, device, connector)
            self.terminate_connection(volume, properties)
Ejemplo n.º 17
0
Archivo: utils.py Proyecto: Qeas/cinder
def brick_get_connector_properties(multipath=False, enforce_multipath=False):
    """wrapper for the brick calls to automatically set
    the root_helper needed for cinder.

    :param multipath:         A boolean indicating whether the connector can
                              support multipath.
    :param enforce_multipath: If True, it raises exception when multipath=True
                              is specified but multipathd is not running.
                              If False, it falls back to multipath=False
                              when multipathd is not running.
    """

    root_helper = get_root_helper()
    return connector.get_connector_properties(root_helper,
                                              CONF.my_ip,
                                              multipath,
                                              enforce_multipath)
Ejemplo n.º 18
0
    def copy_volume_data(self, context, src_vol, dest_vol, remote=None):
        """Copy data from src_vol to dest_vol."""
        LOG.debug(
            _("copy_data_between_volumes %(src)s -> %(dest)s.") % {"src": src_vol["name"], "dest": dest_vol["name"]}
        )

        properties = initiator.get_connector_properties()
        dest_remote = True if remote in ["dest", "both"] else False
        dest_orig_status = dest_vol["status"]
        try:
            dest_attach_info = self._attach_volume(context, dest_vol, properties, remote=dest_remote)
        except Exception:
            with excutils.save_and_reraise_exception():
                msg = _("Failed to attach volume %(vol)s")
                LOG.error(msg % {"vol": dest_vol["id"]})
                self.db.volume_update(context, dest_vol["id"], {"status": dest_orig_status})

        src_remote = True if remote in ["src", "both"] else False
        src_orig_status = src_vol["status"]
        try:
            src_attach_info = self._attach_volume(context, src_vol, properties, remote=src_remote)
        except Exception:
            with excutils.save_and_reraise_exception():
                msg = _("Failed to attach volume %(vol)s")
                LOG.error(msg % {"vol": src_vol["id"]})
                self.db.volume_update(context, src_vol["id"], {"status": src_orig_status})
                self._copy_volume_data_cleanup(context, dest_vol, properties, dest_attach_info, dest_remote, force=True)

        try:
            volume_utils.copy_volume(
                src_attach_info["device"]["path"], dest_attach_info["device"]["path"], src_vol["size"]
            )
            copy_error = False
        except Exception:
            with excutils.save_and_reraise_exception():
                msg = _("Failed to copy volume %(src)s to %(dest)d")
                LOG.error(msg % {"src": src_vol["id"], "dest": dest_vol["id"]})
                copy_error = True
        finally:
            self._copy_volume_data_cleanup(
                context, dest_vol, properties, dest_attach_info, dest_remote, force=copy_error
            )
            self._copy_volume_data_cleanup(context, src_vol, properties, src_attach_info, src_remote, force=copy_error)
Ejemplo n.º 19
0
    def backup_volume(self, context, backup, backup_service):
        """Create a new backup from an existing volume."""
        volume = self.db.volume_get(context, backup['volume_id'])

        LOG.debug(_('Creating a new backup for volume %s.') % volume['name'])

        root_helper = 'sudo cinder-rootwrap %s' % CONF.rootwrap_config
        properties = initiator.get_connector_properties(root_helper)
        attach_info = self._attach_volume(context, volume, properties)

        try:
            volume_path = attach_info['device']['path']
            with utils.temporary_chown(volume_path):
                with fileutils.file_open(volume_path) as volume_file:
                    backup_service.backup(backup, volume_file)

        finally:
            self._detach_volume(attach_info)
            self.terminate_connection(volume, properties)
Ejemplo n.º 20
0
    def restore_backup(self, context, backup, volume, backup_service):
        """Restore an existing backup to a new or existing volume."""
        LOG.debug(_('Restoring backup %(backup)s to '
                    'volume %(volume)s.') %
                  {'backup': backup['id'],
                   'volume': volume['name']})

        root_helper = 'sudo cinder-rootwrap %s' % CONF.rootwrap_config
        properties = initiator.get_connector_properties(root_helper)
        attach_info = self._attach_volume(context, volume, properties)

        try:
            volume_path = attach_info['device']['path']
            with utils.temporary_chown(volume_path):
                with fileutils.file_open(volume_path, 'wb') as volume_file:
                    backup_service.restore(backup, volume['id'], volume_file)

        finally:
            self._detach_volume(attach_info)
            self.terminate_connection(volume, properties)
Ejemplo n.º 21
0
    def backup_volume(self, context, backup, backup_service):
        """Create a new backup from an existing volume."""
        volume = self.db.volume_get(context, backup['volume_id'])

        LOG.debug(_('Creating a new backup for volume %s.') %
                  volume['name'])

        root_helper = 'sudo cinder-rootwrap %s' % CONF.rootwrap_config
        properties = initiator.get_connector_properties(root_helper)
        attach_info = self._attach_volume(context, volume, properties)

        try:
            volume_path = attach_info['device']['path']
            with utils.temporary_chown(volume_path):
                with fileutils.file_open(volume_path) as volume_file:
                    backup_service.backup(backup, volume_file)

        finally:
            self._detach_volume(attach_info)
            self.terminate_connection(volume, properties)
Ejemplo n.º 22
0
    def restore_backup(self, context, backup, volume, backup_service):
        """Restore an existing backup to a new or existing volume."""
        LOG.debug(_('Restoring backup %(backup)s to '
                    'volume %(volume)s.') %
                  {'backup': backup['id'],
                   'volume': volume['name']})

        root_helper = 'sudo cinder-rootwrap %s' % CONF.rootwrap_config
        properties = initiator.get_connector_properties(root_helper)
        attach_info = self._attach_volume(context, volume, properties)

        try:
            volume_path = attach_info['device']['path']
            with utils.temporary_chown(volume_path):
                with fileutils.file_open(volume_path, 'wb') as volume_file:
                    backup_service.restore(backup, volume['id'], volume_file)

        finally:
            self._detach_volume(attach_info)
            self.terminate_connection(volume, properties)
Ejemplo n.º 23
0
    def copy_volume_data(self, context, src_vol, dest_vol, remote=None):
        """Copy data from src_vol to dest_vol."""
        LOG.debug(
            _('copy_data_between_volumes %(src)s -> %(dest)s.') % {
                'src': src_vol['name'],
                'dest': dest_vol['name']
            })

        properties = initiator.get_connector_properties()
        dest_remote = True if remote in ['dest', 'both'] else False
        dest_orig_status = dest_vol['status']
        try:
            dest_attach_info = self._attach_volume(context,
                                                   dest_vol,
                                                   properties,
                                                   remote=dest_remote)
        except Exception:
            with excutils.save_and_reraise_exception():
                msg = _("Failed to attach volume %(vol)s")
                LOG.error(msg % {'vol': dest_vol['id']})
                self.db.volume_update(context, dest_vol['id'],
                                      {'status': dest_orig_status})

        src_remote = True if remote in ['src', 'both'] else False
        src_orig_status = src_vol['status']
        try:
            src_attach_info = self._attach_volume(context,
                                                  src_vol,
                                                  properties,
                                                  remote=src_remote)
        except Exception:
            with excutils.save_and_reraise_exception():
                msg = _("Failed to attach volume %(vol)s")
                LOG.error(msg % {'vol': src_vol['id']})
                self.db.volume_update(context, src_vol['id'],
                                      {'status': src_orig_status})
                self._copy_volume_data_cleanup(context,
                                               dest_vol,
                                               properties,
                                               dest_attach_info,
                                               dest_remote,
                                               force=True)

        try:
            volume_utils.copy_volume(src_attach_info['device']['path'],
                                     dest_attach_info['device']['path'],
                                     src_vol['size'])
            copy_error = False
        except Exception:
            with excutils.save_and_reraise_exception():
                msg = _("Failed to copy volume %(src)s to %(dest)d")
                LOG.error(msg % {'src': src_vol['id'], 'dest': dest_vol['id']})
                copy_error = True
        finally:
            self._copy_volume_data_cleanup(context,
                                           dest_vol,
                                           properties,
                                           dest_attach_info,
                                           dest_remote,
                                           force=copy_error)
            self._copy_volume_data_cleanup(context,
                                           src_vol,
                                           properties,
                                           src_attach_info,
                                           src_remote,
                                           force=copy_error)