Merge "Prevent v1_api from making requests to v2_registry"
This commit is contained in:
commit
345db72180
@ -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:
|
||||
|
@ -34,10 +34,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…
x
Reference in New Issue
Block a user