Exemple #1
0
 def wrapper(self, ctx, res_id, *args, **kwargs):
     try:
         res = method(self, ctx, res_id, *args, **kwargs)
     except (keystone_exception.NotFound, cinder_exception.NotFound):
         _reraise(exception.VolumeNotFound(volume_id=res_id))
     except cinder_exception.OverLimit:
         _reraise(exception.OverQuota(overs='snapshots'))
     return res
Exemple #2
0
 def wrapper(self, ctx, volume_id, *args, **kwargs):
     try:
         res = method(self, ctx, volume_id, *args, **kwargs)
     except (keystone_exception.NotFound, cinder_exception.NotFound):
         _reraise(exception.VolumeNotFound(volume_id=volume_id))
     except cinder_exception.OverLimit as e:
         _reraise(exception.OverQuota(message=e.message))
     return res
Exemple #3
0
 def test_swap_volume_with_nonexistent_dest_in_body(self, mock_update):
     mock_update.side_effect = [
         None, exception.VolumeNotFound(volume_id=FAKE_UUID_C)
     ]
     body = {'volumeAttachment': {'volumeId': FAKE_UUID_C}}
     self.assertRaises(exc.HTTPBadRequest,
                       self._test_swap,
                       self.attachments,
                       body=body)
Exemple #4
0
def fake_get_volume(self, context, id):
    if id == FAKE_UUID_A:
        status = 'in-use'
        attach_status = 'attached'
    elif id == FAKE_UUID_B:
        status = 'available'
        attach_status = 'detached'
    else:
        raise exception.VolumeNotFound(volume_id=id)
    return {'id': id, 'status': status, 'attach_status': attach_status}
Exemple #5
0
 def wrapper(self, ctx, volume_id, *args, **kwargs):
     try:
         res = method(self, ctx, volume_id, *args, **kwargs)
     except cinder_exception.ClientException:
         exc_type, exc_value, exc_trace = sys.exc_info()
         if isinstance(exc_value, cinder_exception.NotFound):
             exc_value = exception.VolumeNotFound(volume_id=volume_id)
         elif isinstance(exc_value, cinder_exception.BadRequest):
             exc_value = exception.InvalidInput(reason=exc_value.message)
         raise exc_value, None, exc_trace
     return res
Exemple #6
0
    def get(self, context, volume_id):
        if volume_id == 87654321:
            return {'id': volume_id,
                    'attach_time': '13:56:24',
                    'status': 'in-use'}

        for v in self.volume_list:
            if v['id'] == str(volume_id):
                return v

        raise exception.VolumeNotFound(volume_id=volume_id)
Exemple #7
0
 def wrapper(self, ctx, volume_id, *args, **kwargs):
     try:
         res = method(self, ctx, volume_id, *args, **kwargs)
     except (cinder_exception.ClientException,
             keystone_exception.ClientException):
         exc_type, exc_value, exc_trace = sys.exc_info()
         if isinstance(
                 exc_value,
             (keystone_exception.NotFound, cinder_exception.NotFound)):
             exc_value = exception.VolumeNotFound(volume_id=volume_id)
         six.reraise(exc_value, None, exc_trace)
     return res
Exemple #8
0
 def wrapper(self, ctx, volume_id, *args, **kwargs):
     try:
         res = method(self, ctx, volume_id, *args, **kwargs)
     except (keystone_exception.NotFound, cinder_exception.NotFound):
         _reraise(exception.VolumeNotFound(volume_id=volume_id))
     except keystone_exception.RequestEntityTooLarge as e:
         _reraise(exception.VolumeLimitExceeded(reason=e.message))
     except cinder_exception.OverLimit as e:
         _reraise(exception.VolumeLimitExceeded(reason=e.message))
     except (cinder_exception.BadRequest,
             keystone_exception.BadRequest) as e:
         _reraise(exception.InvalidInput(reason=e))
     return res
