def remove_layered_product_cert(self, system_info, base_pid):
        # Remove the layered product certificate before install package
        logger.info(
            "------------------ Begin to remove the none base product cert before install the packages -----------------------"
        )
        cmd = "ls /etc/pki/product/"
        ret, output = RemoteSHH().run_cmd(system_info, cmd,
                                          "Trying to list product cert...")

        product_cert_list = output.split()
        remove_list = list(set(product_cert_list) - set(base_pid))

        if len(remove_list) == 0:
            logger.info(
                "There is only base product cert, no need to remove any layered product cert."
            )
        else:
            for cert in remove_list:
                cmd = "rm -f /etc/pki/product/{0}".format(cert)
                ret, output = RemoteSHH().run_cmd(
                    system_info, cmd,
                    "Trying to remove the layered product cert {0}...".format(
                        cert))
                if ret == 0:
                    logger.info(
                        "It is successful to remove the none base product cert: {0}"
                        .format(cert))
        logger.info(
            "--------------------End to remove the none product cert before install the packages-----------------------------"
        )
    def remove_channels(self, system_info, username, password, channels=None):
        if channels == None:
            cmd = "rhn-channel --list --user=%s --password=%s" % (username,
                                                                  password)
            ret, output = RemoteSHH().run_cmd(
                system_info, cmd,
                "Trying to list all added channel already...")
            channels = output.splitlines()

        if not isinstance(channels, list):
            channels = [channels]

        for channel in channels:
            cmd = "rhn-channel --remove --channel=%s --user=%s --password=%s" % (
                channel, username, password)
            ret, output = RemoteSHH().run_cmd(
                system_info, cmd,
                "Trying to remove channel {0}".format(channel))
            if ret == 0:
                logger.info("It's successful to remove channel %s." % channel)
                return True
            else:
                logger.info("Test Failed - Failed to remove channel %s." %
                            channel)
                return False
示例#3
0
    def add_channels(self, system_info, username, password, channels):
        channel_default = []
        cmd = "rhn-channel --list --user=%s --password=%s" % (username, password)
        ret, output = RemoteSHH().run_cmd(system_info, cmd, "Trying to list the channel which was added by default after register...")
        if ret == 0:
            channel_default = output.splitlines()
            logger.info("It's successful to get default channel from Satellite 5 server: %s" % channel_default)

        if not isinstance(channels, list):
            channels = [channels]

        for channel in channels:
            if channel not in channel_default:
                # Add channel
                cmd = "rhn-channel --add --channel=%s --user=%s --password=%s" % (channel, username, password)
                ret, output = RemoteSHH().run_cmd(system_info, cmd, "add channel %s" % channel)

            cmd = "rhn-channel --list --user=%s --password=%s" % (username, password)
            ret, output = RemoteSHH().run_cmd(system_info, cmd, "Trying to check if channel {0} was added successfully...".format(channel))
            channel_added = output.splitlines()

            if ret == 0 and channel in channel_added:
                logger.info("It's successful to add channel %s." % channel)
                return True
            else:
                logger.error("Test Failed - Failed to add channel %s." % channel)
                return False
    def stop_rhsmcertd(self, system_info):
        # Stop rhsmcertd service. As headling(autosubscribe) operation will be run every 2 mins after start up system,
        # then every 24 hours after that, which will influence our subscribe test.
        cmd = 'service rhsmcertd status'
        ret, output = RemoteSHH().run_cmd(
            system_info, cmd, "Trying to get status of service rhsmcertd...")
        if 'stopped' in output or 'Stopped' in output:
            return True

        cmd = 'service rhsmcertd stop'
        ret, output = RemoteSHH().run_cmd(
            system_info, cmd, "Trying to stop service rhsmcertd...")
        if ret == 0:
            cmd = 'service rhsmcertd status'
            ret, output = RemoteSHH().run_cmd(
                system_info, cmd,
                "Trying to get status of service rhsmcertd...")
            if 'stopped' in output or 'Stopped' in output:
                logger.info("It's successful to stop rhsmcertd service.")
                return True
            else:
                logger.error("Failed to stop rhsmcertd service.")
                return False
        else:
            logger.error("Failed to stop rhsmcertd service.")
            return False
    def register(self, system_info, username, password, server_url):
        cmd = "rhnreg_ks --username=%s --password=%s --serverUrl=%s" % (
            username, password, server_url)

        if self.isregistered(system_info):
            if not self.unregister(system_info):
                logger.info(
                    "The system is failed to unregister from rhn server, try to use '--force'!"
                )
                cmd += " --force"

        ret, output = RemoteSHH().run_cmd(
            system_info, cmd, "Trying to register to rhn server...")
        if ret == 0:
            logger.info("It's successful to register to rhn server.")
            cmd = "rm -rf /var/cache/yum/*"
            ret, output = RemoteSHH().run_cmd(
                system_info, cmd,
                "Trying to clean the yum cache after register...")
            if ret == 0:
                logger.info("It's successful to clean the yum cache.")
            else:
                logger.warning("Failed to clean the yum cache.")
            return True
        else:
            # Error Message:
            # Invalid username/password combination
            logger.error("Test Failed - Failed to register with rhn server.")
            return False
