6 from TestKey import TestKey
7 from TestUser import TestUser
8 from TestNode import TestNode
9 from TestSsh import TestSsh
13 def __init__ (self,test_plc,test_site,slice_spec):
14 self.test_plc=test_plc
15 self.test_site=test_site
16 #self.slice_spec=plc_spec_sfa['slices_sfa'][0]
17 self.slice_spec=slice_spec
18 self.test_ssh=TestSsh(self.test_plc.test_ssh)
21 return self.slice_spec['slice_fields']['name']
24 for username,keyname in self.slice_spec['usernames']:
25 key_spec=self.test_plc.locate_key(keyname)
26 test_key=TestKey(self.test_plc,key_spec)
27 publickey=test_key.publicpath()
28 privatekey=test_key.privatepath()
29 if os.path.isfile(publickey) and os.path.isfile(privatekey):
31 return (found,privatekey)
35 self.test_plc.run_in_guest("sfi.py -d /root/.sfi/ add slice.xml")==0
37 def create_slice(self):
38 auth=self.test_plc.plc_spec['sfa']['SFA_REGISTRY_ROOT_AUTH']
40 self.test_plc.run_in_guest("sfi.py -d /root/.sfi/ create %s.main.sfaslicea1 slice.rspec"%auth)==0
42 def update_slice(self):
43 auth=self.test_plc.plc_spec['sfa']['SFA_REGISTRY_ROOT_AUTH']
45 self.test_plc.run_in_guest("sfi.py -d /root/.sfi/ create %s.main.sfaslicea1 slice.rspec"%auth)==0
47 def delete_slice(self):
48 auth=self.test_plc.plc_spec['sfa']['SFA_REGISTRY_ROOT_AUTH']
49 self.test_plc.run_in_guest("sfi.py -d /root/.sfi/ delete %s.main.sfaslicea1"%auth)
51 self.test_plc.run_in_guest("sfi.py -d /root/.sfi/ remove -t slice %s.main.sfaslicea1"%auth)==0
53 def check_slice_sfa(self,options,timeout_minutes=40,silent_minutes=30,period=15):
54 timeout = datetime.datetime.now()+datetime.timedelta(minutes=timeout_minutes)
55 graceout = datetime.datetime.now()+datetime.timedelta(minutes=silent_minutes)
57 (found,remote_privatekey)=self.locate_key()
59 utils.header("WARNING: Cannot find a valid key for slice %s"%self.name())
62 # convert nodenames to real hostnames
63 slice_spec = self.slice_spec
66 for nodename in slice_spec['nodenames']:
67 (site_spec,node_spec) = self.test_plc.locate_node(nodename)
68 tocheck.append(node_spec['node_fields']['hostname'])
70 utils.header("checking ssh access into slice %s on nodes %r"%(self.name(),tocheck))
71 utils.header("max timeout is %d minutes, silent for %d minutes (period is %s)"%\
72 (timeout_minutes,silent_minutes,period))
74 for hostname in tocheck:
75 (site_spec,node_spec) = self.test_plc.locate_hostname(hostname)
76 date_test_ssh = TestSsh (hostname,key=remote_privatekey,username=self.name())
77 command = date_test_ssh.actual_command("echo hostname ; hostname; echo id; id; echo uname -a ; uname -a")
78 date = utils.system (command, silent=datetime.datetime.now() < graceout)
80 utils.header("Successfuly entered slice %s on %s"%(self.name(),hostname))
81 tocheck.remove(hostname)
83 # real nodes will have been checked once in case they're up - skip if not
84 if TestNode.is_real_model(node_spec['node_fields']['model']):
85 utils.header("WARNING : Checking slice %s on real node %s skipped"%(self.name(),hostname))
86 tocheck.remove(hostname)
87 # nm restart after first failure, if requested
88 if options.forcenm and hostname not in restarted:
89 utils.header ("forcenm option : restarting nm on %s"%hostname)
90 restart_test_ssh=TestSsh(hostname,key="keys/key1.rsa")
91 access=restart_test_ssh.actual_command('service nm restart')
93 utils.header('nm restarted on %s'%hostname)
95 utils.header('Failed to restart nm on %s'%(hostname))
96 restarted.append(hostname)
100 if datetime.datetime.now() > timeout:
101 for hostname in tocheck:
102 utils.header("FAILURE to ssh into %s@%s"%(self.name(),hostname))
104 # wait for the period