Migrate Get Requests invocations(libraries)
[integration/test.git] / tools / odl-mdsal-clustering-tests / clustering-performance-test / config_cleanup.py
1 #!/usr/bin/python
2 import argparse
3 import requests
4 import sys
5
6
7 __author__ = "Jan Medved"
8 __copyright__ = "Copyright(c) 2014, Cisco Systems, Inc."
9 __license__ = "New-style BSD"
10 __email__ = "jmedved@cisco.com"
11
12
13 getheaders = {"Accept": "application/json"}
14
15
16 def cleanup_config_fl(host, port):
17     global getheaders
18
19     url = "http://" + host + ":" + port + "/wm/staticflowentrypusher/clear/all/json"
20     r = requests.get(url, headers=getheaders)
21     return r.status_code
22
23
24 def cleanup_config_odl(host, port, auth):
25     global getheaders
26
27     url = (
28         "http://" + host + ":" + port + "/restconf/config/opendaylight-inventory:nodes"
29     )
30
31     if not auth:
32         r = requests.delete(url, headers=getheaders)
33     else:
34         r = requests.delete(url, headers=getheaders, auth=("admin", "admin"))
35
36     return r.status_code
37
38
39 if __name__ == "__main__":
40
41     parser = argparse.ArgumentParser(description="Cleans up the config space")
42     parser.add_argument(
43         "--host",
44         default="127.0.0.1",
45         help="host where " "odl controller is running (default is 127.0.0.1)",
46     )
47     parser.add_argument(
48         "--port",
49         default="8181",
50         help="port on " "which odl's RESTCONF is listening (default is 8181)",
51     )
52     parser.add_argument(
53         "--auth",
54         dest="auth",
55         action="store_true",
56         default=False,
57         help="Use authenticated access to REST "
58         "(username: 'admin', password: 'admin').",
59     )
60     parser.add_argument(
61         "--controller",
62         choices=["odl", "floodlight"],
63         default="odl",
64         help="Controller type (ODL or Floodlight); default odl (OpenDaylight)",
65     )
66
67     in_args = parser.parse_args()
68
69     if in_args.controller == "odl":
70         sts = cleanup_config_odl(in_args.host, in_args.port, in_args.auth)
71         exp = 200
72     elif in_args.controller == "floodlight":
73         sts = cleanup_config_fl(in_args.host, in_args.port)
74         exp = 204
75     else:
76         print("Unknown controller type")
77         sys.exit(-1)
78
79     if sts != exp:
80         print("Failed to delete nodes in the config space, code %d" % sts)
81     else:
82         print("Nodes in config space deleted.")