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