def test_add_sudo(): tmpuser = config.core.user try: config.core.user = '******' assert utils.add_sudo('ls').startswith('sudo') config.core.user = '' assert utils.add_sudo('ls') == 'ls' finally: config.core.user = tmpuser
def is_lrmd_accessible(self): if not (is_program(lrmadmin_prog) and is_process("lrmd")): return False cmd = add_sudo(">/dev/null 2>&1 %s -C" % lrmadmin_prog) if options.regression_tests: print ".EXT", cmd return subprocess.call(cmd, shell=True) == 0
def is_lrmd_accessible(self): if not (is_program(lrmadmin_prog) and is_process("lrmd")): return False cmd = add_sudo(">/dev/null 2>&1 %s -C" % lrmadmin_prog) if options.regression_tests: print ".EXT", cmd return subprocess.call( cmd, shell=True) == 0
def crm_mon(opts=''): """ Run 'crm_mon -1' opts: Additional options to pass to crm_mon returns: rc, stdout """ has_crm_mon() status_cmd = "%s -1 %s" % (crm_mon_prog, opts) return utils.get_stdout(utils.add_sudo(status_cmd))
def cibdump2tmp(): cmd = add_sudo(cib_dump) if options.regression_tests: print ".EXT", cmd p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) try: tmpf = str2tmp(''.join(p.stdout)) p.wait() except IOError, msg: common_err(msg) return None
def sudocall(cmd): cmd = add_sudo(cmd) if options.regression_tests: print ".EXT", cmd p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) try: outp, errp = p.communicate() p.wait() return p.returncode, outp, errp except IOError, msg: common_err("running %s: %s" % (cmd, msg)) return None, None, None
def cibdump2elem(section=None): if section: cmd = "%s -o %s" % (cib_dump, section) else: cmd = cib_dump cmd = add_sudo(cmd) if options.regression_tests: print ".EXT", cmd p = subprocess.Popen( cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) try: (outp, err_outp) = p.communicate() p.wait() rc = p.returncode except IOError, msg: common_err("running %s: %s" % (cmd, msg)) return None
def crm_mon(opts=''): """ Run 'crm_mon -1' opts: Additional options to pass to crm_mon returns: rc, stdout """ global _crm_mon if _crm_mon is None: if not utils.is_program("crm_mon"): raise IOError("crm_mon not available, check your installation") _, out = utils.get_stdout("crm_mon --help") if "--pending" in out: _crm_mon = "crm_mon -1 -j" else: _crm_mon = "crm_mon -1" status_cmd = "%s %s" % (_crm_mon, opts) return utils.get_stdout(utils.add_sudo(status_cmd))
def cibdump2elem(section=None): if section: cmd = "%s -o %s" % (cib_dump, section) else: cmd = cib_dump cmd = add_sudo(cmd) if options.regression_tests: print ".EXT", cmd p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) try: (outp, err_outp) = p.communicate() p.wait() rc = p.returncode except IOError, msg: common_err("running %s: %s" % (cmd, msg)) return None
def crm_mon(opts=''): """ Run 'crm_mon -1' opts: Additional options to pass to crm_mon returns: rc, stdout """ global _crm_mon if _crm_mon is None: prog = utils.is_program("crm_mon") if not prog: raise IOError("crm_mon not available, check your installation") _, out = utils.get_stdout("%s --help" % (prog)) if "--pending" in out: _crm_mon = "%s -1 -j" % (prog) else: _crm_mon = "%s -1" % (prog) status_cmd = "%s %s" % (_crm_mon, opts) return utils.get_stdout(utils.add_sudo(status_cmd))
def do_diff(self, context): "usage: diff" rc, s = utils.get_stdout(utils.add_sudo("%s -d" % self.extcmd_stdout)) utils.page_string(s)