first draft for testing initscripts by name or by body
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Wed, 16 Mar 2011 17:51:21 +0000 (18:51 +0100)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Wed, 16 Mar 2011 17:51:21 +0000 (18:51 +0100)
system/TestPlc.py
system/TestSlice.py
system/TestSliver.py
system/config_default.py

index b13914f..5a79bd2 100644 (file)
@@ -980,9 +980,9 @@ class TestPlc:
     def do_check_initscripts(self):
         overall = True
         for slice_spec in self.plc_spec['slices']:
-            if not slice_spec.has_key('initscriptname'):
+            if not slice_spec.has_key('initscriptstamp'):
                 continue
-            initscript=slice_spec['initscriptname']
+            stamp=slice_spec['initscriptstamp']
             for nodename in slice_spec['nodenames']:
                 (site,node) = self.locate_node (nodename)
                 # xxx - passing the wrong site - probably harmless
@@ -990,7 +990,7 @@ class TestPlc:
                 test_slice = TestSlice (self,test_site,slice_spec)
                 test_node = TestNode (self,test_site,node)
                 test_sliver = TestSliver (self, test_node, test_slice)
-                if not test_sliver.check_initscript(initscript):
+                if not test_sliver.check_initscript_stamp(stamp):
                     overall = False
         return overall
            
index 994a378..7620277 100644 (file)
@@ -55,9 +55,14 @@ class TestSlice:
             hostnames += [test_node.name()]
         utils.header("Adding %r in %s"%(hostnames,slice_name))
         self.test_plc.apiserver.AddSliceToNodes(auth, slice_name, hostnames)
-        if self.slice_spec.has_key('initscriptname'):
+        # add initscript body or name as appropriate
+        if self.slice_spec.has_key('initscriptbody'):
+            isbody=self.slice_spec['initscriptbody']
+            utils.header("Adding initscript body %s in %s"%(isbody,slice_name))
+            self.test_plc.apiserver.AddSliceTag(self.test_plc.auth_root(), slice_name,'initscript_body',body)
+        elif self.slice_spec.has_key('initscriptname'):
             isname=self.slice_spec['initscriptname']
-            utils.header("Adding initscript %s in %s"%(isname,slice_name))
+            utils.header("Adding initscript name %s in %s"%(isname,slice_name))
             self.test_plc.apiserver.AddSliceTag(self.test_plc.auth_root(), slice_name,'initscript',isname)
         if self.slice_spec.has_key ('vref'):
             vref_value=self.slice_spec['vref']
index 0d5ab64..c4b3fb8 100644 (file)
@@ -34,11 +34,9 @@ class TestSliver:
     def name (self):
         return "%s@%s"%(self.test_slice.name(),self.test_node.name())
 
-    def check_initscript(self,initscript):
-        slice_spec=self.test_slice.slice_spec
-        initscript = slice_spec['initscriptname']
-        utils.header("Checking initscript %s on sliver %s"%(initscript,self.name()))
-        return self.test_ssh.run("ls -l /tmp/%s.stamp"%initscript)==0
+    def check_initscript_stamp(self,stamp):
+        utils.header("Checking for initscript stamp %s on sliver %s"%(stamp,self.name()))
+        return self.test_ssh.run("ls -l /tmp/%s.stamp"%stamp)==0
     
     def run_tcp_server (self,port,timeout=10):
         server_command = "./tcptest.py server -p %d -t %d"%(port,timeout)
index 2e9056c..39d5e41 100644 (file)
@@ -147,52 +147,64 @@ def keys (options,index):
                               'key': public_key}}
              ]
 
-def initscripts(options,index): 
-    initscripts= [ { 'initscript_fields' : 
-                     { 'enabled' : True,
-                       'name':'script1',
-                       'script' : """#! /bin/sh
-(echo Starting test initscript: script1; date) >> /tmp/script1.stamp
-# expected to be 'start'
-command=$1; shift
-# get slice name
-slicename=$1; shift
-echo "This is the stdout of the sliver $slicename initscript $command (exp. start) pid=$$" 
-echo "This is the stderr of the sliver $slicename initscript $command (exp. start) pid=$$" 1>&2
-""",
-                       }},
-                   { 'initscript_fields' : 
-                     { 'enabled' : True,
-                       'name':'script2',
-                       'script' : """#! /bin/sh
-(echo Starting loop-forever test initscript: script2; date) >> /tmp/script2.stamp
-# expected to be 'start'
+
+############################## initscripts
+initscript_by_name="""#! /bin/sh
+builtin="the_script_name"
+stamp=/tmp/$builtin.stamp
 command=$1; shift
-# get slice name
 slicename=$1; shift
-while true; do
-echo "This is the stdout of the loop-for-ever sliver initscript $slicename $command (exp. start) $$" 
-echo "This is the stderr of the loop-for-ever sliver initscript $slicename $command (exp. start) $$" 1>&2
-sleep 10
-done
-""",
-                       }},
-                   ]
-    return initscripts
+case $command in 
+start)
+  (echo Starting test initscript: $builtin on slicename $slicename ; date) >> $stamp
+  echo "This is the stdout of the sliver $slicename initscript $command (exp. start) pid=$$" 
+  echo "This is the stderr of the sliver $slicename initscript $command (exp. start) pid=$$" 1>&2
+;;
+stop)
+  rm $stamp
+;;
+restart)
+  echo "Dummy restart"
+;;
+*)
+  echo "Unknown command in initscript $command"
+;;
+esac
+"""
+
+initscript_by_body=initscript_by_name.replace("the_script_name","the_script_body")
 
+# one single initscript in the InitScripts table
+def initscripts(options,index): 
+    return [ { 'initscript_fields' : { 'enabled' : True,
+                                       'name':'the_script_name',
+                                       'script' : initscript_by_name,
+                                       }},
+             ]
+
+# always return 2 slices
+# one has an initscript body, the other one an initscript name
 def slices (options,index):
-    return [ { 'slice_fields': {'name':'%s_pslc%d'%(login_base(index),i),
-                                'instantiation':'plc-instantiated',
-                                'url':'http://foo%d.com'%index,
-                                'description':'testslice number %d'%i,
-                                'max_nodes':2,
-                                },
-               'usernames' : [ 'pi','tech','techuser' ],
-               'nodenames' : all_nodenames(options,index),
-               'initscriptname' : 'script%d'%(((i-1)%2)+1),
-               'sitename' : login_base(index),
-               'owner' : 'pi',
-               } for i in range (2*index-1,2*index+1) ]
+    def theslice (i):
+        slice_spec = { 'slice_fields': {'name':'%s_pslc%d'%(login_base(index),i),
+                                        'instantiation':'plc-instantiated',
+                                        'url':'http://foo%d.com'%index,
+                                        'description':'testslice number %d'%i,
+                                        'max_nodes':2,
+                                        },
+                       'usernames' : [ 'pi','tech','techuser' ],
+                       'nodenames' : all_nodenames(options,index),
+                       'sitename' : login_base(index),
+                       'owner' : 'pi',
+                       }
+        # odd one has an initscript_body
+        if i%2==1:
+            slice_spec['initscriptbody']=initscript_by_body
+            slice_spec['initscriptstamp']='the_script_body'
+        else:
+            slice_spec['initscriptname']='the_script_name'
+            slice_spec['initscriptstamp']='the_script_name'
+    return [ theslice(1) for i in range (2*index-1,2*index+1) ]
 
 def all_slicenames (options,index):
     return [ slice['slice_fields']['name'] for slice in slices(options,index)]