X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=system%2FTestPool.py;h=87e1b97693ce52af7f1b01386858dc01947557e2;hb=ebe66d736a4375cf0da02b59dbe4e33cebf8f4b5;hp=85a73973540c7678a7cada84cbbee6cc3ac33133;hpb=d3427e2d3f6716ab70e0fc87ce70ff341125076c;p=tests.git diff --git a/system/TestPool.py b/system/TestPool.py index 85a7397..87e1b97 100644 --- a/system/TestPool.py +++ b/system/TestPool.py @@ -1,5 +1,7 @@ # -# Thierry Parmentelat - INRIA Sophia Antipolis +# Thierry Parmentelat +# Copyright (C) 2010 INRIA +# # # pool class # @@ -33,29 +35,39 @@ 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) + utils.header('TestPool.locate_entry: Could not locate entry for %r in pool:'%hostname_or_ip) return None - def next_free (self): - if self.options.quiet: - print 'TestPool is looking for a %s'%self.message, - for (hostname,ip,user_data) in self.pool: + # the hostnames provided (from a tracker) are considered last + def next_free (self, tracker_hostnames): + utils.header('TestPool is looking for a %s'%self.message) + # 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: - utils.header('TestPool : checking %s'%hostname) - if self.options.quiet: - print '.', + utils.header('TestPool : checking %s'%hostname) if self.free_hostname(hostname): - if not self.options.quiet: - utils.header('%s is available'%hostname) - else: - print '' + utils.header('%s is available'%hostname) self.busy.append(hostname) return (hostname,ip,user_data) else: @@ -68,7 +80,7 @@ class TestPoolIP (TestPool): TestPool.__init__(self,pool,options,"free IP address") def free_hostname (self, hostname): - return not TestPoolIP.check_ping(hostname) + return not self.check_ping(hostname) # OS-dependent ping option (support for macos, for convenience) ping_timeout_option = None @@ -95,7 +107,7 @@ class TestPoolQemu (TestPool): TestPool.__init__(self,pool,options,"free qemu box") def free_hostname (self, hostname): - return not TestPoolQemu.busy_qemu(hostname) + return not self.busy_qemu(hostname) # is there a qemu runing on that box already ? def busy_qemu (self, hostname):