示例#6
0
 def download_cert(self, system_info, sat5_server):
     cert_download_path = "/usr/share/rhn/RHN-ORG-TRUSTED-SSL-CERT"
     RemoteSHH().run_cmd(system_info, "rm -rf {0}".format(cert_download_path), "Trying to remove old cert {0} before download it...".format(cert_download_path))
     cmd = "wget http://%s/pub/RHN-ORG-TRUSTED-SSL-CERT -O %s" % (sat5_server, cert_download_path)
     ret, output = RemoteSHH().run_cmd(system_info, cmd, "Trying to download cert {0}...".format(cert_download_path))
     if ret == 0:
         logger.info("It's successful to download ssl CA cert {0}.".format(cert_download_path))
         return True
     else:
         logger.error("Test Failed - Failed to download ssl CA cert {0}.".format(cert_download_path))
         return False
    def config_testing_environment(self, system_info, hostname, baseurl):
        # Config hostname and baseurl in /etc/rhsm/rhsm.conf
        cmd = "subscription-manager config --server.hostname={0}".format(
            hostname)
        RemoteSHH().run_cmd(
            system_info, cmd,
            "Trying to set hostname in /etc/rhsm/rhsm.conf...")

        cmd = "subscription-manager config --rhsm.baseurl={0}".format(baseurl)
        RemoteSHH().run_cmd(system_info, cmd,
                            "Trying to set baseurl in /etc/rhsm/rhsm.conf...")
示例#8
0
 def get_master_release(self, system_info):
     ret, output = RemoteSHH().run_cmd(
         system_info, "rpm -q redhat-lsb",
         "Trying to check if command redhat-lsb is installed...")
     if "not installed" in output:
         RemoteSHH().run_cmd(
             system_info, "yum install -y redhat-lsb",
             "Trying to check if command redhat-lsb is installed...")
     ret, release = RemoteSHH().run_cmd(
         system_info, "lsb_release -r -s",
         "Trying to restore those non-redhat repos...")
     master_release = release.split(".")[0]
     return master_release
