7 from TestSsh import TestSsh
10 # (*) plc trackers remembers the running myplcs
11 # (*) qemu trackers keeps track of the running qemu nodes
13 # trackers allow us to let the test run after the build has finished,
14 # and to kill/stop the oldest instances later when we need space
17 #################### Tracker
20 def __init__ (self, options,filename, instances):
22 self.filename=filename
23 self.instances=instances
25 tracks=file(self.filename).readlines()
26 tracks = [ track.strip() for track in tracks ]
29 self.tracks = [track for track in tracks if track]
32 out = file(self.filename,'w')
33 for track in self.tracks:
34 out.write('%s\n'%(track))
37 def record (self,track):
38 for already in self.tracks:
40 print '%s is already included in %s'%(already,self.filename)
42 if self.options.dry_run:
43 print 'dry_run: Tracker.record - skipping %s'%(track)
45 self.tracks.append( track )
46 print "Recorded %s in tracker %s"%(track,self.filename)
48 # this actually stops the old instances to fit the number of instances
50 # number of instances to stop
51 how_many=len(self.tracks)-self.instances
52 # nothing todo until we have more than keep_vservers in the tracker
54 print 'Tracker.free : limit %d not reached'%self.instances
56 to_stop = self.tracks[:how_many]
58 command = self.stop_command (track)
60 if not self.options.dry_run:
61 self.tracks = self.tracks[how_many:]
63 # this stops ALL known instances
65 for track in self.tracks:
66 command=self.stop_command(track)
68 if not self.options.dry_run:
71 class TrackerPlc (Tracker):
73 DEFAULT_FILENAME=os.environ['HOME']+"/tracker-plcs"
74 # how many concurrent plcs are we keeping alive - adjust with the IP pool size
75 DEFAULT_MAX_INSTANCES = 12
77 def __init__ (self,options,filename=None,instances=0):
78 if not filename: filename=TrackerPlc.DEFAULT_FILENAME
79 if not instances: instances=TrackerPlc.DEFAULT_MAX_INSTANCES
80 Tracker.__init__(self,options,filename,instances)
82 def record (self, hostname, vservername):
83 Tracker.record (self,"%s@%s"%(hostname,vservername))
85 def stop_command (self, track):
86 (hostname,vservername) = track.split('@')
87 return TestSsh(hostname).actual_command("vserver --silent %s stop"%vservername)
90 class TrackerQemu (Tracker):
92 DEFAULT_FILENAME=os.environ['HOME']+"/tracker-emus"
93 # how many concurrent plcs are we keeping alive - adjust with the IP pool size
94 DEFAULT_MAX_INSTANCES = 2
96 def __init__ (self,options,filename=None,instances=0):
97 if not filename: filename=TrackerQemu.DEFAULT_FILENAME
98 if not instances: instances=TrackerQemu.DEFAULT_MAX_INSTANCES
99 Tracker.__init__(self,options,filename,instances)
101 def record (self, hostname, buildname, nodename):
102 Tracker.record (self,"%s@%s@%s"%(hostname,buildname,nodename))
104 def stop_command (self, track):
105 (hostname,buildname,nodename) = track.split('@')
106 return TestSsh(hostname).actual_command("%s/qemu-%s/qemu-kill-node this"%(buildname,nodename))