*Add TestSliver class.
authorTony Mack <tmack@cs.princeton.edu>
Tue, 19 Feb 2008 09:11:07 +0000 (09:11 +0000)
committerTony Mack <tmack@cs.princeton.edu>
Tue, 19 Feb 2008 09:11:07 +0000 (09:11 +0000)
*Add  checktcp step to  test the  connexion on both  client(slice*@node*) and server(slice**@node**) side.

system/TestPlc.py
system/TestSlice.py
system/TestSliver.py [new file with mode: 0644]
system/config_onelab.py

index db196f3..c590fdb 100644 (file)
@@ -14,6 +14,7 @@ from TestNode import TestNode
 from TestUser import TestUser
 from TestKey import TestKey
 from TestSlice import TestSlice
+from TestSliver import TestSliver
 from TestBox import TestBox
 
 # step methods must take (self, options) and return a boolean
@@ -462,7 +463,6 @@ class TestPlc:
     def do_check_nodesSsh(self,minutes):
         # compute timeout
         timeout = datetime.datetime.now()+datetime.timedelta(minutes=minutes)
-        #graceout = datetime.datetime.now()+datetime.timedelta(minutes=gracetime)
         tocheck = self.all_hostnames()
         self.scan_publicKeys(tocheck)
         utils.header("checking Connectivity on nodes %r"%tocheck)
@@ -478,8 +478,8 @@ class TestPlc:
                     (site_spec,node_spec)=self.locate_node(hostname)
                     if TestNode.is_real_model(node_spec['node_fields']['model']):
                         utils.header ("WARNING : check ssh access into real node %s - skipped"%hostname)
-                    tocheck.remove(hostname)
-            if not tocheck:
+                       tocheck.remove(hostname)
+            if  not tocheck:
                 return True
             if datetime.datetime.now() > timeout:
                 for hostname in tocheck:
@@ -502,14 +502,16 @@ class TestPlc:
         return True
 
     def do_check_intiscripts(self):
-           for site_spec in self.plc_spec['sites']:
-                   test_site = TestSite (self,site_spec)
-                   for slice_spec in self.plc_spec['slices']:
-                           test_slice=TestSlice (self,test_site,slice_spec)
-                           init_status=test_slice.get_initscript()
-                           if (not init_status):
-                                   return False
-                   return init_status
+       for site_spec in self.plc_spec['sites']:
+               test_site = TestSite (self,site_spec)
+               test_node = TestNode (self,test_site,site_spec['nodes'])
+               for slice_spec in self.plc_spec['slices']:
+                       test_slice=TestSlice (self,test_site,slice_spec)
+                       test_sliver=TestSliver(self,test_node,test_slice)
+                       init_status=test_sliver.get_initscript(slice_spec)
+                       if (not init_status):
+                               return False
+               return init_status
            
     def check_initscripts(self, options):
            return self.do_check_intiscripts()
@@ -561,8 +563,13 @@ class TestPlc:
         return True
 
     def check_tcp (self, options):
-        print 'check_tcp not yet implemented'
-        return True
+           #we just need to create a sliver object nothing else
+           test_sliver=TestSliver(self,
+                                  TestNode(self, TestSite(self,self.plc_spec['sites'][0]),
+                                           self.plc_spec['sites'][0]['nodes'][0]),
+                                  TestSlice(self,TestSite(self,self.plc_spec['sites'][0]),
+                                            self.plc_spec['slices']))
+           return test_sliver.do_check_tcp(self.plc_spec['tcp_param'],options)
 
     # returns the filename to use for sql dump/restore, using options.dbname if set
     def dbfile (self, database, options):
index 73c047e..81ad596 100644 (file)
@@ -17,6 +17,11 @@ class TestSlice:
     def name(self):
         return self.slice_spec['slice_fields']['name']
 
+    def get_slice(self,slice_name):
+        for slice_spec in self.test_plc.plc_spec['slices']:
+            if(slice_spec['slice_fields']['name']== slice_name):
+                return slice_spec
+
     def delete_slice(self):
         owner_spec = self.test_site.locate_user(self.slice_spec['owner'])
         auth = TestUser(self,self.test_site,owner_spec).auth()
@@ -79,19 +84,6 @@ class TestSlice:
 
         return (found,remote_privatekey)
 
-    def get_initscript(self):
-        (found,remote_privatekey)=self.locate_key(self.slice_spec)
-        if not found :
-            raise Exception,"Cannot find a valid key for slice %s"%self.name()
-        for hostname in  self.slice_spec['nodenames']:
-            utils.header("Checking initiscript %s on the slice %s@%s"
-                         %(self.slice_spec['initscriptname'],self.name(),hostname))
-            init_file=self.test_plc.run_in_guest('ssh -i %s %s@%s ls -l /tmp/init* '%(remote_privatekey,self.name(),hostname))
-            if ( init_file):
-                return False
-            
-        return True
-    
     def do_check_slice(self,options):
         bool=True
         self.clear_known_hosts()
