return key
raise Exception,"Cannot locate key %s"%key_name
+ def locate_private_key_from_key_names (self, key_names):
+ # locate the first avail. key
+ found=False
+ for key_name in key_names:
+ key_spec=self.locate_key(key_name)
+ test_key=TestKey(self,key_spec)
+ publickey=test_key.publicpath()
+ privatekey=test_key.privatepath()
+ if os.path.isfile(publickey) and os.path.isfile(privatekey):
+ found=True
+ if found: return privatekey
+ else: return None
+
def locate_slice (self, slicename):
for slice in self.plc_spec['slices']:
if slice['slice_fields']['name'] == slicename:
(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):
timeout = datetime.datetime.now()+datetime.timedelta(minutes=timeout_minutes)
graceout = datetime.datetime.now()+datetime.timedelta(minutes=silent_minutes)
# 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())
+ 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 self.test_plc.run_in_guest(command)!=0: return False
return True
+ def plc_name (self):
+ return "%s_%s"%(self.test_auth_sfa.login_base,self.slice_spec['name'])
+
# all local nodes in slice ?
def sfa_check_slice_plc (self,options):
"check sfa_create_slice at the plcs - all local nodes should be in slice"
- login_base=self.test_auth_sfa.login_base
- slice_name = "%s_%s"%(login_base,self.slice_spec['name'])
- slice=self.test_plc.apiserver.GetSlices(self.test_plc.auth_root(), slice_name)[0]
+ slice=self.test_plc.apiserver.GetSlices(self.test_plc.auth_root(), self.plc_name())[0]
nodes=self.test_plc.apiserver.GetNodes(self.test_plc.auth_root(), {'peer_id':None})
result=True
for node in nodes:
self.test_plc.run_in_guest(self.sfi_pi("delete %s"%(self.hrn(),)))
return self.test_plc.run_in_guest(self.sfi_pi("remove -t slice %s"%(self.hrn(),)))==0
+ def locate_private_key(self):
+ return self.test_plc.locate_private_key_from_key_names ( [ self.slice_spec['key_name'] ] )
+
# check the resulting sliver
def ssh_slice_sfa(self,options,timeout_minutes=40,silent_minutes=30,period=15):
"tries to ssh-enter the SFA slice"
timeout = datetime.datetime.now()+datetime.timedelta(minutes=timeout_minutes)
graceout = datetime.datetime.now()+datetime.timedelta(minutes=silent_minutes)
# locate a key
- (found,remote_privatekey)=self.locate_key()
- if not found :
- utils.header("WARNING: Cannot find a valid key for slice %s"%self.plc_name())
+ 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
restarted=[]
tocheck=[]
- for nodename in self.auth_sfa_spec['nodenames']:
+ for nodename in self.slice_spec['nodenames']:
(site_spec,node_spec) = self.test_plc.locate_node(nodename)
tocheck.append(node_spec['node_fields']['hostname'])
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.plc_name())
+ date_test_ssh = TestSsh (hostname,key=private_key,username=self.plc_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 date==0:
print str(e)
def create_test_ssh(self):
- (found,privatekey) = self.get_privateKey()
- if not found:
+ private_key = self.test_slice.locate_private_key()
+ if not private_key:
raise Exception,"Cannot find the private key for slice %s"%self.test_slice.name()
- return TestSsh (self.test_node.name(),key=privatekey,username=self.test_slice.name(),
+ return TestSsh (self.test_node.name(),key=private_key,username=self.test_slice.name(),
# so that copies end up in the home dir
buildname=".")
def sfi_path(self): return self.test_auth_sfa.sfi_path()
def qualified(self,name): return self.test_auth_sfa.qualified(name)
+ def sfi_pi(self,*args,**kwds): return self.test_auth_sfa.sfi_pi(*args, **kwds)
+ def sfi_user(self,*args,**kwds): return self.test_auth_sfa.sfi_user(*args, **kwds)
# xxx todo - not the right place any longer - or is it ?
def sfa_add_user (self,options):
"add a regular user using sfi add"
sfi_add_options = self.user_spec['sfi_options']
user_hrn = self.qualified(self.user_spec['name'])
- command="sfi -d %s add"%(self.sfi_path())
+ command="%s add"%(self.sfi_path())
command += " --type user"
command += " --xrn %s"%user_hrn
command += " --email %s"%self.user_spec['email']
# handle key separately because of embedded whitespace
# hack - the user's pubkey is avail from his hrn
command += " -k %s/%s.pub"%(self.sfi_path(),user_hrn)
- return self.test_plc.run_in_guest(command)==0
+ return self.test_plc.run_in_guest(self.sfi_pi(command))==0
def sfa_update_user (self,options):
"update a user record using sfi update"
def sfa_delete_user(self,options):
"run sfi delete on user record"
- auth=self.test_auth_sfa.root_hrn()
+ user_hrn = self.qualified(self.user_spec['name'])
+ command="remove -t user %s"%user_hrn
return \
- self.test_plc.run_in_guest("sfi -d %s remove -t user %s.%s.%s"%(
- self.sfi_path(),auth,self.login_base,self.regularuser))==0
+ self.test_plc.run_in_guest(self.sfi_pi(command))==0