Exemple #1
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)
 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" + "\) =>")
 def upload_content(connection, repolist, path):
     '''
     upload content to a custom repository
     '''
     # Check whether "path" is a file or a directory.
     # If it is a directory, get a list of *.rpm files in it.
     path_type = Util.get_file_type(connection, path)
     if path_type == "regular file":
         content = [basename(path)]
     elif path_type == "directory":
         content = Util.get_rpms_in_dir(connection, path)
     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 = []
     # Continue in rhui-manager.
     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, timeout=60)
 def sync_cds(connection, cdslist):
     '''
     sync an individual CDS immediately
     '''
     RHUIManager.screen(connection, "sync")
     Expect.enter(connection, "sc")
     RHUIManager.select(connection, cdslist)
     RHUIManager.proceed_with_check(connection, "The following CDS instances will be scheduled for synchronization:", cdslist)
     RHUIManager.quit(connection)
 def sync_cluster(connection, clusterlist):
     '''
     sync a CDS cluster immediately
     '''
     RHUIManager.screen(connection, "sync")
     Expect.enter(connection, "sl")
     RHUIManager.select(connection, clusterlist)
     RHUIManager.proceed_with_check(connection, "The following CDS clusters will be scheduled for synchronization:", clusterlist)
     RHUIManager.quit(connection)
Exemple #6
0
 def subscriptions_unregister(connection, names):
     '''
     unregister a Red Hat subscription from RHUI
     '''
     RHUIManager.screen(connection, "subscriptions")
     Expect.enter(connection, "d")
     RHUIManager.select(connection, names)
     RHUIManager.proceed_with_check(connection,
                                    "The following subscriptions will be unregistered:",
                                    names)
     RHUIManager.quit(connection)
 def add_rh_repo_by_product(connection, productlist):
     '''
     add a new Red Hat content repository (By Product)
     '''
     RHUIManager.screen(connection, "repo")
     Expect.enter(connection, "a")
     Expect.expect(connection, "Import Repositories:.*to abort:", 660)
     Expect.enter(connection, "2")
     RHUIManager.select(connection, productlist)
     RHUIManager.proceed_with_check(connection, "The following products will be deployed:", productlist)
     Expect.expect(connection, ".*rhui \(" + "repo" + "\) =>")
 def sync_repo(connection, repolist):
     '''
     sync an individual repository immediately
     '''
     RHUIManager.screen(connection, "sync")
     Expect.enter(connection, "sr")
     Expect.expect(connection, "Select one or more repositories.*for more commands:", 60)
     Expect.enter(connection, "l")
     RHUIManager.select(connection, repolist)
     RHUIManager.proceed_with_check(connection, "The following repositories will be scheduled for synchronization:", repolist)
     RHUIManager.quit(connection)
 def subscriptions_unregister(connection, names):
     """unregister one or more Red Hat subscriptions from RHUI"""
     RHUIManager.screen(connection, "subscriptions")
     Expect.enter(connection, "d")
     try:
         RHUIManager.select(connection, names)
     except ExpectFailed:
         Expect.enter(connection, "q")
         raise RuntimeError("subscription(s) not registered: %s" % names)
     RHUIManager.proceed_with_check(
         connection, "The following subscriptions will be unregistered:",
         names)
     RHUIManager.quit(connection)
 def add_rh_repo_by_product(connection, productlist):
     '''
     add a new Red Hat content repository (By Product)
     '''
     RHUIManager.screen(connection, "repo")
     Expect.enter(connection, "a")
     Expect.expect(connection, "Import Repositories:.*to abort:", 660)
     Expect.enter(connection, "2")
     RHUIManager.select(connection, productlist)
     RHUIManager.proceed_with_check(connection,
                                    "The following products will be deployed:",
                                    productlist)
     RHUIManager.quit(connection)
 def add_rh_repo_by_repo(connection, repolist):
     '''
     add a new Red Hat content repository (By Repository)
     '''
     RHUIManager.screen(connection, "repo")
     Expect.enter(connection, "a")
     Expect.expect(connection, "Import Repositories:.*to abort:", 660)
     Expect.enter(connection, "3")
     RHUIManager.select(connection, repolist)
     repolist_mod = list(repolist)
     for repo in repolist:
         repolist_mod.append(re.sub(" \\\\\([a-zA-Z0-9_-]*\\\\\) \\\\\(Yum\\\\\)", "", repo))
     RHUIManager.proceed_with_check(connection, "The following product repositories will be deployed:", repolist_mod)
     Expect.expect(connection, ".*rhui \(" + "repo" + "\) =>")
