2 The purpose of this script to create enough traffic in config datastore
3 to trigger creation of Snapshot.
4 This script uses PATCH http method for handling "moving segment" of cars.
5 The car data is minimal, containing only an ID (car-<num>).
6 This script is tailored to behavior of Berylium-SR2,
7 if the behavior changes, new script will be needed.
19 The main function that does it all.
21 TODO: Move argument parsing to a separate function,
22 so allow the main logic to be started programmatically?
26 car_entry_template = string.Template(''' {
30 patch_data_template = string.Template('''{
31 "ietf-restconf:yang-patch": {
36 "operation": "replace",
37 "target": "/car:car-entry[car:id='0']",
49 parser = argparse.ArgumentParser(description="Config datastore"
51 parser.add_argument("--host", default="127.0.0.1",
52 help="Host where odl controller is running."
53 "(default: 127.0.0.1)")
54 parser.add_argument("--port", default="8181",
55 help="Port on which odl's RESTCONF is listening"
57 parser.add_argument("--start-id", type=int, default=1,
58 help="ID number of the first car. (default:1)")
59 parser.add_argument("--segment-size", type=int, default=1,
60 help="Number of cars in segment. (default:1)")
61 parser.add_argument("--iterations", type=int, default=1,
62 help="How many times the segment sent. (default:1)")
63 parser.add_argument("--move-per-iter", type=int, default=1,
64 help="Each segment has IDs moved by this. (default:1)")
65 parser.add_argument("--user", help="Restconf user name", default="admin")
66 parser.add_argument("--password", help="Restconf password", default="admin")
68 args = parser.parse_args()
71 url = "http://" + args.host + ':' + args.port + "/restconf/config/car:cars"
72 auth = (args.user, args.password)
73 headers = {"Content-Type": "application/yang.patch+json"}
74 session = requests.Session()
75 for iteration in range(args.iterations):
77 for num_entry in range(args.segment_size):
78 num_id = args.start_id + iteration * args.move_per_iter + num_entry
79 entry_list.append(car_entry_template.substitute({"NUM": str(num_id)}))
80 mapping = {"ID": str(iteration), "ENTRIES": ",\n".join(entry_list)}
81 data = patch_data_template.substitute(mapping)
82 response = session.patch(url=url, auth=auth, headers=headers, data=data)
83 if response.status_code not in [200, 201, 204]:
84 print "status:", response.status_code
85 print "text:", response.text
89 if __name__ == "__main__":