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'
35 def localize_qemus (self,plcs,options):
37 # all plcs on the same vserver box
38 plc_box = self.plc_boxes()[0]
41 label=options.personality.replace("linux","")
44 qemu_pool = TestPoolQemu (self.qemus_ip_pool(), options)
46 for index in range(options.size):
49 ip_or_hostname=options.ips_qemu.pop()
50 (hostname,ip,unused)=qemu_pool.locate_entry(ip_or_hostname)
52 (hostname,ip,unused) = qemu_pool.next_free()
54 node_map += [ ('node%d'%index, {'host_box':hostname},) ]
56 mapper = {'plc': [ ('*' , {'hostname':plc_box,
57 'PLC_DB_HOST':plc_box,
58 'PLC_API_HOST':plc_box,
59 'PLC_BOOT_HOST':plc_box,
60 'PLC_WWW_HOST':plc_box,
61 'name':'%s-'+label } )
66 return TestMapper(plcs,options).map(mapper)
69 def localize_nodes (self, plcs, options):
71 ip_pool = TestPoolIP (self.nodes_ip_pool(),options)
72 network_dict = self.network_dict()
74 test_mapper = TestMapper (plcs, options)
76 all_nodenames = test_mapper.node_names()
78 for nodename in all_nodenames:
80 ip_or_hostname=options.ips_node.pop()
81 print 'debug','in',ip_or_hostname,'out',ip_pool.locate_entry(ip_or_hostname)
82 (hostname,ip,mac)=ip_pool.locate_entry(ip_or_hostname)
84 (hostname,ip,mac) = ip_pool.next_free()
85 utils.header('Attaching node %s to %s (%s)'%(nodename,hostname,ip))
86 node_dict= {'node_fields:hostname':hostname,
87 'interface_fields:ip':ip,
88 'interface_fields:mac':mac,
91 node_dict.update(network_dict)
92 maps.append ( ( nodename, node_dict) )
94 plc_map = [ ( '*' , { 'PLC_NET_DNS1' : network_dict [ 'interface_fields:dns1' ],
95 'PLC_NET_DNS2' : network_dict [ 'interface_fields:dns2' ], } ) ]
97 return test_mapper.map ({'node': maps, 'plc' : plc_map } )
100 def localize_plcs (self,plcs,options):
102 utils.header ("Turning configuration into a vserver-based one for onelab")
104 ip_pool = TestPoolIP (self.plcs_ip_pool(),options)
109 ip_or_hostname=options.ips_plc.pop()
110 (hostname,ip,mac)=ip_pool.locate_entry(ip_or_hostname)
112 utils.header("Using user-provided %s %s for plc %s"%(
113 hostname,ip_or_hostname,plc['name']))
115 (hostname,ip,mac)=ip_pool.next_free()
117 utils.header("Using auto-allocated %s %s for plc %s"%(
118 hostname,ip,plc['name']))
120 ### rewrite fields in plc
121 # compute a helpful vserver name - remove domain in hostname
122 simplehostname=hostname.split('.')[0]
123 vservername = options.buildname
125 vservername = "%s-%s" % (vservername,simplehostname)
128 vservername = "%s-%d-%s" % (vservername,plc_counter,simplehostname)
130 plc['vservername']=vservername
132 plc['name'] = "%s_%s"%(plc['name'],simplehostname)
133 utils.header("Attaching plc %s to vserver %s (%s)"%(
134 plc['name'],plc['vservername'],plc['vserverip']))
135 for key in [ 'PLC_DB_HOST', 'PLC_API_HOST', 'PLC_WWW_HOST', 'PLC_BOOT_HOST',]:
140 # as a plc step this should return a boolean
141 def step_pre (self,plc):
142 return self.trqemu_record (plc) and self.trqemu_free(plc)
144 def step_post (self,plc):
145 return self.trplc_record (plc) and self.trplc_free(plc)
147 def step_cleanup (self,plc):
148 return self.trqemu_cleanup(plc) and self.trplc_cleanup(plc)
150 def step_list (self,plc):
151 return self.trqemu_list(plc) and self.trplc_list(plc)
154 def trqemu_record (self,plc):
155 tracker=TrackerQemu(plc.options,instances=self.max_qemus()-1)
156 for site_spec in plc.plc_spec['sites']:
157 for node_spec in site_spec['nodes']:
158 tracker.record(node_spec['host_box'],plc.options.buildname,node_spec['node_fields']['hostname'])
162 def trqemu_free (self,plc):
163 tracker=TrackerQemu(plc.options,instances=self.max_qemus()-1)
164 for site_spec in plc.plc_spec['sites']:
165 for node_spec in site_spec['nodes']:
171 def trplc_record (self,plc):
172 tracker = TrackerPlc(plc.options,instances=self.max_plcs())
173 tracker.record(plc.test_ssh.hostname,plc.vservername)
177 def trplc_free (self,plc):
178 tracker = TrackerPlc(plc.options,instances=self.max_plcs())
184 def trqemu_cleanup (self,plc):
185 tracker=TrackerQemu(plc.options,instances=self.max_qemus()-1)
186 for site_spec in plc.plc_spec['sites']:
187 for node_spec in site_spec['nodes']:
192 def trplc_cleanup (self,plc):
193 tracker = TrackerPlc(plc.options,instances=self.max_plcs())
198 def trqemu_list (self,plc):
199 TrackerQemu(plc.options,instances=self.max_qemus()-1).list()
202 def trplc_list (self,plc):
203 TrackerPlc(plc.options,instances=self.max_plcs()).list()