Ejemplo n.º 1
0
    def test_create_failed(self):
        cinder.get_cinder_client_version(self.ctx).AndReturn('2')
        cinder.cinderclient(self.ctx).AndRaise(cinder_exception.BadRequest(''))
        self.mox.ReplayAll()

        self.assertRaises(exception.InvalidInput, self.api.create, self.ctx, 1,
                          '', '')
Ejemplo n.º 2
0
 def test_attachment_update_attachment_no_connector(self,
                                                    mock_cinderclient):
     """Tests that the translate_cinder_exception decorator is used."""
     # fake out the volume bad request error
     mock_cinderclient.return_value.attachments.update.side_effect = (
         cinder_exception.BadRequest(400))
     self.assertRaises(exception.InvalidInput,
                       self.api.attachment_update,
                       self.ctx, uuids.attachment_id, connector=None)
Ejemplo n.º 3
0
    def test_attach_volumes_client_init_failure(self, mock_client, mock_get,
                                                mock_set_meta, mock_session):
        connector = {'foo': 'bar'}
        volumes = ['111111111-0000-0000-0000-000000000003']
        mock_client.side_effect = cinder_exceptions.BadRequest(400)

        with task_manager.acquire(self.context, self.node.uuid) as task:
            self.assertRaises(exception.StorageError, cinder.attach_volumes,
                              task, volumes, connector)
Ejemplo n.º 4
0
    def test_get_failed(self):
        volume_id = 'volume_id'
        cinder.cinderclient(self.ctx).AndRaise(cinder_exception.NotFound(''))
        cinder.cinderclient(self.ctx).AndRaise(cinder_exception.BadRequest(''))
        self.mox.ReplayAll()

        self.assertRaises(exception.VolumeNotFound, self.api.get, self.ctx,
                          volume_id)
        self.assertRaises(exception.InvalidInput, self.api.get, self.ctx,
                          volume_id)
Ejemplo n.º 5
0
    def test_reserve_failed(self):
        self.v_client.volumes.reserve.side_effect = (
            cinder_exceptions.BadRequest(400))
        try:
            with volume_actions.Reserve(*self.command_args) as cmd:
                cmd.reserve()
        except cinder_exceptions.BadRequest:
            self.v_client.volumes.unreserve.assert_called_once_with(
                self.volume_id)

        self.v_client.volumes.reserve.assert_called_once_with(self.volume_id)
Ejemplo n.º 6
0
    def test_execute_error(self):
        @tools.screen_all_logs
        def do_check(ex, status, code, message):
            self.controller.reset_mock()
            self.controller.fake_action.side_effect = ex

            res = self.request.send(self.application)

            self.assertEqual(status, res.status_code)
            self.assertEqual('text/xml', res.content_type)
            expected_xml = fakes.XML_ERROR_TEMPLATE % {
                'code': code,
                'message': message,
                'request_id': self.fake_context.request_id
            }
            self.assertThat(res.body.decode("utf-8"),
                            matchers.XMLMatches(expected_xml))
            self.controller.fake_action.assert_called_once_with(
                self.fake_context, param='fake_param')

        do_check(exception.EC2Exception('fake_msg'), 400, 'EC2Exception',
                 'fake_msg')
        do_check(KeyError('fake_msg'), 500, 'KeyError',
                 'Unknown error occurred.')
        do_check(exception.InvalidVpcIDNotFound('fake_msg'), 400,
                 'InvalidVpcID.NotFound', 'fake_msg')
        do_check(nova_exception.BadRequest(400, message='fake_msg'), 400,
                 'BadRequest', 'fake_msg')
        do_check(glance_exception.HTTPBadRequest(), 400, 'HTTPBadRequest',
                 'HTTP HTTPBadRequest')
        do_check(cinder_exception.BadRequest(400, message='fake_msg'), 400,
                 'BadRequest', 'fake_msg')
        do_check(neutron_exception.BadRequest(message='fake_msg'), 400,
                 'BadRequest', 'fake_msg')
        do_check(keystone_exception.BadRequest(message='fake_msg'), 400,
                 'BadRequest', 'fake_msg (HTTP 400)')
        do_check(
            botocore_exceptions.ClientError(
                {
                    'Error': {
                        'Code': '',
                        'Message': ''
                    },
                    'Code': 'FakeCode',
                    'Message': 'fake_msg'
                }, 'register_image'), 400, 'FakeCode', 'fake_msg')
