6 from qa.PLCs import PLC, PLCs
8 class delete_test_data(Test):
10 Removes the test data found in config from the plc db
13 def call(self, plc_name = None):
15 # Determine which plc to talk to
16 plc = self.config.get_plc(plc_name)
18 auth = plc.config.auth
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 \
27 sitelist = filter(this_plc, self.config.sites.values())
28 nodegrouplist = filter(this_plc, self.config.nodegroups.values())
30 # Deleting the site should delete everything associated with it
31 # including nodes, persons
34 api.DeleteSite(auth, site['login_base'])
35 if self.config.verbose:
36 utils.header("Test data deleted", logfile = self.config.logfile)
38 if self.config.verbose:
39 utils.header("Error deleting %s" % site['login_base'], logfile = self.config.logfile)
41 for nodegroup in nodegrouplist:
43 api.DeleteNodeGroup(auth, nodegroup['name'])
44 if self.config.verbose:
45 utils.header("NodeGroups deleted", logfile = self.config.logfile)
47 if self.config.verbose:
48 utils.header("Error deleting %s" % nodegroup['name'], logfile = self.config.logfile)
51 if __name__ == '__main__':
52 args = tuple(sys.argv[1:])
53 delete_test_data()(*args)