def execute(cmd=None, shell=True, echo=True): """ Execute the given 'cmd' @returns (rcode, stdout, stderr) """ if echo: cij.emph("cij.util.execute: shell: %r, cmd: %r" % (shell, cmd)) rcode = 1 stdout, stderr = ("", "") if cmd: if shell: cmd = " ".join(cmd) proc = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=shell, close_fds=True) stdout, stderr = proc.communicate() rcode = proc.returncode if rcode and echo: cij.warn("cij.util.execute: stdout: %s" % stdout) cij.err("cij.util.execute: stderr: %s" % stderr) cij.err("cij.util.execute: rcode: %s" % rcode) return rcode, stdout, stderr
def comp_meta(file_bef, file_aft, mode="pfail"): """Compare chunk meta, mode=[pfail, power, reboot]""" if env(): cij.err("cij.nvme.comp_meta: Invalid NVMe ENV.") return 1 nvme = cij.env_to_dict(PREFIX, EXPORTED + REQUIRED) num_chk = int(nvme["LNVM_TOTAL_CHUNKS"]) meta_bef = cij.bin.Buffer(types=get_descriptor_table(nvme['SPEC_VERSION']), length=num_chk) meta_aft = cij.bin.Buffer(types=get_descriptor_table(nvme['SPEC_VERSION']), length=num_chk) meta_bef.read(file_bef) meta_aft.read(file_aft) for chk in range(num_chk): ignore = ["WL", "RSV0"] # PFAIL: BEFORE IS OPEN CHUNK, WRITE POINTER IS NOT SURE, IGNORE if mode == "pfail" and meta_bef[chk].CS == 4: ignore.append("WP") # COMPARE CHUNK META if meta_bef.compare(meta_aft, chk, ignore=ignore): cij.warn("META_BUFF_BEF[%s]:" % chk) meta_bef.dump(chk) cij.warn("META_BUFF_AFT[%s]:" % chk) meta_aft.dump(chk) cij.err("Error compare, CHUNK: %s" % chk) return 1 return 0
def env(): """Verify SSH variables and construct exported variables""" ssh = cij.env_to_dict(PREFIX, REQUIRED) if "KEY" in ssh: ssh["KEY"] = cij.util.expand_path(ssh["KEY"]) if cij.ENV.get("SSH_PORT") is None: cij.ENV["SSH_PORT"] = "22" cij.warn("cij.ssh.env: SSH_PORT was not set, assigned: %r" % ( cij.ENV.get("SSH_PORT") )) if cij.ENV.get("SSH_CMD_TIME") is None: cij.ENV["SSH_CMD_TIME"] = "1" cij.warn("cij.ssh.env: SSH_CMD_TIME was not set, assigned: %r" % ( cij.ENV.get("SSH_CMD_TIME") )) return 0
def terminate(self): """Terminate DMESG job""" if self.__thread: cmd = ["who am i"] status, output, _ = cij.util.execute(cmd, shell=True, echo=True) if status: cij.warn("cij.dmesg.terminate: who am i failed") return 1 tty = output.split()[1] cmd = ["pkill -f '{}' -t '{}'".format(" ".join(self.__prefix), tty)] status, _, _ = cij.util.execute(cmd, shell=True, echo=True) if status: cij.warn("cij.dmesg.terminate: pkill failed") return 1 self.__thread.join() self.__thread = None return 0