more consistently rename plc_spec['hostname'] into plc_spec['host_box']
[tests.git] / system / Substrate.py
index 4ec0c43..cffc5fa 100644 (file)
@@ -136,14 +136,14 @@ class Pool:
 
     def next_free (self):
         for i in self.pool:
-            if i.status in ['busy','mine','starting' ]: continue
-            i.status='mine'
-            return (i.hostname,i.userdata)
+            if i.status == 'free':
+                i.status='mine'
+                return (i.hostname,i.userdata)
         raise Exception,"No IP address available in pool %s"%self.message
 
-# OS-dependent ping option (support for macos, for convenience)
+    # OS-dependent ping option (support for macos, for convenience)
     ping_timeout_option = None
-# checks whether a given hostname/ip responds to ping
+    # checks whether a given hostname/ip responds to ping
     def check_ping (self,hostname):
         if not Pool.ping_timeout_option:
             (status,osname) = commands.getstatusoutput("uname -s")
@@ -161,7 +161,7 @@ class Pool:
         return status == 0
 
     # the place were other test instances tell about their not-yet-started
-    # instances
+    # instances, that go undetected through sensing
     starting='/root/starting'
     def add_starting (self, name):
         try:    items=[line.strip() for line in file(Pool.starting).readlines()]
@@ -176,11 +176,10 @@ class Pool:
         except: items=[]
         for item in items:
             for i in self.pool:
-                if i.hostname==item: i.status='starting'
+                if i.hostname==item and i.status==None: i.status='starting'
 
-    def release_my_fakes (self):
+    def release_my_starting (self):
         for i in self.pool:
-            print 'releasing-scanning','hostname',i.hostname,'status',i.status
             if i.status=='mine': 
                 self.del_starting(i.hostname)
                 i.status=None
@@ -194,8 +193,6 @@ class Pool:
                 if item != name: f.write(item+'\n')
             f.close()
     
-    
-        
 ####################
 class Box:
     def __init__ (self,hostname):
@@ -407,8 +404,9 @@ class PlcBox (Box):
 #            print self.margin_outline(self.vplcname(longname)),"%(vserver_line)s [=%(longname)s]"%locals()
 
         # scan timestamps
+        running_ctx_ids = [ i.ctxid for i in self.plc_instances ]
         command=   ['grep','.']
-        command += ['/vservers/%s/timestamp'%b for b in ctx_dict.values()]
+        command += ['/vservers/%s/timestamp'%b for b in running_ctx_ids]
         command += ['/dev/null']
         ts_lines=self.backquote_ssh(command,trash_err=True).split('\n')
         for ts_line in ts_lines:
@@ -421,6 +419,7 @@ class PlcBox (Box):
                 q=self.plc_instance_by_vservername(vservername)
                 if not q: 
                     print 'WARNING unattached plc instance',ts_line
+                    print 'was expeting to find',vservername,'in',[i.vservername for i in self.plc_instances]
                     continue
                 q.set_timestamp(timestamp)
             except:  print 'WARNING, could not parse ts line',ts_line
@@ -598,9 +597,6 @@ class Substrate:
         self.vplc_pool = Pool (self.vplc_ips(),"for vplcs")
         self.vnode_pool = Pool (self.vnode_ips(),"for vnodes")
 
-        self.vnode_pool.list()
-
-
 #    def build_box_names (self):
 #        return [ h for h in self.build_boxes_spec() ]
 #    def plc_boxes (self):
@@ -664,8 +660,8 @@ class Substrate:
         if options.ips_vplc:
             vplc_hostname=options.ips_vplc.pop()
         else:
-            self.vplc_pool.load_starting()
             self.vplc_pool.sense()
+            self.vplc_pool.load_starting()
             (vplc_hostname,unused)=self.vplc_pool.next_free()
         vplc_ip = self.vplc_pool.get_ip(vplc_hostname)
         self.vplc_pool.add_starting(vplc_hostname)
@@ -679,7 +675,7 @@ class Substrate:
         #### apply in the plc_spec
         # # informative
         # label=options.personality.replace("linux","")
-        mapper = {'plc': [ ('*' , {'hostname':plc_box.hostname,
+        mapper = {'plc': [ ('*' , {'host_box':plc_box.hostname,
                                    # 'name':'%s-'+label,
                                    'name': plc_name,
                                    'vservername':vservername,
@@ -732,12 +728,10 @@ class Substrate:
             if options.ips_vnode:
                 vnode_hostname=options.ips_vnode.pop()
                 mac=self.vnode_pool.retrieve_userdata(vnode_hostname)
-                print 'case 1 hostname',vnode_hostname,'mac',mac
             else:
-                self.vnode_pool.load_starting()
                 self.vnode_pool.sense()
+                self.vnode_pool.load_starting()
                 (vnode_hostname,mac)=self.vnode_pool.next_free()
-                print 'case 2 hostname',vnode_hostname,'mac',mac
             ip=self.vnode_pool.get_ip (vnode_hostname)
             self.vnode_pool.add_starting(vnode_hostname)
 
@@ -769,8 +763,8 @@ class Substrate:
 
     #################### release:
     def release (self,options):
-        self.vplc_pool.release_my_fakes()
-        self.vnode_pool.release_my_fakes()
+        self.vplc_pool.release_my_starting()
+        self.vnode_pool.release_my_starting()
         pass
 
     #################### show results for interactive mode