- auth=self.test_plc.auth_root()
- self.test_plc.server.DeleteNode(auth,self.name())
-
- 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)
- utils.header('Actual status for node %s is [%s]'%(hostname,node_status))
- if (node_status[0]['boot_state'] == 'boot'):
- utils.header('%s has reached boot state'%hostname)
- status=True
- elif (node_status[0]['boot_state'] == 'dbg' ):
- utils.header('%s has reached debug state'%hostname)
- return status
-
- def conffile(self,image,hostname,path):
- model=self.node_spec['node_fields']['model']
- 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 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=open(path+'/qemu-'+hostname+'/MAC','a')
- file.write('%s\n'%mac)
- file.write(dest_dir)
- file.close()
- 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(createdir_command)
- scp_command = "scp -r %s/qemu-%s/* root@%s:/root/%s"%(path,hostname,host_box,dest_dir)
- utils.system(scp_command)
-
- def create_boot_cd(self,path):
- model=self.node_spec['node_fields']['model']
- node_spec=self.node_spec
- hostname=node_spec['node_fields']['hostname']
- encoded=self.test_plc.server.GetBootMedium(self.test_plc.auth_root(), hostname, 'node-iso', '')
- if (encoded == ''):
- raise Exception, 'boot.iso not found'
-
- if model.find("vmware") >= 0:
- utils.header('Initializing vmplayer area for node %s'%hostname)
- clean_dir="rm -rf %s/vmplayer-%s"%(path,hostname)
- mkdir_command="mkdir -p %s/vmplayer-%s"%(path,hostname)
- tar_command="tar -C %s/template-vmplayer -cf - . | tar -C %s/vmplayer-%s -xf -"%(path,path,hostname)
- utils.system(clean_dir)
- utils.system(mkdir_command)
- utils.system(tar_command);
- utils.header('Creating boot medium for node %s'%hostname)
- file=open(path+'/vmplayer-'+hostname+'/boot_file.iso','w')
- elif model.find("qemu") >= 0:
- clean_dir="rm -rf %s/qemu-%s"%(path,hostname)
- mkdir_command="mkdir -p %s/qemu-%s"%(path,hostname)
- utils.system(clean_dir)
- utils.system(mkdir_command)
- copy_command="cp -r %s/template-Qemu/* %s/qemu-%s"%(path,path,hostname)
- utils.system(copy_command)
- utils.header('Creating boot medium for node %s'%hostname)
- file=open(path+'/qemu-'+hostname+'/boot_file.iso','w')
+ auth = self.test_plc.auth_root()
+ self.test_plc.apiserver.DeleteNode(auth,self.name())
+
+ # Do most of the stuff locally - will be pushed on host_box - *not* the plc - later if needed
+ def qemu_local_init(self):
+ "all nodes : init a clean local directory for holding node-dep stuff like iso image..."
+ utils.system("rm -rf {}".format(self.nodedir()))
+ utils.system("mkdir {}".format(self.nodedir()))
+ if not self.is_qemu():
+ return True
+ return utils.system("rsync -v -a --exclude .svn template-qemu/ {}/"\
+ .format(self.nodedir())) == 0
+
+ def bootcd(self):
+ "all nodes: invoke GetBootMedium and store result locally"
+ utils.header("Calling GetBootMedium for {}".format(self.name()))
+ # this would clearly belong in the config but, well ..
+ options = []
+ if self.is_qemu():
+ options.append('serial')
+ options.append('no-hangcheck')
+ options.append('systemd-debug')
+ encoded = self.test_plc.apiserver.GetBootMedium(self.test_plc.auth_root(),
+ self.name(), 'node-iso', '', options)
+ if encoded == '':
+ raise Exception('GetBootmedium failed')
+
+ filename = "{}/{}.iso".format(self.nodedir(), self.name())
+ utils.header('Storing boot medium into {}'.format(filename))
+
+ # xxx discovered with python3, but a long stading issue:
+ # encoded at this point is a str instead of a bytes
+ # Quick & dirty : we convert this explicitly to a bytearray
+ # Longer run : clearly it seems like the plcapi server side should
+ # tag its result with <base64></base64> rather than as a string
+ bencoded = str.encode(encoded)
+ if self.dry_run():
+ print("Dry_run: skipped writing of iso image")
+ return True