Search in sources :

Example 91 with SSHCommandResult

use of com.redhat.qe.tools.SSHCommandResult in project rhsm-qe by RedHatQE.

the class SubscriptionManagerTasks method listInstalledProducts.

/**
 * @return SSHCommandResult from "subscription-manager-cli list --installed"
 */
public SSHCommandResult listInstalledProducts() {
    SSHCommandResult sshCommandResult = list(null, null, null, Boolean.TRUE, null, null, null, null, null, null, null, null, null, null);
    if (getCurrentProductCertFiles().isEmpty()) /*&& getCurrentEntitlementCertFiles().isEmpty() NOT NEEDED AFTER DESIGN CHANGE FROM BUG 736424*/
    {
        Assert.assertTrue(sshCommandResult.getStdout().trim().equals("No installed products to list"), "No installed products to list");
    } else {
        // Assert.assertContainsMatch(sshCommandResult.getStdout(), "Installed Product Status"); // produces too much logging
        String title = "Installed Product Status";
        Assert.assertTrue(sshCommandResult.getStdout().contains(title), "The list of installed products is entitled '" + title + "'.");
    }
    return sshCommandResult;
}
Also used : SSHCommandResult(com.redhat.qe.tools.SSHCommandResult)

Example 92 with SSHCommandResult

use of com.redhat.qe.tools.SSHCommandResult in project rhsm-qe by RedHatQE.

the class SubscriptionManagerTasks method installReleasedRhnClassicPackages.

