- def do_check_slices(self,options):
- bool=True
- self.clear_known_hosts()
- start_time = datetime.datetime.now()
- dead_time=start_time + datetime.timedelta(minutes=15)
- for slice_spec in self.test_plc.plc_spec['slices']:
- for hostname in slice_spec['nodenames']:
- slicename=slice_spec['slice_fields']['name']
- (found,remote_privatekey)=self.locate_key(slice_spec)
- if( not found):
- raise Exception,"Cannot find a valid key for slice %s"%slicename
- break
- while(bool):
- utils.header('trying to connect to %s@%s'%(slicename,hostname))
- Date=self.test_plc.run_in_guest('ssh -i %s %s@%s date'%(remote_privatekey,slicename,hostname))
- if (Date==0):
- break
- elif ( start_time <= dead_time ) :
- start_time=datetime.datetime.now()+ datetime.timedelta(seconds=45)
- time.sleep(45)
- elif (options.forcenm):
- utils.header('%s@%s : restarting nm in case is in option on %s'%(slicename,hostname,hostname))
- access=self.test_plc.run_in_guest('ssh -i /etc/planetlab/root_ssh_key.rsa root@%s service nm restart'%hostname)
+ # when we expect the slice is not reachable
+ def ssh_slice_off (self, options, *args, **kwds):
+ "tries to ssh-enter the slice with the user key, expecting it to be unreachable"
+ return self.do_ssh_slice(options, expected=False, *args, **kwds)
+
+ def do_ssh_slice(self,options,expected=True,timeout_minutes=20,silent_minutes=10,period=15):
+ timeout = datetime.datetime.now()+datetime.timedelta(minutes=timeout_minutes)
+ graceout = datetime.datetime.now()+datetime.timedelta(minutes=silent_minutes)
+ # locate a key
+ private_key=self.locate_private_key()
+ if not private_key :
+ utils.header("WARNING: Cannot find a valid key for slice %s"%self.name())
+ return False
+
+ # convert nodenames to real hostnames
+ slice_spec = self.slice_spec
+ restarted=[]
+ tocheck=[]
+ for nodename in slice_spec['nodenames']:
+ (site_spec,node_spec) = self.test_plc.locate_node(nodename)
+ tocheck.append(node_spec['node_fields']['hostname'])
+
+ if expected: msg="ssh slice access enabled"
+ else: msg="ssh slice access disabled"
+
+ utils.header("checking for %s -- slice %s on nodes %r"%(msg,self.name(),tocheck))
+ utils.header("max timeout is %d minutes, silent for %d minutes (period is %s)"%\
+ (timeout_minutes,silent_minutes,period))
+ while tocheck:
+ for hostname in tocheck:
+ (site_spec,node_spec) = self.test_plc.locate_hostname(hostname)
+ date_test_ssh = TestSsh (hostname,key=private_key,username=self.name())
+ command = date_test_ssh.actual_command("echo hostname ; hostname; echo id; id; echo uname -a ; uname -a")
+ date = utils.system (command, silent=datetime.datetime.now() < graceout)
+ if getattr(options,'dry_run',None): return True
+ if expected: success = date==0
+ else: success = date!=0
+
+ if success:
+ utils.header("OK %s - slice=%s@%s"%(msg,self.name(),hostname))
+ tocheck.remove(hostname)
+ else:
+ # real nodes will have been checked once in case they're up - skip if not
+ if TestNode.is_real_model(node_spec['node_fields']['model']):
+ utils.header("WARNING : Checking slice %s on real node %s skipped"%(self.name(),hostname))
+ tocheck.remove(hostname)
+ # nm restart after first failure, if requested
+ if options.forcenm and hostname not in restarted:
+ utils.header ("forcenm option : restarting nm on %s"%hostname)
+ restart_test_ssh=TestSsh(hostname,key="keys/key_admin.rsa")
+ access=restart_test_ssh.actual_command('service nm restart')