Allow arbitrary client-specific options
There are occasionally some client-specific things that would be handy to be able to configure about behaviors. For instance, the only config file that ansible's openstack inventory has is clouds.yaml. Rather than teaching os-client-config about such things, allow a pass-through config section. Apply key normalization to _'s like other configs, and merge the clouds and secure files so that the sections behave like other OCC config sections. Change-Id: If307e95006abf6e1efbbd77cfc99e5fdfed6c80a
This commit is contained in:
parent
f4237a809c
commit
837ca71228
@ -253,6 +253,19 @@ class OpenStackConfig(object):
|
||||
# Flag location to hold the peeked value of an argparse timeout value
|
||||
self._argv_timeout = False
|
||||
|
||||
def get_extra_config(self, key, defaults=None):
|
||||
"""Fetch an arbitrary extra chunk of config, laying in defaults.
|
||||
|
||||
:param string key: name of the config section to fetch
|
||||
:param dict defaults: (optional) default values to merge under the
|
||||
found config
|
||||
"""
|
||||
if not defaults:
|
||||
defaults = {}
|
||||
return _merge_clouds(
|
||||
self._normalize_keys(defaults),
|
||||
self._normalize_keys(self.cloud_config.get(key, {})))
|
||||
|
||||
def _load_config_file(self):
|
||||
return self._load_yaml_json_file(self._config_files)
|
||||
|
||||
|
@ -121,6 +121,10 @@ USER_CONF = {
|
||||
'region_name': 'test-region',
|
||||
}
|
||||
},
|
||||
'ansible': {
|
||||
'expand-hostvars': False,
|
||||
'use_hostnames': True,
|
||||
},
|
||||
}
|
||||
SECURE_CONF = {
|
||||
'clouds': {
|
||||
|
@ -372,6 +372,27 @@ class TestConfigArgparse(base.TestCase):
|
||||
|
||||
self.assertDictEqual({'compute_api_version': 1}, fixed_args)
|
||||
|
||||
def test_extra_config(self):
|
||||
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
|
||||
vendor_files=[self.vendor_yaml])
|
||||
|
||||
defaults = {'use_hostnames': False, 'other-value': 'something'}
|
||||
ansible_options = c.get_extra_config('ansible', defaults)
|
||||
|
||||
# This should show that the default for use_hostnames above is
|
||||
# overridden by the value in the config file defined in base.py
|
||||
# It should also show that other-value key is normalized and passed
|
||||
# through even though there is no corresponding value in the config
|
||||
# file, and that expand-hostvars key is normalized and the value
|
||||
# from the config comes through even though there is no default.
|
||||
self.assertDictEqual(
|
||||
{
|
||||
'expand_hostvars': False,
|
||||
'use_hostnames': True,
|
||||
'other_value': 'something',
|
||||
},
|
||||
ansible_options)
|
||||
|
||||
def test_register_argparse_cloud(self):
|
||||
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
|
||||
vendor_files=[self.vendor_yaml])
|
||||
|
Loading…
x
Reference in New Issue
Block a user