Ejemplo n.º 7
0
    def _validate_response(self, response):
        """
        Validates an HTTP response to a REST API request made by this service.

        The method will simply return if the HTTP error code indicates success
        (i.e. between 200 and 300).
        Any other errors, this method will raise the exception.
        Note: Appropriate exceptions to be added...
        Nova client throws an exception for 404

        :param response: the HTTP response to validate
        """
        if response is None:
            return
        httpResponse = response[0]
        # Any non-successful response >399 is an error
        if httpResponse.status_code >= httplib.BAD_REQUEST:
            LOG.critical(_("Service: got this response: %s") % httpResponse)
            LOG.debug("Service: got this response: %s" % httpResponse)
            raise exceptions.BadRequest(httpResponse)
Ejemplo n.º 8
0
    def test_detach_volumes_client_init_failure(self, mock_client, mock_get,
                                                mock_set_meta, mock_session):

        connector = {'foo': 'bar'}
        volumes = ['111111111-0000-0000-0000-000000000003']

        with task_manager.acquire(self.context, self.node.uuid) as task:
            mock_client.side_effect = cinder_exceptions.BadRequest(400)
            self.assertRaises(exception.StorageError, cinder.detach_volumes,
                              task, volumes, connector)
            # While we would be permitting failures, this is an
            # exception that must be raised since the client
            # cannot be initialized.
            mock_client.side_effect = exception.InvalidParameterValue('error')
            self.assertRaises(exception.StorageError,
                              cinder.detach_volumes,
                              task,
                              volumes,
                              connector,
                              allow_errors=True)
Ejemplo n.º 9
0
    def test_create_failed(self, mock_cinderclient):
        mock_cinderclient.return_value.volumes.create.side_effect = (
            cinder_exception.BadRequest(''))

        self.assertRaises(exception.InvalidInput, self.api.create, self.ctx, 1,
                          '', '')
Ejemplo n.º 10
0
 def test_create_failed(self):
     cinder.cinderclient.side_effect = cinder_exception.BadRequest(400)
     self.assertRaises(exception.InvalidInput, self.api.create, self.ctx, 1,
                       '', '')