Exemple #9
0
    def delete_volume(self, volume, is_snapshot=False):
        """Delete SolidFire Volume from device.

        SolidFire allows multipe volumes with same name,
        volumeID is what's guaranteed unique.

        """

        LOG.debug(_("Enter SolidFire delete_volume..."))
        sf_account_name = socket.getfqdn() + '-' + volume['project_id']
        sfaccount = self._get_sfaccount_by_name(sf_account_name)
        if sfaccount is None:
            raise exception.SfAccountNotFound(account_name=sf_account_name)

        params = {'accountID': sfaccount['accountID']}
        data = self._issue_api_request('ListVolumesForAccount', params)
        if 'result' not in data:
            raise exception.SolidFireAPIDataException(data=data)

        if is_snapshot:
            seek = 'OS-SNAPID-%s' % (volume['id'])
        else:
            seek = 'OS-VOLID-%s' % volume['id']
            #params = {'name': 'OS-VOLID-:%s' % volume['id'],

        found_count = 0
        volid = -1
        for v in data['result']['volumes']:
            if v['name'] == seek:
                found_count += 1
                volid = v['volumeID']

        if found_count == 0:
            raise exception.VolumeNotFound(volume_id=volume['id'])

        if found_count > 1:
            LOG.debug(_("Deleting volumeID: %s"), volid)
            raise exception.DuplicateSfVolumeNames(vol_name=volume['id'])

        params = {'volumeID': volid}
        data = self._issue_api_request('DeleteVolume', params)
        if 'result' not in data:
            raise exception.SolidFireAPIDataException(data=data)

        LOG.debug(_("Leaving SolidFire delete_volume"))
Exemple #10
0
 def wrapper(self, ctx, volume_id, *args, **kwargs):
     try:
         res = method(self, ctx, volume_id, *args, **kwargs)
     except (cinder_exception.ClientException,
             keystone_exception.ClientException):
         exc_type, exc_value, exc_trace = sys.exc_info()
         if isinstance(exc_value, (keystone_exception.NotFound,
                                   cinder_exception.NotFound)):
             exc_value = exception.VolumeNotFound(volume_id=volume_id)
         elif isinstance(exc_value, (keystone_exception.BadRequest,
                                     cinder_exception.BadRequest)):
             exc_value = exception.InvalidInput(reason=exc_value.message)
         raise exc_value, None, exc_trace
     except (cinder_exception.ConnectionError,
             keystone_exception.ConnectionError):
         exc_type, exc_value, exc_trace = sys.exc_info()
         exc_value = exception.CinderConnectionFailed(
                                                reason=exc_value.message)
         raise exc_value, None, exc_trace
     return res
Exemple #11
0
    def _do_create_snapshot(self, snapshot, snapshot_name):
        """Creates a snapshot."""
        LOG.debug(_("Enter SolidFire create_snapshot..."))
        sf_account_name = socket.getfqdn() + '-' + snapshot['project_id']
        sfaccount = self._get_sfaccount_by_name(sf_account_name)
        if sfaccount is None:
            raise exception.SfAccountNotFound(account_name=sf_account_name)

        params = {'accountID': sfaccount['accountID']}
        data = self._issue_api_request('ListVolumesForAccount', params)
        if 'result' not in data:
            raise exception.SolidFireAPIDataException(data=data)

        found_count = 0
        volid = -1
        for v in data['result']['volumes']:
            if v['name'] == 'OS-VOLID-%s' % snapshot['volume_id']:
                found_count += 1
                volid = v['volumeID']

        if found_count == 0:
            raise exception.VolumeNotFound(volume_id=snapshot['volume_id'])
        if found_count != 1:
            raise exception.DuplicateSfVolumeNames(vol_name='OS-VOLID-%s' %
                                                   snapshot['volume_id'])

        params = {
            'volumeID': int(volid),
            'name': snapshot_name,
            'attributes': {
                'OriginatingVolume': volid
            }
        }

        data = self._issue_api_request('CloneVolume', params)
        if 'result' not in data:
            raise exception.SolidFireAPIDataException(data=data)

        return (data, sfaccount)
Exemple #12
0
 def not_found(context):
     raise exception.VolumeNotFound(volume_id=5)
