Due to a bug in python, deepcopy does not work on dictionaries with lists as values. This patch adds a workaround function to utils and uses them when in the functions updating SSH keys.
Signed-off-by: Helga Velroyen <[email protected]> --- lib/backend.py | 5 ++--- lib/utils/algo.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/backend.py b/lib/backend.py index ce5bb6a..bce7b2d 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -60,7 +60,6 @@ import stat import tempfile import time import zlib -import copy import contextlib import collections @@ -1586,7 +1585,7 @@ def AddNodeSshKeyBulk(node_list, base_data[constants.SSHS_SSH_AUTHORIZED_KEYS] = \ (constants.SSHS_ADD, keys_by_uuid_auth) - pot_mc_data = copy.deepcopy(base_data) + pot_mc_data = utils.CopyDictWithLists(base_data) keys_by_uuid_pub = ssh.QueryPubKeyFile( [node_info.uuid for node_info in node_list if node_info.to_public_keys], @@ -1740,7 +1739,7 @@ def RemoveNodeSshKey(node_uuid, node_name, dircheck=False) ssh.RemoveAuthorizedKeys(auth_key_file, keys[node_uuid]) - pot_mc_data = copy.deepcopy(base_data) + pot_mc_data = utils.CopyDictWithLists(base_data) if from_public_keys: pot_mc_data[constants.SSHS_SSH_PUBLIC_KEYS] = \ diff --git a/lib/utils/algo.py b/lib/utils/algo.py index f4f1074..7ecb829 100644 --- a/lib/utils/algo.py +++ b/lib/utils/algo.py @@ -330,3 +330,24 @@ class RunningTimeout(object): return max(0.0, remaining_timeout) return remaining_timeout + + +def CopyDictWithLists(data): + """Makes a copy of the dictionary containing lists as values. + + Due to a bug in python (http://bugs.python.org/issue1515), deepcopy + fails on dictionaries with nested mutable data structures. As a workaround, + we introduce this poor man's copy function for SSH update data. + + @param data: dictionary with lists as values + @type data: dict of strings to strings and lists of strings + + """ + new_data = {} + for key, value in data.items(): + if isinstance(value, list): + new_value = value[:] + else: + new_value = value + new_data[key] = new_value + return new_data -- 2.6.0.rc2.230.g3dd15c0
