Fixes Glance Registry V2 client
Add an optional configuration step to glance.db.get_api(). This step is then used in glance.db.registry.api in order to ensure that the registry client has been configured in time for the registry db driver's use. Closes bug: #1302345 Change-Id: Id2c52c423b411ec20bdfa76ee91837c98b1613ef Co-Authored-By: Mark J. Washenberger <mark.washenberger@markwash.net>
This commit is contained in:
parent
a18cbfd029
commit
abf2dd8ee8
|
@ -31,7 +31,10 @@ CONF.import_opt('metadata_encryption_key', 'glance.common.config')
|
|||
|
||||
|
||||
def get_api():
|
||||
return importutils.import_module(CONF.data_api)
|
||||
api = importutils.import_module(CONF.data_api)
|
||||
if hasattr(api, 'configure'):
|
||||
api.configure()
|
||||
return api
|
||||
|
||||
|
||||
def unwrap(db_api):
|
||||
|
|
|
@ -37,6 +37,10 @@ from glance.registry.client.v2 import api
|
|||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def configure():
|
||||
api.configure_registry_client()
|
||||
|
||||
|
||||
def _get_client(func):
|
||||
"""Injects a client instance to the each function
|
||||
|
||||
|
|
|
@ -13,8 +13,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import glance.db.registry.api
|
||||
from glance.registry.client.v2 import api
|
||||
import glance.db
|
||||
from glance.tests import functional
|
||||
import glance.tests.functional.db as db_tests
|
||||
from glance.tests.functional.db import base
|
||||
|
@ -22,8 +21,8 @@ from glance.tests.functional.db import base
|
|||
|
||||
def get_db(config):
|
||||
config(group='database', connection='sqlite://')
|
||||
api.configure_registry_client()
|
||||
return glance.db.registry.api
|
||||
config(data_api='glance.db.registry.api')
|
||||
return glance.db.get_api()
|
||||
|
||||
|
||||
def reset_db(db_api):
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
import uuid
|
||||
|
||||
import mock
|
||||
from oslo.config import cfg
|
||||
|
||||
from glance.common import crypt
|
||||
|
@ -29,6 +30,28 @@ import glance.tests.utils as test_utils
|
|||
CONF = cfg.CONF
|
||||
CONF.import_opt('metadata_encryption_key', 'glance.common.config')
|
||||
|
||||
|
||||
@mock.patch('glance.openstack.common.importutils.import_module')
|
||||
class TestDbUtilities(test_utils.BaseTestCase):
|
||||
def setUp(self):
|
||||
super(TestDbUtilities, self).setUp()
|
||||
self.config(data_api='silly pants')
|
||||
self.api = mock.Mock()
|
||||
|
||||
def test_get_api_calls_configure_if_present(self, import_module):
|
||||
import_module.return_value = self.api
|
||||
self.assertEqual(glance.db.get_api(), self.api)
|
||||
import_module.assert_called_once_with('silly pants')
|
||||
self.api.configure.assert_called_once_with()
|
||||
|
||||
def test_get_api_skips_configure_if_missing(self, import_module):
|
||||
import_module.return_value = self.api
|
||||
del self.api.configure
|
||||
self.assertEqual(glance.db.get_api(), self.api)
|
||||
import_module.assert_called_once_with('silly pants')
|
||||
self.assertFalse(hasattr(self.api, 'configure'))
|
||||
|
||||
|
||||
UUID1 = 'c80a1a6c-bd1f-41c5-90ee-81afedb1d58d'
|
||||
UUID2 = 'a85abd86-55b3-4d5b-b0b4-5d0a6e6042fc'
|
||||
UUID3 = '971ec09a-8067-4bc8-a91f-ae3557f1c4c7'
|
||||
|
|
Loading…
Reference in New Issue