diff options
-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]) |