miscell cosmetic + pass the substrate object to TestBonding so it can compute an...
[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         nodegrouplist = filter(this_plc, self.config.nodegroups.values())
29                 
30         # Deleting the site should delete everything associated with it
31         # including nodes, persons
32         for site in sitelist:
33             try:
34                 api.DeleteSite(auth, site['login_base'])
35                 if self.config.verbose:
36                     utils.header("Test data deleted", logfile = self.config.logfile)
37             except:
38                 if self.config.verbose:
39                     utils.header("Error deleting %s" % site['login_base'], logfile = self.config.logfile)               
40         # Delete nodegroups
41         for nodegroup in nodegrouplist:
42             try:
43                 api.DeleteNodeGroup(auth, nodegroup['name'])
44                 if self.config.verbose:
45                     utils.header("NodeGroups deleted", logfile = self.config.logfile)
46             except:
47                 if self.config.verbose:
48                     utils.header("Error deleting %s" % nodegroup['name'], logfile = self.config.logfile)        
49         return 1 
50         
51 if __name__ == '__main__':
52     args = tuple(sys.argv[1:])
53     delete_test_data()(*args)