1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
# Copyright (c) 2012 Rackspace Hosting
5
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6
# not use this file except in compliance with the License. You may obtain
7
# a copy of the License at
9
# http://www.apache.org/licenses/LICENSE-2.0
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
# License for the specific language governing permissions and limitations
17
"""Unit tests for SQLAlchemy specific code."""
19
from eventlet import db_pool
25
from nova import context
26
from nova.db.sqlalchemy import session
30
class DbPoolTestCase(test.TestCase):
32
super(DbPoolTestCase, self).setUp()
33
self.flags(sql_dbpool_enable=True)
35
self.project_id = 'fake'
36
self.context = context.RequestContext(self.user_id, self.project_id)
38
self.skipTest("Unable to test due to lack of MySQLdb")
40
def test_db_pool_option(self):
41
self.flags(sql_idle_timeout=11, sql_min_pool_size=21,
46
class FakeConnectionPool(db_pool.ConnectionPool):
47
def __init__(self, mod_name, **kwargs):
48
info['module'] = mod_name
49
info['kwargs'] = kwargs
50
super(FakeConnectionPool, self).__init__(mod_name,
53
def connect(self, *args, **kwargs):
54
raise test.TestingException()
56
self.stubs.Set(db_pool, 'ConnectionPool',
59
sql_connection = 'mysql://user:pass@127.0.0.1/nova'
60
self.assertRaises(test.TestingException, session.create_engine,
63
self.assertEqual(info['module'], MySQLdb)
64
self.assertEqual(info['kwargs']['max_idle'], 11)
65
self.assertEqual(info['kwargs']['min_size'], 21)
66
self.assertEqual(info['kwargs']['max_size'], 42)