diff options
| author | Y Bharath <y.bharath@samsung.com> | 2025-03-24 13:13:22 +0530 |
|---|---|---|
| committer | Y Bharath <y.bharath@samsung.com> | 2025-03-24 17:54:20 +0530 |
| commit | 0885d2232c4a253f29970f58336de610991f0cd4 (patch) | |
| tree | 8310047e71569d6b01a24cc6a8cea06f0baa8cbc /tests | |
| parent | 44c4743e08710fd9dda12105ff6fbec2547faf51 (diff) | |
tests: Handling potential errors gracefully
Handling potential errors gracefully at exa-receive.py
Signed-off-by: y-bharath14 <y.bharath@samsung.com>
Diffstat (limited to 'tests')
| -rwxr-xr-x | tests/topotests/lib/exa-receive.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/tests/topotests/lib/exa-receive.py b/tests/topotests/lib/exa-receive.py index 2ea3a75a5f..9035b6ab15 100755 --- a/tests/topotests/lib/exa-receive.py +++ b/tests/topotests/lib/exa-receive.py @@ -19,8 +19,23 @@ parser.add_argument( parser.add_argument("peer", type=int, help="The peer number") args = parser.parse_args() -savepath = os.path.join(args.logdir, "peer{}-received.log".format(args.peer)) -routesavefile = open(savepath, "w") +# Ensure log directory exists +logdir = args.logdir +if not os.path.exists(logdir): + try: + # Create a new log directory + os.makedirs(logdir) + except OSError as e: + print(f"Error in creating log directory: {e}") + exit(1) + +savepath = os.path.join(logdir, f"peer{args.peer}-received.log") + +try: + routesavefile = open(savepath, "w") +except IOError as e: + print(f"Error in opening log file: {e}") + exit(1) while True: try: |