Exemple #13
0
def fake_attach_volume_not_found_vol(self, context, instance, volume_id,
                                     device, disk_bus, device_type):
    raise exception.VolumeNotFound(volume_id=volume_id)
Exemple #14
0
def fake_volume_get_not_found(*args, **kwargs):
    raise exception.VolumeNotFound(volume_id=UUID1)
Exemple #15
0
def stub_volume_notfound(self, context, volume_id):
    raise exc.VolumeNotFound(volume_id=volume_id)
Exemple #16
0
 def stub_volume_get_raise_exc(self, context, volume_id):
     raise exception.VolumeNotFound(volume_id=volume_id)
Exemple #17
0
 def _translate_volume_exception(self, volume_id, exc_value):
     if isinstance(exc_value, cinder_exception.NotFound):
         return exception.VolumeNotFound(volume_id=volume_id)
     elif isinstance(exc_value, cinder_exception.BadRequest):
         return exception.InvalidInput(reason=exc_value.message)
     return exc_value
Exemple #18
0
        def fake_get(self_api, context, volume_id, microversion=None):

            # TODO(lyarwood): Refactor this block into something sensible and
            # reusable by other tests.
            # Check for the special swap volumes.
            attachments = self.volume_to_attachment[volume_id]
            if volume_id in (self.SWAP_OLD_VOL, self.SWAP_ERR_OLD_VOL):
                volume = {
                    'status': 'available',
                    'display_name': 'TEST1',
                    'attach_status': 'detached',
                    'id': volume_id,
                    'multiattach': False,
                    'size': 1
                }
                if ((self.swap_volume_instance_uuid
                     and volume_id == self.SWAP_OLD_VOL)
                        or (self.swap_volume_instance_error_uuid
                            and volume_id == self.SWAP_ERR_OLD_VOL)):
                    if volume_id == self.SWAP_OLD_VOL:
                        instance_uuid = self.swap_volume_instance_uuid
                    else:
                        instance_uuid = self.swap_volume_instance_error_uuid

                    if attachments:
                        attachment = list(attachments.values())[0]

                        volume.update({
                            'status': 'in-use',
                            'attachments': {
                                instance_uuid: {
                                    'mountpoint': '/dev/vdb',
                                    'attachment_id': attachment['id']
                                }
                            },
                            'attach_status': 'attached',
                        })
                    return volume

            # Check to see if the volume is attached.
            if attachments:
                # The volume is attached.
                attachment = list(attachments.values())[0]
                volume = {
                    'status': 'in-use',
                    'display_name': volume_id,
                    'attach_status': 'attached',
                    'id': volume_id,
                    'multiattach': _is_multiattach(volume_id),
                    'size': 1,
                    'attachments': {
                        attachment['instance_uuid']: {
                            'attachment_id': attachment['id'],
                            'mountpoint': '/dev/vdb'
                        }
                    }
                }
            else:
                # This is a test that does not care about the actual details.
                volume = {
                    'status': 'available',
                    'display_name': volume_id,
                    'attach_status': 'detached',
                    'id': volume_id,
                    'multiattach': _is_multiattach(volume_id),
                    'size': 1
                }

            if 'availability_zone' not in volume:
                volume['availability_zone'] = self.az

            # Check for our special image-backed volume.
            if volume_id in (
                    self.IMAGE_BACKED_VOL,
                    self.IMAGE_WITH_TRAITS_BACKED_VOL,
            ):
                # Make it a bootable volume.
                volume['bootable'] = True
                if volume_id == self.IMAGE_BACKED_VOL:
                    # Add the image_id metadata.
                    volume['volume_image_metadata'] = {
                        # There would normally be more image metadata in here.
                        'image_id': '155d900f-4e14-4e4c-a73d-069cbf4541e6'
                    }
                elif volume_id == self.IMAGE_WITH_TRAITS_BACKED_VOL:
                    # Add the image_id metadata with traits.
                    volume['volume_image_metadata'] = {
                        'image_id': '155d900f-4e14-4e4c-a73d-069cbf4541e6',
                        "trait:HW_CPU_X86_SGX": "required",
                    }

            # If we haven't called migrate_volume_completion then return
            # a migration_status of migrating
            if (volume_id == self.MULTIATTACH_RO_MIGRATE_OLD_VOL
                    and not self.multiattach_ro_migrated):
                volume['migration_status'] = 'migrating'

            # If we have migrated and are still GET'ing the new volume
            # return raise VolumeNotFound
            if (volume_id == self.MULTIATTACH_RO_MIGRATE_NEW_VOL
                    and self.multiattach_ro_migrated):
                raise exception.VolumeNotFound(
                    volume_id=self.MULTIATTACH_RO_MIGRATE_NEW_VOL)

            return volume
