diff options
author | David Shrewsbury <shrewsbury.dave@gmail.com> | 2015-11-17 15:17:55 -0500 |
---|---|---|
committer | Monty Taylor <mordred@inaugust.com> | 2015-12-14 16:14:47 -0500 |
commit | 837ca712288ceffea5b54ceaeb349d6577f38360 (patch) | |
tree | 6822c3dffe25417e99a815395c05c8b0a505dbfd | |
parent | f4237a809cccbbffce2233b1f283b36a9ebb75c1 (diff) | |
download | os-client-config-837ca712288ceffea5b54ceaeb349d6577f38360.tar.gz |
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
-rw-r--r-- | os_client_config/config.py | 13 | ||||
-rw-r--r-- | os_client_config/tests/base.py | 4 | ||||
-rw-r--r-- | os_client_config/tests/test_config.py | 21 |
3 files changed, 38 insertions, 0 deletions
diff --git a/os_client_config/config.py b/os_client_config/config.py index 70989bf..ab3a003 100644 --- a/os_client_config/config.py +++ b/os_client_config/config.py @@ -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) diff --git a/os_client_config/tests/base.py b/os_client_config/tests/base.py index 6d9e093..fdc50cd 100644 --- a/os_client_config/tests/base.py +++ b/os_client_config/tests/base.py @@ -121,6 +121,10 @@ USER_CONF = { 'region_name': 'test-region', } }, + 'ansible': { + 'expand-hostvars': False, + 'use_hostnames': True, + }, } SECURE_CONF = { 'clouds': { diff --git a/os_client_config/tests/test_config.py b/os_client_config/tests/test_config.py index a6a35ad..98aaf79 100644 --- a/os_client_config/tests/test_config.py +++ b/os_client_config/tests/test_config.py @@ -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]) |