aboutsummaryrefslogtreecommitdiff
path: root/tests/test_merge_yaml.py
diff options
context:
space:
mode:
authorWill Szumski <will@stackhpc.com>2019-09-30 10:49:39 +0100
committerWill Szumski <will@stackhpc.com>2020-05-11 13:47:12 +0100
commit69a6acf7a80b89673db596b1635dc272eb54f3b6 (patch)
tree0af849f881fd00f5b9ba424b2ec594fdd6157c95 /tests/test_merge_yaml.py
parent4fcbdd77401691dde1c433b6c40e9ddbb506070d (diff)
downloadkolla-ansible-69a6acf7a80b89673db596b1635dc272eb54f3b6.tar.gz
kolla-ansible-69a6acf7a80b89673db596b1635dc272eb54f3b6.zip
Add extend_lists option to merge_yaml
This allows you to extend lists in yaml config. This is useful, for example, in prometheus.yml, where it would be nice to be able to extend the scrape_configs to include exporters that aren't packaged with kolla-ansible. This would provide a mechanism to do so. Change-Id: I7a10e363f42e8ffaae3c0d2c2a758853e2cab7e1 Related: blueprint custom-prometheus-targets
Diffstat (limited to 'tests/test_merge_yaml.py')
-rw-r--r--tests/test_merge_yaml.py50
1 files changed, 49 insertions, 1 deletions
diff --git a/tests/test_merge_yaml.py b/tests/test_merge_yaml.py
index 00b56614c..5c6baa182 100644
--- a/tests/test_merge_yaml.py
+++ b/tests/test_merge_yaml.py
@@ -16,12 +16,12 @@
import imp
import os
+from ansible.errors import AnsibleModuleError
from oslotest import base
PROJECT_DIR = os.path.abspath(os.path.join(os. path.dirname(__file__), '../'))
MERGE_YAML_FILE = os.path.join(PROJECT_DIR,
'ansible/action_plugins/merge_yaml.py')
-
merge_yaml = imp.load_source('merge_yaml', MERGE_YAML_FILE)
@@ -126,3 +126,51 @@ class MergeYamlConfigTest(base.BaseTestCase):
}
}
self.assertDictEqual(actual, expected)
+
+ def test_merge_nested_extend_lists(self):
+ initial_conf = {
+ 'level0': {
+ 'level1': {
+ "mylist": ["one", "two"]
+ },
+ }
+ }
+
+ extension = {
+ 'level0': {
+ 'level1': {
+ "mylist": ["three"]
+ },
+ }
+ }
+
+ actual = merge_yaml.Utils.update_nested_conf(
+ initial_conf, extension, extend_lists=True)
+ expected = {
+ 'level0': {
+ 'level1': {
+ "mylist": ["one", "two", "three"]
+ },
+ }
+ }
+ self.assertDictEqual(actual, expected)
+
+ def test_merge_nested_extend_lists_mismatch_types(self):
+ initial_conf = {
+ 'level0': {
+ 'level1': {
+ "mylist": ["one", "two"]
+ },
+ }
+ }
+
+ extension = {
+ 'level0': {
+ 'level1': {
+ "mylist": "three"
+ },
+ }
+ }
+ with self.assertRaisesRegex(AnsibleModuleError, "Failure merging key"):
+ merge_yaml.Utils.update_nested_conf(
+ initial_conf, extension, extend_lists=True)