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)
34 return self.test_plc.run_in_guest("sfi.py -d /root/.sfi/ add slice.xml")==0
36 def create_slice(self):
37 auth=self.test_plc.plc_spec['sfa']['SFA_REGISTRY_ROOT_AUTH']
38 self.test_plc.run_in_guest("sfi.py -d /root/.sfi/ resources -o /root/.sfi/resources_in.rspec")
39 self.test_plc.run_in_guest(
40 "sfiListNodes.py -i /root/.sfi/resources_in.rspec -o /root/.sfi/all_nodes.txt")
41 self.test_plc.run_in_guest(
42 "sfiAddSliver.py -i /root/.sfi/resources_in.rspec -n /root/.sfi/all_nodes.txt -o /root/.sfi/resources_out.rspec")
43 return self.test_plc.run_in_guest("sfi.py -d /root/.sfi/ create %s.main.fslc1 resources_out.rspec"%auth)==0
45 def update_slice(self):
46 auth=self.test_plc.plc_spec['sfa']['SFA_REGISTRY_ROOT_AUTH']
47 self.test_plc.run_in_guest("sfi.py -d /root/.sfi/ resources -o /root/.sfi/resources_in.rspec")
48 self.test_plc.run_in_guest(
49 "sfiListNodes.py -i /root/.sfi/resources_in.rspec -o /root/.sfi/all_nodes.txt")
50 self.test_plc.run_in_guest(
51 "sfiAddSliver.py -i /root/.sfi/resources_in.rspec -n /root/.sfi/all_nodes.txt -o /root/.sfi/resources_out.rspec")
52 return self.test_plc.run_in_guest("sfi.py -d /root/.sfi/ create %s.main.fslc1 resources_out.rspec"%auth)==0
54 def delete_slice(self):
55 auth=self.test_plc.plc_spec['sfa']['SFA_REGISTRY_ROOT_AUTH']
56 self.test_plc.run_in_guest("sfi.py -d /root/.sfi/ delete %s.main.fslc1"%auth)
57 return self.test_plc.run_in_guest("sfi.py -d /root/.sfi/ remove -t slice %s.main.fslc1"%auth)==0
59 def check_slice_sfa(self,options,timeout_minutes=40,silent_minutes=30,period=15):
60 timeout = datetime.datetime.now()+datetime.timedelta(minutes=timeout_minutes)
61 graceout = datetime.datetime.now()+datetime.timedelta(minutes=silent_minutes)
63 (found,remote_privatekey)=self.locate_key()
65 utils.header("WARNING: Cannot find a valid key for slice %s"%self.name())
68 # convert nodenames to real hostnames
69 slice_spec = self.slice_spec
72 for nodename in slice_spec['nodenames']:
73 (site_spec,node_spec) = self.test_plc.locate_node(nodename)
74 tocheck.append(node_spec['node_fields']['hostname'])
76 utils.header("checking ssh access into slice %s on nodes %r"%(self.name(),tocheck))
77 utils.header("max timeout is %d minutes, silent for %d minutes (period is %s)"%\
78 (timeout_minutes,silent_minutes,period))
80 for hostname in tocheck:
81 (site_spec,node_spec) = self.test_plc.locate_hostname(hostname)
82 date_test_ssh = TestSsh (hostname,key=remote_privatekey,username=self.name())
83 command = date_test_ssh.actual_command("echo hostname ; hostname; echo id; id; echo uname -a ; uname -a")
84 date = utils.system (command, silent=datetime.datetime.now() < graceout)
86 utils.header("Successfuly entered slice %s on %s"%(self.name(),hostname))
87 tocheck.remove(hostname)
89 # real nodes will have been checked once in case they're up - skip if not
90 if TestNode.is_real_model(node_spec['node_fields']['model']):
91 utils.header("WARNING : Checking slice %s on real node %s skipped"%(self.name(),hostname))
92 tocheck.remove(hostname)
93 # nm restart after first failure, if requested
94 if options.forcenm and hostname not in restarted:
95 utils.header ("forcenm option : restarting nm on %s"%hostname)
96 restart_test_ssh=TestSsh(hostname,key="keys/key1.rsa")
97 access=restart_test_ssh.actual_command('service nm restart')
99 utils.header('nm restarted on %s'%hostname)
101 utils.header('Failed to restart nm on %s'%(hostname))
102 restarted.append(hostname)
106 if datetime.datetime.now() > timeout:
107 for hostname in tocheck:
108 utils.header("FAILURE to ssh into %s@%s"%(self.name(),hostname))
110 # wait for the period