summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDharini Chandrasekar <dharini.chandrasekar@intel.com>2017-02-09 18:34:02 +0000
committerDharini Chandrasekar <dharini.chandrasekar@intel.com>2017-02-09 18:44:08 +0000
commitc74e6bb8ddee8ad1ad2479f3fcfd8396dedef55b (patch)
treed23b54d37b3796c927e25862034243616c282bd8
parentb628acec24b256c7121f1fe85e0a2ab25fe335df (diff)
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
Notes
Notes (review): Code-Review+1: Sean McGinnis <sean.mcginnis@gmail.com> Code-Review+2: Brian Rosmaita <rosmaita.fossdev@gmail.com> Code-Review+2: Abhishek Kekane <abhishek.kekane@nttdata.com> Workflow+1: Brian Rosmaita <rosmaita.fossdev@gmail.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Thu, 10 Aug 2017 15:59:51 +0000 Reviewed-on: https://review.openstack.org/431709 Project: openstack/glance Branch: refs/heads/master
-rw-r--r--glance/api/v1/upload_utils.py2
-rw-r--r--glance/db/__init__.py20
-rw-r--r--glance/tests/unit/test_db.py5
3 files changed, 24 insertions, 3 deletions
diff --git a/glance/api/v1/upload_utils.py b/glance/api/v1/upload_utils.py
index bfdd264..a4710ee 100644
--- a/glance/api/v1/upload_utils.py
+++ b/glance/api/v1/upload_utils.py
@@ -84,7 +84,7 @@ def upload_data_to_store(req, image_meta, image_data, store, notifier):
84 """ 84 """
85 image_id = image_meta['id'] 85 image_id = image_meta['id']
86 86
87 db_api = glance.db.get_api() 87 db_api = glance.db.get_api(v1_mode=True)
88 image_size = image_meta.get('size') 88 image_size = image_meta.get('size')
89 89
90 try: 90 try:
diff --git a/glance/db/__init__.py b/glance/db/__init__.py
index 914fe2a..238c163 100644
--- a/glance/db/__init__.py
+++ b/glance/db/__init__.py
@@ -36,10 +36,26 @@ CONF.import_opt('image_size_cap', 'glance.common.config')
36CONF.import_opt('metadata_encryption_key', 'glance.common.config') 36CONF.import_opt('metadata_encryption_key', 'glance.common.config')
37 37
38 38
39def get_api(): 39def get_api(v1_mode=False):
40 api = importutils.import_module(CONF.data_api) 40 """
41 When using v2_registry with v2_api or alone, it is essential that the opt
42 'data_api' be set to 'glance.db.registry.api'. This requires us to
43 differentiate what this method returns as the db api. i.e., we do not want
44 to return 'glance.db.registry.api' for a call from v1 api.
45 Reference bug #1516706
46 """
47 if v1_mode:
48 # prevent v1_api from talking to v2_registry.
49 if CONF.data_api == 'glance.db.simple.api':
50 api = importutils.import_module(CONF.data_api)
51 else:
52 api = importutils.import_module('glance.db.sqlalchemy.api')
53 else:
54 api = importutils.import_module(CONF.data_api)
55
41 if hasattr(api, 'configure'): 56 if hasattr(api, 'configure'):
42 api.configure() 57 api.configure()
58
43 return api 59 return api
44 60
45 61
diff --git a/glance/tests/unit/test_db.py b/glance/tests/unit/test_db.py
index 28c50af..55ff0b1 100644
--- a/glance/tests/unit/test_db.py
+++ b/glance/tests/unit/test_db.py
@@ -55,6 +55,11 @@ class TestDbUtilities(test_utils.BaseTestCase):
55 import_module.assert_called_once_with('silly pants') 55 import_module.assert_called_once_with('silly pants')
56 self.assertFalse(hasattr(self.api, 'configure')) 56 self.assertFalse(hasattr(self.api, 'configure'))
57 57
58 def test_get_api_calls_for_v1_api(self, import_module):
59 api = glance.db.get_api(v1_mode=True)
60 self.assertNotEqual(api, self.api)
61 import_module.assert_called_once_with('glance.db.sqlalchemy.api')
62 api.configure.assert_called_once_with()
58 63
59UUID1 = 'c80a1a6c-bd1f-41c5-90ee-81afedb1d58d' 64UUID1 = 'c80a1a6c-bd1f-41c5-90ee-81afedb1d58d'
60UUID2 = 'a85abd86-55b3-4d5b-b0b4-5d0a6e6042fc' 65UUID2 = 'a85abd86-55b3-4d5b-b0b4-5d0a6e6042fc'