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 localize_qemus (self,plcs,options):
42 # all plcs on the same vserver box
43 plc_box = self.plc_boxes()[0]
46 label=options.personality.replace("linux","")
49 qemu_pool = TestPoolQemu (self.qemus_ip_pool(), options)
51 for index in range(options.size):
54 ip_or_hostname=options.ips_qemu.pop()
55 (hostname,ip,unused)=qemu_pool.locate_entry(ip_or_hostname)
57 (hostname,ip,unused) = qemu_pool.next_free()
59 node_map += [ ('node%d'%index, {'host_box':hostname},) ]
61 mapper = {'plc': [ ('*' , {'hostname':plc_box,
62 'PLC_DB_HOST':plc_box,
63 'PLC_API_HOST':plc_box,
64 'PLC_BOOT_HOST':plc_box,
65 'PLC_WWW_HOST':plc_box,
66 'name':'%s-'+label } )
71 return TestMapper(plcs,options).map(mapper)
74 def localize_nodes (self, plcs, options):
76 ip_pool = TestPoolIP (self.nodes_ip_pool(),options)
77 network_dict = self.network_dict()
79 test_mapper = TestMapper (plcs, options)
81 all_nodenames = test_mapper.node_names()
83 for nodename in all_nodenames:
85 ip_or_hostname=options.ips_node.pop()
86 print 'debug','in',ip_or_hostname,'out',ip_pool.locate_entry(ip_or_hostname)
87 (hostname,ip,mac)=ip_pool.locate_entry(ip_or_hostname)
89 (hostname,ip,mac) = ip_pool.next_free()
90 utils.header('Attaching node %s to %s (%s)'%(nodename,hostname,ip))
91 node_dict= {'node_fields:hostname':hostname,
92 'interface_fields:ip':ip,
93 'interface_fields:mac':mac,
96 node_dict.update(network_dict)
97 maps.append ( ( nodename, node_dict) )
99 plc_map = [ ( '*' , { 'PLC_NET_DNS1' : network_dict [ 'interface_fields:dns1' ],
100 'PLC_NET_DNS2' : network_dict [ 'interface_fields:dns2' ], } ) ]
102 return test_mapper.map ({'node': maps, 'plc' : plc_map } )
105 def localize_plcs (self,plcs,options):
107 utils.header ("Turning configuration into a vserver-based one for onelab")
108 ip_pool = TestPoolIP (self.plcs_ip_pool(),options)
113 ip_or_hostname=options.ips_plc.pop()
114 (hostname,ip,mac)=ip_pool.locate_entry(ip_or_hostname)
116 utils.header("Using user-provided %s %s for plc %s"%(
117 hostname,ip_or_hostname,plc['name']))
119 (hostname,ip,mac)=ip_pool.next_free()
121 utils.header("Using auto-allocated %s %s for plc %s"%(
122 hostname,ip,plc['name']))
124 ### rewrite fields in plc
125 # compute a helpful vserver name - remove domain in hostname
126 simplehostname=hostname.split('.')[0]
127 vservername = options.buildname
129 vservername = "%s-%s" % (vservername,simplehostname)
132 vservername = "%s-%d-%s" % (vservername,plc_counter,simplehostname)
134 plc['vservername']=vservername
136 plc['name'] = "%s_%s"%(plc['name'],simplehostname)
137 utils.header("Attaching plc %s to vserver %s (%s)"%(
138 plc['name'],plc['vservername'],plc['vserverip']))
139 for key in [ 'PLC_DB_HOST', 'PLC_API_HOST', 'PLC_WWW_HOST', 'PLC_BOOT_HOST',]:
144 # as a plc step this should return a boolean
145 def step_pre (self,plc):
146 return self.trqemu_record (plc) and self.trqemu_free(plc)
148 def step_post (self,plc):
149 return self.trplc_record (plc) and self.trplc_free(plc)
151 def step_cleanup (self,plc):
152 return self.trqemu_cleanup(plc) and self.trplc_cleanup(plc)
154 def step_list (self,plc):
155 return self.trqemu_list(plc) and self.trplc_list(plc)
158 def trqemu_record (self,plc):
159 tracker=TrackerQemu(plc.options,instances=self.max_qemus()-1)
160 for site_spec in plc.plc_spec['sites']:
161 for node_spec in site_spec['nodes']:
162 tracker.record(node_spec['host_box'],plc.options.buildname,node_spec['node_fields']['hostname'])
166 def trqemu_free (self,plc):
167 tracker=TrackerQemu(plc.options,instances=self.max_qemus()-1)
168 for site_spec in plc.plc_spec['sites']:
169 for node_spec in site_spec['nodes']:
175 def trplc_record (self,plc):
176 tracker = TrackerPlc(plc.options,instances=self.max_plcs())
177 tracker.record(plc.test_ssh.hostname,plc.vservername)
181 def trplc_free (self,plc):
182 tracker = TrackerPlc(plc.options,instances=self.max_plcs())
188 def trqemu_cleanup (self,plc):
189 tracker=TrackerQemu(plc.options,instances=self.max_qemus()-1)
190 for site_spec in plc.plc_spec['sites']:
191 for node_spec in site_spec['nodes']:
196 def trplc_cleanup (self,plc):
197 tracker = TrackerPlc(plc.options,instances=self.max_plcs())
202 def trqemu_list (self,plc):
203 TrackerQemu(plc.options,instances=self.max_qemus()-1).list()
206 def trplc_list (self,plc):
207 TrackerPlc(plc.options,instances=self.max_plcs()).list()
210 def localize_rspec (self,plcs,options):
212 utils.header ("Localize SFA Slice RSpec")
215 for site in plc['sites']:
216 for node in site['nodes']:
217 plc['sfa']['sfa_slice_rspec']['part4'] = node['node_fields']['hostname']