+
+ 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
+ else:
+ retcod, output = \
+ utils.output_of(test_ssh.actual_command("cat /vservers/{}/etc/slicefamily 2> /dev/null")\
+ .format(vservername))
+ # get last line only as ssh pollutes the output
+ slicefamily = output.split("\n")[-1]
+ utils.header("Found slicefamily '{}'for slice {}".format(slicefamily,slicename))
+ if retcod != 0:
+ return False
+ utils.header("Checking system slice {} using vserver-stat".format(slicename))
+ return test_ssh.run("vserver-stat | grep {}".format(vservername), dry_run=dry_run) == 0
+
+