Exemplo n.º 1
0
 def wrapper(self, ctx, snapshot_id, *args, **kwargs):
     try:
         res = method(self, ctx, snapshot_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.SnapshotNotFound(snapshot_id=snapshot_id)
         raise exc_value, None, exc_trace
     except cinder_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
Exemplo n.º 2
0
 def wrapper(self, ctx, *args, **kwargs):
     try:
         res = method(self, ctx, *args, **kwargs)
     except (cinder_exception.ConnectionError,
             keystone_exception.ConnectionError) as exc:
         err_msg = encodeutils.exception_to_unicode(exc)
         _reraise(exception.CinderConnectionFailed(reason=err_msg))
     except (keystone_exception.BadRequest,
             cinder_exception.BadRequest) as exc:
         err_msg = encodeutils.exception_to_unicode(exc)
         _reraise(exception.InvalidInput(reason=err_msg))
     except (keystone_exception.Forbidden,
             cinder_exception.Forbidden) as exc:
         err_msg = encodeutils.exception_to_unicode(exc)
         _reraise(exception.Forbidden(err_msg))
     return res
Exemplo n.º 3
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
     except cinder_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
Exemplo n.º 4
0
 def wrapper(self, ctx, *args, **kwargs):
     try:
         res = method(self, ctx, *args, **kwargs)
     except (cinder_exception.ConnectionError,
             keystone_exception.ConnectionError):
         exc_type, exc_value, exc_trace = sys.exc_info()
         _reraise(
             exception.CinderConnectionFailed(
                 reason=six.text_type(exc_value)))
     except (keystone_exception.BadRequest, cinder_exception.BadRequest):
         exc_type, exc_value, exc_trace = sys.exc_info()
         _reraise(exception.InvalidInput(reason=six.text_type(exc_value)))
     except (keystone_exception.Forbidden, cinder_exception.Forbidden):
         exc_type, exc_value, exc_trace = sys.exc_info()
         _reraise(exception.Forbidden(six.text_type(exc_value)))
     return res
Exemplo n.º 5
0
 def wrapper(self, ctx, snapshot_id, *args, **kwargs):
     try:
         res = method(self, ctx, snapshot_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.SnapshotNotFound(snapshot_id=snapshot_id)
         six.reraise(exc_value, None, exc_trace)
     except (cinder_exception.ConnectionError,
             keystone_exception.ConnectionError):
         exc_type, exc_value, exc_trace = sys.exc_info()
         reason = six.text_type(exc_value)
         exc_value = exception.CinderConnectionFailed(reason=reason)
         six.reraise(exc_value, None, exc_trace)
     return res
Exemplo n.º 6
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=six.text_type(exc_value))
         six.reraise(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=six.text_type(exc_value))
         six.reraise(exc_value, None, exc_trace)
     return res
 def __call__(self, *args, **kwargs):
     self.call_count += 1
     if self.raise_count == 0:
         self.raise_count += 1
         raise exception.CinderConnectionFailed(reason='Fake Cinder error')
Exemplo n.º 8
0
 def attach_volume(*args, **kwargs):
     raise exception.CinderConnectionFailed(
         reason="Connection timed out")
Exemplo n.º 9
0
class GetBDMImageMetadataTestCase(test.NoDBTestCase):
    def setUp(self):
        super().setUp()
        self.compute_api = compute_api.API()
        self.context = context.RequestContext('fake', 'fake')

    def _test_get_bdm_image_metadata__bootable(self, is_bootable=False):
        block_device_mapping = [{
            'id': 1,
            'device_name': 'vda',
            'no_device': None,
            'virtual_name': None,
            'snapshot_id': None,
            'volume_id': '1',
            'delete_on_termination': False,
        }]

        expected_meta = {
            'min_disk': 0,
            'min_ram': 0,
            'properties': {},
            'size': 0,
            'status': 'active',
        }

        def get_vol_data(*args, **kwargs):
            return {'bootable': is_bootable}

        with mock.patch.object(
                self.compute_api.volume_api,
                'get',
                side_effect=get_vol_data,
        ):
            if not is_bootable:
                self.assertRaises(exception.InvalidBDMVolumeNotBootable,
                                  block_device.get_bdm_image_metadata,
                                  self.context, self.compute_api.image_api,
                                  self.compute_api.volume_api,
                                  block_device_mapping)
            else:
                meta = block_device.get_bdm_image_metadata(
                    self.context, self.compute_api.image_api,
                    self.compute_api.volume_api, block_device_mapping)
                self.assertEqual(expected_meta, meta)

    def test_get_bdm_image_metadata__non_bootable(self):
        self._test_get_bdm_image_metadata__bootable(False)

    def test_get_bdm_image_metadata__bootable(self):
        self._test_get_bdm_image_metadata__bootable(True)

    def test_get_bdm_image_metadata__basic_property(self):
        block_device_mapping = [{
            'id': 1,
            'device_name': 'vda',
            'no_device': None,
            'virtual_name': None,
            'snapshot_id': None,
            'volume_id': '1',
            'delete_on_termination': False,
        }]
        fake_volume = {
            'volume_image_metadata': {
                'min_ram': 256,
                'min_disk': 128,
                'foo': 'bar',
            },
        }
        with mock.patch.object(
                self.compute_api.volume_api,
                'get',
                return_value=fake_volume,
        ):
            meta = block_device.get_bdm_image_metadata(
                self.context, self.compute_api.image_api,
                self.compute_api.volume_api, block_device_mapping)
            self.assertEqual(256, meta['min_ram'])
            self.assertEqual(128, meta['min_disk'])
            self.assertEqual('active', meta['status'])
            self.assertEqual('bar', meta['properties']['foo'])

    def test_get_bdm_image_metadata__snapshot_basic_property(self):
        block_device_mapping = [{
            'id': 1,
            'device_name': 'vda',
            'no_device': None,
            'virtual_name': None,
            'snapshot_id': '2',
            'volume_id': None,
            'delete_on_termination': False,
        }]
        fake_volume = {
            'volume_image_metadata': {
                'min_ram': 256,
                'min_disk': 128,
                'foo': 'bar',
            },
        }
        fake_snapshot = {'volume_id': '1'}
        with test.nested(
                mock.patch.object(self.compute_api.volume_api,
                                  'get',
                                  return_value=fake_volume),
                mock.patch.object(self.compute_api.volume_api,
                                  'get_snapshot',
                                  return_value=fake_snapshot),
        ) as (volume_get, volume_get_snapshot):
            meta = block_device.get_bdm_image_metadata(
                self.context, self.compute_api.image_api,
                self.compute_api.volume_api, block_device_mapping)

            self.assertEqual(256, meta['min_ram'])
            self.assertEqual(128, meta['min_disk'])
            self.assertEqual('active', meta['status'])
            self.assertEqual('bar', meta['properties']['foo'])
            volume_get_snapshot.assert_called_once_with(
                self.context, block_device_mapping[0]['snapshot_id'])
            volume_get.assert_called_once_with(self.context,
                                               fake_snapshot['volume_id'])

    @mock.patch.object(
        cinder.API,
        'get',
        side_effect=exception.CinderConnectionFailed(reason='error'))
    def test_get_bdm_image_metadata__cinder_down(self, mock_get):
        bdms = [
            objects.BlockDeviceMapping(
                **fake_block_device.FakeDbBlockDeviceDict({
                    'id': 1,
                    'volume_id': 1,
                    'source_type': 'volume',
                    'destination_type': 'volume',
                    'device_name': 'vda',
                }))
        ]
        self.assertRaises(exception.CinderConnectionFailed,
                          block_device.get_bdm_image_metadata,
                          self.context,
                          self.compute_api.image_api,
                          self.compute_api.volume_api,
                          bdms,
                          legacy_bdm=True)