Updated code to match new rules
[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 = 'http://' + host + ":" + port + '/restconf/config/opendaylight-inventory:nodes'
28
29     if not auth:
30         r = requests.delete(url, headers=getheaders)
31     else:
32         r = requests.delete(url, headers=getheaders, auth=('admin', 'admin'))
33
34     return r.status_code
35
36
37 if __name__ == "__main__":
38
39     parser = argparse.ArgumentParser(description='Cleans up the config space')
40     parser.add_argument('--host', default='127.0.0.1', help='host where '
41                         'odl controller is running (default is 127.0.0.1)')
42     parser.add_argument('--port', default='8181', help='port on '
43                         'which odl\'s RESTCONF is listening (default is 8181)')
44     parser.add_argument('--auth', dest='auth', action='store_true', default=False,
45                         help="Use authenticated access to REST "
46                         "(username: 'admin', password: 'admin').")
47     parser.add_argument('--controller', choices=['odl', 'floodlight'], default='odl',
48                         help='Controller type (ODL or Floodlight); default odl (OpenDaylight)')
49
50     in_args = parser.parse_args()
51
52     if in_args.controller == 'odl':
53         sts = cleanup_config_odl(in_args.host, in_args.port, in_args.auth)
54         exp = 200
55     elif in_args.controller == 'floodlight':
56         sts = cleanup_config_fl(in_args.host, in_args.port)
57         exp = 204
58     else:
59         print 'Unknown controller type'
60         sys.exit(-1)
61
62     if sts != exp:
63         print 'Failed to delete nodes in the config space, code %d' % sts
64     else:
65         print 'Nodes in config space deleted.'