'Test volume creation with default volume type.'

@mock.patch('cinder.quota.QUOTAS.rollback', new=mock.MagicMock())
@mock.patch('cinder.quota.QUOTAS.commit', new=mock.MagicMock())
@mock.patch('cinder.quota.QUOTAS.reserve', return_value=['RESERVATION'])
def test_create_volume_with_volume_type(self, _mock_reserve):

    volume_api = cinder.volume.api.API()
    volume = volume_api.create(self.context, 1, 'name', 'description')
    self.assertIsNone(volume['volume_type_id'])
    self.assertIsNone(volume['encryption_key_id'])
    vol_type = conf_fixture.def_vol_type
    db.volume_type_create(context.get_admin_context(), {'name': vol_type, 'extra_specs': {}})
    db_vol_type = db.volume_type_get_by_name(context.get_admin_context(), vol_type)
    volume = volume_api.create(self.context, 1, 'name', 'description')
    self.assertEqual(db_vol_type.get('id'), volume['volume_type_id'])
    self.assertIsNone(volume['encryption_key_id'])
    vol_type = 'test'
    db.volume_type_create(context.get_admin_context(), {'name': vol_type, 'extra_specs': {}})
    db_vol_type = db.volume_type_get_by_name(context.get_admin_context(), vol_type)
    volume = volume_api.create(self.context, 1, 'name', 'description', volume_type=db_vol_type)
    self.assertEqual(db_vol_type.get('id'), volume['volume_type_id'])
