From 30002a4de79900bea9a8d47c1b9e1bea54a152db Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Mon, 26 Mar 2012 09:47:26 -0400 Subject: [PATCH] Improve performance of safe_log(). This patch addresses a minor performance regression in a recent change to this function. This change ensures that the deep copy is only done if we really need to. Previously, the deep copy was being done for all messages that included a 'method', not just messages with a method that contain an argument to be sanitized. Change-Id: I190c5963ecaf70b0aea4e12a2fdc19deb5c1fea2 --- nova/rpc/common.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/nova/rpc/common.py b/nova/rpc/common.py index 03fe14e1..95c24581 100644 --- a/nova/rpc/common.py +++ b/nova/rpc/common.py @@ -127,7 +127,12 @@ class Connection(object): def _safe_log(log_func, msg, msg_data): """Sanitizes the msg_data field before logging.""" - has_method = 'method' in msg_data + SANITIZE = { + 'set_admin_password': ('new_pass',), + 'run_instance': ('admin_password',), + } + + has_method = 'method' in msg_data and msg_data['method'] in SANITIZE has_context_token = '_context_auth_token' in msg_data has_token = 'auth_token' in msg_data @@ -137,10 +142,6 @@ def _safe_log(log_func, msg, msg_data): msg_data = copy.deepcopy(msg_data) if has_method: - SANITIZE = { - 'set_admin_password': ('new_pass',), - 'run_instance': ('admin_password',), - } method = msg_data['method'] if method in SANITIZE: args_to_sanitize = SANITIZE[method]