Exemple #12
0
 def sync_repo(connection, repolist):
     '''
     sync an individual repository immediately
     '''
     RHUIManager.screen(connection, "sync")
     Expect.enter(connection, "sr")
     Expect.expect(connection,
                   "Select one or more repositories.*for more commands:",
                   60)
     Expect.enter(connection, "l")
     RHUIManager.select(connection, repolist)
     RHUIManager.proceed_with_check(
         connection, "The following repositories will be scheduled " +
         "for synchronization:", repolist)
     RHUIManager.quit(connection)
Exemple #13
0
 def add_rh_repo_by_repo(connection, repolist):
     '''
     add a new Red Hat content repository (By Repository)
     '''
     RHUIManager.screen(connection, "repo")
     Expect.enter(connection, "a")
     Expect.expect(connection, "Import Repositories:.*to abort:", 660)
     Expect.enter(connection, "3")
     RHUIManager.select(connection, repolist)
     repolist_mod = list(repolist)
     for repo in repolist:
         repolist_mod.append(
             re.sub(" \([a-zA-Z0-9_-]*\) \([a-zA-Z]*\)", "", repo))
     RHUIManager.proceed_with_check(
         connection, "The following product repositories will be deployed:",
         repolist_mod)
     RHUIManager.quit(connection)
 def add_docker_container(connection, containername, containerid="", displayname=""):
     '''
     add a new Red Hat docker container
     '''
     RHUIManager.screen(connection, "repo")
     Expect.enter(connection, "ad")
     Expect.expect(connection, "Name of the container in the registry:")
     Expect.enter(connection, containername)
     Expect.expect(connection, "Unique ID for the container .*]", 60)
     Expect.enter(connection, containerid)
     Expect.expect(connection, "Display name for the container.*]:")
     Expect.enter(connection, displayname)
     RHUIManager.proceed_with_check(connection, "The following container will be added:",
     ["Container Id: " + containername.replace("/","_").replace(".","_"),
      "Display Name: " + displayname,
      "Upstream Container Name: " + containername])
     Expect.expect(connection, ".*rhui \(" + "repo" + "\) =>")
 def add_container(connection, containername, containerid="", displayname="", credentials=""):
     '''
     add a new Red Hat container
     '''
     default_registry = Helpers.get_registry_url("default", connection)
     # if the credentials parameter is supplied, it's supposed to be a list containing:
     #   0 - registry hostname if not using the default one
     #   1 - username (if required; the default registry requires the RH (CCSP) login)
     #   2 - password (if required)
     # do NOT supply them if they're in rhui-tools.conf and you want to use the default registry;
     # this method will fail otherwise, because it will expect rhui-manager to ask for them
     RHUIManager.screen(connection, "repo")
     Expect.enter(connection, "ad")
     Expect.expect(connection, "Specify URL of registry .*:")
     if credentials and credentials[0]:
         registry = credentials[0]
         Expect.enter(connection, registry)
     else:
         registry = default_registry
         Expect.enter(connection, "")
     Expect.expect(connection, "Name of the container in the registry:")
     Expect.enter(connection, containername)
     Expect.expect(connection, "Unique ID for the container .*]", 60)
     Expect.enter(connection, containerid)
     Expect.expect(connection, "Display name for the container.*]:")
     Expect.enter(connection, displayname)
     # login & password provided, or a non-default registry specified
     if credentials or registry != default_registry:
         Expect.expect(connection, "Registry username:"******"Registry password:"******"")
     if not containerid:
         containerid = Util.safe_pulp_repo_name(containername)
     if not displayname:
         displayname = Util.safe_pulp_repo_name(containername)
     RHUIManager.proceed_with_check(connection,
                                    "The following container will be added:",
                                    ["Registry URL: " + registry,
                                     "Container Id: " + containerid,
                                     "Display Name: " + displayname,
                                     "Upstream Container Name: " + containername])
     RHUIManager.quit(connection)
 def add_rh_repo_by_repo(connection, repolist):
     '''
     add a new Red Hat content repository (By Repository)
     '''
     RHUIManager.screen(connection, "repo")
     Expect.enter(connection, "a")
     Expect.expect(connection, "Import Repositories:.*to abort:", 660)
     Expect.enter(connection, "3")
     RHUIManager.select(connection, repolist)
     repolist_mod = list(repolist)
     for repo in repolist:
         # strip " (kind)"
         repo_stripped = re.sub(r" \([a-zA-Z]*\)$", "", repo)
         # strip " (version)" if present (if "(RPMs)" isn't there instead)
         repo_stripped = re.sub(r" \((?!RPMs)[a-zA-Z0-9_-]*\)$", "", repo_stripped)
         repolist_mod.append(repo_stripped)
     RHUIManager.proceed_with_check(connection,
                                    "The following product repositories will be deployed:",
                                    repolist_mod)
     RHUIManager.quit(connection)
