File tree Expand file tree Collapse file tree 4 files changed +34
-5
lines changed Expand file tree Collapse file tree 4 files changed +34
-5
lines changed Original file line number Diff line number Diff line change 31
31
32
32
33
33
def get_api ():
34
- return importutils .import_module (CONF .data_api )
34
+ api = importutils .import_module (CONF .data_api )
35
+ if hasattr (api , 'configure' ):
36
+ api .configure ()
37
+ return api
35
38
36
39
37
40
def unwrap (db_api ):
Original file line number Diff line number Diff line change 37
37
LOG = logging .getLogger (__name__ )
38
38
39
39
40
+ def configure ():
41
+ api .configure_registry_client ()
42
+
43
+
40
44
def _get_client (func ):
41
45
"""Injects a client instance to the each function
42
46
Original file line number Diff line number Diff line change 13
13
# License for the specific language governing permissions and limitations
14
14
# under the License.
15
15
16
- import glance .db .registry .api
17
- from glance .registry .client .v2 import api
16
+ import glance .db
18
17
from glance .tests import functional
19
18
import glance .tests .functional .db as db_tests
20
19
from glance .tests .functional .db import base
21
20
22
21
23
22
def get_db (config ):
24
23
config (group = 'database' , connection = 'sqlite://' )
25
- api . configure_registry_client ( )
26
- return glance .db .registry . api
24
+ config ( data_api = 'glance.db.registry.api' )
25
+ return glance .db .get_api ()
27
26
28
27
29
28
def reset_db (db_api ):
Original file line number Diff line number Diff line change 16
16
17
17
import uuid
18
18
19
+ import mock
19
20
from oslo .config import cfg
20
21
21
22
from glance .common import crypt
29
30
CONF = cfg .CONF
30
31
CONF .import_opt ('metadata_encryption_key' , 'glance.common.config' )
31
32
33
+
34
+ @mock .patch ('glance.openstack.common.importutils.import_module' )
35
+ class TestDbUtilities (test_utils .BaseTestCase ):
36
+ def setUp (self ):
37
+ super (TestDbUtilities , self ).setUp ()
38
+ self .config (data_api = 'silly pants' )
39
+ self .api = mock .Mock ()
40
+
41
+ def test_get_api_calls_configure_if_present (self , import_module ):
42
+ import_module .return_value = self .api
43
+ self .assertEqual (glance .db .get_api (), self .api )
44
+ import_module .assert_called_once_with ('silly pants' )
45
+ self .api .configure .assert_called_once_with ()
46
+
47
+ def test_get_api_skips_configure_if_missing (self , import_module ):
48
+ import_module .return_value = self .api
49
+ del self .api .configure
50
+ self .assertEqual (glance .db .get_api (), self .api )
51
+ import_module .assert_called_once_with ('silly pants' )
52
+ self .assertFalse (hasattr (self .api , 'configure' ))
53
+
54
+
32
55
UUID1 = 'c80a1a6c-bd1f-41c5-90ee-81afedb1d58d'
33
56
UUID2 = 'a85abd86-55b3-4d5b-b0b4-5d0a6e6042fc'
34
57
UUID3 = '971ec09a-8067-4bc8-a91f-ae3557f1c4c7'
You can’t perform that action at this time.
0 commit comments