public void installReleasedRhnClassicPackages(String installOptions, List<String> installPackages) throws IOException, JSONException {
    // make sure installOptions begins with --disablerepo=* to make sure the installs ONLY come from the released-rhn57-tools repo we are about to define
    if (!installOptions.contains("--disablerepo=*"))
        installOptions = "--disablerepo=* " + installOptions;
    // avoid ERROR: can not find RHNS CA file: /usr/share/rhn/RHN-ORG-TRUSTED-SSL-CERT
    installOptions += " --disableplugin=rhnplugin";
    // locally create a yum.repos.d released-rhn57-tools repo file
    String repo = "released-rhn57-tools";
    // this will be in the automation.dir directory on hudson (workspace/automatjon/sm)
    File file = new File("tmp/" + repo + ".repo");
    // http://download.devel.redhat.com/released/RHN-Tools-5.7-RHEL-6/i386/tree/RHNTools/
    String basearch = arch;
    // all the rhn tools are noarch packages, so it really should not matter what basearch we use so long as the path exists.  I see arches ppc64 s390x x86_64 for RHN-Tools-5.7-RHEL-7.  I see arches i386 ppc64 s390x x86_64 for RHN-Tools-5.7-RHEL-6.
    if (arch.equals("i686"))
        basearch = "x86_64";
    if (arch.equals("s390"))
        basearch = "s390x";
    if (arch.equals("ppc"))
        basearch = "ppc64";
    String baseurl;
    // <p>The document has moved <a href="http://download-node-02.eng.bos.redhat.com/released/RHN-Tools-5.7-RHEL-6/i686/tree/RHNTools/">here</a>.</p>
    baseurl = "http://download.devel.redhat.com/released/RHN-Tools-5.7-RHEL-" + redhatReleaseX + "/" + basearch + "/tree/RHNTools/";
    // Bug 1432642 fails on RHE7 because...  repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
    baseurl = "http://download-node-02.eng.bos.redhat.com/released/RHN-Tools-5.7-RHEL-" + redhatReleaseX + "/" + basearch + "/tree/RHNTools/";
    // recommended by Tomas Mlcoch in https://projects.engineering.redhat.com/browse/RCM-13960
    baseurl = "http://pulp.dist.prod.ext.phx2.redhat.com/content/dist/rhel/server/" + redhatReleaseX + "/" + redhatReleaseX + "Server/" + basearch + "/rhn-tools/os/";
    // check the baseurl for problems
    SSHCommandResult baseurlTestResult = sshCommandRunner.runCommandAndWait("curl --stderr /dev/null --insecure --request GET " + baseurl);
    if (baseurlTestResult.getStdout().contains("404 Not Found") || baseurlTestResult.getStdout().contains("The document has moved")) {
        log.warning("Cannot installReleasedRhnClassicPackages from baseurl '" + baseurl + "'.");
        Assert.fail("The Released RHN Tools baseurl '" + baseurl + "' had problems.  Instruct the automator to verify the assembly of this baseurl.");
    }
    // write out the rows of the table...
    Writer output = new BufferedWriter(new FileWriter(file));
    // write the released-rhn57-tools repo
    output.write("[" + repo + "]\n");
    output.write("name     = Released RHN 5.7 Tools for RHEL" + redhatReleaseX + "\n");
    output.write("enabled  = 0\n");
    // needed since the latest extras packages may not be signed until on REL_PREP
    output.write("gpgcheck = 0\n");
    output.write("baseurl  = " + baseurl + "\n");
    output.write("\n");
    output.close();
    installOptions += " --enablerepo=" + repo;
    RemoteFileTasks.putFile(sshCommandRunner, file.getPath(), "/etc/yum.repos.d/", "0644");
    // locally create a yum.repos.d latest-rhelX-variant repo file
    repo = "latest-rhel" + redhatReleaseX + "-" + variant;
    // this will be in the automation.dir directory on hudson (workspace/automatjon/sm)
    file = new File("tmp/" + repo + ".repo");
    // http://download.devel.redhat.com/rel-eng/latest-RHEL-6/compose/Server/x86_64/os/
    basearch = arch;
    // all the i686 arch packages are found in the i386 base arch path
    if (arch.equals("i686"))
        basearch = "i386";
    // all the ppc arch packages are found in the ppc64 base arch path
    if (arch.equals("s390"))
        basearch = "s390x";
    // all the ppc arch packages are found in the ppc64 base arch path
    if (arch.equals("ppc"))
        basearch = "ppc64";
    // <p>The document has moved <a href="http://download-node-02.eng.bos.redhat.com/rel-eng/latest-RHEL-6/compose/Client/i686/os/">here</a>.</p>
    baseurl = "http://download.devel.redhat.com/rel-eng/latest-RHEL-" + redhatReleaseX + "/compose/" + variant + "/" + basearch + "/os/";
    baseurl = "http://download-node-02.eng.bos.redhat.com/rel-eng/latest-RHEL-" + redhatReleaseX + "/compose/" + variant + "/" + basearch + "/os/";
    // check the baseurl for problems
    baseurlTestResult = sshCommandRunner.runCommandAndWait("curl --stderr /dev/null --insecure --request GET " + baseurl);
    if (baseurlTestResult.getStdout().contains("404 Not Found") || baseurlTestResult.getStdout().contains("The document has moved")) {
        log.warning("Cannot installReleasedRhnClassicPackages from baseurl '" + baseurl + "'.");
        Assert.fail("The Released RHN Tools baseurl '" + baseurl + "' had problems.  Instruct the automator to verify the assembly of this baseurl.");
    }
    // write out the rows of the table...
    output = new BufferedWriter(new FileWriter(file));
    // write the latest-rhel6 repo
    output.write("[" + repo + "]\n");
    output.write("name     = Latest RHEL" + redhatReleaseX + " " + variant + "\n");
    output.write("enabled  = 0\n");
    // needed since the latest extras packages may not be signed until on REL_PREP
    output.write("gpgcheck = 0\n");
    output.write("baseurl  = " + baseurl + "\n");
    output.write("\n");
    output.close();
    installOptions += " --enablerepo=" + repo;
    RemoteFileTasks.putFile(sshCommandRunner, file.getPath(), "/etc/yum.repos.d/", "0644");
    // assemble the packages to be updated (note: if the list is empty, then all packages will be updated)
    String installPackagesAsString = "";
    for (String installPackage : installPackages) installPackagesAsString += installPackage + " ";
    installPackagesAsString = installPackagesAsString.trim();
    // run yum install
    Assert.assertEquals(sshCommandRunner.runCommandAndWait("yum -y install " + installPackagesAsString + " " + installOptions).getExitCode(), Integer.valueOf(0), "Yum successfully installed RHN Classic packages");
}
Also used : SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) FileWriter(java.io.FileWriter) File(java.io.File) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer) BufferedWriter(java.io.BufferedWriter)

Example 93 with SSHCommandResult

use of com.redhat.qe.tools.SSHCommandResult in project rhsm-qe by RedHatQE.

the class SubscriptionManagerTasks method getYumListOfAvailablePackagesFromRepo.