示例#9
0
    def unregister(self, system_info,):
        cmd = "rm -rf /etc/sysconfig/rhn/systemid"
        (ret1, output1) = RemoteSHH().run_cmd(system_info, cmd, "Trying to unregister from Satellite 5 - delete systemid...")

        cmd = "sed -i 's/enabled = 1/enabled = 0/' /etc/yum/pluginconf.d/rhnplugin.conf"
        (ret2, output2) = RemoteSHH().run_cmd(system_info, cmd, "Trying to unregister from Satellite 5 - modify rhnplugin.conf...")

        if ret1 == 0 and ret2 == 0:
            logger.info("It's successful to unregister from Satellite 5 server.")
            return True
        else:
            logger.error("Test Failed - Failed to unregister from Satellite 5 server.")
            return False
 def redhat_repo_backup(self, system_info):
     # Download content of file redhat.repo remotely, and save it locally
     remote_path = "/etc/yum.repos.d/redhat.repo"
     local_path = os.path.join(os.getcwd(), "redhat.repo")
     RemoteSHH().download_file(system_info, remote_path, local_path)
     ret, output = RemoteSHH().run_cmd(
         None, "ls {0}".format(local_path),
         "Trying to check {0}.".format(local_path))
     if "No such file or directory" in output:
         logger.warning("Failed to download {0} to {1}".format(
             remote_path, local_path))
     else:
         logger.info("It's successful to download {0} to {1}".format(
             remote_path, local_path))
    def verify_productid_in_entitlement_cert(self, system_info,
                                             entitlement_cert, pid):
        # Verify if one specific product id in one entitlement cert
        cmd = "rct cat-cert /etc/pki/entitlement/{0} | grep ID | egrep -v 'Stacking ID|Pool ID'".format(
            entitlement_cert)
        ret, output = RemoteSHH().run_cmd(
            system_info, cmd,
            "Trying to check PID {0} in entitlement certificate {1} with rct..."
            .format(pid, entitlement_cert))

        if ret == 0:
            # Output:
            #    ID: 240
            #    ID: 281
            #    ID: 285
            #    ID: 286
            #    ID: 69
            #    ID: 83
            #    ID: 85
            if pid in [i.split(":")[1].strip() for i in output.splitlines()]:
                logger.info(
                    "It's successful to verify PID {0} in entitlement certificate {1}."
                    .format(pid, entitlement_cert))
                return True
            else:
                logger.error(
                    "Test Failed - Failed to verify PID {0} in entitlement certificate {1}."
                    .format(pid, entitlement_cert))
                return False
        else:
            # Output:
            # sh: rct: command not found
            prefix_str = '1.3.6.1.4.1.2312.9.1.'
            cmd = 'openssl x509 -text -noout -in /etc/pki/entitlement/{0} | grep --max-count=1 -A 1 {1}{2}'.format(
                entitlement_cert, prefix_str, pid)
            ret, output = RemoteSHH().run_cmd(
                system_info, cmd,
                "Trying to check PID {0} in entitlement certificate {1} with openssl..."
                .format(pid, entitlement_cert))
            if ret == 0 and output != '':
                logger.info(
                    "It's successful to verify PID {0} in entitlement certificate {1}."
                    .format(pid, entitlement_cert))
                return True
            else:
                logger.error(
                    "Test Failed - Failed to verify PID {0} in entitlement certificate {1}."
                    .format(pid, entitlement_cert))
                return False
    def verify_channels(self, system_info, manifest_xml, username, password,
                        current_arch, variant):
        # For now, this function can be only tested on RHEL6, as there is no param --available-channels on RHEL5
        logger.info("--------------- Begin to verify channel ---------------")
        # Get all channels which are not added
        available_channels = []
        cmd = "rhn-channel --available-channels --user=%s --password=%s" % (
            username, password)
        ret, output = RemoteSHH().run_cmd(
            system_info, cmd,
            "Trying to get available channels with command rhn-channel...")
        if ret == 0:
            available_channels = output.splitlines()
        else:
            logger.error("Failed to get available channels.")

        # Get all channels which are already added
        added_channels = []
        cmd = "rhn-channel --list --user=%s --password=%s" % (username,
                                                              password)
        ret, output = RemoteSHH().run_cmd(
            system_info, cmd,
            "Trying to get added channels with command rhn-channel...")
        if ret == 0:
            added_channels = output.splitlines()
        else:
            logger.error("Failed to get added channels.")

        channels_rhn = available_channels + added_channels

        # Get all channels from manifest which are needed testing
        channels_manifest = self.get_channels_from_manifest(
            manifest_xml, current_arch, variant)
        list1 = self.cmp_arrays(channels_manifest, channels_rhn)
        if len(list1) > 0:
            logger.error("Failed to verify channel.")
            logger.info(
                'Below are channels in provided manifest but not in rhn-channel:'
            )
            self.print_list(list1)
            logger.error(
                "--------------- End to verify channel: FAIL ---------------")
            logger.error("Test Failed - Failed to verify channel.")
            return False
        else:
            logger.info("All expected channels exist in test list!")
            logger.info(
                "--------------- End to verify channel: PASS ---------------")
            return True
    def get_sku_pool(self, system_info):
        # Get available entitlement pools
        time.sleep(5)
        cmd = "subscription-manager  list --avail --all| egrep 'SKU|Pool ID' | grep -v Subscription"
        ret, output = RemoteSHH().run_cmd(
            system_info, cmd,
            "Trying to list all available SKU and Pool ID...")

        sku_pool_dict = {}
        if ret == 0:
            if output != "":
                i = 0
                sku = ""
                for line in output.splitlines():
                    if line != "":
                        if i % 2 == 0:
                            sku = line.split(":")[1].strip()
                        if i % 2 != 0:
                            pool = line.split(":")[1].strip()
                            if i != 0:
                                if sku in sku_pool_dict.keys():
                                    sku_pool_dict[sku].append(pool)
                                else:
                                    sku_pool_dict[sku] = [pool]
                        i += 1
            else:
                logger.error("No suitable pools!")
                logger.error("Test Failed - Failed to get available pools.")
        else:
            logger.error("Test Failed - Failed to get available pools.")

        return sku_pool_dict
