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'
26 plcs = self.localize_nodes(plcs,options)
28 print '* Could not localize nodes','--',e,'--','exiting'
31 plcs = self.localize_plcs(plcs,options)
33 print '* Could not localize plcs','--',e,'--','exiting'
36 plcs = self.localize_rspec(plcs,options)
38 print '* Could not localize RSpec','--',e,'--','exiting'
42 def localize_qemus (self,plcs,options):
44 # all plcs on the same vserver box
45 plc_box = self.plc_boxes()[0]
48 label=options.personality.replace("linux","")
51 qemu_pool = TestPoolQemu (self.qemus_ip_pool(), options)
53 for index in range(options.size):
56 ip_or_hostname=options.ips_qemu.pop()
57 (hostname,ip,unused)=qemu_pool.locate_entry(ip_or_hostname)
59 tracker=TrackerQemu(options,instances=self.max_qemus()-1)
60 (hostname,ip,unused) = qemu_pool.next_free(tracker.hostnames())
62 node_map += [ ('node%d'%index, {'host_box':hostname},) ]
64 mapper = {'plc': [ ('*' , {'hostname':plc_box,
65 'PLC_DB_HOST':plc_box,
66 'PLC_API_HOST':plc_box,
67 'PLC_BOOT_HOST':plc_box,
68 'PLC_WWW_HOST':plc_box,
69 'name':'%s-'+label } )
74 return TestMapper(plcs,options).map(mapper)
77 def localize_nodes (self, plcs, options):
79 ip_pool = TestPoolIP (self.nodes_ip_pool(),options)
80 network_dict = self.network_dict()
82 test_mapper = TestMapper (plcs, options)
84 all_nodenames = test_mapper.node_names()
86 for nodename in all_nodenames:
88 ip_or_hostname=options.ips_node.pop()
89 print 'debug','in',ip_or_hostname,'out',ip_pool.locate_entry(ip_or_hostname)
90 (hostname,ip,mac)=ip_pool.locate_entry(ip_or_hostname)
92 tracker=TrackerQemu(options,instances=self.max_qemus()-1)
93 (hostname,ip,mac) = ip_pool.next_free(tracker.nodenames())
94 utils.header('Attaching node %s to %s (%s)'%(nodename,hostname,ip))
95 node_dict= {'node_fields:hostname':hostname,
96 'interface_fields:ip':ip,
97 'interface_fields:mac':mac,
100 node_dict.update(network_dict)
101 maps.append ( ( nodename, node_dict) )
103 plc_map = [ ( '*' , { 'PLC_NET_DNS1' : network_dict [ 'interface_fields:dns1' ],
104 'PLC_NET_DNS2' : network_dict [ 'interface_fields:dns2' ], } ) ]
106 return test_mapper.map ({'node': maps, 'plc' : plc_map } )
109 def localize_plcs (self,plcs,options):
111 utils.header ("Turning configuration into a vserver-based one for onelab")
112 ip_pool = TestPoolIP (self.plcs_ip_pool(),options)
117 ip_or_hostname=options.ips_plc.pop()
118 (hostname,ip,mac)=ip_pool.locate_entry(ip_or_hostname)
120 utils.header("Using user-provided %s %s for plc %s"%(
121 hostname,ip_or_hostname,plc['name']))
123 tracker = TrackerPlc(options,instances=self.max_plcs())
124 (hostname,ip,mac)=ip_pool.next_free(tracker.plcnames())
126 utils.header("Using auto-allocated %s %s for plc %s"%(
127 hostname,ip,plc['name']))
129 ### rewrite fields in plc
130 # compute a helpful vserver name - remove domain in hostname
131 simplehostname=hostname.split('.')[0]
132 vservername = options.buildname
134 vservername = "%s-%s" % (vservername,simplehostname)
137 vservername = "%s-%d-%s" % (vservername,plc_counter,simplehostname)
139 plc['vservername']=vservername
141 plc['name'] = "%s_%s"%(plc['name'],simplehostname)
142 utils.header("Attaching plc %s to vserver %s (%s)"%(
143 plc['name'],plc['vservername'],plc['vserverip']))
144 for key in [ 'PLC_DB_HOST', 'PLC_API_HOST', 'PLC_WWW_HOST', 'PLC_BOOT_HOST',]:
149 # as a plc step this should return a boolean
150 def step_pre (self,plc):
151 return self.trqemu_record (plc) and self.trqemu_free(plc) \
152 and self.trplc_record (plc) and self.trplc_free(plc)
154 def step_post (self,plc):
157 def step_cleanup (self,plc):
158 return self.trqemu_cleanup(plc) and self.trplc_cleanup(plc)
160 def step_list (self,plc):
161 return self.trqemu_list(plc) and self.trplc_list(plc)
164 def trqemu_record (self,plc):
165 tracker=TrackerQemu(plc.options,instances=self.max_qemus()-1)
166 for site_spec in plc.plc_spec['sites']:
167 for node_spec in site_spec['nodes']:
168 tracker.record(node_spec['host_box'],plc.options.buildname,node_spec['node_fields']['hostname'])
172 def trqemu_free (self,plc):
173 tracker=TrackerQemu(plc.options,instances=self.max_qemus()-1)
174 for site_spec in plc.plc_spec['sites']:
175 for node_spec in site_spec['nodes']:
181 def trplc_record (self,plc):
182 tracker = TrackerPlc(plc.options,instances=self.max_plcs())
183 tracker.record(plc.test_ssh.hostname,plc.vservername)
187 def trplc_free (self,plc):
188 tracker = TrackerPlc(plc.options,instances=self.max_plcs())
194 def trqemu_cleanup (self,plc):
195 tracker=TrackerQemu(plc.options,instances=self.max_qemus()-1)
196 for site_spec in plc.plc_spec['sites']:
197 for node_spec in site_spec['nodes']:
202 def trplc_cleanup (self,plc):
203 tracker = TrackerPlc(plc.options,instances=self.max_plcs())
208 def trqemu_list (self,plc):
209 TrackerQemu(plc.options,instances=self.max_qemus()-1).list()
212 def trplc_list (self,plc):
213 TrackerPlc(plc.options,instances=self.max_plcs()).list()
216 def localize_rspec (self,plcs,options):
218 utils.header ("Localize SFA Slice RSpec")
221 for site in plc['sites']:
222 for node in site['nodes']:
223 plc['sfa']['sfa_slice_rspec']['part4'] = node['node_fields']['hostname']
224 plc['sfa']['SFA_REGISTRY_HOST'] = plc['PLC_DB_HOST']
225 plc['sfa']['SFA_AGGREGATE_HOST'] = plc['PLC_DB_HOST']
226 plc['sfa']['SFA_SM_HOST'] = plc['PLC_DB_HOST']
227 plc['sfa']['SFA_PLC_DB_HOST'] = plc['PLC_DB_HOST']
228 plc['sfa']['SFA_PLC_URL'] = 'https://' + plc['PLC_API_HOST'] + ':443/PLCAPI/'