fix errors
[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 = self.config.get_plc(plc_name)
17         api = plc.config.api
18         auth = plc.config.auth
19         
20         # Search config for objects that belong to this plc
21         # Any object with 'plc' defined as this plc's name or with 
22         # no 'plc' defined will be added
23         this_plc = lambda object: 'plc' not in object or \
24                                   'plc' in object and object['plc'] == plc['name'] or \
25                                   object['plc'] == None
26
27         sitelist = filter(this_plc, self.config.sites.values())
28                 
29         # Deleting the site should delete everything associated with it
30         # including nodes, persons
31         for site in sitelist:
32             try:
33                 api.DeleteSite(auth, site['login_base'])
34                 if self.config.verbose:
35                     utils.header("Test data deleted")
36             except:
37                 if self.config.verbose:
38                     utils.header("Error deleting %s" % site['login_base'])              
39         return 1 
40         
41 if __name__ == '__main__':
42     args = tuple(sys.argv[1:])
43     delete_test_data()(*args)