def runcmd(self, cmd, cmddesc=None, targetmachine_ip=None, targetmachine_user=None, targetmachine_pass=None, timeout=None): if targetmachine_ip != None and targetmachine_ip != "": if targetmachine_user != None and targetmachine_user != "": commander = Command(targetmachine_ip, targetmachine_user, targetmachine_pass) else: commander = Command(targetmachine_ip, "root", "red2015") else: commander = Command(get_exported_param("REMOTE_IP"), "root", "red2015") return commander.run(cmd, timeout, cmddesc)
def get_os_serials(self): cmd = "uname -r | awk -F \"el\" '{print substr($2,1,1)}'" (ret, output) = Command().run(cmd, comments=False) if ret == 0: return output.strip("\n").strip(" ") logger.info("It's successful to get system serials.") else: logger.info("It's failed to get system serials.")
def configure_stage_host(self, stage_name): ''' configure the host machine for stage ''' # configure /etc/rhsm/rhsm.conf to stage candlepin cmd = "sed -i -e 's/hostname = subscription.rhn.redhat.com/hostname = %s/g' /etc/rhsm/rhsm.conf" % stage_name ret, output = Command().run(cmd) if ret == 0: logger.info("Succeeded to configure rhsm.conf for stage") else: raise FailException("Failed to configure rhsm.conf for stage")
def get_delivered_param(self, param_name): cmd = "echo $%s" % param_name ret, output = Command().run(cmd) output = output.strip("\n").strip(" ") if ret == 0: logger.info("Succeeded to get parameter %s=%s" % (param_name, output)) return output else: raise FailException("Failed to get parameter %s" % param_name)
def configure_sam_host(self, samhostname, samhostip): ''' configure the host machine for sam ''' if samhostname != None and samhostip != None: # add sam hostip and hostname in /etc/hosts cmd = "sed -i '/%s/d' /etc/hosts; echo '%s %s' >> /etc/hosts" % ( samhostname, samhostip, samhostname) ret, output = Command().run(cmd) if ret == 0: logger.info("Succeeded to configure /etc/hosts") else: raise FailException("Failed to configure /etc/hosts") # config hostname, prefix, port, and repo_ca_crt by installing candlepin-cert cmd = "rpm -qa | grep candlepin-cert-consumer" ret, output = Command().run(cmd) if ret == 0: logger.info( "candlepin-cert-consumer-%s-1.0-1.noarch has already exist, remove it first." % samhostname) cmd = "rpm -e candlepin-cert-consumer-%s-1.0-1.noarch" % samhostname ret, output = Command().run(cmd) if ret == 0: logger.info( "Succeeded to uninstall candlepin-cert-consumer-%s-1.0-1.noarch." % samhostname) else: raise FailException( "Failed to uninstall candlepin-cert-consumer-%s-1.0-1.noarch." % samhostname) cmd = "rpm -ivh http://%s/pub/candlepin-cert-consumer-%s-1.0-1.noarch.rpm" % ( samhostip, samhostname) ret, output = Command().run(cmd) if ret == 0: logger.info( "Succeeded to install candlepin cert and configure the system with sam configuration as %s." % samhostip) else: raise FailException( "Failed to install candlepin cert and configure the system with sam configuration as %s." % samhostip)
def runcmd(self, cmd, desc=None, timeout=None, showlogger=True): commander = Command(get_exported_param("REMOTE_IP"), "root", "red2015") return commander.run(cmd, timeout, showlogger)
class VIRTWHOBase(unittest.TestCase): # ======================================================== # 0. Basic Functions # ======================================================== commander = Command()