3 # Copyright (c) 2016 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 """This script provides simple reservation mechanism to avoid
17 simultaneous use of nodes listed in topology file.
18 As source of truth is used DUT1 node from the topology file."""
22 from resources.libraries.python.ssh import SSH
25 RESERVATION_DIR = "/tmp/reservation_dir"
28 parser = argparse.ArgumentParser()
29 parser.add_argument("-t", "--topo", required=True,
31 parser.add_argument("-c", "--cancel", help="Cancel reservation",
33 args = parser.parse_args()
34 topology_file = args.topo
35 cancel_reservation = args.cancel
37 work_file = open(topology_file)
38 topology = load(work_file.read())['nodes']
40 #we are using DUT1 node because we expect DUT1 to be a linux host
41 #we don't use TG because we don't expect TG to be linux only host
43 tg_node = topology["DUT1"]
45 print "Topology file does not contain 'DUT1' node"
51 #For system reservation we use mkdir it is an atomic operation and we can
52 #store additional data (time, client_ID, ..) within reservation directory
53 if cancel_reservation:
54 ret, _, err = ssh.exec_command("rm -r {}".format(RESERVATION_DIR))
56 ret, _, err = ssh.exec_command("mkdir {}".format(RESERVATION_DIR))
59 print("{} unsuccessful:\n{}".
60 format(("Cancellation " if cancel_reservation else "Reservation"),
64 if __name__ == "__main__":