2 The purpose of this script to create enough traffic in config datastore
3 to trigger creation of Snapshot.
4 This script uses PUT http method for handling/replacing "moving segment" of cars.
5 The car data is minimal, containing only an ID (car-<num>).
17 The main function that does it all.
19 TODO: Move argument parsing to a separate function,
20 so allow the main logic to be started programmatically?
24 car_entry_template = string.Template(''' {
28 patch_data_template = string.Template('''{
37 parser = argparse.ArgumentParser(description="Config datastore"
39 parser.add_argument("--host", default="127.0.0.1",
40 help="Host where odl controller is running."
41 "(default: 127.0.0.1)")
42 parser.add_argument("--port", default="8181",
43 help="Port on which odl's RESTCONF is listening"
45 parser.add_argument("--start-id", type=int, default=1,
46 help="ID number of the first car. (default:1)")
47 parser.add_argument("--segment-size", type=int, default=1,
48 help="Number of cars in segment. (default:1)")
49 parser.add_argument("--iterations", type=int, default=1,
50 help="How many times the segment sent. (default:1)")
51 parser.add_argument("--move-per-iter", type=int, default=1,
52 help="Each segment has IDs moved by this. (default:1)")
53 parser.add_argument("--user", help="Restconf user name", default="admin")
54 parser.add_argument("--password", help="Restconf password", default="admin")
56 args = parser.parse_args()
59 url = "http://" + args.host + ':' + args.port + "/restconf/config/car:cars"
60 auth = (args.user, args.password)
61 headers = {"Content-Type": "application/json"}
62 session = requests.Session()
63 for iteration in range(args.iterations):
65 for num_entry in range(args.segment_size):
66 num_id = args.start_id + iteration * args.move_per_iter + num_entry
67 entry_list.append(car_entry_template.substitute({"NUM": str(num_id)}))
68 mapping = {"ID": str(iteration), "ENTRIES": ",\n".join(entry_list)}
69 data = patch_data_template.substitute(mapping)
70 response = session.put(url=url, auth=auth, headers=headers, data=data)
71 if response.status_code not in [200, 201, 204]:
72 print "status: {}".format(response.status_code)
73 print "text: {}".format(response.text)
77 if __name__ == "__main__":