def name(self):
return self.node_spec['node_fields']['hostname']
+ def is_vmware (self):
+ model=self.node_spec['node_fields']['model']
+ return model.find("vmware") >= 0
+
+ def is_qemu (self):
+ model=self.node_spec['node_fields']['model']
+ return model.find("qemu") >= 0
+
+ def host_box (self):
+ try:
+ return self.node_spec['host_box']
+ except:
+ return 'localhost'
+
def create_node (self):
ownername = self.node_spec['owner']
user_spec = self.test_site.locate_user(ownername)
auth=self.test_plc.auth_root()
self.test_plc.server.DeleteNode(auth,self.name())
- def get_node_status(self,hostname,host_box):
+ def get_node_status(self,hostname):
filter=['boot_state']
status=False
node_status=self.test_plc.server.GetNodes(self.test_plc.auth_root(),hostname, filter)
def conffile(self,image,hostname,path):
model=self.node_spec['node_fields']['model']
- if model.find("vmware") >= 0:
- host_box=self.node_spec['node_fields']['host_box']
+ if self.is_vmware():
+ host_box=self.host_box()
template='%s/template-vmplayer/node.vmx'%(path)
actual='%s/vmplayer-%s/node.vmx'%(path,hostname)
sed_command="sed -e s,@BOOTCD@,%s,g %s > %s"%(image,template,actual)
utils.header('Creating %s from %s'%(actual,template))
utils.system(sed_command)
- elif model.find("qemu") >= 0:
- host_box=self.node_spec['node_fields']['host_box']
+ elif self.is_qemu():
+ host_box=self.host_box()
mac=self.node_spec['network_fields']['mac']
dest_dir="qemu-%s"%(hostname)
utils.header('Storing the mac address for node %s'%hostname)
file.write('%s\n'%mac)
file.write(dest_dir)
file.close()
- utils.header ('Transfert of configuration files for node %s into %s '%(hostname,host_box))
+ utils.header ('Transferring configuration files for node %s into %s '%(hostname,host_box))
cleandir_command="ssh root@%s rm -rf %s"%(host_box, dest_dir)
createdir_command = "ssh root@%s mkdir -p %s"%(host_box, dest_dir)
utils.system(cleandir_command)
utils.system('cd %s/vmplayer-%s ; DISPLAY=%s vmplayer node.vmx < /dev/null >/dev/null 2>/dev/null &'%(path,hostname,display))
def start_qemu (self, options):
- host_box=self.node_spec['node_fields']['host_box']
+ host_box=self.host_box()
hostname=self.node_spec['node_fields']['hostname']
path=options.path
display=options.display
utils.system("ssh root@%s ~/%s/env-qemu start "%(host_box, dest_dir ))
utils.system("ssh root@%s DISPLAY=%s ~/%s/start-qemu-node %s & "%( host_box, display, dest_dir, dest_dir))
- def stop_qemu(self,host_box, hostname):
+ def stop_qemu(self):
+ if not self.is_qemu():
+ return True
+ hostname=self.node_spec['node_fields']['hostname']
+ host_box=self.host_box()
+ utils.system('ssh root@%s killall qemu'%host_box)
utils.header('Stoping qemu emulation of %s on the host machine %s and Restoring the initial network'
%(hostname,host_box))
utils.system("ssh root@%s ~/qemu-%s/env-qemu stop "%(host_box, hostname ))
+ return True
if self.vserver:
return "vserver %s exec %s"%(self.vservername,command)
else:
- return "chroot /plc/root %s"%command
+ return "chroot /plc/root sh -c \\\"%s\\\""%command
def ssh_command(self,command):
if self.is_local():
for site_spec in self.plc_spec['sites']:
test_site = TestSite (self,site_spec)
for node_spec in site_spec['nodes']:
- test_node=TestNode (self,test_site,node_spec)
- model=node_spec['node_fields']['model']
- host_box=node_spec['node_fields']['host_box']
- hostname=node_spec['node_fields']['hostname']
- print model
- if model.find("qemu") >= 0:
- utils.system('ssh root@%s killall qemu'%host_box)
- test_node.stop_qemu(host_box,hostname)
+ TestNode (self,test_site,node_spec).stop_qemu()
+ def clear_ssh_config (self):
+ # using ssh -o "BatchMode yes" is too tricky due to quoting - let's use the config
+ utils.header("Setting BatchMode and StrictHostKeyChecking in ssh config")
+ self.run_in_guest("sed -i -e '/BatchMode/d' /root/.ssh/config 2> /dev/null")
+ self.run_in_guest_piped("echo BatchMode yes", "cat >> /root/.ssh/config")
+ self.run_in_guest("sed -i -e '/StrictHostKeyChecking/d' /root/.ssh/config 2> /dev/null")
+ self.run_in_guest_piped("echo StrictHostKeyChecking no", "cat >> /root/.ssh/config")
+
#################### step methods
### uninstall
hostname=node_spec['node_fields']['hostname']
if (hostname in notfullybooted_nodes): #to avoid requesting already booted node
test_node=TestNode (self,test_site,node_spec)
- host_box=node_spec['node_fields']['host_box']
- node_status=test_node.get_node_status(hostname,host_box)
+ host_box=test_node.host_box()
+ node_status=test_node.get_node_status(hostname)
if (node_status):
booted_nodes.append(hostname)
del notfullybooted_nodes[notfullybooted_nodes.index(hostname)]
self.test_site=test_site
self.slice_spec=slice_spec
+ def name(self):
+ return self.slice_spec['slice_fields']['name']
+
def delete_slice(self):
owner_spec = self.test_site.locate_user(self.slice_spec['owner'])
auth = TestUser(self,self.test_site,owner_spec).auth()
isname=self.slice_spec['initscriptname']
utils.header("Adding initscript %s in %s"%(isname,slice_name))
self.test_plc.server.AddSliceAttribute(self.test_plc.auth_root(), slice_name,'initscript',isname)
-
-
- def delete_known_hosts(self):
- utils.header("Messing with known_hosts (cleaning hostnames starting with 'test[0-9]')")
- sed_command="sed -i -e '/^test[0-9]/d' /root/.ssh/known_hosts"
- self.test_plc.run_in_guest(sed_command)
+ def clear_known_hosts (self):
+ utils.header("Messing with known_hosts for slice %s"%self.name())
+ # scan nodenames
+ for nodename in self.slice_spec['nodenames']:
+ self.test_plc.run_in_guest("sed -i -e '/^%s/d' /root/.ssh/known_hosts"%nodename)
+
###the logic is quit wrong, must be rewritten
def do_check_slices(self):
- utils.header("waiting for the nodes to fully boot")
- time.sleep(300)
+ # Do not wait here, as this step can be run directly in which case you don't want to wait
+ # just add the 5 minutes to the overall timeout
+ #utils.header("Waiting for the nodes to fully boot")
+ #time.sleep(300)
bool=bool1=True
secondes=15
- self.delete_known_hosts()
+ self.test_plc.clear_ssh_config()
+ self.clear_known_hosts()
start_time = datetime.datetime.now()
- dead_time=start_time + datetime.timedelta(minutes=6)
+ dead_time=start_time + datetime.timedelta(minutes=11)
for slice_spec in self.test_plc.plc_spec['slices']:
for hostname in slice_spec['nodenames']:
slicename=slice_spec['slice_fields']['name']
onelab="one-lab.org"
# use a model that contains "vmware" to get the node actually started
+# host_box is taken as 'localhost' if omitted (should be a direct field in the node spec)
def nodes():
nodes= [ {'node_fields': {'hostname': 'test1.one-lab.org',
- 'model':'vmware/minhw',
- 'host_box' : 'localhost'},
+ 'model':'vmware/minhw', },
+ 'host_box' : 'test.one-lab.org',
'owner' : 'pi',
'network_fields': { 'method':'static',
'type':'ipv4',
},
},
{ 'node_fields': {'hostname':'test2.one-lab.org',
- 'model':'vmware/minhw',
- 'host_box': 'localhost'},
+ 'model':'vmware/minhw', } ,
+ 'host_box' : 'test.one-lab.org',
'owner' : 'tech',
'network_fields': {'method':'static',
'type':'ipv4',
# we use only thw Qemu node for this config
def nodes():
nodes= [ {'node_fields': {'hostname': 'lysithea.inria.fr',
- 'model':'qemu/minhw',
- 'host_box': 'bellami.inria.fr'},
+ 'model':'qemu/minhw', } ,
+ 'host_box': 'bellami.inria.fr',
'owner' : 'pi',
'network_fields': { 'method':'static',
'type':'ipv4',