Prevent v1_api from making requests to v2_registry
In glance v2, when one opts to use v2_registry, it is required that 'data_api' is set to 'glance.db.registry.api'. This is returned by method 'get_api()' which currently simply returns whatever is provided to 'data_api'. This is suitable for v2. But when using v1, this same method is used to fetch the db api. This returns 'glance.db.registry.api' which inturn relies on the registry rpc client (v2). To prevent this, this patch proposes to change what get_api() will return based on whether it is serving v1 api or v2 api. Change-Id: Ifef36859b3f7692769a6991364b6063c9f7cc451 Closes-Bug: 1516706
This commit is contained in:
parent
b628acec24
commit
c74e6bb8dd
|
@ -84,7 +84,7 @@ def upload_data_to_store(req, image_meta, image_data, store, notifier):
|
|||
"""
|
||||
image_id = image_meta['id']
|
||||
|
||||
db_api = glance.db.get_api()
|
||||
db_api = glance.db.get_api(v1_mode=True)
|
||||
image_size = image_meta.get('size')
|
||||
|
||||
try:
|
||||
|
|
|
@ -36,10 +36,26 @@ CONF.import_opt('image_size_cap', 'glance.common.config')
|
|||
CONF.import_opt('metadata_encryption_key', 'glance.common.config')
|
||||
|
||||
|
||||
def get_api():
|
||||
api = importutils.import_module(CONF.data_api)
|
||||
def get_api(v1_mode=False):
|
||||
"""
|
||||
When using v2_registry with v2_api or alone, it is essential that the opt
|
||||
'data_api' be set to 'glance.db.registry.api'. This requires us to
|
||||
differentiate what this method returns as the db api. i.e., we do not want
|
||||
to return 'glance.db.registry.api' for a call from v1 api.
|
||||
Reference bug #1516706
|
||||
"""
|
||||
if v1_mode:
|
||||
# prevent v1_api from talking to v2_registry.
|
||||
if CONF.data_api == 'glance.db.simple.api':
|
||||
api = importutils.import_module(CONF.data_api)
|
||||
else:
|
||||
api = importutils.import_module('glance.db.sqlalchemy.api')
|
||||
else:
|
||||
api = importutils.import_module(CONF.data_api)
|
||||
|
||||
if hasattr(api, 'configure'):
|
||||
api.configure()
|
||||
|
||||
return api
|
||||
|
||||
|
||||
|
|
|
@ -55,6 +55,11 @@ class TestDbUtilities(test_utils.BaseTestCase):
|
|||
import_module.assert_called_once_with('silly pants')
|
||||
self.assertFalse(hasattr(self.api, 'configure'))
|
||||
|
||||
def test_get_api_calls_for_v1_api(self, import_module):
|
||||
api = glance.db.get_api(v1_mode=True)
|
||||
self.assertNotEqual(api, self.api)
|
||||
import_module.assert_called_once_with('glance.db.sqlalchemy.api')
|
||||
api.configure.assert_called_once_with()
|
||||
|
||||
UUID1 = 'c80a1a6c-bd1f-41c5-90ee-81afedb1d58d'
|
||||
UUID2 = 'a85abd86-55b3-4d5b-b0b4-5d0a6e6042fc'
|
||||
|
|
Loading…
Reference in New Issue