From 0a23d3eab5ce2719dc1e65e911cc29a9623177f4 Mon Sep 17 00:00:00 2001 From: Bill Wall Date: Fri, 26 Jul 2024 15:42:09 -0500 Subject: [PATCH 1/3] Fix logging conflicts Added unique log file naming by default. Added a "None" option for logging that will direct logging to devNull (cross-platform) --- qwalk.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/qwalk.py b/qwalk.py index 5e84d0f..4fd8039 100755 --- a/qwalk.py +++ b/qwalk.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- import argparse +import datetime import os import sys @@ -20,7 +21,7 @@ def main() -> None: ) parser.add_argument("-d", help="Starting directory", required=True) parser.add_argument("-g", help="Run with filesystem changes", action="store_true") - parser.add_argument("-l", help="Log file", default="output-walk-log.txt") + parser.add_argument("-l", help="Log file. Use 'None' to disable logging.", default=datetime.datetime.now().strftime("%Y%m%dT%H%M%S-") + "output-walk-log.txt") parser.add_argument( "-c", help="Class to run.", @@ -38,6 +39,10 @@ def main() -> None: print("-" * 80) sys.exit(0) + # If the log parameter is set to "None" send logs to devNull + if args.l == "None": + args.l == os.devnull + QWalkWorker.run_all( args.s, args.u, From 66bef932035a022596f2742c98b7377f29730da2 Mon Sep 17 00:00:00 2001 From: Bill Wall Date: Fri, 26 Jul 2024 15:44:57 -0500 Subject: [PATCH 2/3] Secure password entry Added option to securely provide the password via getpass and removed the default of 'admin' from the parameter. --- qwalk.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/qwalk.py b/qwalk.py index 4fd8039..435badb 100755 --- a/qwalk.py +++ b/qwalk.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- import argparse import datetime +import getpass import os import sys @@ -17,7 +18,7 @@ def main() -> None: "-u", help="Qumulo API user", default=os.getenv("QUSER") or "admin" ) parser.add_argument( - "-p", help="Qumulo API password", default=os.getenv("QPASS") or "admin" + "-p", help="Qumulo API password", default=os.getenv("QPASS") ) parser.add_argument("-d", help="Starting directory", required=True) parser.add_argument("-g", help="Run with filesystem changes", action="store_true") @@ -39,6 +40,10 @@ def main() -> None: print("-" * 80) sys.exit(0) + # Prompt for password if one was not given by ENV or command entry + if not args.p: + args.p = getpass.getpass() + # If the log parameter is set to "None" send logs to devNull if args.l == "None": args.l == os.devnull From 77ec2ea938f248ac1c7c9cef9be65db7b6817ac2 Mon Sep 17 00:00:00 2001 From: Bill Wall Date: Fri, 26 Jul 2024 15:47:30 -0500 Subject: [PATCH 3/3] Added check for running directly on Q node Added a check and override parameter for preventing the script from running directly on a Qumulo node. --- qwalk.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/qwalk.py b/qwalk.py index 435badb..24ce7e1 100755 --- a/qwalk.py +++ b/qwalk.py @@ -23,6 +23,7 @@ def main() -> None: parser.add_argument("-d", help="Starting directory", required=True) parser.add_argument("-g", help="Run with filesystem changes", action="store_true") parser.add_argument("-l", help="Log file. Use 'None' to disable logging.", default=datetime.datetime.now().strftime("%Y%m%dT%H%M%S-") + "output-walk-log.txt") + parser.add_argument("-f", help="Force script to run on directly on a Qumulo node.", action="store_true") parser.add_argument( "-c", help="Class to run.", @@ -40,6 +41,13 @@ def main() -> None: print("-" * 80) sys.exit(0) + # Make sure we're not running directly on a Qumulo node + RunningOnNode=os.system("qq cluster_conf | jq -cr .cluster_name > " + os.devnull + " 2>&1 ") + if RunningOnNode == 0: + print("The qwalk command should not be executed direcly on a Qumulo node.") + if not args.f: + exit(1) + # Prompt for password if one was not given by ENV or command entry if not args.p: args.p = getpass.getpass()