V2 RpcApi should register when db pool is enabled

The rpc api controller registers the public methods of db_api
But, use_tpool is True, the thread pool wrapper's methods are
used which would lead to failures.

Fixes Bug #1221037

Change-Id: Iaba10178c7da1548257e2180658c2dc8ba3e048b
This commit is contained in:
sridevik 2013-09-12 08:43:29 -05:00
parent 7d7bf3f04b
commit 52ab24bbac
4 changed files with 41 additions and 3 deletions

View File

@ -42,6 +42,11 @@ def get_api():
return ThreadPoolWrapper(CONF.data_api)
def unwrap(db_api):
if not CONF.use_tpool:
return db_api
return db_api.unwrap()
# attributes common to all models
BASE_MODEL_ATTRS = set(['id', 'created_at', 'updated_at', 'deleted_at',
'deleted'])
@ -286,3 +291,6 @@ class ThreadPoolWrapper(object):
output = tpool.execute(original, *args, **kwargs)
return output
return wrapper
def unwrap(self):
return self.wrapped

View File

@ -48,7 +48,7 @@ class Controller(rpc.Controller):
# db_api as a resource to expose.
db_api = glance.db.get_api()
db_api.setup_db_env()
self.register(db_api)
self.register(glance.db.unwrap(db_api))
def create_resource():

View File

@ -20,6 +20,7 @@ from oslo.config import cfg
import testtools
from glance import db as db_api
import glance.db
from glance.openstack.common import importutils
CONF = cfg.CONF
@ -39,6 +40,18 @@ class DbApiTest(testtools.TestCase):
self.assertFalse(isinstance(dbapi, db_api.ThreadPoolWrapper))
self.assertEqual(importutils.import_module(CONF.data_api), dbapi)
def test_unwrap_dbapi_when_db_pool_is_enabled(self):
CONF.set_override('use_tpool', False)
dbapi = db_api.get_api()
self.assertEqual(importutils.import_module(CONF.data_api),
glance.db.unwrap(dbapi))
def test_unwrap_dbapi_when_db_pool_is_disabled(self):
CONF.set_override('use_tpool', True)
dbapi = db_api.get_api()
self.assertEqual(importutils.import_module(CONF.data_api),
glance.db.unwrap(dbapi))
def method_for_test_1(*args, **kwargs):
return args, kwargs
@ -46,8 +59,6 @@ def method_for_test_1(*args, **kwargs):
class ThreadPoolWrapper(testtools.TestCase):
def test_thread_pool(self):
module = importutils.import_module('glance.tests.functional.db.'
'test_db_api')
CONF.set_override('use_tpool', True)
CONF.set_override('data_api', 'glance.tests.functional.db.'
'test_db_api')
@ -59,6 +70,15 @@ class ThreadPoolWrapper(testtools.TestCase):
dbapi.method_for_test_1(1, 2, kwarg='arg')
tpool.execute.assert_called_with(method_for_test_1, 1, 2, kwarg='arg')
def test_unwrap(self):
CONF.set_override('use_tpool', True)
CONF.set_override('data_api', 'glance.tests.functional.db.'
'test_db_api')
dbapi = db_api.get_api()
self.assertEqual(importutils.import_module(CONF.data_api),
dbapi.unwrap())
def tearDown(self):
super(ThreadPoolWrapper, self).tearDown()
CONF.set_override('use_tpool', False)

View File

@ -1256,3 +1256,13 @@ class TestRegistryRPC(base.IsolatedUnitTest):
memb_list = json.loads(res.body)[0]
self.assertEquals(len(memb_list), 0)
class TestRegistryRPCDBPoolEnabled(TestRegistryRPC):
def setUp(self):
CONF.set_override('use_tpool', True)
super(TestRegistryRPCDBPoolEnabled, self).setUp()
def tearDown(self):
super(TestRegistryRPCDBPoolEnabled, self).tearDown()
CONF.set_override('use_tpool', False)