triggers all scripts in qaapi/qa/tests/node in one node's root context
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 19 Aug 2008 13:08:03 +0000 (13:08 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 19 Aug 2008 13:08:03 +0000 (13:08 +0000)
and all scripts in qaapi/qa/tests/slice in one slice
NOTES
results are ignored for now
running in a slice does not yet get root privileges

system/TestNode.py
system/TestPlc.py
system/TestSlice.py
system/TestSliver.py
system/TestSsh.py
system/utils.py

index f990e71..a32ce67 100644 (file)
@@ -209,26 +209,29 @@ class TestNode:
         TestSsh(self.name()).clear_known_hosts()
         return True
 
-    def check_sanity_node_script (self,local_script):
+    def create_test_ssh(self):
         # get the plc's keys for entering the node
         vservername=self.test_plc.vservername
+        # assuming we've run testplc.fetch_keys()
         key = "keys/%(vservername)s.rsa"%locals()
+        return TestSsh(self.name(), buildname=self.buildname(), key=key)
+
+    def check_sanity (self):
+        extensions = [ 'py','pl','sh' ]
+        path='tests/qaapi/qa/tests/node/'
+        scripts=utils.locate_sanity_scripts ('node '+self.name(), path,extensions)
+        overall = True
+        for script in scripts:
+            if not self.check_sanity_script (script):
+                overall = False
+        return overall
+
+    def check_sanity_script (self,local_script):
         # push the script on the node's root context
-        ssh_handle = TestSsh(self.name(),
-                             buildname=self.buildname(),
-                             key=key)
+        ssh_handle=self.create_test_ssh()
         ssh_handle.copy_home(local_script)
         if ssh_handle.run("./"+os.path.basename(local_script)) != 0:
             print "WARNING: sanity check script %s FAILED"
             # xxx - temporary : always return true for now
             #return False
         return True
-    
-    def check_sanity_node (self):
-        # locate the relevant scripts - xxx
-        scripts = [ 'tests/qaapi/qa/tests/node/vsys_launch.pl' ]
-        overall = True
-        for script in scripts:
-            if not self.check_sanity_node_script (script):
-                overall = False
-        return overall
index 1deb7a7..cd9f222 100644 (file)
@@ -179,6 +179,37 @@ class TestPlc:
                 return slice
         raise Exception,"Cannot locate slice %s"%slicename
 
+    def all_sliver_objs (self):
+        result=[]
+        for slice_spec in self.plc_spec['slices']:
+            slicename = slice_spec['slice_fields']['name']
+            for nodename in slice_spec['nodenames']:
+                result.append(self.locate_sliver_obj (nodename,slicename))
+        return result
+
+    def locate_sliver_obj (self,nodename,slicename):
+        (site,node) = self.locate_node(nodename)
+        slice = self.locate_slice (slicename)
+        # build objects
+        test_site = TestSite (self, site)
+        test_node = TestNode (self, test_site,node)
+        # xxx the slice site is assumed to be the node site - mhh - probably harmless
+        test_slice = TestSlice (self, test_site, slice)
+        return TestSliver (self, test_node, test_slice)
+
+    def locate_first_node(self):
+        nodename=self.plc_spec['slices'][0]['nodenames'][0]
+        (site,node) = self.locate_node(nodename)
+        test_site = TestSite (self, site)
+        test_node = TestNode (self, test_site,node)
+        return test_node
+
+    def locate_first_sliver (self):
+        slice_spec=self.plc_spec['slices'][0]
+        slicename=slice_spec['slice_fields']['name']
+        nodename=slice_spec['nodenames'][0]
+        return self.locate_sliver_obj(nodename,slicename)
+
     # all different hostboxes used in this plc
     def gather_hostBoxes(self):
         # maps on sites and nodes, return [ (host_box,test_node) ]
@@ -373,13 +404,17 @@ class TestPlc:
     # fetches the ssh keys in the plc's /etc/planetlab and stores them in keys/
     # for later direct access to the nodes
     def fetch_keys(self):
+        dir="./keys"
+        if not os.path.isdir(dir):
+            os.mkdir(dir)
         prefix = 'root_ssh_key'
         vservername=self.vservername
+        overall=True
         for ext in [ 'pub', 'rsa' ] :
             src="/vservers/%(vservername)s/etc/planetlab/%(prefix)s.%(ext)s"%locals()
             dst="keys/%(vservername)s.%(ext)s"%locals()
-            self.run_in_guest_piped
-            self.test_ssh.fetch(src,dst)
+            if self.test_ssh.fetch(src,dst) != 0: overall=False
+        return overall
 
     def sites (self):
         return self.do_sites()
@@ -607,14 +642,16 @@ class TestPlc:
     @node_mapper
     def export_qemu (self): pass
         
-    @node_mapper
-    def check_sanity_node (self): pass
-    @slice_mapper_options
-    def check_sanity_slice (self) : pass
+    ### check sanity : invoke scripts from qaapi/qa/tests/{node,slice}
+    def check_sanity_node (self): 
+        return self.locate_first_node().check_sanity()
+    def check_sanity_sliver (self) : 
+        return self.locate_first_sliver().check_sanity()
     
     def check_sanity (self):
-        return self.check_sanity_node() and self.check_sanity_slice()
+        return self.check_sanity_node() and self.check_sanity_sliver()
 
+    ### initscripts
     def do_check_initscripts(self):
         overall = True
         for slice_spec in self.plc_spec['slices']:
@@ -652,6 +689,7 @@ class TestPlc:
                 print 'deletion went wrong - probably did not exist'
         return True
 
+    ### manage slices
     def slices (self):
         return self.do_slices()
 
@@ -681,24 +719,6 @@ class TestPlc:
     @node_mapper
     def start_node (self) : pass
 
-    def all_sliver_objs (self):
-        result=[]
-        for slice_spec in self.plc_spec['slices']:
-            slicename = slice_spec['slice_fields']['name']
-            for nodename in slice_spec['nodenames']:
-                result.append(self.locate_sliver_obj (nodename,slicename))
-        return result
-
-    def locate_sliver_obj (self,nodename,slicename):
-        (site,node) = self.locate_node(nodename)
-        slice = self.locate_slice (slicename)
-        # build objects
-        test_site = TestSite (self, site)
-        test_node = TestNode (self, test_site,node)
-        # xxx the slice site is assumed to be the node site - mhh - probably harmless
-        test_slice = TestSlice (self, test_site, slice)
-        return TestSliver (self, test_node, test_slice)
-
     def check_tcp (self):
         specs = self.plc_spec['tcp_test']
         overall=True
index fb8935f..a72c680 100644 (file)
@@ -130,6 +130,3 @@ class TestSlice:
         # for an empty slice
         return True
 
-    def check_sanity_slice (self):
-        print 'TestSlice.check_sanity_slice (run scripts in slice): XXX todo'
-        return True
index 9dcda2b..7369a8d 100644 (file)
@@ -23,7 +23,7 @@ class TestSliver:
     def create_test_ssh(self):
         (found,privatekey) = self.get_privateKey()
         if not found:
-            raise Exception,"Cannot find a valid key for slice %s"%self.test_slice.name()
+            raise Exception,"Cannot find the private key for slice %s"%self.test_slice.name()
         return TestSsh (self.test_node.name(),key=privatekey,username=self.test_slice.name(),
                         # so that copies end up in the home dir
                         buildname=".")
@@ -50,3 +50,23 @@ class TestSliver:
     def tar_var_logs (self):
         return self.test_ssh.actual_command("sudo tar -C /var/log -cf - .")
     
+    def check_sanity (self):
+        print 'WARNING: slice sanity check scripts NOT (yet?) run in sudo'
+        extensions = [ 'py','pl','sh' ]
+        path='tests/qaapi/qa/tests/slice/'
+        scripts=utils.locate_sanity_scripts ('sliver '+self.name(), path,extensions)
+        overall = True
+        for script in scripts:
+            if not self.check_sanity_script (script):
+                overall = False
+        return overall
+
+    def check_sanity_script (self,local_script):
+        ssh_handle=self.create_test_ssh()
+        ssh_handle.copy_home(local_script)
+        if ssh_handle.run("./"+os.path.basename(local_script)) != 0:
+            print "WARNING: sanity check script %s FAILED"
+            # xxx - temporary : ignore result and always return true for now
+            #return False
+        return True
+    
index 6f11344..5b5ce94 100644 (file)
@@ -154,7 +154,7 @@ class TestSsh:
             if recursive: command += "-r "
             command += self.key_part()
             command += "%s:%s/%s %s"%(self.hostname_part(),self.buildname,remote_file,local_file)
-        utils.system(command)
+        return utils.system(command)
 
     # this is only to avoid harmless message when host cannot be identified
     # convenience only
@@ -163,5 +163,5 @@ class TestSsh:
     def clear_known_hosts (self):
         known_hosts = "%s/.ssh/known_hosts"%os.getenv("HOME")
         utils.header("Clearing entry for %s in %s"%(self.hostname,known_hosts))
-        utils.system("sed -i -e /^%s/d %s"%(self.hostname,known_hosts))
+        return utils.system("sed -i -e /^%s/d %s"%(self.hostname,known_hosts))
         
index d17dbef..42eb93b 100644 (file)
@@ -1,7 +1,5 @@
 # $Id$
-import time
-import os
-import re
+import time, os, re, glob
 from pprint import PrettyPrinter
 
 options={}
@@ -134,3 +132,10 @@ def match (string, pattern):
     pattern=pattern.replace("?",".")
     return re.compile(pattern).match(string)
     
+def locate_sanity_scripts (message,path,extensions):
+    print message,'searching',path,'for extensions',extensions
+    scripts=[]
+    for ext in extensions:
+        scripts += glob.glob (path+'/*.'+ext)
+    return scripts
+