diff --git a/lib/utils.py b/lib/utils.py index 48388babe45aa8e823cd8b81200949e90bed97aa..49f4c99d63d369578aaa5561a74918a7286392b1 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -373,32 +373,6 @@ def FingerprintFiles(files): return ret -def CheckDict(target, template, logname=None): - """Ensure a dictionary has a required set of keys. - - For the given dictionaries I{target} and I{template}, ensure - I{target} has all the keys from I{template}. Missing keys are added - with values from template. - - @type target: dict - @param target: the dictionary to update - @type template: dict - @param template: the dictionary holding the default values - @type logname: str or None - @param logname: if not None, causes the missing keys to be - logged with this name - - """ - missing = [] - for k in template: - if k not in target: - missing.append(k) - target[k] = template[k] - - if missing and logname: - logging.warning('%s missing keys %s', logname, ', '.join(missing)) - - def ForceDictType(target, key_types, allowed_values=None): """Force the values of a dict to have certain types. diff --git a/test/ganeti.utils_unittest.py b/test/ganeti.utils_unittest.py index 846b4b44624796b8b3167daf38c24dbb73a21d90..ddb47000da16c8d0f2a75018f0206503b27e1ef7 100755 --- a/test/ganeti.utils_unittest.py +++ b/test/ganeti.utils_unittest.py @@ -40,7 +40,7 @@ from ganeti import constants from ganeti import utils from ganeti import errors from ganeti.utils import IsProcessAlive, RunCmd, \ - RemoveFile, CheckDict, MatchNameComponent, FormatUnit, \ + RemoveFile, MatchNameComponent, FormatUnit, \ ParseUnit, AddAuthorizedKey, RemoveAuthorizedKey, \ ShellQuote, ShellQuoteArgs, TcpPing, ListVisibleFiles, \ SetEtcHostsEntry, RemoveEtcHostsEntry, FirstFree, OwnIpAddress, \ @@ -306,27 +306,6 @@ class TestRename(unittest.TestCase): mkdir=True) -class TestCheckdict(unittest.TestCase): - """Test case for the CheckDict function""" - - def testAdd(self): - """Test that CheckDict adds a missing key with the correct value""" - - tgt = {'a':1} - tmpl = {'b': 2} - CheckDict(tgt, tmpl) - if 'b' not in tgt or tgt['b'] != 2: - self.fail("Failed to update dict") - - - def testNoUpdate(self): - """Test that CheckDict does not overwrite an existing key""" - tgt = {'a':1, 'b': 3} - tmpl = {'b': 2} - CheckDict(tgt, tmpl) - self.failUnlessEqual(tgt['b'], 3) - - class TestMatchNameComponent(unittest.TestCase): """Test case for the MatchNameComponent function"""