From a4a6a4fa72553f29b3fe89b15b18e6996738cba6 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 11 Nov 2020 17:21:58 -0500 Subject: [PATCH] Add -q option to dump mmapplypolicy command and quit --- gpfs-scan-files.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/gpfs-scan-files.py b/gpfs-scan-files.py index 0300b88..251f08b 100755 --- a/gpfs-scan-files.py +++ b/gpfs-scan-files.py @@ -69,10 +69,10 @@ def _ncheck_output(cmds): def get_hostname(): return os.uname()[1] -def run_mmapplypolicy(exefile, target_dir, policy_file, temp_dir, out_dir, include_dir_file): +def run_mmapplypolicy(exefile, target_dir, policy_file, temp_dir, out_dir, include_dir_file, cmdonly=False): # Ensure we are runnning mmapplypolicy on the correct host hostname = get_hostname() - if not hostname in MMAPPLY_HOSTS: + if not hostname in MMAPPLY_HOSTS and not cmdonly: print_error(" When using the -s option, you must run on one of the DDN NSD nodes (%s)" % ",".join(MMAPPLY_HOSTS)) # Create output directories if not os.path.isdir(out_dir ): os.makedirs(out_dir ) @@ -104,6 +104,9 @@ def run_mmapplypolicy(exefile, target_dir, policy_file, temp_dir, out_dir, inclu cmd = "%(exefile)s %(target_dir)s -s %(temp_dir)s -I defer -P %(policy_file)s -f %(out_dir)s -a4" % locals() else: cmd = "%(exefile)s %(target_dir)s -s %(temp_dir)s -I defer -P %(policy_file)s -f %(out_dir)s -i %(include_dir_file)s -a4" % locals() + if cmdonly: + print ("mmapplypolicy command is (%s)" % cmd) + sys.exit() p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE) out,err = p.communicate() with open(out_dir + "/mm.out", "w") as fout: print(out,file=fout) @@ -259,7 +262,7 @@ def add_date(datetime, days): # Read arguments from command line def parse_args(args): try: - opts,args = getopt.getopt(sys.argv[1:],'s:p:D:C:H:hId:o:i:') + opts,args = getopt.getopt(sys.argv[1:],'s:p:D:C:H:hId:o:i:q') except getopt.GetoptError as e: Usage(" ERROR: " + str(e)) opts = dict(opts) @@ -294,6 +297,7 @@ def Usage(msg=None): -I Create new empty datbase file in DBNAME given by -D -o Output directory for mmapplypolicy, must be on scratch partition. Only valid with -s option. Default value is %s + -q With -s, print mmapplypolicy command only """ % DEF_OUTDIR ) if msg: print();print(msg);print() @@ -344,7 +348,7 @@ def main(): policy_file = out_dir + "/policy_file" target_dir = opts['-s'] include_dir_file = opts['-i'] if '-i' in opts else None - rc = run_mmapplypolicy(MMAPPLYPOLICY,target_dir,policy_file,temp_dir,out_dir, include_dir_file) + rc = run_mmapplypolicy(MMAPPLYPOLICY,target_dir,policy_file,temp_dir,out_dir, include_dir_file, '-q' in opts) #rc = run_test(temp_dir,out_dir) if rc>0: print_warn(" mmapplypolicy return code is (%d)" % rc)