6 from TestSsh import TestSsh
9 # (*) plc trackers remembers the running myplcs
10 # (*) qemu trackers keeps track of the running qemu nodes
12 # trackers allow us to let the test run after the build has finished,
13 # and to kill/stop the oldest instances later when we need space
16 #################### Tracker
19 def __init__ (self, options,filename, instances):
21 self.filename=filename
22 self.instances=instances
24 tracks=file(self.filename).readlines()
25 tracks = [ track.strip() for track in tracks ]
28 self.tracks = [track for track in tracks if track]
31 out = file(self.filename,'w')
32 for track in self.tracks:
33 out.write('%s\n'%(track))
36 def record (self,track):
37 for already in self.tracks:
39 print '%s is already included in %s'%(already,self.filename)
41 if self.options.dry_run:
42 print 'dry_run: Tracker.record - skipping %s'%(track)
44 self.tracks.append( track )
45 print "Recorded %s in tracker %s"%(track,self.filename)
47 # this actually stops the old instances to fit the number of instances
49 # number of instances to stop
50 how_many=len(self.tracks)-self.instances
51 # nothing todo until we have more than keep_vservers in the tracker
53 print 'Tracker.free : limit %d not reached'%self.instances
55 to_stop = self.tracks[:how_many]
57 command = self.stop_command (track)
59 if not self.options.dry_run:
60 self.tracks = self.tracks[how_many:]
62 # this stops ALL known instances
64 for track in self.tracks:
65 command=self.stop_command(track)
67 if not self.options.dry_run:
70 class TrackerPlc (Tracker):
72 DEFAULT_FILENAME=os.environ['HOME']+"/tracker-plcs"
73 # how many concurrent plcs are we keeping alive - adjust with the IP pool size
74 DEFAULT_MAX_INSTANCES = 12
76 def __init__ (self,options,filename=None,instances=0):
77 if not filename: filename=TrackerPlc.DEFAULT_FILENAME
78 if not instances: instances=TrackerPlc.DEFAULT_MAX_INSTANCES
79 Tracker.__init__(self,options,filename,instances)
81 def record (self, hostname, vservername):
82 Tracker.record (self,"%s@%s"%(hostname,vservername))
84 def stop_command (self, track):
85 (hostname,vservername) = track.split('@')
86 return TestSsh(hostname).actual_command("vserver --silent %s stop"%vservername)
89 class TrackerQemu (Tracker):
91 DEFAULT_FILENAME=os.environ['HOME']+"/tracker-emus"
92 # how many concurrent plcs are we keeping alive - adjust with the IP pool size
93 DEFAULT_MAX_INSTANCES = 2
95 def __init__ (self,options,filename=None,instances=0):
96 if not filename: filename=TrackerQemu.DEFAULT_FILENAME
97 if not instances: instances=TrackerQemu.DEFAULT_MAX_INSTANCES
98 Tracker.__init__(self,options,filename,instances)
100 def record (self, hostname, buildname, nodename):
101 Tracker.record (self,"%s@%s@%s"%(hostname,buildname,nodename))
103 def stop_command (self, track):
104 (hostname,buildname,nodename) = track.split('@')
105 return TestSsh(hostname).actual_command("%s/qemu-%s/qemu-kill-node this"%(buildname,nodename))