Ejemplo n.º 11
0
class CinderApiTestCase(test.TestCase):
    def setUp(self):
        super(CinderApiTestCase, self).setUp()

        self.api = cinder.API()
        self.cinderclient = FakeCinderClient()
        self.ctx = context.get_admin_context()
        self.mock_object(cinder, 'cinderclient',
                         mock.Mock(return_value=self.cinderclient))
        self.mock_object(cinder, '_untranslate_volume_summary_view',
                         lambda ctx, vol: vol)
        self.mock_object(cinder, '_untranslate_snapshot_summary_view',
                         lambda ctx, snap: snap)

    def test_get(self):
        volume_id = 'volume_id1'
        result = self.api.get(self.ctx, volume_id)
        self.assertEqual(volume_id, result['id'])

    @ddt.data(
        {
            'cinder_e': cinder_exception.NotFound(404),
            'manila_e': exception.VolumeNotFound
        },
        {
            'cinder_e': cinder_exception.BadRequest(400),
            'manila_e': exception.InvalidInput
        },
    )
    @ddt.unpack
    def test_get_failed(self, cinder_e, manila_e):
        cinder.cinderclient.side_effect = cinder_e
        volume_id = 'volume_id'
        self.assertRaises(manila_e, self.api.get, self.ctx, volume_id)

    def test_create(self):
        result = self.api.create(self.ctx, 1, '', '')
        self.assertEqual('created_id', result['id'])

    def test_create_failed(self):
        cinder.cinderclient.side_effect = cinder_exception.BadRequest(400)
        self.assertRaises(exception.InvalidInput, self.api.create, self.ctx, 1,
                          '', '')

    def test_create_not_found_error(self):
        cinder.cinderclient.side_effect = cinder_exception.NotFound(404)
        self.assertRaises(exception.NotFound, self.api.create, self.ctx, 1, '',
                          '')

    def test_create_failed_exception(self):
        cinder.cinderclient.side_effect = Exception("error msg")
        self.assertRaises(exception.ManilaException, self.api.create, self.ctx,
                          1, '', '')

    def test_get_all(self):
        cinder._untranslate_volume_summary_view.return_value = ['id1', 'id2']
        self.assertEqual([{
            'id': 'id1'
        }, {
            'id': 'id2'
        }], self.api.get_all(self.ctx))

    def test_check_attach_volume_status_error(self):
        volume = {'status': 'error'}
        self.assertRaises(exception.InvalidVolume, self.api.check_attach,
                          self.ctx, volume)

    def test_check_attach_volume_already_attached(self):
        volume = {'status': 'available'}
        volume['attach_status'] = "attached"
        self.assertRaises(exception.InvalidVolume, self.api.check_attach,
                          self.ctx, volume)

    def test_check_attach_availability_zone_differs(self):
        volume = {'status': 'available'}
        volume['attach_status'] = "detached"
        instance = {'availability_zone': 'zone1'}
        volume['availability_zone'] = 'zone2'
        cinder.CONF.set_override('cinder_cross_az_attach', False)
        self.assertRaises(exception.InvalidVolume, self.api.check_attach,
                          self.ctx, volume, instance)
        volume['availability_zone'] = 'zone1'
        self.assertIsNone(self.api.check_attach(self.ctx, volume, instance))
        cinder.CONF.reset()

    def test_check_attach(self):
        volume = {'status': 'available'}
        volume['attach_status'] = "detached"
        volume['availability_zone'] = 'zone1'
        instance = {'availability_zone': 'zone1'}
        cinder.CONF.set_override('cinder_cross_az_attach', False)
        self.assertIsNone(self.api.check_attach(self.ctx, volume, instance))
        cinder.CONF.reset()

    def test_check_detach(self):
        volume = {'status': 'available'}
        self.assertRaises(exception.InvalidVolume, self.api.check_detach,
                          self.ctx, volume)
        volume['status'] = 'non-available'
        self.assertIsNone(self.api.check_detach(self.ctx, volume))

    def test_update(self):
        fake_volume = {'fake': 'fake'}
        self.mock_object(self.cinderclient.volumes, 'get',
                         mock.Mock(return_value=fake_volume))
        self.mock_object(self.cinderclient.volumes, 'update')
        fake_volume_id = 'fake_volume'
        fake_data = {'test': 'test'}

        self.api.update(self.ctx, fake_volume_id, fake_data)

        self.cinderclient.volumes.get.assert_called_once_with(fake_volume_id)
        self.cinderclient.volumes.update.assert_called_once_with(
            fake_volume, **fake_data)

    def test_reserve_volume(self):
        self.mock_object(self.cinderclient.volumes, 'reserve')
        self.api.reserve_volume(self.ctx, 'id1')
        self.cinderclient.volumes.reserve.assert_called_once_with('id1')

    def test_unreserve_volume(self):
        self.mock_object(self.cinderclient.volumes, 'unreserve')
        self.api.unreserve_volume(self.ctx, 'id1')
        self.cinderclient.volumes.unreserve.assert_called_once_with('id1')

    def test_begin_detaching(self):
        self.mock_object(self.cinderclient.volumes, 'begin_detaching')
        self.api.begin_detaching(self.ctx, 'id1')
        self.cinderclient.volumes.begin_detaching.assert_called_once_with(
            'id1')

    def test_roll_detaching(self):
        self.mock_object(self.cinderclient.volumes, 'roll_detaching')
        self.api.roll_detaching(self.ctx, 'id1')
        self.cinderclient.volumes.roll_detaching.assert_called_once_with('id1')

    def test_attach(self):
        self.mock_object(self.cinderclient.volumes, 'attach')
        self.api.attach(self.ctx, 'id1', 'uuid', 'point')
        self.cinderclient.volumes.attach.assert_called_once_with(
            'id1', 'uuid', 'point')

    def test_detach(self):
        self.mock_object(self.cinderclient.volumes, 'detach')
        self.api.detach(self.ctx, 'id1')
        self.cinderclient.volumes.detach.assert_called_once_with('id1')

    def test_initialize_connection(self):
        self.mock_object(self.cinderclient.volumes, 'initialize_connection')
        self.api.initialize_connection(self.ctx, 'id1', 'connector')
        self.cinderclient.volumes.initialize_connection.\
            assert_called_once_with('id1', 'connector')

    def test_terminate_connection(self):
        self.mock_object(self.cinderclient.volumes, 'terminate_connection')
        self.api.terminate_connection(self.ctx, 'id1', 'connector')
        self.cinderclient.volumes.terminate_connection.\
            assert_called_once_with('id1', 'connector')

    def test_delete(self):
        self.mock_object(self.cinderclient.volumes, 'delete')
        self.api.delete(self.ctx, 'id1')
        self.cinderclient.volumes.delete.assert_called_once_with('id1')

    def test_get_snapshot(self):
        snapshot_id = 'snapshot_id1'
        result = self.api.get_snapshot(self.ctx, snapshot_id)
        self.assertEqual(snapshot_id, result['id'])

    def test_get_snapshot_failed(self):
        cinder.cinderclient.side_effect = cinder_exception.NotFound(404)
        snapshot_id = 'snapshot_id'
        self.assertRaises(exception.VolumeSnapshotNotFound,
                          self.api.get_snapshot, self.ctx, snapshot_id)

    def test_get_all_snapshots(self):
        cinder._untranslate_snapshot_summary_view.return_value = ['id1', 'id2']
        self.assertEqual([{
            'id': 'id1'
        }, {
            'id': 'id2'
        }], self.api.get_all_snapshots(self.ctx))

    def test_create_snapshot(self):
        result = self.api.create_snapshot(self.ctx, {'id': 'id1'}, '', '')
        self.assertEqual('created_id', result['id'])

    def test_create_force(self):
        result = self.api.create_snapshot_force(self.ctx, {'id': 'id1'}, '',
                                                '')
        self.assertEqual('created_id', result['id'])

    def test_delete_snapshot(self):
        self.mock_object(self.cinderclient.volume_snapshots, 'delete')
        self.api.delete_snapshot(self.ctx, 'id1')
        self.cinderclient.volume_snapshots.delete.assert_called_once_with(
            'id1')
Ejemplo n.º 12
0
    def test_get_failed_badrequest(self, mock_cinderclient):
        mock_cinderclient.return_value.volumes.get.side_effect = (
            cinder_exception.BadRequest(400, '400'))

        self.assertRaises(exception.InvalidInput, self.api.get, self.ctx,
                          'id1')
Ejemplo n.º 13
0
 def test_translate_cinder_exception_cinder_bad_request(self):
     self._do_translate_cinder_exception_test(
         cinder_exception.BadRequest(400, '400'), exception.InvalidInput)
Ejemplo n.º 14
0
 def get(self, tenant_id, **kwargs):
     if "usage" not in kwargs:
         raise exc.BadRequest("There is no arg 'usage' in request")
     return FAKE_QUOTAS