Exemple #19
0
 def get(self, context, volume_id):
     volume = self.volumes.get(volume_id)
     if volume:
         return copy.deepcopy(volume)
     raise exception.VolumeNotFound(volume_id=volume_id)
Exemple #20
0
 def _translate_volume_exception(self, volume_id, exc_value):
     if isinstance(exc_value, cinder_exception.NotFound):
         return exception.VolumeNotFound(volume_id=volume_id)
     return exc_value
Exemple #21
0
 def attach(self, context, volume_id, instance_uuid, mountpoint, mode='rw'):
     volume = self.volumes.get(volume_id)
     if not volume:
         raise exception.VolumeNotFound(volume_id=volume_id)
     volume['attach_status'] = 'attached'
     volume['status'] = 'in-use'
Exemple #22
0
        def fake_get(self_api, context, volume_id, microversion=None):
            volume = {
                'display_name': volume_id,
                'id': volume_id,
                'size': 1,
                'multiattach': _is_multiattach(volume_id),
                'availability_zone': self.az
            }

            # Add any attachment details the fixture has
            fixture_attachments = self.volume_to_attachment[volume_id]
            if fixture_attachments:
                attachments = {}
                for attachment in list(fixture_attachments.values()):
                    instance_uuid = attachment['instance_uuid']
                    # legacy cruft left over from notification tests
                    if (volume_id == self.SWAP_OLD_VOL
                            and self.swap_volume_instance_uuid):
                        instance_uuid = self.swap_volume_instance_uuid

                    if (volume_id == self.SWAP_ERR_OLD_VOL
                            and self.swap_volume_instance_error_uuid):
                        instance_uuid = self.swap_volume_instance_error_uuid
                    attachments[instance_uuid] = {
                        'attachment_id': attachment['id'],
                        'mountpoint': '/dev/vdb',
                    }

                volume.update({
                    'status': 'in-use',
                    'attach_status': 'attached',
                    'attachments': attachments,
                })
            # Otherwise mark the volume as avilable and detached
            else:
                volume.update({
                    'status': 'available',
                    'attach_status': 'detached',
                })

            if volume_id == self.IMAGE_BACKED_VOL:
                volume['bootable'] = True
                volume['volume_image_metadata'] = {
                    'image_id': '155d900f-4e14-4e4c-a73d-069cbf4541e6'
                }

            if volume_id == self.IMAGE_WITH_TRAITS_BACKED_VOL:
                volume['bootable'] = True
                volume['volume_image_metadata'] = {
                    'image_id': '155d900f-4e14-4e4c-a73d-069cbf4541e6',
                    "trait:HW_CPU_X86_SGX": "required",
                }

            # If we haven't called migrate_volume_completion then return
            # a migration_status of migrating
            if (volume_id == self.MULTIATTACH_RO_MIGRATE_OLD_VOL
                    and not self.multiattach_ro_migrated):
                volume['migration_status'] = 'migrating'

            # If we have migrated and are still GET'ing the new volume
            # return raise VolumeNotFound
            if (volume_id == self.MULTIATTACH_RO_MIGRATE_NEW_VOL
                    and self.multiattach_ro_migrated):
                raise exception.VolumeNotFound(
                    volume_id=self.MULTIATTACH_RO_MIGRATE_NEW_VOL)

            return volume