- auth=self.test_plc.auth_root()
- self.test_plc.server.DeleteNode(auth,self.name())
-
- def get_node_status(self,hostname,host_machine):
- 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']
- host_machine=self.node_spec['node_fields']['host_machine']
- if model.find("vmware") >= 0:
- 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:
- 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 ('Transfert of configuration files for node %s into %s '%(hostname,host_machine))
- cleandir_command="ssh root@%s rm -rf %s"%(host_machine, dest_dir)
- createdir_command = "ssh root@%s mkdir -p %s"%(host_machine, dest_dir)
- utils.system(cleandir_command)
- utils.system(createdir_command)
- scp_command = "scp -r %s/qemu-%s/* root@%s:/root/%s"%(path,hostname,host_machine,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'
+ 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
+ else:
+ # with python3 we need to call decodestring here
+ with open(filename,'wb') as storage:
+ storage.write(base64.decodestring(bencoded))
+ return True
+
+ def nodestate_reinstall(self):
+ "all nodes: mark PLCAPI boot_state as reinstall"
+ self.test_plc.apiserver.UpdateNode(self.test_plc.auth_root(),
+ self.name(),{'boot_state':'reinstall'})
+ return True
+
+ def nodestate_safeboot(self):
+ "all nodes: mark PLCAPI boot_state as safeboot"
+ self.test_plc.apiserver.UpdateNode(self.test_plc.auth_root(),
+ self.name(),{'boot_state':'safeboot'})
+ return True
+
+ def nodestate_boot(self):
+ "all nodes: mark PLCAPI boot_state as boot"
+ self.test_plc.apiserver.UpdateNode(self.test_plc.auth_root(),
+ self.name(),{'boot_state':'boot'})
+ return True
+
+ def nodestate_show(self):
+ "all nodes: show PLCAPI boot_state"
+ if self.dry_run():
+ print("Dry_run: skipped getting current node state")
+ return True
+ state = self.test_plc.apiserver.GetNodes(self.test_plc.auth_root(), self.name(), ['boot_state'])[0]['boot_state']
+ print(self.name(),':',state)
+ return True
+
+ def qemu_local_config(self):
+ "all nodes: compute qemu config qemu.conf and store it locally"
+ if not self.is_qemu():
+ return
+ mac = self.node_spec['interface_fields']['mac']
+ hostname = self.node_spec['node_fields']['hostname']
+ ip = self.node_spec['interface_fields']['ip']
+ auth = self.test_plc.auth_root()
+ target_arch = self.test_plc.apiserver.GetPlcRelease(auth)['build']['target-arch']
+ conf_filename = "{}/qemu.conf".format(self.nodedir())
+ if self.dry_run():
+ print("dry_run: skipped actual storage of qemu.conf")
+ return True
+ utils.header('Storing qemu config for {} in {}'.format(self.name(), conf_filename))
+ with open(conf_filename,'w') as file:
+ file.write('MACADDR={}\n'.format(mac))
+ file.write('NODE_ISO={}.iso\n'.format(self.name()))
+ file.write('HOSTNAME={}\n'.format(hostname))
+ file.write('IP={}\n'.format(ip))
+ file.write('TARGET_ARCH={}\n'.format(target_arch))
+ return True
+
+ def qemu_clean(self):
+ utils.header("Cleaning up qemu for host {} on box {}"\
+ .format(self.name(),self.test_box().hostname()))
+ dry_run = self.dry_run()
+ self.test_box().rmdir(self.nodedir(), dry_run=dry_run)
+ return True
+
+ def qemu_export(self):
+ "all nodes: push local node-dep directory on the qemu box"
+ # if relevant, push the qemu area onto the host box
+ if self.test_box().is_local():
+ return True
+ dry_run = self.dry_run()
+ utils.header("Cleaning any former sequel of {} on {}"\
+ .format(self.name(), self.host_box()))
+ utils.header("Transferring configuration files for node {} onto {}"\
+ .format(self.name(), self.host_box()))
+ return self.test_box().copy(self.nodedir(), recursive=True, dry_run=dry_run) == 0