示例#14
0
 def get_avail_space(self, system_info):
     ret, output = RemoteSHH().run_cmd(system_info, "df -H | grep home")
     if "home" in output:
         avail_space = output.split()[3]
     else:
         avail_space = "0"
     return avail_space
示例#15
0
 def get_os_base_arch(self, system_info):
     # Get base arch of current system
     cmd = '''python -c "import yum; yb = yum.YumBase(); print(yb.conf.yumvar)['basearch']"'''
     ret, output = RemoteSHH().run_cmd(
         system_info, cmd, "Trying to get current base arch...")
     if ret == 0 and "Loaded plugins" in output:
         logger.info("It's successful to get current base arch.")
         if "ppc64le" in output:
             base_arch = "ppc64le"
         elif "ppc64" in output:
             base_arch = "ppc64"
         elif "ppc" in output:
             base_arch = "ppc"
         elif "i386" in output:
             base_arch = "i386"
         elif "x86_64" in output:
             base_arch = "x86_64"
         elif "s390x" in output:
             base_arch = "s390x"
         elif "ia64" in output:
             base_arch = "ia64"
         elif "aarch64" in output:
             base_arch = "aarch64"
         else:
             logger.error("No base arch could get from current system.")
             assert False, "Test Failed - Failed to get current base arch."
         logger.info(
             "Base arch for current system is {0}.".format(base_arch))
         return base_arch
     else:
         assert False, "Test Failed - Failed to get current base arch."
 def get_certificate_list(self, system_info):
     cmd = "ls /etc/pki/entitlement/ | grep -v key.pem"
     ret, output = RemoteSHH().run_cmd(
         system_info, cmd,
         "Trying to list all certificate files under /etc/pki/entitlement/..."
     )
     return output.splitlines()
 def change_gpgkey(self, system_info, repo_list):
     # Change gpgkey for all the test repos listed in manifest
     logger.info(
         "--------------- Begin to change gpgkey for test repos ---------------"
     )
     result = True
     for repo in repo_list:
         cmd = "subscription-manager repo-override --repo %s --add=gpgkey:file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-beta,file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release" % repo
         ret, output = RemoteSHH().run_cmd(
             system_info, cmd,
             "Trying to change gpgkey for repo %s in /etc/yum.repos.d/redhat.repo..."
             .format(repo))
         if ret == 0:
             logger.info(
                 "It's successful to change gpgkey for repo {0} in /etc/yum.repos.d/redhat.repo"
                 .format(repo))
             logger.info(
                 "--------------- End to change gpgkey for test repos ---------------"
             )
         else:
             logger.error(
                 "Test Failed - Failed to change gpgkey for repo {0} /etc/yum.repos.d/redhat.repo."
                 .format(repo))
             logger.info(
                 "--------------- End to change gpgkey for test repos ---------------"
             )
             result = False
     return result
    def set_config_file(self, system_info, release_ver, config_file):
        cmd = '''sed -i "s/yumvars\['releasever'\] = /yumvars\['releasever'\] = '%s' # /" %s''' % (
            release_ver, config_file)
        RemoteSHH().run_cmd(
            system_info, cmd,
            "Trying to modify config.py to set the system release as {0}...".
            format(release_ver))

        cmd = '''cat %s | grep "yumvars\['releasever'\]"''' % config_file
        ret, output = RemoteSHH().run_cmd(
            system_info, cmd, "Trying to check the setting in config.py...")
        if release_ver in output:
            logger.info("It's successful to set system release.")
            return True
        else:
            logger.error("Test Failed - Failed to set system release.")
            return False
    def verify_sku_in_entitlement_cert(self, system_info, entitlement_cert,
                                       sku):
        # Verify if one specific sku id in one entitlement cert
        cmd = "rct cat-cert /etc/pki/entitlement/{0} | grep SKU".format(
            entitlement_cert)
        ret, output = RemoteSHH().run_cmd(
            system_info, cmd,
            "Trying to check SKU {0} in entitlement certificate {1} with rct..."
            .format(sku, entitlement_cert))

        if ret == 0:
            # Output:
            # SKU: MCT2887
            if sku in [
                    i.strip().split(":")[1].strip()
                    for i in output.splitlines()
            ]:
                logger.info(
                    "It's successful to verify sku {0} in entitlement certificate {1}."
                    .format(sku, entitlement_cert))
                return True
            else:
                logger.error(
                    "Test Failed - Failed to verify sku {0} in entitlement cert {1}."
                    .format(sku, entitlement_cert))
                return False
        else:
            # Output:
            # sh: rct: command not found
            cmd = 'openssl x509 -text -noout -in /etc/pki/entitlement/{0} | grep {1}'.format(
                entitlement_cert, sku)
            ret, output = RemoteSHH().run_cmd(
                system_info, cmd,
                "Trying to check SKU {0} in entitlement certificate {1} with openssl..."
                .format(sku, entitlement_cert))
            if ret == 0 and output != '':
                logger.info(
                    "It's successful to verify sku {0} in entitlement cert {1}."
                    .format(sku, entitlement_cert))
                return True
            else:
                logger.error(
                    "Test Failed - Failed to verify sku {0} in entitlement cert {1}."
                    .format(sku, entitlement_cert))
                return False
