Merge "Add ability to skip yaml loading"

This commit is contained in:
Jenkins 2017-03-07 19:21:48 +00:00 committed by Gerrit Code Review
commit 9c550021d3
4 changed files with 51 additions and 5 deletions

View File

@ -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)

View File

@ -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:

View File

@ -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])

View 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.