- for keyname in user_spec['keynames']:
- key_spec=self.test_plc.locate_key(keyname)
- test_key=TestKey(self.test_plc,key_spec)
- publickey=test_key.publicpath()
- privatekey=test_key.privatepath()
- keyname=test_key.name()
- if os.path.isfile(publickey) and os.path.isfile(privatekey):
- found=True
- #create dir in plc root image
- remote_privatekey="/root/keys/%s.rsa"%keyname
- if not os.path.isfile(remote_privatekey):
- self.test_plc.run_in_guest("mkdir -p /root/keys" )
- self.test_plc.copy_in_guest(privatekey,remote_privatekey,True)
-
- 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()
- start_time = datetime.datetime.now()
- dead_time=start_time + datetime.timedelta(minutes=15)
+ key_names += user_spec['key_names']
+ return self.test_plc.locate_private_key_from_key_names (key_names)
+
+ # for TestPlc.slice_mapper__tasks
+ # i.e. returns a list of CompleterTasks that are merged into the same Completer run
+ # to avoid waiting for as many slices as the Plc has
+ # also the __doc__ lines are used for the TestPlc methods, e.g. just 'ssh_slice'
+ def ssh_slice__tasks (self, options, *args, **kwds):
+ "tries to ssh-enter the slice with the user key, to check for slice creation"
+ return self.ssh_tasks(options, expected=True, *args, **kwds)
+
+ # when we expect the slice is not reachable
+ def ssh_slice_off__tasks (self, options, *args, **kwds):
+ "tries to ssh-enter the slice with the user key, expecting it to be unreachable"
+ return self.ssh_tasks(options, expected=False, *args, **kwds)
+
+ def ssh_tasks(self,options, expected=True, command=None):
+# timeout_minutes=20, silent_minutes=10, period_seconds=15):
+# timeout = timedelta(minutes=timeout_minutes)
+# graceout = timedelta(minutes=silent_minutes)
+# period = timedelta(seconds=period_seconds)
+ if not command:
+ command = "echo hostname ; hostname; echo id; id; echo uname -a ; uname -a"
+ # locate a key
+ private_key = self.locate_private_key()
+ if not private_key :
+ utils.header("WARNING: Cannot find a valid key for slice {}".format(self.name()))
+ return False
+
+ # convert nodenames to real hostnames
+ if expected: msg="ssh slice access enabled"
+ else: msg="ssh slice access disabled"
+ utils.header("checking for {} -- slice {}".format(msg, self.name()))
+
+ tasks=[]
+ slicename=self.name()
+ dry_run = getattr(options, 'dry_run', False)
+ for nodename in self.slice_spec['nodenames']:
+ site_spec, node_spec = self.test_plc.locate_node(nodename)
+ tasks.append( CompleterTaskSliceSsh(self.test_plc, node_spec['node_fields']['hostname'],
+ slicename, private_key, command, expected, dry_run))
+ return tasks
+
+ def ssh_slice_basics (self, options, *args, **kwds):
+ "the slice is expected to be UP and we just check a few simple sanity commands, including 'ps' to check for /proc"
+ overall = True
+ if not self.do_ssh_slice_once(options, expected=True, command='true'): overall=False
+ if not self.do_ssh_slice_once(options, expected=False, command='false'): overall=False
+ if not self.do_ssh_slice_once(options, expected=False, command='someimprobablecommandname'): overall=False
+ if not self.do_ssh_slice_once(options, expected=True, command='ps'): overall=False
+ if not self.do_ssh_slice_once(options, expected=False, command='ls /vservers'): overall=False
+ return overall
+
+ # pick just one nodename and runs the ssh command once
+ def do_ssh_slice_once(self, options, command, expected):
+ # locate a key
+ private_key=self.locate_private_key()
+ if not private_key :
+ utils.header("WARNING: Cannot find a valid key for slice {}".format(self.name()))
+ return False
+
+ # convert nodenames to real hostnames