// @Deprecated	// replaced by public ArrayList<String> getYumListAvailable (String options)
public ArrayList<String> getYumListOfAvailablePackagesFromRepo(String repoLabel) {
    if (true)
        return getYumListAvailable("--disablerepo=* --enablerepo=" + repoLabel);
    // the deprecated implementation of this method follows...
    ArrayList<String> packages = new ArrayList<String>();
    sshCommandRunner.runCommandAndWaitWithoutLogging("killall -9 yum");
    int min = 5;
    log.fine("Using a timeout of " + min + " minutes for next ssh command...");
    // SSHCommandResult result = sshCommandRunner.runCommandAndWait("yum list available",Long.valueOf(min*60000));
    // --disableplugin=rhnplugin helps avoid: up2date_client.up2dateErrors.AbuseError
    SSHCommandResult result = sshCommandRunner.runCommandAndWait("yum list available --disablerepo=* --enablerepo=" + repoLabel + " --disableplugin=rhnplugin", Long.valueOf(min * 60000));
    // Example result.getStdout()
    // xmltex.noarch                             20020625-16.el6                      red-hat-enterprise-linux-6-entitlement-alpha-rpms
    // xmlto.x86_64                              0.0.23-3.el6                         red-hat-enterprise-linux-6-entitlement-alpha-rpms
    // xmlto-tex.noarch                          0.0.23-3.el6                         red-hat-enterprise-linux-6-entitlement-alpha-rpms
    // xorg-x11-apps.x86_64                      7.4-10.el6                           red-hat-enterprise-linux-6-entitlement-alpha-rpms
    String regex = "(\\S+) +(\\S+) +" + repoLabel + "$";
    Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
    Matcher matcher = pattern.matcher(result.getStdout());
    if (!matcher.find()) {
        log.fine("Did NOT find any available packages from repoLabel: " + repoLabel);
        return packages;
    }
    // assemble the list of packages and return them
    do {
        // group(1) is the pkg,  group(2) is the version
        packages.add(matcher.group(1));
    } while (matcher.find());
    return packages;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) ArrayList(java.util.ArrayList)

Example 94 with SSHCommandResult

use of com.redhat.qe.tools.SSHCommandResult in project rhsm-qe by RedHatQE.

the class SubscriptionManagerTasks method refresh.

/**
 * "subscription-manager-cli refresh"
 * @param proxy TODO
 * @param proxyuser TODO
 * @param proxypassword TODO
 * @param noproxy TODO
 */
public SSHCommandResult refresh(String proxy, String proxyuser, String proxypassword, String noproxy) {
    SSHCommandResult sshCommandResult = refresh_(proxy, proxyuser, proxypassword, noproxy);
    String refreshStdoutMsg = sshCommandResult.getStdout().trim();
    refreshStdoutMsg = workaroundForBug906550(refreshStdoutMsg);
    // assert results for a successful clean
    Assert.assertEquals(sshCommandResult.getExitCode(), Integer.valueOf(0), "The exit code from the refresh command indicates a success.");
    Assert.assertEquals(refreshStdoutMsg, "All local data refreshed");
    // from the refresh command
    return sshCommandResult;
}
Also used : SSHCommandResult(com.redhat.qe.tools.SSHCommandResult)

Example 95 with SSHCommandResult

use of com.redhat.qe.tools.SSHCommandResult in project rhsm-qe by RedHatQE.

the class SubscriptionManagerTasks method version_.

/**
 * version without asserting results
 * @param proxy TODO
 * @param proxyuser TODO
 * @param proxypassword TODO
 * @param noproxy TODO
 * @return result of the command line call to subscription-manager version
 */
public SSHCommandResult version_(String proxy, String proxyuser, String proxypassword, String noproxy) {
    String command = versionCommand(proxy, proxyuser, proxypassword, noproxy);
    // run command without asserting results
    SSHCommandResult sshCommandResult = sshCommandRunner.runCommandAndWait(command);
    logRuntimeErrors(sshCommandResult);
    return sshCommandResult;
}
Also used : SSHCommandResult(com.redhat.qe.tools.SSHCommandResult)

Aggregations

SSHCommandResult (com.redhat.qe.tools.SSHCommandResult)553 Test (org.testng.annotations.Test)416 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)401 SkipException (org.testng.SkipException)219 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)201 ArrayList (java.util.ArrayList)101 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)79 BigInteger (java.math.BigInteger)68 File (java.io.File)58 SubscriptionPool (rhsm.data.SubscriptionPool)53 JSONObject (org.json.JSONObject)47 HashMap (java.util.HashMap)42 ProductSubscription (rhsm.data.ProductSubscription)31 EntitlementCert (rhsm.data.EntitlementCert)30 List (java.util.List)21 YumRepo (rhsm.data.YumRepo)18 ProductCert (rhsm.data.ProductCert)17 Repo (rhsm.data.Repo)16 InstalledProduct (rhsm.data.InstalledProduct)15 Calendar (java.util.Calendar)13