summaryrefslogtreecommitdiffstats
path: root/deploy
diff options
context:
space:
mode:
authorJonas Bjurel <jonas.bjurel@ericsson.com>2016-06-16 13:51:55 +0000
committerGerrit Code Review <gerrit@172.30.200.206>2016-06-16 13:51:55 +0000
commitf2c53cb47c52f295568639919c407080ecf92b03 (patch)
tree133143f1775def64962b7f196ae4e1716b6b60ce /deploy
parentaace3a2620c1c49932c7c82ed6cc154c78d19bef (diff)
parentb89bb115265ecda35dac2f9d4356bfbf0368faed (diff)
Merge "Add command line argument masking for exec_cmd"
Diffstat (limited to 'deploy')
-rw-r--r--deploy/common.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/deploy/common.py b/deploy/common.py
index 9c0f8abd1..9654b3771 100644
--- a/deploy/common.py
+++ b/deploy/common.py
@@ -1,6 +1,7 @@
###############################################################################
# Copyright (c) 2015 Ericsson AB and others.
# szilard.cserey@ericsson.com
+# peter.barabas@ericsson.com
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
@@ -38,7 +39,21 @@ out_handler.setFormatter(formatter)
LOG.addHandler(out_handler)
os.chmod(LOGFILE, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
-def exec_cmd(cmd, check=True, attempts=1, delay=5, verbose=False):
+
+def mask_arguments(cmd, mask_args, mask_str):
+ cmd_line = cmd.split()
+ for pos in mask_args:
+ # Don't mask the actual command; also check if we don't reference
+ # beyond bounds
+ if pos == 0 or pos >= len(cmd_line):
+ continue
+ cmd_line[pos] = mask_str
+ return ' '.join(cmd_line)
+
+
+def exec_cmd(cmd, check=True, attempts=1, delay=5, verbose=False, mask_args=[], mask_str='*****'):
+ masked_cmd = mask_arguments(cmd, mask_args, mask_str)
+
# a negative value means forever
while attempts != 0:
attempts = attempts - 1
@@ -52,18 +67,18 @@ def exec_cmd(cmd, check=True, attempts=1, delay=5, verbose=False):
break
time.sleep(delay)
if verbose:
- log('%d attempts left: %s' % (attempts, cmd))
+ log('%d attempts left: %s' % (attempts, masked_cmd))
response = response.strip()
if check:
if return_code > 0:
stderr = stderr.strip()
- print "Failed command: " + str(cmd)
+ print "Failed command: " + str(masked_cmd)
print "Command returned response: " + str(stderr)
print "Command return code: " + str(return_code)
raise Exception(stderr)
else:
- print "Command: " + str(cmd)
+ print "Command: " + str(masked_cmd)
print str(response)
return response
return response, return_code