aboutsummaryrefslogtreecommitdiff
path: root/tests/test_merge_yaml.py
diff options
context:
space:
mode:
authorDoug Szumski <doug@stackhpc.com>2018-10-30 15:38:14 +0000
committerDoug Szumski <doug@stackhpc.com>2018-11-05 18:09:22 +0000
commitbadb41a49c4b304bc525ba3fb997ef9288e3a6e9 (patch)
tree3f7cdfa2f919e6442ffc05dd672b99835dfcaf10 /tests/test_merge_yaml.py
parent58eec5ca12aa3e2c0bbfc7cfb00beee82ff199d2 (diff)
downloadkolla-ansible-badb41a49c4b304bc525ba3fb997ef9288e3a6e9.tar.gz
kolla-ansible-badb41a49c4b304bc525ba3fb997ef9288e3a6e9.zip
Support merging nested yaml config
Closes-Bug: 1786741 Change-Id: Ic217f3f8194cdcb5e28045e771a0160c1f12280e
Diffstat (limited to 'tests/test_merge_yaml.py')
-rw-r--r--tests/test_merge_yaml.py128
1 files changed, 128 insertions, 0 deletions
diff --git a/tests/test_merge_yaml.py b/tests/test_merge_yaml.py
new file mode 100644
index 000000000..00b56614c
--- /dev/null
+++ b/tests/test_merge_yaml.py
@@ -0,0 +1,128 @@
+#!/usr/bin/env python
+
+# Copyright 2018 StackHPC Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import imp
+import os
+
+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)
+
+
+class MergeYamlConfigTest(base.BaseTestCase):
+
+ def test_merge_no_update(self):
+ initial_conf = {
+ 'foo': 'bar',
+ 'egg': 'spam'
+ }
+ actual = merge_yaml.Utils.update_nested_conf(initial_conf, {})
+ expected = {
+ 'foo': 'bar',
+ 'egg': 'spam'
+ }
+ self.assertDictEqual(actual, expected)
+
+ def test_merge_flat_update_key(self):
+ initial_conf = {
+ 'foo': 'bar',
+ 'egg': 'spam'
+ }
+ actual = merge_yaml.Utils.update_nested_conf(
+ initial_conf, {'egg': 'ham'})
+ expected = {
+ 'foo': 'bar',
+ 'egg': 'ham'
+ }
+ self.assertDictEqual(actual, expected)
+
+ def test_merge_flat_new_key(self):
+ initial_conf = {
+ 'foo': 'bar',
+ 'egg': 'spam'
+ }
+ actual = merge_yaml.Utils.update_nested_conf(
+ initial_conf, {'spam': 'ham'})
+ expected = {
+ 'foo': 'bar',
+ 'egg': 'spam',
+ 'spam': 'ham'
+ }
+ self.assertDictEqual(actual, expected)
+
+ def test_merge_nested_update_key(self):
+ initial_conf = {
+ 'foo': {
+ 'a': 'b',
+ },
+ 'bar': {
+ 'a': False,
+ 'b': 'INFO'
+ }
+ }
+ actual = merge_yaml.Utils.update_nested_conf(
+ initial_conf, {'bar': {'a': True}})
+ expected = {
+ 'foo': {
+ 'a': 'b',
+ },
+ 'bar': {
+ 'a': True,
+ 'b': 'INFO'
+ }
+ }
+ self.assertDictEqual(actual, expected)
+
+ def test_merge_nested_new_key(self):
+ initial_conf = {
+ 'foo': {
+ 'a': 'b',
+ 'c': 30
+ }
+ }
+ actual = merge_yaml.Utils.update_nested_conf(
+ initial_conf, {'egg': {'spam': 10}})
+ expected = {
+ 'foo': {
+ 'a': 'b',
+ 'c': 30,
+ },
+ 'egg': {
+ 'spam': 10,
+ }
+ }
+ self.assertDictEqual(actual, expected)
+
+ def test_merge_nested_new_nested_key(self):
+ initial_conf = {
+ 'foo': {
+ 'a': 'b',
+ 'c': 30
+ }
+ }
+ actual = merge_yaml.Utils.update_nested_conf(
+ initial_conf, {'foo': {'spam': 10}})
+ expected = {
+ 'foo': {
+ 'a': 'b',
+ 'c': 30,
+ 'spam': 10,
+ }
+ }
+ self.assertDictEqual(actual, expected)