self.add_nodes()
+ def check_vsys_defaults (self, options, *args, **kwds):
+ "check vsys tags match PLC_VSYS_DEFAULTS"
+ auth = self.owner_auth()
+ slice_fields = self.slice_spec['slice_fields']
+ slice_name = slice_fields['name']
+ vsys_tags = self.test_plc.apiserver.GetSliceTags (auth,{'tagname':'vsys','name':slice_name})
+ values=[ st['value'] for st in vsys_tags ]
+ expected=self.test_plc.plc_spec['expected_vsys_tags']
+ result = set(values) == set(expected)
+ if not result:
+ print 'Check vsys defaults with slice %s'%slice_name
+ print 'Expected %s'%expected
+ print 'Got %s'%values
+ return result
+
# just add the nodes and handle tags
def add_nodes (self):
auth = self.owner_auth()
(len(node_ids),slice_name))
self.test_plc.apiserver.DeleteSliceFromNodes (auth,slice_name, node_ids)
- def locate_key(self):
- # locate the first avail. key
- found=False
+ def locate_private_key(self):
+ key_names=[]
for username in self.slice_spec['usernames']:
user_spec=self.test_site.locate_user(username)
- for key_name in user_spec['key_names']:
- key_spec=self.test_plc.locate_key(key_name)
- test_key=TestKey(self.test_plc,key_spec)
- publickey=test_key.publicpath()
- privatekey=test_key.privatepath()
- if os.path.isfile(publickey) and os.path.isfile(privatekey):
- found=True
- return (found,privatekey)
-
+ key_names += user_spec['key_names']
+ return self.test_plc.locate_private_key_from_key_names (key_names)
# trying to reach the slice through ssh - expected to answer
def ssh_slice (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):
+ def do_ssh_slice(self,options,expected=True,timeout_minutes=20,silent_minutes=10,period=15,command=None):
timeout = datetime.datetime.now()+datetime.timedelta(minutes=timeout_minutes)
graceout = datetime.datetime.now()+datetime.timedelta(minutes=silent_minutes)
+ if not command:
+ command="echo hostname ; hostname; echo id; id; echo uname -a ; uname -a"
# locate a key
- (found,remote_privatekey)=self.locate_key()
- if not found :
+ 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
while tocheck:
for hostname in tocheck:
(site_spec,node_spec) = self.test_plc.locate_hostname(hostname)
- date_test_ssh = TestSsh (hostname,key=remote_privatekey,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)
+ test_ssh = TestSsh (hostname,key=private_key,username=self.name())
+ full_command = test_ssh.actual_command(command)
+ retcod = utils.system (full_command, silent=datetime.datetime.now() < graceout)
if getattr(options,'dry_run',None): return True
- if expected: success = date==0
- else: success = date!=0
+ if expected: success = retcod==0
+ else: success = retcod!=0
if success:
utils.header("OK %s - slice=%s@%s"%(msg,self.name(),hostname))
time.sleep (period)
# for an empty slice
return True
+
+ 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
+ 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 %s"%self.name())
+ return False
+
+ # convert nodenames to real hostnames
+ slice_spec = self.slice_spec
+ nodename=slice_spec['nodenames'][0]
+ (site_spec,node_spec) = self.test_plc.locate_node(nodename)
+ hostname=node_spec['node_fields']['hostname']
+
+ if expected: msg="%s to return TRUE from ssh"%command
+ else: msg="%s to return FALSE from ssh"%command
+
+ utils.header("checking %s -- slice %s on node %s"%(msg,self.name(),hostname))
+ (site_spec,node_spec) = self.test_plc.locate_hostname(hostname)
+ test_ssh = TestSsh (hostname,key=private_key,username=self.name())
+ full_command = test_ssh.actual_command(command)
+ retcod = utils.system (full_command,silent=True)
+ if getattr(options,'dry_run',None): return True
+ if expected: success = retcod==0
+ else: success = retcod!=0
+ if not success: utils.header ("WRONG RESULT for %s"%msg)
+ return success