Browse Source

Merge "fixes how os-apply-config handles invalid json"

Zuul 1 year ago
parent
commit
81baf73ae8
2 changed files with 8 additions and 2 deletions
  1. 1
    1
      os_apply_config/collect_config.py
  2. 7
    1
      os_apply_config/tests/test_collect_config.py

+ 1
- 1
os_apply_config/collect_config.py View File

@@ -58,7 +58,7 @@ def merge_configs(parsed_configs):
58 58
     '''Returns deep-merged dict from passed list of dicts.'''
59 59
     final_conf = {}
60 60
     for conf in parsed_configs:
61
-        if conf:
61
+        if conf and isinstance(conf, dict):
62 62
             final_conf = _deep_merge_dict(final_conf, conf)
63 63
     return final_conf
64 64
 

+ 7
- 1
os_apply_config/tests/test_collect_config.py View File

@@ -109,6 +109,11 @@ class TestMergeConfigs(testtools.TestCase):
109 109
         result = collect_config.merge_configs(type_conflict)
110 110
         self.assertEqual({'a': [7, 8, 9]}, result)
111 111
 
112
+    def test_merge_configs_nested_type_conflict(self):
113
+        type_conflict = [{'a': {'foo': 'bar'}}, {'a': 'shazam'}]
114
+        result = collect_config.merge_configs(type_conflict)
115
+        self.assertEqual({'a': 'shazam'}, result)
116
+
112 117
     def test_merge_configs_list_conflict(self):
113 118
         list_conflict = [{'a': [1, 2, 3]},
114 119
                          {'a': [4, 5, 6]}]
@@ -116,6 +121,7 @@ class TestMergeConfigs(testtools.TestCase):
116 121
         self.assertEqual({'a': [4, 5, 6]}, result)
117 122
 
118 123
     def test_merge_configs_empty_notdict(self):
119
-        list_conflict = [[], {'a': '1'}, '', None, {'b': '2'}, {}]
124
+        list_conflict = [[], {'a': '1'}, '', None, 'tacocat',
125
+                         {'b': '2'}, {}, 'baseball']
120 126
         result = collect_config.merge_configs(list_conflict)
121 127
         self.assertEqual({'a': '1', 'b': '2'}, result)

Loading…
Cancel
Save