Add ability to skip yaml loading
Added a flag, 'load_yaml_config' that defaults to True. If set to false, no clouds.yaml files will be loaded. This is beneficial if os-client-config wants to be used inside of a service where end-user clouds.yaml files would make things more confusing. Change-Id: Idbc82bb931e9edf1bbcc575237c0e202e219c218
This commit is contained in:
parent
cbb38f38bc
commit
81e04fcec6
@ -24,7 +24,8 @@ __version__ = pbr.version.VersionInfo('os_client_config').version_string()
|
||||
|
||||
|
||||
def get_config(service_key=None, options=None, **kwargs):
|
||||
config = OpenStackConfig()
|
||||
load_yaml_config = kwargs.pop('load_yaml_config', True)
|
||||
config = OpenStackConfig(load_yaml_config=load_yaml_config)
|
||||
if options:
|
||||
config.register_argparse_arguments(options, sys.argv, service_key)
|
||||
parsed_options = options.parse_known_args(sys.argv)
|
||||
|
@ -173,13 +173,19 @@ class OpenStackConfig(object):
|
||||
def __init__(self, config_files=None, vendor_files=None,
|
||||
override_defaults=None, force_ipv4=None,
|
||||
envvar_prefix=None, secure_files=None,
|
||||
pw_func=None, session_constructor=None):
|
||||
pw_func=None, session_constructor=None,
|
||||
load_yaml_config=True):
|
||||
self.log = _log.setup_logging(__name__)
|
||||
self._session_constructor = session_constructor
|
||||
|
||||
self._config_files = config_files or CONFIG_FILES
|
||||
self._secure_files = secure_files or SECURE_FILES
|
||||
self._vendor_files = vendor_files or VENDOR_FILES
|
||||
if load_yaml_config:
|
||||
self._config_files = config_files or CONFIG_FILES
|
||||
self._secure_files = secure_files or SECURE_FILES
|
||||
self._vendor_files = vendor_files or VENDOR_FILES
|
||||
else:
|
||||
self._config_files = []
|
||||
self._secure_files = []
|
||||
self._vendor_files = []
|
||||
|
||||
config_file_override = os.environ.pop('OS_CLIENT_CONFIG_FILE', None)
|
||||
if config_file_override:
|
||||
|
@ -16,6 +16,7 @@ import argparse
|
||||
import copy
|
||||
import os
|
||||
|
||||
import extras
|
||||
import fixtures
|
||||
import testtools
|
||||
import yaml
|
||||
@ -577,6 +578,37 @@ class TestConfigArgparse(base.TestCase):
|
||||
self.assertEqual(cc.region_name, 'region2')
|
||||
self.assertEqual('my-network', cc.config['external_network'])
|
||||
|
||||
def test_get_one_cloud_no_yaml_no_cloud(self):
|
||||
c = config.OpenStackConfig(load_yaml_config=False)
|
||||
|
||||
self.assertRaises(
|
||||
exceptions.OpenStackConfigException,
|
||||
c.get_one_cloud,
|
||||
cloud='_test_cloud_regions', region_name='region2', argparse=None)
|
||||
|
||||
def test_get_one_cloud_no_yaml(self):
|
||||
c = config.OpenStackConfig(load_yaml_config=False)
|
||||
|
||||
cc = c.get_one_cloud(
|
||||
region_name='region2', argparse=None,
|
||||
**base.USER_CONF['clouds']['_test_cloud_regions'])
|
||||
# Not using assert_cloud_details because of cache settings which
|
||||
# are not present without the file
|
||||
self.assertIsInstance(cc, cloud_config.CloudConfig)
|
||||
self.assertTrue(extras.safe_hasattr(cc, 'auth'))
|
||||
self.assertIsInstance(cc.auth, dict)
|
||||
self.assertIsNone(cc.cloud)
|
||||
self.assertIn('username', cc.auth)
|
||||
self.assertEqual('testuser', cc.auth['username'])
|
||||
self.assertEqual('testpass', cc.auth['password'])
|
||||
self.assertFalse(cc.config['image_api_use_tasks'])
|
||||
self.assertTrue('project_name' in cc.auth or 'project_id' in cc.auth)
|
||||
if 'project_name' in cc.auth:
|
||||
self.assertEqual('testproject', cc.auth['project_name'])
|
||||
elif 'project_id' in cc.auth:
|
||||
self.assertEqual('testproject', cc.auth['project_id'])
|
||||
self.assertEqual(cc.region_name, 'region2')
|
||||
|
||||
def test_fix_env_args(self):
|
||||
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
|
||||
vendor_files=[self.vendor_yaml])
|
||||
|
7
releasenotes/notes/load-yaml-3177efca78e5c67a.yaml
Normal file
7
releasenotes/notes/load-yaml-3177efca78e5c67a.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
features:
|
||||
- Added a flag, 'load_yaml_config' that defaults to True.
|
||||
If set to false, no clouds.yaml files will be loaded. This
|
||||
is beneficial if os-client-config wants to be used inside of
|
||||
a service where end-user clouds.yaml files would make things
|
||||
more confusing.
|
Loading…
x
Reference in New Issue
Block a user