示例#20
0
 def isregistered(self, system_info,):
     cmd = "ls /etc/sysconfig/rhn/systemid"
     ret, output = RemoteSHH().run_cmd(system_info, cmd, "Trying to check if registered to Satellite 5 server...")
     if ret == 0:
         logger.info("The system is registered to Satellite 5 server now.")
         return True
     else:
         logger.info("The system is not registered to Satellite 5 server now.")
         return False
示例#21
0
    def installation(self, system_info, manifest_xml, channel):
        # Install binary packages with yum
        # There are source rpms in channels, but they can only be downloaded through the customer portal web site.  They aren't exposed to yum/yumdownloader/repoquery.
        # RHN APIs that can be used to query the source packages available, but the APIs are only available to RHN admins. So, let's not worry about SRPMs for now.
        # Download source rpms from the customer portal web site - ignored for now
        logger.info("--------------- Begin to verify packages full installation for channel {0} ---------------".format(channel))

        # Get all packages already installed in testing system before installation testing
        system_pkglist = self.get_sys_pkglist(system_info)

        # Store the failed packages when 'yum remove'.
        remove_failed_pkglist = []

        # Get packages from manifest
        package_list = SAT5ReadXML().get_package_list(manifest_xml, channel)
        logger.info("There are {0} packages need to install for channel {0}.".format(len(package_list), package_list))
        self.print_list(package_list)

        result = True
        number = 0
        total_number = len(package_list)
        for pkg in package_list:
            number += 1
            cmd = "yum install -y %s" % pkg
            ret, output = RemoteSHH().run_cmd(system_info, cmd, "Trying to yum install package {0} of channel {1}".format(pkg, channel))

            if ret == 0:
                if ("Complete!" in output) or ("Nothing to do" in output) or ("conflicts" in output):
                    logger.info("It's successful to install package [{0}/{1}] {2} of channel {3}...".format(number, total_number, pkg, channel))
                else:
                    logger.error("Test Failed - Failed to install package [{0}/{1}] {2} of channel {3}...".format(number, total_number, pkg, channel))
                    result = False
            else:
                if "conflicts" in output:
                    logger.info("It's successful to install package [{0}/{1}] {2} of channel {3}...".format(number, total_number, pkg, channel))
                else:
                    logger.error("Test Failed - Failed to install package [{0}/{1}] {2} of channel {3}...".format(number, total_number, pkg, channel))
                    result = False

            if result:
                if pkg not in system_pkglist:
                    # Remove package if it is not in the system package list.
                    # It is used to solve the dependency issue which describe in https://bugzilla.redhat.com/show_bug.cgi?id=1272902.
                    if not self.remove_pkg(system_info, pkg, channel):
                        remove_failed_pkglist.append(pkg)
                        logging.warning("Failed to remove {0} of channel {1}.".format(pkg, channel))

        if len(remove_failed_pkglist) != 0:
            logger.warning("Failed to remove following {0} packages for channel {1}:".format(len(remove_failed_pkglist), channel))
            self.print_list(remove_failed_pkglist)

        if result:
            logger.info("--------------- End to verify packages full installation for channel {0}: PASS ---------------".format(channel))
        else:
            logger.error("--------------- End to verify packages full installation for channel {0}: FAIL ---------------".format(channel))
        return result
 def disable_all_repo(self, system_info):
     # Disabling all default enabled repos
     cmd = "subscription-manager repos --disable=*"
     ret, output = RemoteSHH().run_cmd(system_info, cmd,
                                       "Trying to disable all repos...")
     if ret == 0:
         logger.info("sucessfully disabled all repos")
         return True
     else:
         logger.error("test Failed - Failed to diable default enabled repo")
         return False
 def clean_yum_cache(self, system_info, releasever_set):
     # Clean yum cache
     cmd = 'yum clean all --enablerepo=* {0}'.format(releasever_set)
     ret, output = RemoteSHH().run_cmd(system_info, cmd,
                                       "Trying to yum clean cache...")
     if ret == 0:
         logger.info("It's successful to clean yum cache")
         return True
     else:
         logger.error("Test Failed - Failed to clean yum cache")
         return False
示例#24
0
 def write_polarion_props(self, system_info):
     # Generate file polarion.prop on jenkins slave machine for Polarion case properties to create run automatically
     master_relase = self.get_master_release(system_info)
     cmd = "cat ../polarion.prop | grep Master_Release"
     ret, output = RemoteSHH().run_cmd(
         None, cmd, "Trying to get current base arch...")
     if "Master_Release" not in output:
         with open("../polarion.prop", 'a+') as f:
             #f.write("Master_Release={0}".format(master_relase))
             f.write("PROP_FILE_NAME=$WORKSPACE/POLARION_PROPS_RHEL{0}\n".
                     format(master_relase))
示例#25
0
    def remove_non_redhat_repo(self, system_info):
        # Backup non-redhat repo
        backup_path = "/tmp/backup_repo"
        cmd = "mkdir -p {0}; cp /etc/yum.repos.d/beaker* {0}".format(
            backup_path)
        RemoteSHH().run_cmd(
            system_info, cmd,
            "Trying to backup non-redhat repos to {0}...".format(backup_path))

        # Remove non-redhat repo
        cmd = "ls /etc/yum.repos.d/* | grep -v redhat.repo | xargs rm -rf"
        RemoteSHH().run_cmd(
            system_info, cmd,
            "Trying to delete non-redhat repos to avoid affection...")

        # Check remove result
        cmd = "ls /etc/yum.repos.d/"
        RemoteSHH().run_cmd(
            system_info, cmd,
            "Trying to check the result of remove non-redhat repos...")
    def verify_productid_in_product_cert(self, system_info, pid, base_pid):
        # Check product id in product entitlement certificate
        str = '1.3.6.1.4.1.2312.9.1.'

        time.sleep(20)
        ret, output = RemoteSHH().run_cmd(
            system_info, "ls /etc/pki/product/",
            "Trying to list all the product certificates...")
        product_ids = output.split()

        if "{0}.pem".format(pid) in product_ids:
            logger.info(
                "It's successful to install the product cert {0}!".format(pid))

            cmd = 'openssl x509 -text -noout -in /etc/pki/product/{0}.pem | grep {1}{2}'.format(
                pid, str, pid)
            ret, output = RemoteSHH().run_cmd(
                system_info, cmd,
                "Trying to verify product id in product certificate...")

            if ret == 0 and output != '':
                logger.info(
                    "It's successful to verify PID {0} in product cert.".
                    format(pid))
                return True
            else:
                logger.error(
                    "Test Failed - Failed to verify PID {0} in product cert.".
                    format(pid))
                return False
        else:
            error_list = list(set(product_ids) - set([base_pid]))
            if len(error_list) == 0:
                logger.error(
                    "Test Failed - Failed to install the product cert {0}.pem."
                    .format(pid))
            else:
                logger.error(
                    "Test Failed - Failed to install correct product cert {0}, but installed cert {1}."
                    .format(pid, error_list))
            return False
    def subscribe_pool(self, system_info, poolid):
        cmd = "subscription-manager subscribe --pool={0}".format(poolid)
        ret, output = RemoteSHH().run_cmd(
            system_info, cmd,
            "Trying to subscribe with poolid {0}".format(poolid))

        if ret == 0:
            logger.info("It's successful to subscribe.")
            return True
        else:
            logger.error("Test Failed - Failed to subscribe.")
            return False
 def check_registered(self, system_info):
     # Check if registered
     cmd = "subscription-manager identity"
     ret, output = RemoteSHH().run_cmd(
         system_info, cmd,
         "Trying to check if registered with cdn server...")
     if ret == 0:
         logger.info("The system is registered with cdn server now.")
         return True
     else:
         logger.info("The system is not registered with cdn server now.")
         return False
 def disable_repo(self, system_info, repo):
     # Disable a repo after finish testing this repo
     cmd = "subscription-manager repos --disable={0}".format(repo)
     ret, output = RemoteSHH().run_cmd(
         system_info, cmd, "Trying to disable repo {0}...".format(repo))
     if ret == 0:
         logger.info("It's successful to disable repo {0}.".format(repo))
         return True
     else:
         logger.error(
             "Test Failed - Failed to disable repo {0}.".format(repo))
         return False
    def set_release(self, system_info, release_ver):
        releasever_set = ""
        master_release = self.get_master_release(system_info)
        config_file = self.get_config_file(master_release)

        cmd = "subscription-manager release --set={0}".format(release_ver)
        ret, output = RemoteSHH().run_cmd(
            system_info, cmd,
            "Trying to set release version as {0}...".format(release_ver))

        if ret == 0 and 'Release set to' in output:
            logger.info("It's successful to set system release as {0}.".format(
                release_ver))
            cmd = "subscription-manager release"
            RemoteSHH().run_cmd(
                system_info, cmd,
                "Trying to check the release version after setting...".format(
                    release_ver))
        elif ret == 0 and 'Usage: subscription-manager' in output:
            self.set_config_file(system_info, release_ver, config_file)
        elif 'No releases match' in output:
            if master_release == '5':
                self.set_config_file(system_info, release_ver, config_file)
            elif master_release in ["6", "7"]:
                releasever_set = '--releasever=%s' % release_ver
                logger.info(
                    "It's successfully to set variable --releasever={0}.".
                    format(release_ver))
            else:
                logger.error(
                    "Test Failed - Failed to set system release as {0}.".
                    format(release_ver))
                return False
        else:
            logger.error(
                "Test Failed - Failed to set system release as {0}.".format(
                    release_ver))
            return False
        return releasever_set