Merge "Replaced the multi-blaster skeleton with real functionality. multi-blaster...
[integration/test.git] / test / 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 def cleanup_config_fl(host, port):
14     global getheaders
15
16     url = 'http://' + host + ":" + port + '/wm/staticflowentrypusher/clear/all/json'
17     r = requests.get(url, headers=getheaders)
18     return r.status_code
19
20
21 def cleanup_config_odl(host, port, auth):
22     global getheaders
23
24     url = 'http://' + host + ":" + port + '/restconf/config/opendaylight-inventory:nodes'
25
26     if not auth:
27         r = requests.delete(url, headers=getheaders)
28     else:
29         r = requests.delete(url, headers=getheaders, auth=('admin', 'admin'))
30
31     return r.status_code
32
33
34 if __name__ == "__main__":
35
36     parser = argparse.ArgumentParser(description='Cleans up the config space')
37     parser.add_argument('--host', default='127.0.0.1', help='host where '
38                         'odl controller is running (default is 127.0.0.1)')
39     parser.add_argument('--port', default='8181', help='port on '
40                         'which odl\'s RESTCONF is listening (default is 8181)')
41     parser.add_argument('--auth', dest='auth', action='store_true', default=False,
42                         help="Use authenticated access to REST "
43                         "(username: 'admin', password: 'admin').")
44     parser.add_argument('--controller', choices=['odl', 'floodlight'], default='odl',
45                          help='Controller type (ODL or Floodlight); default odl (OpenDaylight)')
46
47     in_args = parser.parse_args()
48
49     if in_args.controller == 'odl':
50         sts = cleanup_config_odl(in_args.host, in_args.port, in_args.auth)
51         exp = 200
52     elif in_args.controller == 'floodlight':
53         sts = cleanup_config_fl(in_args.host, in_args.port)
54         exp = 204
55     else:
56         print 'Unknown controller type'
57         sys.exit(-1)
58
59     if sts != exp:
60         print 'Failed to delete nodes in the config space, code %d' % sts
61     else:
62         print 'Nodes in config space deleted.'
63