Exemple #17
0
 def add_docker_container(connection,
                          containername,
                          containerid="",
                          displayname=""):
     '''
     add a new Red Hat docker container
     '''
     RHUIManager.screen(connection, "repo")
     Expect.enter(connection, "ad")
     Expect.expect(connection, "Name of the container in the registry:")
     Expect.enter(connection, containername)
     Expect.expect(connection, "Unique ID for the container .*]", 60)
     Expect.enter(connection, containerid)
     Expect.expect(connection, "Display name for the container.*]:")
     Expect.enter(connection, displayname)
     RHUIManager.proceed_with_check(
         connection, "The following container will be added:", [
             "Container Id: " +
             containername.replace("/", "_").replace(".", "_"),
             "Display Name: " + displayname,
             "Upstream Container Name: " + containername
         ])
     RHUIManager.quit(connection)
 def add_custom_repo(connection, reponame, displayname="", path="", checksum_alg="1", entitlement="y", entitlement_path="", redhat_gpg="y", custom_gpg=None):
     '''
     create a new custom repository
     '''
     RHUIManager.screen(connection, "repo")
     Expect.enter(connection, "c")
     Expect.expect(connection, "Unique ID for the custom repository.*:")
     Expect.enter(connection, reponame)
     checklist = ["ID: " + reponame]
     state = Expect.expect_list(connection, [(re.compile(".*Display name for the custom repository.*:", re.DOTALL), 1),\
                                            (re.compile(".*Unique ID for the custom repository.*:", re.DOTALL), 2)])
     if state == 1:
         Expect.enter(connection, displayname)
         if displayname != "":
             checklist.append("Name: " + displayname)
         else:   
             checklist.append("Name: " + reponame)
         Expect.expect(connection, "Unique path at which the repository will be served.*:")
         Expect.enter(connection, path)
         if path != "":
             path_real = path
         else:   
             path_real = reponame
         checklist.append("Path: " + path_real)
         Expect.expect(connection, "Enter value.*:")
         Expect.enter(connection, checksum_alg)
         Expect.expect(connection, "Should the repository require an entitlement certificate to access\? \(y/n\)")
         Expect.enter(connection, entitlement)
         if entitlement == "y":
             Expect.expect(connection, "Path that should be used when granting an entitlement for this repository.*:")
             Expect.enter(connection, entitlement_path)
             if entitlement_path != "":
                 checklist.append("Entitlement: " + entitlement_path)
             else:       
                 educated_guess, replace_count = re.subn("(i386|x86_64)", "$basearch", path_real)
                 if replace_count > 1:
                     # bug 815975
                     educated_guess = path_real
                 checklist.append("Entitlement: " + educated_guess)
         Expect.expect(connection, "packages are signed by a GPG key\? \(y/n\)")
         if redhat_gpg == "y" or custom_gpg:
             Expect.enter(connection, "y")
             checklist.append("GPG Check Yes")
             Expect.expect(connection, "Will the repository be used to host any Red Hat GPG signed content\? \(y/n\)")
             Expect.enter(connection, redhat_gpg)
             if redhat_gpg == "y":
                 checklist.append("Red Hat GPG Key: Yes")
             else:       
                 checklist.append("Red Hat GPG Key: No")
             Expect.expect(connection, "Will the repository be used to host any custom GPG signed content\? \(y/n\)")
             if custom_gpg:
                 Expect.enter(connection, "y")
                 Expect.expect(connection, "Enter the absolute path to the public key of the GPG keypair:")
                 Expect.enter(connection, custom_gpg)
                 Expect.expect(connection, "Would you like to enter another public key\? \(y/n\)")
                 Expect.enter(connection, "n")
                 checklist.append("Custom GPG Keys: '" + custom_gpg + "'")
             else:       
                 Expect.enter(connection, "n")
                 checklist.append("Custom GPG Keys: \(None\)")
         else:           
             Expect.enter(connection, "n")
             checklist.append("GPG Check No") 
             checklist.append("Red Hat GPG Key: No")
 
         RHUIManager.proceed_with_check(connection, "The following repository will be created:", checklist)
         Expect.expect(connection, "Successfully created repository *")
         Expect.enter(connection, "home")
     else:      
         Expect.enter(connection, '\x03')
         Expect.expect(connection, "rhui \(" + "repo" + "\) =>")
    def add_custom_repo(connection,
                        reponame,
                        displayname="",
                        path="",
                        checksum_alg="1",
                        entitlement="y",
                        entitlement_path="",
                        redhat_gpg="y",
                        custom_gpg=None):
        '''
        create a new custom repository
        '''
        RHUIManager.screen(connection, "repo")
        Expect.enter(connection, "c")
        Expect.expect(connection, "Unique ID for the custom repository.*:")
        Expect.enter(connection, reponame)
        checklist = ["ID: " + reponame]
        state = Expect.expect_list(connection,
                                   [(re.compile(".*Display name for the custom repository.*:",
                                                re.DOTALL),
                                     1),
                                    (re.compile(".*repository.*already exists.*Unique ID.*:",
                                                re.DOTALL),
                                     2)])
        if state == 1:
            Expect.enter(connection, displayname)
            if displayname != "":
                checklist.append("Name: " + displayname)
            else:
                checklist.append("Name: " + reponame)
            Expect.expect(connection, "Unique path at which the repository will be served.*:")
            Expect.enter(connection, path)
            if path != "":
                path_real = path
            else:
                path_real = reponame
            checklist.append("Path: " + path_real)
            Expect.expect(connection, "Enter value.*:")
            Expect.enter(connection, checksum_alg)
            Expect.expect(connection,
                          "Should the repository require an entitlement certificate " +
                          r"to access\? \(y/n\)")
            Expect.enter(connection, entitlement)
            if entitlement == "y":
                Expect.expect(connection,
                              "Path that should be used when granting an entitlement " +
                              "for this repository.*:")
                Expect.enter(connection, entitlement_path)
                if entitlement_path != "":
                    checklist.append("Entitlement: " + entitlement_path)
                else:
                    educated_guess, replace_count = re.subn("(i386|x86_64)", "$basearch", path_real)
                    if replace_count > 1:
                        # bug 815975
                        educated_guess = path_real
                    checklist.append("Entitlement: " + educated_guess)
            Expect.expect(connection, r"packages are signed by a GPG key\? \(y/n\)")
            if redhat_gpg == "y" or custom_gpg:
                Expect.enter(connection, "y")
                checklist.append("GPG Check Yes")
                Expect.expect(connection,
                              "Will the repository be used to host any " +
                              r"Red Hat GPG signed content\? \(y/n\)")
                Expect.enter(connection, redhat_gpg)
                if redhat_gpg == "y":
                    checklist.append("Red Hat GPG Key: Yes")
                else:
                    checklist.append("Red Hat GPG Key: No")
                Expect.expect(connection,
                              "Will the repository be used to host any " +
                              r"custom GPG signed content\? \(y/n\)")
                if custom_gpg:
                    Expect.enter(connection, "y")
                    Expect.expect(connection,
                                  "Enter the absolute path to the public key of the GPG keypair:")
                    Expect.enter(connection, custom_gpg)
                    Expect.expect(connection,
                                  r"Would you like to enter another public key\? \(y/n\)")
                    Expect.enter(connection, "n")
                    checklist.append("Custom GPG Keys: '" + custom_gpg + "'")
                else:
                    Expect.enter(connection, "n")
                    checklist.append("Custom GPG Keys: (None)")
            else:
                Expect.enter(connection, "n")
                checklist.append("GPG Check No")
                checklist.append("Red Hat GPG Key: No")

            RHUIManager.proceed_with_check(connection,
                                           "The following repository will be created:",
                                           checklist)
            RHUIManager.quit(connection, "Successfully created repository *")
        else:
            Expect.enter(connection, CTRL_C)
            RHUIManager.quit(connection)
            raise AlreadyExistsError()