X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Ftools%2Fscripts%2Ftopo_reservation.py;h=c1b5c4658e544ae2674ea7a4b810b59aa5f4e9e6;hp=73f6d0e81516197535585d2c2c3c26b7ee1f3859;hb=HEAD;hpb=d68951ac245150eeefa6e0f4156e4c1b5c9e9325 diff --git a/resources/tools/scripts/topo_reservation.py b/resources/tools/scripts/topo_reservation.py index 73f6d0e815..f2d18bcafd 100755 --- a/resources/tools/scripts/topo_reservation.py +++ b/resources/tools/scripts/topo_reservation.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -# Copyright (c) 2019 Cisco and/or its affiliates. +# Copyright (c) 2022 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -84,7 +84,7 @@ def main(): ) args = parser.parse_args() - with open(args.topo, "r") as topo_file: + with open(args.topo, u"rt") as topo_file: topology = yaml.safe_load(topo_file.read())[u"nodes"] # Even if TG is not guaranteed to be a Linux host, @@ -100,9 +100,11 @@ def main(): # store additional data (time, client_ID, ..) within reservation directory. if args.cancel: ret, _, err = exec_cmd(node, f"rm -r {RESERVATION_DIR}") - if ret: + # If connection is refused, ret==None. + if ret != 0: print(f"Cancellation unsuccessful:\n{err!r}") - return ret + return 1 + return 0 # Before critical section, output can be outdated already. print(u"Diagnostic commands:") # -d and * are to suppress "total ", see https://askubuntu.com/a/61190 @@ -111,7 +113,10 @@ def main(): # Entering critical section. ret, _, _ = exec_cmd(node, f"mkdir '{RESERVATION_DIR}'") # Critical section is over. - if ret: + if ret is None: + print(u"Failed to connect to testbed.") + return 1 + if ret != 0: _, stdo, _ = exec_cmd(node, f"ls '{RESERVATION_DIR}'/*") print(f"Testbed already reserved by:\n{stdo}") return 2 @@ -119,7 +124,7 @@ def main(): print(u"Reservation success, writing additional info to reservation dir.") ret, _, err = exec_cmd( node, f"touch '{RESERVATION_DIR}/{args.runtag}'") - if ret: + if ret != 0: print(f"Writing test run info failed, but continuing anyway:\n{err!r}") return 0