1919from openstackclient .tests .unit .integ import base as test_base
2020from openstackclient .tests .unit import test_shell
2121
22+ # NOTE(dtroyer): Attempt the import to detect if the SDK installed is new
23+ # enough to contain the os_client_config code. If so, use
24+ # that path for mocks.
25+ CONFIG_MOCK_BASE = "openstack.config.loader"
26+ try :
27+ from openstack .config import defaults # noqa
28+ except ImportError :
29+ # Fall back to os-client-config
30+ CONFIG_MOCK_BASE = "os_client_config.config"
31+
2232
2333class TestIntegShellCliV2 (test_base .TestInteg ):
2434
@@ -389,8 +399,8 @@ def setUp(self):
389399 test_shell .PUBLIC_1 ['public-clouds' ]['megadodo' ]['auth' ]['auth_url' ] \
390400 = test_base .V3_AUTH_URL
391401
392- @mock .patch ("os_client_config.config .OpenStackConfig._load_vendor_file" )
393- @mock .patch ("os_client_config.config .OpenStackConfig._load_config_file" )
402+ @mock .patch (CONFIG_MOCK_BASE + " .OpenStackConfig._load_vendor_file" )
403+ @mock .patch (CONFIG_MOCK_BASE + " .OpenStackConfig._load_config_file" )
394404 def test_shell_args_precedence_1 (self , config_mock , vendor_mock ):
395405 """Precedence run 1
396406
@@ -405,6 +415,7 @@ def vendor_mock_return():
405415 return ('file.yaml' , copy .deepcopy (test_shell .PUBLIC_1 ))
406416 vendor_mock .side_effect = vendor_mock_return
407417
418+ print ("CONFIG_MOCK_BASE=%s" % CONFIG_MOCK_BASE )
408419 _shell = shell .OpenStackShell ()
409420 _shell .run (
410421 "--os-password qaz configuration show" .split (),
@@ -458,8 +469,8 @@ def vendor_mock_return():
458469 # +env, +cli, +occ
459470 # see test_shell_args_precedence_2()
460471
461- @mock .patch ("os_client_config.config .OpenStackConfig._load_vendor_file" )
462- @mock .patch ("os_client_config.config .OpenStackConfig._load_config_file" )
472+ @mock .patch (CONFIG_MOCK_BASE + " .OpenStackConfig._load_vendor_file" )
473+ @mock .patch (CONFIG_MOCK_BASE + " .OpenStackConfig._load_config_file" )
463474 def test_shell_args_precedence_2 (self , config_mock , vendor_mock ):
464475 """Precedence run 2
465476
@@ -474,6 +485,7 @@ def vendor_mock_return():
474485 return ('file.yaml' , copy .deepcopy (test_shell .PUBLIC_1 ))
475486 vendor_mock .side_effect = vendor_mock_return
476487
488+ print ("CONFIG_MOCK_BASE=%s" % CONFIG_MOCK_BASE )
477489 _shell = shell .OpenStackShell ()
478490 _shell .run (
479491 "--os-username zarquon --os-password qaz "
0 commit comments