d831f0a5f722e2664300b720eb4efa580448b86a
[tests.git] / qaapi / qa / tests / delete_test_data.py
1 #!/usr/bin/python
2
3 import os, sys
4 from Test import Test
5 from qa import utils
6 from qa.PLCs import PLC, PLCs
7
8 class delete_test_data(Test):
9     """
10     Removes the test data found in config from the plc db
11     """
12
13     def call(self, plc_name = None):
14
15         # Determine which plc to talk to 
16         plc = PLC(self.config)
17         plcs = getattr(self.config, 'plcs', [])
18         for p in plcs:
19             if p['name'] in [plc_name]:
20                 plc.update(p)
21         plc.config.update_api(plc)
22
23         api = plc.config.api
24         auth = plc.config.auth
25         
26         # Search config for objects that belong to this plc
27         # Any object with 'plc' defined as this plc's name or with 
28         # no 'plc' defined will be added
29         this_plc = lambda object: 'plc' not in object or \
30                                   'plc' in object and object['plc'] == plc['name'] or \
31                                   object['plc'] == None
32
33         sitelist = filter(this_plc, self.config.sites)
34                 
35         # Deleting the site should delete everything associated with it
36         # including nodes, persons
37         for site in sitelist:
38             try:
39                 api.DeleteSite(auth, site['login_base'])
40                 if self.config.verbose:
41                     utils.header("Test data deleted")
42             except:
43                 if self.config.verbose:
44                     utils.header("Error deleting %s" % site['login_base'])              
45         return 1 
46         
47 if __name__ == '__main__':
48     args = tuple(sys.argv[1:])
49     delete_test_data()(*args)