allocate from pool : entries in tracker are considered last
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 11 Feb 2010 09:20:32 +0000 (09:20 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 11 Feb 2010 09:20:32 +0000 (09:20 +0000)
system/Makefile
system/TestPool.py
system/TestResources.py
system/Trackers.py

index 6218052..6830c5c 100644 (file)
@@ -5,11 +5,11 @@ tags:
 
 ####################
 
-########## make sync TESTMASTER=hostname BUILDNAME=vservername
-ifdef TESTMASTER
-ifdef BUILDNAME
-PLCSSH:=root@$(TESTMASTER):$(BUILDNAME)
-endif
+TESTMASTER ?= testmaster.onelab.eu
+
+########## make sync TESTMASTER=hostname BUILD=vservername
+ifdef BUILD
+PLCSSH:=root@$(TESTMASTER):$(BUILD)
 endif
 
 LOCAL_RSYNC_EXCLUDES   := --exclude '*.pyc' --exclude 'arg*'
@@ -19,8 +19,8 @@ RSYNC                 := rsync -a -v $(RSYNC_COND_DRY_RUN) $(RSYNC_EXCLUDES)
 
 sync:
 ifeq (,$(PLCSSH))
-       echo "sync: You must define TESTMASTER and BUILDNAME on the command line"
-       echo " e.g. make sync TESTMASTER=testmaster.onelab.eu BUILDNAME=2009.07.10--1l-f8-32" ; exit 1
+       echo "sync: You must define TESTMASTER and BUILD on the command line"
+       echo " e.g. make sync TESTMASTER=testmaster.onelab.eu BUILD=2009.07.10--1l-f8-32" ; exit 1
 else
        +$(RSYNC) ./ $(PLCSSH)
 endif
index 4c4473e..5ef9497 100644 (file)
@@ -33,22 +33,35 @@ class TestPool:
         self.message=message
 
     # let's be flexible
-    def locate_entry (self, hostname_or_ip, busy=True):
+    def match (self,triple,hostname_or_ip):
+        (h,i,u)=triple
+        return h.find(hostname_or_ip)>=0  or (i and i.find(hostname_or_ip)>=0)
+
+    def locate_entry (self, hostname_or_ip):
         for (h,i,u) in self.pool:
-            if h.find(hostname_or_ip)>=0  or (i and i.find(hostname_or_ip)>=0) :
-                if busy:
-                    self.busy.append(h)
+            if self.match ( (h,i,u,), hostname_or_ip):
+                self.busy.append(h)
                 return (h,i,u)
-        print '* TestPool.locate_entry: Could not locate entry for',hostname_or_ip
-        print '* in pool:'
-        for (h,i,u) in self.pool:
-            print "* \t",i,"\t",h
+        utils.header('TestPool.locate_entry: Could not locate entry for %r in pool:'%hostname_or_ip)
         return None
 
-    def next_free (self):
+    # the hostnames provided (from a tracker) are considered last
+    def next_free (self, tracker_hostnames):
         if self.options.quiet:
             print 'TestPool is looking for a %s'%self.message,
-        for (hostname,ip,user_data) in self.pool:
+        # create 2 lists of (h,i,u) entries, the ones not in the tracker, and the ones in the tracker
+        in_track_pool=[]
+        out_track_pool=[]
+        for (h,i,u) in self.pool:
+            in_tracker=False
+            for hostname in tracker_hostnames:
+                if self.match ( (h,i,u,) , hostname) : in_tracker = True
+            if in_tracker: in_track_pool.append  ( (h,i,u,) )
+            else:          out_track_pool.append ( (h,i,u,) )
+        # consider outsiders first
+        for (hostname,ip,user_data) in out_track_pool + in_track_pool:
+            utils.header ('* candidate %s' % hostname)
+        for (hostname,ip,user_data) in out_track_pool + in_track_pool:
             if hostname in self.busy:
                 continue
             if not self.options.quiet:
index 741e3dc..bd42eed 100644 (file)
@@ -19,6 +19,8 @@ class TestResources:
             plcs = self.localize_qemus(plcs,options)
         except Exception, e:
             print '* Could not localize qemus','--',e,'--','exiting'
+            import traceback
+            traceback.print_exc()
             sys.exit(1)
         try:
             plcs = self.localize_nodes(plcs,options)
@@ -54,7 +56,8 @@ class TestResources:
                 ip_or_hostname=options.ips_qemu.pop()
                 (hostname,ip,unused)=qemu_pool.locate_entry(ip_or_hostname)
             else:
-                (hostname,ip,unused) = qemu_pool.next_free()
+                tracker=TrackerQemu(options,instances=self.max_qemus()-1)
+                (hostname,ip,unused) = qemu_pool.next_free(tracker.hostnames())
 
             node_map += [ ('node%d'%index, {'host_box':hostname},) ]
 
@@ -86,7 +89,8 @@ class TestResources:
                 print 'debug','in',ip_or_hostname,'out',ip_pool.locate_entry(ip_or_hostname)
                 (hostname,ip,mac)=ip_pool.locate_entry(ip_or_hostname)
             else:
-                (hostname,ip,mac) = ip_pool.next_free()
+                tracker=TrackerQemu(options,instances=self.max_qemus()-1)
+                (hostname,ip,mac) = ip_pool.next_free(tracker.nodenames())
             utils.header('Attaching node %s to %s (%s)'%(nodename,hostname,ip))
             node_dict= {'node_fields:hostname':hostname,
                         'interface_fields:ip':ip, 
@@ -116,7 +120,8 @@ class TestResources:
                     utils.header("Using user-provided %s %s for plc %s"%(
                             hostname,ip_or_hostname,plc['name']))
             else:
-                (hostname,ip,mac)=ip_pool.next_free()
+                tracker = TrackerPlc(options,instances=self.max_plcs())
+                (hostname,ip,mac)=ip_pool.next_free(tracker.plcnames())
                 if options.verbose:
                     utils.header("Using auto-allocated %s %s for plc %s"%(
                             hostname,ip,plc['name']))
index 93b917a..17b5c16 100644 (file)
@@ -96,6 +96,12 @@ class TrackerPlc (Tracker):
         (hostname,vservername) = track.split('@')
         return TestSsh(hostname).actual_command("vserver --silent %s stop"%vservername)
         
+    def plcnames (self):
+        return [ self.plcname(track) for track in self.tracks ]
+
+    def plcname (self, track):
+        (hostname,vservername) = track.split('@')
+        return vservername.rsplit('-',1)[1]
 
 class TrackerQemu (Tracker):
 
@@ -114,3 +120,18 @@ class TrackerQemu (Tracker):
     def stop_command (self, track):
         (hostname,buildname,nodename) = track.split('@')
         return TestSsh(hostname).actual_command("%s/qemu-%s/qemu-kill-node this"%(buildname,nodename))
+
+    def hostnames (self):
+        return [ self.hostname(track) for track in self.tracks ]
+
+    def hostname (self, track):
+        (hostname,buildname,nodename) = track.split('@')
+        return hostname
+
+    def nodenames (self):
+        return [ self.nodename(track) for track in self.tracks ]
+        
+    def nodename (self, track):
+        (hostname,buildname,nodename) = track.split('@')
+        return nodename
+