]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
misc.deep_merge: Rewrite for readability
authorZack Cerza <zack@redhat.com>
Thu, 11 Jul 2024 16:06:31 +0000 (10:06 -0600)
committerZack Cerza <zack@redhat.com>
Thu, 11 Jul 2024 22:48:31 +0000 (16:48 -0600)
Partially enabled by not passing MappingProxyType to it any longer.

Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/misc.py
teuthology/suite/merge.py

index 2a9a73f5072bc6a35d7e5f66f83c4784ac16e815..c3d324a4bcdad8ac5502baad5d7eebc907eea82a 100644 (file)
@@ -18,7 +18,6 @@ import re
 from sys import stdin
 import pprint
 import datetime
-from types import MappingProxyType
 
 from tarfile import ReadError
 
@@ -997,21 +996,18 @@ def deep_merge(a: DeepMerge, b: DeepMerge) -> DeepMerge:
     """
     if b is None:
         return a
-    elif isinstance(a, list):
+    if a is None:
+        return deep_merge(b.__class__(), b)
+    if isinstance(a, list):
         assert isinstance(b, list)
         a.extend(b)
         return a
-    elif isinstance(a, dict):
-        assert isinstance(b, dict) or isinstance(b, MappingProxyType)
+    if isinstance(a, dict):
+        assert isinstance(b, dict)
         for (k, v) in b.items():
             a[k] = deep_merge(a.get(k), v)
         return a
-    elif isinstance(b, dict) or isinstance(b, list):
-        return deep_merge(b.__class__(), b)
-    elif isinstance(b, MappingProxyType):
-        return dict() | b
-    else:
-        return b
+    return b
 
 
 def get_valgrind_args(testdir, name, preamble, v, exit_on_first_error=True):
index 4ae9e05bf7dd1ecd2a8c4863a33d9668bf07b401..f13058e47d0720e38477fb70ab9072ae3277308e 100644 (file)
@@ -14,7 +14,7 @@ log = logging.getLogger(__name__)
 TEUTHOLOGY_TEMPLATE = MappingProxyType({
   "teuthology": {
     "fragments_dropped": [],
-    "meta": MappingProxyType({}),
+    "meta": {},
     "postmerge": [],
   }
 })
@@ -114,7 +114,6 @@ def config_merge(configs, suite_name=None, **kwargs):
     postmerge scripts. Logically, if a filter matches then reject will drop
     the entire job (config) from the list.
     """
-
     seed = kwargs.setdefault('seed', 1)
     if not isinstance(seed, int):
         log.debug("no valid seed input: using 1")
@@ -130,7 +129,7 @@ def config_merge(configs, suite_name=None, **kwargs):
             desc = combine_path(suite_name, desc)
 
         yaml_complete_obj = {}
-        deep_merge(yaml_complete_obj, TEUTHOLOGY_TEMPLATE)
+        deep_merge(yaml_complete_obj, dict(TEUTHOLOGY_TEMPLATE))
         for path in paths:
             if path not in yaml_cache:
                 with open(path) as f: