コード例 #1
0
 def select(connection, value_list):
     '''
     Select list of items (multiple choice)
     '''
     for value in value_list:
         match = Expect.match(connection, re.compile(".*-\s+([0-9]+)\s*:[^\n]*\s+" + value + "\s*\n.*for more commands:.*", re.DOTALL))
         Expect.enter(connection, match[0])
         match = Expect.match(connection, re.compile(".*x\s+([0-9]+)\s*:[^\n]*\s+" + value + "\s*\n.*for more commands:.*", re.DOTALL))
         Expect.enter(connection, "l")
     Expect.enter(connection, "c")
コード例 #2
0
    def check_for_package(connection, reponame, package):
        '''
        list packages in a repository
        '''
        RHUIManager.screen(connection, "repo")
        Expect.enter(connection, "p")
        RHUIManager.select_one(connection, reponame)
        Expect.expect(connection, "\(blank line for no filter\):")
        Expect.enter(connection, package)

        pattern = re.compile('.*only\.\r\n(.*)\r\n-+\r\nrhui\s* \(repo\)\s* =>',
                             re.DOTALL)
        ret = Expect.match(connection, pattern, grouplist=[1])[0]
        reslist = map(lambda x: x.strip(), ret.split("\r\n"))
        print reslist
        packagelist = []
        for line in reslist:
            if line == '':
                continue
            if line == 'Packages:':
                continue
            if line == 'No packages found that match the given filter.':
                continue
            if line == 'No packages in the repository.':
                continue
            packagelist.append(line)

        Expect.enter(connection, 'q')
        return packagelist
コード例 #3
0
    def check_for_package(connection, reponame, package):
        '''
        list packages in a repository
        '''
        RHUIManager.screen(connection, "repo")
        Expect.enter(connection, "p")

        RHUIManager.select_one(connection, reponame)
        Expect.expect(connection, r"\(blank line for no filter\):")
        Expect.enter(connection, package)

        pattern = re.compile(r'.*only\.\r\n(.*)\r\n-+\r\nrhui\s* \(repo\)\s* =>',
                             re.DOTALL)
        ret = Expect.match(connection, pattern, grouplist=[1])[0]
        reslist = map(str.strip, str(ret).splitlines())
        packagelist = []
        for line in reslist:
            if line == '':
                continue
            if line == 'Packages:':
                continue
            if line == 'No packages found that match the given filter.':
                continue
            if line == 'No packages in the repository.':
                continue
            packagelist.append(line)
        Expect.enter(connection, 'q')
        return packagelist
コード例 #4
0
    def list(connection):
        '''
        list repositories
        '''
        RHUIManager.screen(connection, "repo")
        Expect.enter(connection, "l")
        # eating prompt!!
        pattern = re.compile('l\r\n(.*)\r\n-+\r\nrhui\s* \(repo\)\s* =>',
                re.DOTALL)
        ret = Expect.match(connection, pattern, grouplist=[1])[0]
        print ret
        reslist = map(lambda x: x.strip(), ret.split("\r\n"))
        print reslist
        repolist = []
        for line in reslist:
            # Readling lines and searching for repos
            if line == '':
                continue
            if "Custom Repositories" in line:
                continue
            if "Red Hat Repositories" in line:
                continue
            if "No repositories are currently managed by the RHUI" in line:
                continue
            repolist.append(line)

        Expect.enter(connection, 'q')
        return repolist
コード例 #5
0
 def upload_content(connection, repolist, path):
     '''
     upload content to a custom repository
     '''
     # Temporarily quit rhui-manager and check whether "path" is a file or a directory.
     # If it is a directory, get a list of *.rpm files in it.
     Expect.enter(connection, 'q')
     Expect.enter(connection, "stat -c %F " + path)
     path_type = Expect.expect_list(
         connection, [(re.compile(".*regular file.*", re.DOTALL), 1),
                      (re.compile(".*directory.*", re.DOTALL), 2)])
     if path_type == 1:
         content = [basename(path)]
     elif path_type == 2:
         Expect.enter(connection, "echo " + path + "/*.rpm")
         output = Expect.match(connection, re.compile("(.*)", re.DOTALL))[0]
         rpm_files = output.splitlines()[1]
         content = []
         for rpm_file in rpm_files.split():
             content.append(basename(rpm_file))
     else:
         # This should not happen. Getting here means that "path" is neither a file nor a directory.
         # Anyway, going on with no content, leaving it up to proceed_with_check() to handle this situation.
         content = []
     # Start rhui-manager again and continue.
     RHUIManager.initial_run(connection)
     RHUIManager.screen(connection, "repo")
     Expect.enter(connection, "u")
     RHUIManager.select(connection, repolist)
     Expect.expect(connection, "will be uploaded:")
     Expect.enter(connection, path)
     RHUIManager.proceed_with_check(connection,
                                    "The following RPMs will be uploaded:",
                                    content)
     RHUIManager.quit(connection)
コード例 #6
0
    def list(connection):
        '''
        list repositories
        '''
        RHUIManager.screen(connection, "repo")
        Expect.enter(connection, "l")
        # eating prompt!!
        pattern = re.compile('l\r\n(.*)\r\n-+\r\nrhui\s* \(repo\)\s* =>',
                             re.DOTALL)
        ret = Expect.match(connection, pattern, grouplist=[1])[0]
        print ret
        reslist = map(lambda x: x.strip(), ret.split("\r\n"))
        print reslist
        repolist = []
        for line in reslist:
            # Readling lines and searching for repos
            if line == '':
                continue
            if "Custom Repositories" in line:
                continue
            if "Red Hat Repositories" in line:
                continue
            if "No repositories are currently managed by the RHUI" in line:
                continue
            repolist.append(line)

        Expect.enter(connection, 'q')
        return repolist
コード例 #7
0
    def upload_rh_certificate(connection, certificate_file="/tmp/extra_rhui_files/rhcert.pem"):
        '''
        upload a new or updated Red Hat content certificate
        '''
        bad_cert_msg = "The provided certificate is expired or invalid"
        incompatible_cert_msg = "does not contain any entitlements"

        RHUIManager.screen(connection, "entitlements")
        Expect.enter(connection, "u")
        Expect.expect(connection, "Full path to the new content certificate:")
        Expect.enter(connection, certificate_file)
        state = Expect.expect_list(connection,
                                   [(re.compile(".*The RHUI will be updated.*", re.DOTALL), 1),
                                    (re.compile(".*Cannot find file.*", re.DOTALL), 2)])
        if state == 2:
            Expect.enter(connection, CTRL_C)
            RHUIManager.quit(connection)
            raise MissingCertificate("No such certificate file: %s" % certificate_file)
        Expect.enter(connection, "y")
        match = Expect.match(connection,
                             re.compile("(.*)" + PROMPT, re.DOTALL))
        matched_string = match[0].replace('l\r\n\r\nRed Hat Entitlements\r\n\r\n  ' +
                                          '\x1b[92mValid\x1b[0m\r\n    ', '', 1)
        if bad_cert_msg in matched_string:
            Expect.enter(connection, 'q')
            raise BadCertificate()
        if incompatible_cert_msg in matched_string:
            Expect.enter(connection, 'q')
            raise IncompatibleCertificate()
        entitlements_list = []
        pattern = re.compile('(.*?\r\n.*?pem)', re.DOTALL)
        for entitlement in pattern.findall(matched_string):
            entitlements_list.append(entitlement.strip())
        Expect.enter(connection, 'q')
        return entitlements_list
コード例 #8
0
 def upload_content(connection, repolist, path):
     '''
     upload content to a custom repository
     '''
     # Temporarily quit rhui-manager and check whether "path" is a file or a directory.
     # If it is a directory, get a list of *.rpm files in it.
     Expect.enter(connection, 'q')
     Expect.enter(connection, "stat -c %F " + path)
     path_type = Expect.expect_list(connection, [(re.compile(".*regular file.*", re.DOTALL), 1), (re.compile(".*directory.*", re.DOTALL), 2)])
     if path_type == 1:
         content = [basename(path)]
     elif path_type == 2:
         Expect.enter(connection, "echo " + path + "/*.rpm")
         output = Expect.match(connection, re.compile("(.*)", re.DOTALL))[0]
         rpm_files = output.splitlines()[1]
         content = []
         for rpm_file in rpm_files.split():
             content.append(basename(rpm_file))
     else:
         # This should not happen. Getting here means that "path" is neither a file nor a directory.
         # Anyway, going on with no content, leaving it up to proceed_with_check() to handle this situation.
         content = []
     # Start rhui-manager again and continue.
     RHUIManager.initial_run(connection)
     RHUIManager.screen(connection, "repo")
     Expect.enter(connection, "u")
     RHUIManager.select(connection, repolist)
     Expect.expect(connection, "will be uploaded:")
     Expect.enter(connection, path)
     RHUIManager.proceed_with_check(connection, "The following RPMs will be uploaded:", content)
     Expect.expect(connection, "rhui \(" + "repo" + "\) =>")
コード例 #9
0
 def select_one(connection, item):
     '''
     Select one item (single choice)
     '''
     match = Expect.match(
         connection,
         re.compile(".*([0-9]+)\s+-\s+" + item + "\s*\n.*to abort:.*",
                    re.DOTALL))
     Expect.enter(connection, match[0])
コード例 #10
0
 def select(connection, value_list):
     '''
     Select list of values (multiple choice)
     '''
     for value in value_list:
         match = Expect.match(
             connection,
             re.compile(
                 ".*-\s+([0-9]+)\s*:[^\n]*\s+" + value +
                 "\s*\n.*for more commands:.*", re.DOTALL))
         Expect.enter(connection, match[0])
         match = Expect.match(
             connection,
             re.compile(
                 ".*x\s+([0-9]+)\s*:[^\n]*\s+" + value +
                 "\s*\n.*for more commands:.*", re.DOTALL))
         Expect.enter(connection, "l")
     Expect.enter(connection, "c")
コード例 #11
0
ファイル: rhuimanager.py プロジェクト: vex21/rhui3-automation
 def list_lines(connection, prompt='', enter_l=True):
     '''
     list items on screen returning a list of lines seen
     eats prompt!!!
     '''
     if enter_l:
         Expect.enter(connection, "l")
     match = Expect.match(connection, re.compile("(.*)" + prompt, re.DOTALL))
     return match[0].split('\r\n')
コード例 #12
0
def _get_repo_status(connection, repo_name):
    '''
    get the status of the given repository
    '''
    Expect.enter(connection, "rhui-manager status")
    status = Expect.match(
        connection,
        re.compile(".*%s[^A-Z]*([A-Za-z]*).*" % re.escape(repo_name),
                   re.DOTALL))[0]
    return status
コード例 #13
0
 def list_lines(connection, prompt='', enter_l=True):
     '''
     list items on screen returning a list of lines seen
     eats prompt!!!
     '''
     if enter_l:
         Expect.enter(connection, "l")
     match = Expect.match(connection, re.compile("(.*)" + prompt,
                                                 re.DOTALL))
     return match[0].split('\r\n')
コード例 #14
0
    def info(connection, repolist):
        '''
        detailed information about repositories

        Method returns list of items from rhui-manager info screen. Some of them are variable and these are replaced by "rh_repo" constant.
        '''
        RHUIManager.screen(connection, "repo")
        Expect.enter(connection, "i")
        RHUIManager.select(connection, repolist)

        try:
            pattern = re.compile(
                '.*for more commands: \r\n\r\nName:\s(.*)\r\n-+\r\nrhui\s* \(repo\)\s* =>',
                re.DOTALL)
            ret = Expect.match(connection, pattern, grouplist=[1])[0]
            print ret
            res = map(lambda x: x.strip(), ret.split("\r\n"))
            reslist = ["Name:"]
            for line in res:
                reslist.extend(
                    map(lambda y: y.strip(), re.split("\s{3}", line)))
            print reslist
            repoinfo = []
            rh_repo = 0
            rh_repo_info = 0
            for line in reslist:
                # Readling lines
                if line == '':
                    continue
                if rh_repo_info == 1:
                    line = "rh_repo"
                    rh_repo_info = 0
                if line == "Red Hat":
                    rh_repo = 1
                if "Relative Path:" in line:
                    if rh_repo == 1:
                        rh_repo_info = 1
                if "Package Count:" in line:
                    if rh_repo == 1:
                        rh_repo_info = 1
                if "Last Sync:" in line:
                    if rh_repo == 1:
                        rh_repo_info = 1
                if "Next Sync:" in line:
                    if rh_repo == 1:
                        rh_repo_info = 1
                repoinfo.append(line)
            print repoinfo

        except:
            repoinfo = []

        Expect.enter(connection, 'q')
        return repoinfo
コード例 #15
0
 def get_repo_status(connection, repo_name):
     '''
     (internally used) method to get the status of the given repository
     '''
     Expect.enter(connection, "rhui-manager status")
     status = Expect.match(
         connection,
         re.compile(
             ".*" + Util.esc_parentheses(repo_name) +
             "[^A-Z]*([A-Za-z]*).*", re.DOTALL))[0]
     return status
コード例 #16
0
 def command_output(connection, command, pattern_tuple, username="******",
         password="******"):
     """return output of a command based on pattern_tuple provided. Output
     is split to lines"""
     Expect.enter(connection, "pulp-admin -u %s -p %s %s" % \
             (username, password, command))
     # eats prompt!
     pattern, group_index = pattern_tuple
     ret = Expect.match(connection, pattern, grouplist=[group_index])[0]
     # reset prompt
     Expect.enter(connection, "")
     return ret.split('\r\n')
コード例 #17
0
    def info(connection, repolist):
        '''
        detailed information about repositories

        Method returns list of items from rhui-manager info screen. Some of them are variable and these are replaced by "rh_repo" constant.
        '''
        RHUIManager.screen(connection, "repo")
        Expect.enter(connection, "i")
        RHUIManager.select(connection, repolist)

        try:
            pattern = re.compile('.*for more commands: \r\n\r\nName:\s(.*)\r\n-+\r\nrhui\s* \(repo\)\s* =>',
                                 re.DOTALL)
            ret = Expect.match(connection, pattern, grouplist=[1])[0]
            print ret
            res = map(lambda x: x.strip(), ret.split("\r\n"))
            reslist = ["Name:"]
            for line in res:
                reslist.extend(map(lambda y: y.strip(), re.split("\s{3}", line)))
            print reslist
            repoinfo = []
            rh_repo = 0
            rh_repo_info = 0
            for line in reslist:
                # Readling lines
                if line == '':
                    continue
                if rh_repo_info == 1:
                    line = "rh_repo"
                    rh_repo_info = 0
                if line == "Red Hat":
                    rh_repo = 1
                if "Relative Path:" in line:
                    if rh_repo == 1:
                        rh_repo_info = 1
                if "Package Count:" in line:
                    if rh_repo == 1:
                        rh_repo_info = 1
                if "Last Sync:" in line:
                    if rh_repo == 1:
                        rh_repo_info = 1
                if "Next Sync:" in line:
                    if rh_repo == 1:
                        rh_repo_info = 1
                repoinfo.append(line)
            print repoinfo

        except:
            repoinfo = []

        Expect.enter(connection, 'q')
        return repoinfo
コード例 #18
0
    def check_detailed_information(connection, repo_data, type_data, gpg_data, package_count):
        '''
        verify that a repository has the expected properties

        repo_data: [string, string]
                   [0]: repo name
                   [1]: relative path
        type_data: [bool, bool]
                   [0]: True? Custom. False? Red Hat.
                   [1]: True? Protected. False? Unprotected. (Only checked with a Custom repo.)
        gpg_data:  [bool, string, bool]
                   [0]: True? GPG Check Yes. False? GPG Check No.
                   [1]: Custom GPG Keys (comma-separated names), or None.
                   [2]: True? Red Hat GPG Key Yes. False? Red Hat GPG Key No.
        '''
        RHUIManager.screen(connection, "repo")
        Expect.enter(connection, "i")
        RHUIManager.select(connection, [repo_data[0]])
        pattern = re.compile(r".*(Name:.*)\r\n\r\n-+\r\nrhui\s* \(repo\)\s* =>", re.DOTALL)
        actual_responses = Expect.match(connection, pattern)[0].splitlines()
        Expect.enter(connection, "q")
        expected_responses = ["Name:                " + repo_data[0]]
        if type_data[0]:
            repo_type = "Custom"
            if type_data[1]:
                relative_path = "protected/" + repo_data[1]
            else:
                relative_path = "unprotected/" + repo_data[1]
        else:
            repo_type = "Red Hat"
            relative_path = repo_data[1]
        expected_responses.append("Type:                " + repo_type)
        expected_responses.append("Relative Path:       " + relative_path)
        if gpg_data[0]:
            expected_responses.append("GPG Check:           Yes")
            if gpg_data[1]:
                expected_responses.append("Custom GPG Keys:     " + gpg_data[1])
            else:
                expected_responses.append("Custom GPG Keys:     (None)")
            if gpg_data[2]:
                expected_responses.append("Red Hat GPG Key:     Yes")
            else:
                expected_responses.append("Red Hat GPG Key:     No")
        else:
            expected_responses.append("GPG Check:           No")
        expected_responses.append("Package Count:       " + str(package_count))
        if repo_type == "Red Hat":
            sync_data = actual_responses.pop()
            nose.tools.ok_("Next Sync:" in sync_data)
            sync_data = actual_responses.pop()
            nose.tools.ok_("Last Sync:" in sync_data)
        nose.tools.eq_(actual_responses, expected_responses)
コード例 #19
0
 def list(connection):
     """
     return the list currently managed CDSes and clusters as it is provided
     by the cds list command
     """
     RHUIManager.screen(connection, "cds")
     Expect.enter(connection, "l")
     # eating prompt!!
     pattern = re.compile("l(\r\n)+(.*)rhui\s* \(cds\)\s* =>", re.DOTALL)
     ret = Expect.match(connection, pattern, grouplist=[2])[0]
     # custom quitting; have eaten the prompt
     Expect.enter(connection, "q")
     return ret
コード例 #20
0
 def _select_cluster(connection, clustername, create_new=True):
     '''
     select cluster
     '''
     try:
         select = Expect.match(connection, re.compile(".*\s+([0-9]+)\s*-\s*" + clustername + "\s*\r\n.*to abort:.*", re.DOTALL))
         Expect.enter(connection, select[0])
     except ExpectFailed as err:
         if not create_new:
             raise err
         Expect.enter(connection, "1")
         Expect.expect(connection, "Enter a[^\n]*CDS cluster name:")
         Expect.enter(connection, clustername)
コード例 #21
0
 def get_cds_status(connection, cdsname):
     '''
     display CDS sync summary
     '''
     RHUIManager.screen(connection, "sync")
     Expect.enter(connection, "dc")
     res_list = Expect.match(connection, re.compile(".*\n" + cdsname.replace(".", "\.") + "[\.\s]*\[([^\n]*)\].*" + cdsname.replace(".", "\.") + "\s*\r\n([^\n]*)\r\n", re.DOTALL), [1, 2], 60)
     connection.cli.exec_command("killall -s SIGINT rhui-manager")
     ret_list = []
     for val in [res_list[0]] + res_list[1].split("             "):
         val = Util.uncolorify(val.strip())
         ret_list.append(val)
     RHUIManager.quit(connection)
     return ret_list
コード例 #22
0
 def list(connection):
     '''
     return the list currently managed CDSes and clusters as it is provided
     by the cds list command
     '''
     RHUIManager.screen(connection, "cds")
     Expect.enter(connection, "l")
     # eating prompt!!
     pattern = re.compile('l(\r\n)+(.*)rhui\s* \(cds\)\s* =>',
             re.DOTALL)
     ret = Expect.match(connection, pattern, grouplist=[2])[0]
     # custom quitting; have eaten the prompt
     Expect.enter(connection, 'q')
     return ret
コード例 #23
0
 def get_repo_status(connection, reponame):
     '''
     display repo sync summary
     '''
     RHUIManager.screen(connection, "sync")
     Expect.enter(connection, "dr")
     reponame_quoted = reponame.replace(".", "\.")
     res = Expect.match(connection, re.compile(".*" + reponame_quoted + "\s*\r\n([^\n]*)\r\n.*", re.DOTALL), [1], 60)[0]
     connection.cli.exec_command("killall -s SIGINT rhui-manager")
     res = Util.uncolorify(res)
     ret_list = res.split("             ")
     for i in range(len(ret_list)):
         ret_list[i] = ret_list[i].strip()
     RHUIManager.quit(connection)
     return ret_list
コード例 #24
0
 def list_custom_entitlements(connection):
     '''
     list custom entitlements
     '''
      
     RHUIManager.screen(connection, "entitlements")
     Expect.enter(connection, "c")
     match = Expect.match(connection, re.compile("c\r\n\r\nCustom Repository Entitlements\r\n\r\n(.*)" + RHUIManagerEntitlements.prompt, re.DOTALL))[0]
     
     repo_list = []
     
     for line in match.splitlines():
         if "Name:" in line:
             repo_list.append(line.replace("Name:", "").strip())
     return sorted(repo_list)
コード例 #25
0
 def _select_cluster(connection, clustername, create_new=True):
     """
     select cluster
     """
     try:
         select = Expect.match(
             connection, re.compile(".*\s+([0-9]+)\s*-\s*" + clustername + "\s*\r\n.*to abort:.*", re.DOTALL)
         )
         Expect.enter(connection, select[0])
     except ExpectFailed as err:
         if not create_new:
             raise err
         Expect.enter(connection, "1")
         Expect.expect(connection, "Enter a[^\n]*CDS cluster name:")
         Expect.enter(connection, clustername)
コード例 #26
0
 def command_output(connection,
                    command,
                    pattern_tuple,
                    username="******",
                    password="******"):
     """return output of a command based on pattern_tuple provided. Output
     is split to lines"""
     Expect.enter(connection, "pulp-admin -u %s -p %s %s" % \
             (username, password, command))
     # eats prompt!
     pattern, group_index = pattern_tuple
     ret = Expect.match(connection, pattern, grouplist=[group_index])[0]
     # reset prompt
     Expect.enter(connection, "")
     return ret.split('\r\n')
コード例 #27
0
 def list_rh_entitlements(connection):
     '''
     list Red Hat entitlements
     '''
     
     RHUIManager.screen(connection, "entitlements")
     Expect.enter(connection, "l")
     match = Expect.match(connection, re.compile("(.*)" + RHUIManagerEntitlements.prompt, re.DOTALL))
     
     matched_string = match[0].replace('l\r\n\r\nRed Hat Entitlements\r\n\r\n  \x1b[92mValid\x1b[0m\r\n    ', '', 1)
     
     entitlements_list = []
     pattern = re.compile('(.*?\r\n.*?pem)', re.DOTALL)
     for entitlement in pattern.findall(matched_string):
         entitlements_list.append(entitlement.strip())
     return entitlements_list
コード例 #28
0
 def get_repo_status(connection, reponame):
     '''
     display repo sync summary
     '''
     RHUIManager.screen(connection, "sync")
     Expect.enter(connection, "dr")
     reponame_quoted = reponame.replace(".", "\.")
     res = Expect.match(
         connection,
         re.compile(".*" + reponame_quoted + "\s*\r\n([^\n]*)\r\n.*",
                    re.DOTALL), [1], 60)[0]
     connection.cli.exec_command("killall -s SIGINT rhui-manager")
     res = Util.uncolorify(res)
     ret_list = res.split("             ")
     for i in range(len(ret_list)):
         ret_list[i] = ret_list[i].strip()
     RHUIManager.quit(connection)
     return ret_list
コード例 #29
0
    def list_custom_entitlements(connection):
        '''
        list custom entitlements
        '''

        RHUIManager.screen(connection, "entitlements")
        Expect.enter(connection, "c")
        match = Expect.match(connection,
                             re.compile("c\r\n\r\nCustom Repository Entitlements\r\n\r\n(.*)" +
                                        PROMPT, re.DOTALL))[0]

        repo_list = []

        for line in match.splitlines():
            if "Name:" in line:
                repo_list.append(line.replace("Name:", "").strip())
        Expect.enter(connection, 'q')
        return sorted(repo_list)
コード例 #30
0
def _get_repo_status(connection, reponame):
    '''
    display repo sync summary
    '''
    RHUIManager.screen(connection, "sync")
    Expect.enter(connection, "dr")
    res = Expect.match(
        connection,
        re.compile(r".*%s\s*\r\n([^\n]*)\r\n.*" % re.escape(reponame),
                   re.DOTALL), [1], 60)[0]
    connection.cli.exec_command("killall -s SIGINT rhui-manager")
    res = Util.uncolorify(res)
    ret_list = res.split("             ")
    for i, _ in enumerate(ret_list):
        ret_list[i] = ret_list[i].strip()

    Expect.enter(connection, CTRL_C)
    Expect.enter(connection, "q")
    return ret_list
コード例 #31
0
 def get_cds_status(connection, cdsname):
     '''
     display CDS sync summary
     '''
     RHUIManager.screen(connection, "sync")
     Expect.enter(connection, "dc")
     res_list = Expect.match(
         connection,
         re.compile(
             ".*\n" + cdsname.replace(".", "\.") + "[\.\s]*\[([^\n]*)\].*" +
             cdsname.replace(".", "\.") + "\s*\r\n([^\n]*)\r\n", re.DOTALL),
         [1, 2], 60)
     connection.cli.exec_command("killall -s SIGINT rhui-manager")
     ret_list = []
     for val in [res_list[0]] + res_list[1].split("             "):
         val = Util.uncolorify(val.strip())
         ret_list.append(val)
     RHUIManager.quit(connection)
     return ret_list
コード例 #32
0
    def list_rh_entitlements(connection):
        '''
        list Red Hat entitlements
        '''

        RHUIManager.screen(connection, "entitlements")
        Expect.enter(connection, "l")
        match = Expect.match(connection,
                             re.compile("(.*)" + PROMPT, re.DOTALL))

        matched_string = match[0].replace('l\r\n\r\nRed Hat Entitlements\r\n\r\n  ' +
                                          '\x1b[92mValid\x1b[0m\r\n    ', '', 1)

        entitlements_list = []
        pattern = re.compile('(.*?\r\n.*?pem)', re.DOTALL)
        for entitlement in pattern.findall(matched_string):
            entitlements_list.append(entitlement.strip())
        Expect.enter(connection, 'q')
        return entitlements_list
コード例 #33
0
ファイル: rhuimanager.py プロジェクト: vex21/rhui3-automation
    def proceed_with_check(connection, caption, value_list, skip_list=[]):
        '''
        Proceed with prior checking the list of values

        Use @param skip_list to skip meaningless 2nd-level headers
        '''
        selected = Expect.match(connection, re.compile(".*" + caption + "\r\n(.*)\r\nProceed\? \(y/n\).*", re.DOTALL))[0].split("\r\n")
        selected_clean = []
        for val in selected:
            val = val.strip()
            val = val.replace("\t", " ")
            val = ' '.join(val.split())
            val = val.replace("(", "\(")
            val = val.replace(")", "\)")
            if val != "" and not val in skip_list:
                selected_clean.append(val)
        if sorted(selected_clean) != sorted(value_list):
            logging.debug("Selected: " + str(selected_clean))
            logging.debug("Expected: " + str(value_list))
            raise ExpectFailed()
        Expect.enter(connection, "y")
コード例 #34
0
    def subscriptions_list(connection, what):
        '''
        list registered or available subscriptions
        '''
        if what == "registered":
            key = "l"
        elif what == "available":
            key = "a"
        else:
            raise ValueError("Unsupported list: " + what)

        RHUIManager.screen(connection, "subscriptions")
        Expect.enter(connection, key)
        lines = Expect.match(connection, re.compile("(.*)" + RHUIManagerSubMan.prompt,
                                                    re.DOTALL))[0]
        sub_list = []
        for line in lines.splitlines():
            # subscription names are on lines that start with two spaces
            if line[:2] == "  ":
                sub_list.append(line.strip())
        Expect.enter(connection, 'q')
        return sub_list
コード例 #35
0
 def list(connection):
     '''
     list repositories
     '''
     RHUIManager.screen(connection, "repo")
     Expect.enter(connection, "l")
     # eating prompt!!
     pattern = re.compile('l\r\n(.*)\r\n-+\r\nrhui\s* \(repo\)\s* =>',
                          re.DOTALL)
     ret = Expect.match(connection, pattern, grouplist=[1])[0]
     reslist = map(lambda x: x.strip(), ret.split("\r\n"))
     repolist = []
     for line in reslist:
         if line in [
                 "", "Custom Repositories", "Red Hat Repositories",
                 "OSTree", "Docker", "Yum",
                 "No repositories are currently managed by the RHUI"
         ]:
             continue
         repolist.append(line)
     Expect.enter(connection, 'q')
     return repolist
コード例 #36
0
    def proceed_with_check(connection, caption, value_list, skip_list=[]):
        '''
        Proceed with prior checking the list of values

        Use @param skip_list to skip meaningless 2nd-level headers
        '''
        selected = Expect.match(
            connection,
            re.compile(".*" + caption + "\r\n(.*)\r\nProceed\? \(y/n\).*",
                       re.DOTALL))[0].split("\r\n")
        selected_clean = []
        for val in selected:
            val = val.strip()
            val = val.replace("\t", " ")
            val = ' '.join(val.split())
            if val != "" and not val in skip_list:
                selected_clean.append(val)
        if sorted(selected_clean) != sorted(value_list):
            logging.debug("Selected: " + str(selected_clean))
            logging.debug("Expected: " + str(value_list))
            raise ExpectFailed()
        Expect.enter(connection, "y")
コード例 #37
0
    def subscriptions_list(connection, what):
        """list registered or available subscriptions"""
        if what == "registered":
            key = "l"
        elif what == "available":
            key = "a"
        else:
            raise ValueError(
                "Unsupported list: %s. Use 'registered' or 'available'." %
                what)

        RHUIManager.screen(connection, "subscriptions")
        Expect.enter(connection, key)
        lines = Expect.match(connection, re.compile("(.*)" + PROMPT,
                                                    re.DOTALL))[0]
        # subscription names are on lines that start with two spaces
        sub_list = [
            line.strip() for line in lines.splitlines()
            if line.startswith("  ")
        ]
        Expect.enter(connection, "q")
        return sub_list
コード例 #38
0
    def upload_rh_certificate(
            connection, certificate_file='/tmp/extra_rhui_files/rhcert.pem'):
        '''
        upload a new or updated Red Hat content certificate
        '''

        if connection.recv_exit_status("ls -la %s" % certificate_file) != 0:
            raise ExpectFailed("Missing certificate file: %s" %
                               certificate_file)

        bad_cert_msg = "The provided certificate is expired or invalid"
        incompatible_cert_msg = "not compatible with the RHUI"

        RHUIManager.screen(connection, "entitlements")
        Expect.enter(connection, "u")
        Expect.expect(connection, "Full path to the new content certificate:")
        Expect.enter(connection, certificate_file)
        Expect.expect(
            connection,
            "The RHUI will be updated with the following certificate:")
        Expect.enter(connection, "y")
        match = Expect.match(
            connection,
            re.compile("(.*)" + RHUIManagerEntitlements.prompt, re.DOTALL))
        matched_string = match[0].replace(
            'l\r\n\r\nRed Hat Entitlements\r\n\r\n  \x1b[92mValid\x1b[0m\r\n    ',
            '', 1)
        if bad_cert_msg in matched_string:
            Expect.enter(connection, 'q')
            raise BadCertificate()
        if incompatible_cert_msg in matched_string:
            Expect.enter(connection, 'q')
            raise IncompatibleCertificate()
        entitlements_list = []
        pattern = re.compile('(.*?\r\n.*?pem)', re.DOTALL)
        for entitlement in pattern.findall(matched_string):
            entitlements_list.append(entitlement.strip())
        Expect.enter(connection, 'q')
        return entitlements_list
コード例 #39
0
    def upload_rh_certificate(connection):
        '''
        upload a new or updated Red Hat content certificate
        '''
        
        certificate_file = '/tmp/extra_rhui_files/rhcert.pem'
        
        if connection.recv_exit_status("ls -la %s" % certificate_file)!=0:
            raise ExpectFailed("Missing certificate file: %s" % certificate_file)

        RHUIManager.screen(connection, "entitlements")
        Expect.enter(connection, "u")
        Expect.expect(connection, "Full path to the new content certificate:")
        Expect.enter(connection, certificate_file)
        Expect.expect(connection, "The RHUI will be updated with the following certificate:")
        Expect.enter(connection, "y")
        match = Expect.match(connection, re.compile("(.*)" + RHUIManagerEntitlements.prompt, re.DOTALL))
        matched_string = match[0].replace('l\r\n\r\nRed Hat Entitlements\r\n\r\n  \x1b[92mValid\x1b[0m\r\n    ', '', 1)
        entitlements_list = []
        pattern = re.compile('(.*?\r\n.*?pem)', re.DOTALL)
        for entitlement in pattern.findall(matched_string):
            entitlements_list.append(entitlement.strip())
        return entitlements_list
コード例 #40
0
    def info(connection, clusterlist):
        """
        display detailed information on a CDS clusters

        @param clusterlist - list of clusters to examine
        @returns a list of Cds instances
        """
        RHUIManager.screen(connection, "cds")
        Expect.enter(connection, "i")
        RHUIManager.select(connection, clusterlist)
        pattern = re.compile(".*-= RHUI CDS Clusters =-(.*)rhui\s* \(cds\)\s* =>", re.DOTALL)
        ret = Expect.match(connection, pattern, grouplist=[1])[0]
        reslist = ret.split("\r\n")
        i = 0
        clusterlist = []
        cluster = {}
        while i < len(reslist):
            line = reslist[i]
            # Readling lines and searching for clusters
            if line.strip() != "":
                if line[:2] == "  " and not line[2:3] in [" ", "-"]:
                    # We've found a new cluster!
                    if cluster != {}:
                        clusterlist.append(cluster)
                        cluster = {}
                    cluster["Name"] = line[2:]
                    i += 2
                    while reslist[i][:4] == "    " or reslist[i] == "":
                        if reslist[i] == "":
                            i += 1
                            continue
                        line = reslist[i].strip()
                        if line == "CDS Instances":
                            # Figuring out cds instances
                            instances = []
                            i += 2
                            while reslist[i].strip() != "":
                                # New cds
                                cds = reslist[i].strip()
                                hostname = reslist[i + 1].strip().split(":")[1].strip()
                                client = reslist[i + 2].strip().split(":")[1].strip()
                                instances.append(
                                    RhuiCds(
                                        name=reslist[i].strip(),
                                        hostname=hostname,
                                        client_hostname=client,
                                        description="RHUI CDS",
                                        cluster=cluster["Name"],
                                    )
                                )
                                i += 3
                            cluster["Instances"] = sorted(instances)
                        elif line == "Repositories":
                            # Figuring out repositories
                            repositories = []
                            i += 2
                            while reslist[i].strip() != "":
                                # New repo
                                repo = reslist[i].strip()
                                i += 1
                                if repo == "(None)":
                                    # no repos, continue with next (empty)
                                    # line
                                    continue
                                repositories.append(repo)
                            cluster["Repositories"] = repositories
                            # update all cluster CDSes with appropriate repo
                            # records
                            for cds in cluster["Instances"]:
                                cds.repos = repositories
                            break
                        else:
                            i += 1
            i += 1

        if cluster != {}:
            clusterlist.append(cluster)
        cdses = []
        for cluster in clusterlist:
            cdses.extend(cluster["Instances"])
        Expect.enter(connection, "q")
        return cdses
コード例 #41
0
    def info(connection, clusterlist):
        '''
        display detailed information on a CDS clusters

        @param clusterlist - list of clusters to examine
        @returns a list of Cds instances
        '''
        RHUIManager.screen(connection, "cds")
        Expect.enter(connection, "i")
        RHUIManager.select(connection, clusterlist)
        pattern = re.compile('.*-= RHUI CDS Clusters =-(.*)rhui\s* \(cds\)\s* =>',
                re.DOTALL)
        ret = Expect.match(connection, pattern, grouplist=[1])[0]
        reslist = ret.split("\r\n")
        i = 0
        clusterlist = []
        cluster = {}
        while i < len(reslist):
            line = reslist[i]
            # Readling lines and searching for clusters
            if line.strip() != '':
                if line[:2] == '  ' and not line[2:3] in [' ', '-']:
                    # We've found a new cluster!
                    if cluster != {}:
                        clusterlist.append(cluster)
                        cluster = {}
                    cluster['Name'] = line[2:]
                    i += 2
                    while reslist[i][:4] == '    ' or reslist[i] == '':
                        if reslist[i] == '':
                            i += 1
                            continue
                        line = reslist[i].strip()
                        if line == "CDS Instances":
                            # Figuring out cds instances
                            instances = []
                            i += 2
                            while reslist[i].strip() != "":
                                # New cds
                                cds = reslist[i].strip()
                                hostname = reslist[i + 1].strip().split(':')[1].strip()
                                client = reslist[i + 2].strip().split(':')[1].strip()
                                instances.append(RhuiCds(name=reslist[i].strip(), hostname=hostname, client_hostname=client,
                                    description='RHUI CDS',
                                    cluster=cluster['Name']))
                                i += 3
                            cluster['Instances'] = sorted(instances)
                        elif line == "Repositories":
                            # Figuring out repositories
                            repositories = []
                            i += 2
                            while reslist[i].strip() != "":
                                # New repo
                                repo = reslist[i].strip()
                                i += 1
                                if repo == '(None)':
                                    # no repos, continue with next (empty)
                                    # line
                                    continue
                                repositories.append(repo)
                            cluster['Repositories'] = repositories
                            # update all cluster CDSes with appropriate repo
                            # records
                            for cds in cluster['Instances']:
                                cds.repos = repositories
                            break
                        else:
                            i += 1
            i += 1

        if cluster != {}:
            clusterlist.append(cluster)
        cdses = []
        for cluster in clusterlist:
            cdses.extend(cluster['Instances'])
        Expect.enter(connection, 'q')
        return cdses
コード例 #42
0
ファイル: rhuimanager.py プロジェクト: vex21/rhui3-automation
 def select_one(connection, item):
     '''
     Select one item (single choice)
     '''
     match = Expect.match(connection, re.compile(".*([0-9]+)\s+-\s+" + value + "\s*\n.*to abort:.*", re.DOTALL))
     Expect.enter(connection, match[0])