X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=deploy%2Fcommon.py;h=80832e201dc242b382b31897e738f126469ea942;hb=3e469e46e9766b1b4d443167e64e2887140c107c;hp=9c0f8abd182ef5be8d92bf7786afb9bcb37b9359;hpb=294150c7f9e36477ff0a25f947fb2c8002999a3b;p=fuel.git diff --git a/deploy/common.py b/deploy/common.py index 9c0f8abd1..80832e201 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 @@ -17,6 +18,7 @@ import shutil import stat import errno import time +import shlex N = {'id': 0, 'status': 1, 'name': 2, 'cluster': 3, 'ip': 4, 'mac': 5, 'roles': 6, 'pending_roles': 7, 'online': 8, 'group_id': 9} @@ -36,9 +38,23 @@ if os.path.isfile(LOGFILE): out_handler = logging.FileHandler(LOGFILE, mode='w') out_handler.setFormatter(formatter) LOG.addHandler(out_handler) -os.chmod(LOGFILE, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) +os.chmod(LOGFILE, 0664) + + +def mask_arguments(cmd, mask_args, mask_str): + cmd_line = shlex.split(cmd) + 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) -def exec_cmd(cmd, check=True, attempts=1, delay=5, verbose=False): # a negative value means forever while attempts != 0: attempts = attempts - 1 @@ -52,18 +68,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