*Add checktcp step to test the connexion on both client(slice*@node*) and server(slice**@node**) side.
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
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)
(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:
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()
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):
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()
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()
--- /dev/null
+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
+
+
}]
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',
'keys' : keys(),
'initscripts': initscripts(),
'slices' : slices(),
+ 'tcp_param' : tcp_param(),
}
def config (plc_specs,options):