- ssh = SSH()
- ssh.connect(tg_node)
-
- #For system reservation we use mkdir it is an atomic operation and we can
- #store additional data (time, client_ID, ..) within reservation directory
- if cancel_reservation:
- ret, _, err = ssh.exec_command("rm -r {}".format(RESERVATION_DIR))
- else:
- ret, _, err = ssh.exec_command("mkdir {}".format(RESERVATION_DIR))
-
- if ret != 0:
- print("{} unsuccessful:\n{}".
- format(("Cancellation " if cancel_reservation else "Reservation"),
- err))
+ # For system reservation we use mkdir it is an atomic operation and we can
+ # store additional data (time, client_ID, ..) within reservation directory.
+ if args.cancel:
+ ret, _, err = exec_cmd(tgn, "rm -r {}".format(RESERVATION_DIR))
+ if ret:
+ print "Cancellation unsuccessful:\n{}".format(err)
+ return ret
+ # Before critical section, output can be outdated already.
+ print "Diagnostic commands:"
+ # -d and * are to supress "total <size>", see https://askubuntu.com/a/61190
+ diag_cmd(tgn, "ls --full-time -cd '{dir}'/*".format(dir=RESERVATION_DIR))
+ diag_cmd(tgn, "head -1 '{dir}/run.url'".format(dir=RESERVATION_DIR))
+ print "Attempting reservation."
+ # Entering critical section.
+ # TODO: Add optional argument to exec_cmd_no_error to make it
+ # sys.exit(ret) instead raising? We do not want to deal with stacktrace.
+ ret, _, err = exec_cmd(tgn, "mkdir '{dir}'".format(dir=RESERVATION_DIR))
+ # Critical section is over.
+ if ret:
+ print "Reservation unsuccessful:\n{}".format(err)
+ return ret
+ # Here the script knows it is the only owner of the testbed.
+ print "Success, writing test run info to reservation dir."
+ # TODO: Add optional argument to exec_cmd_no_error to print message
+ # to console instead raising? We do not want to deal with stacktrace.
+ ret2, _, err = exec_cmd(
+ tgn, "touch '{dir}/{runtag}' && ( echo '{url}' > '{dir}/run.url' )"\
+ .format(dir=RESERVATION_DIR, runtag=args.runtag, url=args.url))
+ if ret2:
+ print "Writing test run info failed, but continuing anyway:\n{}".format(
+ err)