diff --git a/system/TestSliver.py b/system/TestSliver.py
new file mode 100644 (file)
index 0000000..527a519
--- /dev/null
@@ -0,0 +1,89 @@
+import utils
+import os, os.path
+import datetime
+import time
+
+
+class TestSliver:
+
+    def __init__ (self,test_plc,test_node,test_slice):
+        self.test_plc=test_plc
+       self.test_node=test_node
+        self.test_slice=test_slice
+            
+    def get_privateKey(self,slice_spec):
+        try:
+            (found,remote_privatekey)=self.test_slice.locate_key(slice_spec)
+            return (found,remote_privatekey)
+        except Exception,e:
+            print str(e)
+            
+    def get_initscript(self,slice_spec):
+       (found,remote_privatekey)=self.get_privateKey(slice_spec)
+        if not found :
+            raise Exception,"Cannot find a valid key for slice %s"%self.test_slice.name()
+        for hostname in  slice_spec['nodenames']:
+            utils.header("Checking initiscript %s on the slice %s@%s"
+                         %(slice_spec['initscriptname'],self.test_slice.name(),hostname))
+            init_file=self.test_plc.run_in_guest('ssh -i %s %s@%s ls -l /tmp/init* '
+                                                 %(remote_privatekey,self.test_slice.name(),hostname))
+            if ( init_file):
+                return False
+            
+        return True
+    
+    def run_tcpcheck(self,peer_spec,remote_privatekey):
+        if peer_spec['peer_name']=="server":
+            tcp_command="ssh -i %s %s@%s ./tcptest.py server -t 10"%(remote_privatekey, peer_spec['slice_name'],
+                                                                   peer_spec['server_name'])
+            return self.test_plc.run_in_guest(tcp_command)
+        
+        else:
+            tcp_command="ssh -i %s %s@%s ./tcptest.py client -a %s -p %d"%(remote_privatekey, peer_spec['slice_name'],
+                                                                           peer_spec['client_name'],peer_spec['peer_server'],
+                                                                           peer_spec['server_port'])
+            return self.test_plc.run_in_guest(tcp_command)
+
+
+
+    def do_check_tcp(self,tcp_param,options):
+        for tcp_spec in tcp_param:
+            #copy the tcptest file under the chroot
+            path=options.path
+            localfile=path+"/tcptest.py"
+            remotefile="tcptest.py"
+            self.test_plc.copy_in_guest(localfile, remotefile, False)
+            peer_param=tcp_spec['tcp_fields']
+            if (tcp_spec['tcp_fields']['peer_name']=='server'):
+                #server instruction
+                utils.header("Transfert the tcp script to the server at %s@%s"%(peer_param['slice_name'],
+                                                                                peer_param['server_name']))
+                slice_spec=self.test_slice.get_slice(peer_param['slice_name'])
+                (found,remote_privatekey)=self.get_privateKey(slice_spec)
+                cp_server_command="scp -i %s ./tcptest.py %s@%s:"%(remote_privatekey,peer_param['slice_name'],
+                                                                   peer_param['server_name'])
+                self.test_plc.run_in_guest(cp_server_command)
+                serv_status=self.run_tcpcheck(peer_param,remote_privatekey)
+                if (serv_status):
+                    utils.header("FAILED to check loop Connexion  on the %s server side"%peer_param['server_name'])
+                    return False
+            else:
+                #Client instruction
+                utils.header("Transfert the tcp script to the client at %s@%s" %(peer_param['slice_name'],
+                                                                                 peer_param['client_name']))
+                slice_spec=self.test_slice.get_slice(peer_param['slice_name'])
+                (found,remote_privatekey)=self.get_privateKey(slice_spec)
+                cp_client_command="scp -i %s ./tcptest.py %s@%s:"%(remote_privatekey, peer_param['slice_name'],
+                                                                   peer_param['client_name'])
+                self.test_plc.run_in_guest(cp_client_command)
+                client_status=self.run_tcpcheck(peer_param,remote_privatekey)
+                if ( serv_status):
+                    utils.header("FAILED to Contact the server %s from the client side %s"%(peer_param['peer_server'],
+                                                                                            peer_param['client_name']))
+                    return False
+
+
+        self.test_plc.run_in_guest("rm -rf tcptest.py")
+        return True
+
+
index dba7546..c11f638 100644 (file)
@@ -178,6 +178,27 @@ def slices ():
                }]
     return both
 
+def all_slicenames ():
+    return [ slice['slice_fields']['name'] for slice in slices()]
+
+def tcp_param():
+    param = [{ 'tcp_fields' :  {'peer_name' : 'server',
+                                'slice_name' :all_slicenames()[0],
+                                'server_name': all_nodenames()[0]
+                                },
+               
+               },
+             { 'tcp_fields':{'peer_name' : 'client',
+                             'slice_name' :all_slicenames()[1],
+                             'client_name': all_nodenames()[1],
+                             'peer_server' :  all_nodenames()[0],
+                             'server_port' : 22
+                             },
+               },
+             
+             ]
+    return param
+
 def plc () :
     return { 
         'name' : 'onelabtest',
@@ -202,6 +223,7 @@ def plc () :
         'keys' : keys(),
         'initscripts': initscripts(),
         'slices' : slices(),
+        'tcp_param' : tcp_param(),
     }
 
 def config (plc_specs,options):