8 from TestMapper import TestMapper
9 from TestPool import TestPoolQemu, TestPoolIP
10 from Trackers import TrackerPlc, TrackerQemu
14 # need more specialization, see an example in OnelabTestResources
17 def localize (self,plcs,options):
19 plcs = self.localize_qemus(plcs,options)
21 print '* Could not localize qemus','--',e,'--','exiting'
24 plcs = self.localize_nodes(plcs,options)
26 print '* Could not localize nodes','--',e,'--','exiting'
29 plcs = self.localize_plcs(plcs,options)
31 print '* Could not localize plcs','--',e,'--','exiting'
34 plcs = self.localize_rspec(plcs,options)
36 print '* Could not localize RSpec','--',e,'--','exiting'
40 def qemus_ip_pool(self):
41 return self.qemus_ip_pool_64()
43 return len(self.qemus_ip_pool())
45 return len(self.plcs_ip_pool())
47 def localize_qemus (self,plcs,options):
49 # all plcs on the same vserver box
50 plc_box = self.plc_boxes()[0]
53 label=options.personality.replace("linux","")
56 qemu_pool = TestPoolQemu (self.qemus_ip_pool(), options)
58 for index in range(options.size):
61 ip_or_hostname=options.ips_qemu.pop()
62 (hostname,ip,unused)=qemu_pool.locate_entry(ip_or_hostname)
64 (hostname,ip,unused) = qemu_pool.next_free()
66 node_map += [ ('node%d'%index, {'host_box':hostname},) ]
68 mapper = {'plc': [ ('*' , {'hostname':plc_box,
69 'PLC_DB_HOST':plc_box,
70 'PLC_API_HOST':plc_box,
71 'PLC_BOOT_HOST':plc_box,
72 'PLC_WWW_HOST':plc_box,
73 'name':'%s-'+label } )
78 return TestMapper(plcs,options).map(mapper)
81 def localize_nodes (self, plcs, options):
83 ip_pool = TestPoolIP (self.nodes_ip_pool(),options)
84 network_dict = self.network_dict()
86 test_mapper = TestMapper (plcs, options)
88 all_nodenames = test_mapper.node_names()
90 for nodename in all_nodenames:
92 ip_or_hostname=options.ips_node.pop()
93 print 'debug','in',ip_or_hostname,'out',ip_pool.locate_entry(ip_or_hostname)
94 (hostname,ip,mac)=ip_pool.locate_entry(ip_or_hostname)
96 (hostname,ip,mac) = ip_pool.next_free()
97 utils.header('Attaching node %s to %s (%s)'%(nodename,hostname,ip))
98 node_dict= {'node_fields:hostname':hostname,
99 'interface_fields:ip':ip,
100 'interface_fields:mac':mac,
103 node_dict.update(network_dict)
104 maps.append ( ( nodename, node_dict) )
106 plc_map = [ ( '*' , { 'PLC_NET_DNS1' : network_dict [ 'interface_fields:dns1' ],
107 'PLC_NET_DNS2' : network_dict [ 'interface_fields:dns2' ], } ) ]
109 return test_mapper.map ({'node': maps, 'plc' : plc_map } )
112 def localize_plcs (self,plcs,options):
114 utils.header ("Turning configuration into a vserver-based one for onelab")
115 ip_pool = TestPoolIP (self.plcs_ip_pool(),options)
120 ip_or_hostname=options.ips_plc.pop()
121 (hostname,ip,mac)=ip_pool.locate_entry(ip_or_hostname)
123 utils.header("Using user-provided %s %s for plc %s"%(
124 hostname,ip_or_hostname,plc['name']))
126 (hostname,ip,mac)=ip_pool.next_free()
128 utils.header("Using auto-allocated %s %s for plc %s"%(
129 hostname,ip,plc['name']))
131 ### rewrite fields in plc
132 # compute a helpful vserver name - remove domain in hostname
133 simplehostname=hostname.split('.')[0]
134 vservername = options.buildname
136 vservername = "%s-%s" % (vservername,simplehostname)
139 vservername = "%s-%d-%s" % (vservername,plc_counter,simplehostname)
141 plc['vservername']=vservername
143 plc['name'] = "%s_%s"%(plc['name'],simplehostname)
144 utils.header("Attaching plc %s to vserver %s (%s)"%(
145 plc['name'],plc['vservername'],plc['vserverip']))
146 for key in [ 'PLC_DB_HOST', 'PLC_API_HOST', 'PLC_WWW_HOST', 'PLC_BOOT_HOST',]:
151 # as a plc step this should return a boolean
152 def step_pre (self,plc):
153 return self.trqemu_record (plc) and self.trqemu_free(plc)
155 def step_post (self,plc):
156 return self.trplc_record (plc) and self.trplc_free(plc)
158 def step_cleanup (self,plc):
159 return self.trqemu_cleanup(plc) and self.trplc_cleanup(plc)
161 def step_list (self,plc):
162 return self.trqemu_list(plc) and self.trplc_list(plc)
165 def trqemu_record (self,plc):
166 tracker=TrackerQemu(plc.options,instances=self.max_qemus()-1)
167 for site_spec in plc.plc_spec['sites']:
168 for node_spec in site_spec['nodes']:
169 tracker.record(node_spec['host_box'],plc.options.buildname,node_spec['node_fields']['hostname'])
173 def trqemu_free (self,plc):
174 tracker=TrackerQemu(plc.options,instances=self.max_qemus()-1)
175 for site_spec in plc.plc_spec['sites']:
176 for node_spec in site_spec['nodes']:
182 def trplc_record (self,plc):
183 tracker = TrackerPlc(plc.options,instances=self.max_plcs()-1)
184 tracker.record(plc.test_ssh.hostname,plc.vservername)
188 def trplc_free (self,plc):
189 tracker = TrackerPlc(plc.options,instances=self.max_plcs()-1)
195 def trqemu_cleanup (self,plc):
196 tracker=TrackerQemu(plc.options,instances=self.max_qemus()-1)
197 for site_spec in plc.plc_spec['sites']:
198 for node_spec in site_spec['nodes']:
203 def trplc_cleanup (self,plc):
204 tracker = TrackerPlc(plc.options,instances=self.max_plcs()-1)
209 def trqemu_list (self,plc):
210 TrackerQemu(plc.options,instances=self.max_qemus()-1).list()
213 def trplc_list (self,plc):
214 TrackerPlc(plc.options,instances=self.max_plcs()-1).list()
217 def localize_rspec (self,plcs,options):
219 utils.header ("Localize SFA Slice RSpec")
222 for site in plc['sites']:
223 for node in site['nodes']:
224 plc['sfa']['sfa_slice_rspec']['part4'] = node['node_fields']['hostname']
225 plc['sfa']['SFA_REGISTRY_HOST'] = plc['PLC_DB_HOST']
226 plc['sfa']['SFA_AGGREGATE_HOST'] = plc['PLC_DB_HOST']
227 plc['sfa']['SFA_SM_HOST'] = plc['PLC_DB_HOST']
228 plc['sfa']['SFA_PLC_DB_HOST'] = plc['PLC_DB_HOST']
229 plc['sfa']['SFA_PLC_URL'] = 'https://' + plc['PLC_API_HOST'] + ':443/PLCAPI/'