+ if self.is_qemu():
+ self.start_qemu()
+ else:
+ utils.header("TestNode.qemu_start : {} model {} taken as real node"\
+ .format(self.name(), model))
+ return True
+
+ def qemu_timestamp(self):
+ "all nodes: start the qemu instance (also runs qemu-bridge-init start)"
+ test_box = self.test_box()
+ test_box.run_in_buildname("mkdir -p {}".format(self.nodedir()), dry_run=self.dry_run())
+ now = int(time.time())
+ return test_box.run_in_buildname("echo {:d} > {}/timestamp"\
+ .format(now, self.nodedir()), dry_run=self.dry_run()) == 0
+
+ def start_qemu(self):
+ test_box = self.test_box()
+ utils.header("Starting qemu node {} on {}".format(self.name(), test_box.hostname()))
+
+ test_box.run_in_buildname("{}/qemu-bridge-init start >> {}/log.txt"\
+ .format(self.nodedir(), self.nodedir()),
+ dry_run=self.dry_run())
+ # kick it off in background, as it would otherwise hang
+ test_box.run_in_buildname("{}/qemu-start-node 2>&1 >> {}/log.txt"\
+ .format(self.nodedir(), self.nodedir()))
+
+ def list_qemu(self):
+ utils.header("Listing qemu for host {} on box {}"\
+ .format(self.name(), self.test_box().hostname()))
+ command = "{}/qemu-kill-node -l {}".format(self.nodedir(), self.name())
+ self.test_box().run_in_buildname(command, dry_run=self.dry_run())
+ return True
+
+ def kill_qemu(self):
+ #Prepare the log file before killing the nodes
+ test_box = self.test_box()
+ # kill the right processes
+ utils.header("Stopping qemu for node {} on box {}"\
+ .format(self.name(), self.test_box().hostname()))
+ command = "{}/qemu-kill-node {}".format(self.nodedir(),self.name())
+ self.test_box().run_in_buildname(command, dry_run=self.dry_run())
+ return True
+
+ def gather_qemu_logs(self):
+ if not self.is_qemu():
+ return True
+ remote_log = "{}/log.txt".format(self.nodedir())
+ local_log = "logs/node.qemu.{}.txt".format(self.name())
+ self.test_box().test_ssh.fetch(remote_log,local_log,dry_run=self.dry_run())
+
+ def keys_clear_known_hosts(self):
+ "remove test nodes entries from the local known_hosts file"
+ TestSsh(self.name()).clear_known_hosts()
+ return True
+
+ def create_test_ssh(self):
+ # get the plc's keys for entering the node
+ vservername = self.test_plc.vservername
+### # assuming we've run testplc.fetch_keys()
+### key = "keys/{vservername}.rsa".format(**locals())
+ # fetch_keys doesn't grab the root key anymore
+ key = "keys/key_admin.rsa"
+ return TestSsh(self.name(), buildname=self.buildname(), key=key)
+
+ def check_hooks(self):
+ extensions = [ 'py','pl','sh' ]
+ path = 'hooks/node'
+ scripts = utils.locate_hooks_scripts('node '+self.name(), path,extensions)
+ overall = True
+ for script in scripts:
+ if not self.check_hooks_script(script):
+ overall = False
+ return overall
+
+ def check_hooks_script(self,local_script):
+ # push the script on the node's root context
+ script_name = os.path.basename(local_script)
+ utils.header("NODE hook {} ({})".format(script_name, self.name()))
+ test_ssh = self.create_test_ssh()
+ test_ssh.copy_home(local_script)
+ if test_ssh.run("./"+script_name) != 0:
+ utils.header("WARNING: node hooks check script {} FAILED (ignored)"\
+ .format(script_name))
+ #return False
+ return True
+ else:
+ utils.header("SUCCESS: node hook {} OK".format(script_name))
+ return True
+
+ def has_libvirt(self):
+ test_ssh = self.create_test_ssh()
+ return test_ssh.run("rpm -q --quiet libvirt-client") == 0
+
+ def _check_system_slice(self, slicename, dry_run=False):
+ sitename = self.test_plc.plc_spec['settings']['PLC_SLICE_PREFIX']
+ vservername = "{}_{}".format(sitename, slicename)
+ test_ssh = self.create_test_ssh()
+ if self.has_libvirt():
+ utils.header("Checking system slice {} using virsh".format(slicename))
+ return test_ssh.run("virsh --connect lxc:// list | grep -q ' {} '".format(vservername),
+ dry_run = dry_run) == 0