Search in sources :

Example 96 with BugzillaAPIException

use of com.redhat.qe.auto.bugzilla.BugzillaAPIException in project rhsm-qe by RedHatQE.

the class GoldenTicketTests method testGoldenTicketFunctionality.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-47902", "RHEL7-96740" }, linkedWorkItems = { @LinkedItem(// RHSM-REQ : Org/Environment Level Content Access
workitemId = "RHEL6-47900", project = Project.RHEL6, role = DefTypes.Role.VERIFIES), @LinkedItem(// RHSM-REQ : Org/Environment Level Content Access
workitemId = "RHEL7-85127", project = Project.RedHatEnterpriseLinux7, role = DefTypes.Role.VERIFIES) }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier3")
@Test(description = "Verify golden ticket entitlement is granted when system is registered to an org that has contentAccessMode set", groups = { "Tier3Tests", "blockedByBug-1425438" }, enabled = true)
public void testGoldenTicketFunctionality() throws Exception {
    CandlepinTasks.setAttributeForOrg(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, org, attributeName, attributeValue);
    clienttasks.register(sm_clientUsername, sm_clientPassword, org, null, null, null, null, null, null, null, (String) null, null, null, null, true, null, null, null, null, null);
    clienttasks.autoheal(null, null, true, null, null, null, null);
    String ExpectedRepoMsg = "There were no available repositories matching the specified criteria.";
    if (clienttasks.isPackageVersion("subscription-manager", "<=", "1.18.9-1")) {
        SSHCommandResult repoResult = clienttasks.repos(false, false, true, (String) null, null, null, null, null, null);
        Assert.assertEquals(repoResult.getStdout().toString().trim(), ExpectedRepoMsg);
        clienttasks.refresh(null, null, null, null);
    }
    // verify only the extra entitlement cert granted by or/environment is
    // present
    List<EntitlementCert> entitlementCerts = clienttasks.getCurrentEntitlementCerts();
    Assert.assertTrue(entitlementCerts.size() == 1, "Only extra entitlement granted by the org/environment is present");
    // verify repos --list lists all the repos but none of them are enabled when the system has golden ticket certificate access
    SSHCommandResult resultListEnabled = clienttasks.repos(false, true, false, (String) null, null, null, null, null, null);
    Assert.assertEquals(resultListEnabled.getStdout().toString().trim(), ExpectedRepoMsg);
    SSHCommandResult resultListDisabled = clienttasks.repos(false, false, true, (String) null, null, null, null, null, null);
    Assert.assertNotEquals(resultListDisabled.getStdout().toString().trim(), ExpectedRepoMsg);
    // Verify status cmd message on a system that has golden ticket
    // Todo add assert for golden ticket mode note once fixed
    SSHCommandResult statusResult = clienttasks.status(null, null, null, null, null);
    String expectedStatus = "Overall Status: Invalid";
    Assert.assertTrue(statusResult.getStdout().contains(expectedStatus), "Expecting '" + expectedStatus + "The status of machine is still invalid despite having golden ticket entitlement");
    // verify list --consumed displays the goldenticket entitlement
    SSHCommandResult listConsumedResult = clienttasks.list(null, null, true, null, null, null, null, null, null, null, null, null, null, null);
    String expectedMessageForListConsumed = "No consumed subscription pools to list";
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.20.2-1")) {
        // commit da72dfcbbb2c3a44393edb9e46e1583d05cc140a
        expectedMessageForListConsumed = "No consumed subscription pools were found.";
    }
    // TEMPORARY WORKAROUND FOR BUG
    // Bug 1425438 - subscription-manager list --consumed shows the consumption of extra entitlement granted from the organization or environment.
    String bugId = "1425438";
    boolean invokeWorkaroundWhileBugIsOpen = true;
    try {
        if (invokeWorkaroundWhileBugIsOpen && BzChecker.getInstance().isBugOpen(bugId)) {
            log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId).toString() + " Bugzilla " + bugId + ".  (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId + ")");
            SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId);
        } else {
            invokeWorkaroundWhileBugIsOpen = false;
        }
    } catch (BugzillaAPIException be) {
    /* ignore exception */
    } catch (RuntimeException re) {
    /* ignore exception */
    }
    if (invokeWorkaroundWhileBugIsOpen) {
        log.warning("Skipping assertion: " + "subscription-manager list --consumed does not list golden ticket entitlement");
    } else
        // END OF WORKAROUND
        Assert.assertTrue(listConsumedResult.getStdout().trim().equals(expectedMessageForListConsumed), "Expecting '" + expectedMessageForListConsumed + "subscription-manager list --consumed doesnot list golden ticket entitlement");
    // verify after manually deleting the certs from /etc/pki/entitlement dir , refresh command regenerates the entitlement
    clienttasks.removeAllCerts(false, true, false);
    Assert.assertTrue(clienttasks.getCurrentEntitlementCerts().size() == 0, "Golden ticket cert is successfully removed");
    clienttasks.refresh(null, null, null, null);
    Assert.assertTrue(clienttasks.getCurrentEntitlementCerts().size() == 1, "Golden ticket regenerated successfully");
    resultListDisabled = clienttasks.repos(false, false, true, (String) null, null, null, null, null, null);
    Assert.assertNotEquals(resultListDisabled.getStdout().toString().trim(), ExpectedRepoMsg);
    // Verify remove --all command doesnot remove the golden ticket entitlement along with other subscriptions
    clienttasks.subscribe(true, null, null, (String) null, null, null, null, null, null, null, null, null, null);
    Assert.assertTrue(clienttasks.getCurrentEntitlementCerts().size() > 1, "There are more subscriptions attached other than the golden ticket");
    SSHCommandResult AutoAttachlistConsumedResult = clienttasks.list(null, null, true, null, null, null, null, null, null, null, null, null, null, null);
    Assert.assertFalse(AutoAttachlistConsumedResult.getStdout().trim().equals(expectedMessageForListConsumed), "Expecting'" + expectedMessageForListConsumed + "subscription-manager list --consumed lists the subscriptions consumed after auto-attach command is successful");
    clienttasks.unsubscribe_(true, null, (String) null, null, null, null, null);
    List<EntitlementCert> entitlementCertsAfterRemoveAll = clienttasks.getCurrentEntitlementCerts();
    Assert.assertTrue(entitlementCertsAfterRemoveAll.size() == 1, "Only extra entitlement granted by the org/environment is present");
    // verify removing the golden ticekt entitlement by subscription-manager remove --serial <serial_id> fails to remove the golden ticket entitlement
    List<EntitlementCert> entitlementCertsToRemove = EntitlementCert.findAllInstancesWithMatchingFieldFromList("poolId", "Not Available", clienttasks.getCurrentEntitlementCerts());
    for (EntitlementCert entitlementCert : entitlementCertsToRemove) {
        SSHCommandResult removeResult = clienttasks.unsubscribe_(null, entitlementCert.serialNumber, null, null, null, null, null);
        String ExpectedMessageForRemove = "The entitlement server failed to remove these serial numbers:" + "\n";
        ExpectedMessageForRemove += "   " + entitlementCert.serialNumber;
        Assert.assertEquals(removeResult.getStdout().trim(), ExpectedMessageForRemove);
    }
    clienttasks.repos(false, false, false, "*", null, null, null, null, null);
    resultListEnabled = clienttasks.repos(false, true, false, (String) null, null, null, null, null, null);
    Assert.assertNotEquals(resultListEnabled.getStdout().toString().trim(), ExpectedRepoMsg);
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 97 with BugzillaAPIException

use of com.redhat.qe.auto.bugzilla.BugzillaAPIException in project rhsm-qe by RedHatQE.

the class SubscriptionManagerTasks method unregister.

/**
 * "subscription-manager-cli unregister"
 * @param proxy TODO
 * @param proxyuser TODO
 * @param proxypassword TODO
 * @param noproxy TODO
 */
public SSHCommandResult unregister(String proxy, String proxyuser, String proxypassword, String noproxy) {
    SSHCommandResult sshCommandResult = unregister_(proxy, proxyuser, proxypassword, noproxy);
    // assert results for a successful de-registration
    if (sshCommandResult.getExitCode() == 0) {
        String unregisterSuccessMsg = "System has been unregistered.";
        // introduced by commit 217c3863448478d06c5008694e327e048cc54f54 Bug 1443101: Provide feedback for force register
        String unregisterFromMsg = "Unregistering from: ";
        // TEMPORARY WORKAROUND FOR BUG
        // Status: 	VERIFIED
        boolean invokeWorkaroundWhileBugIsOpen = false;
        try {
            String bugId = "878657";
            if (invokeWorkaroundWhileBugIsOpen && BzChecker.getInstance().isBugOpen(bugId)) {
                log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId).toString() + " Bugzilla " + bugId + ".  (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId + ")");
                SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId);
            } else {
                invokeWorkaroundWhileBugIsOpen = false;
            }
        } catch (BugzillaAPIException be) {
        /* ignore exception */
        } catch (RuntimeException re) {
        /* ignore exception */
        }
        if (invokeWorkaroundWhileBugIsOpen)
            unregisterSuccessMsg = "System has been un-registered.";
        // END OF WORKAROUND
        // TEMPORARY WORKAROUND FOR BUG
        // Status: 	CLOSED ERRATA
        invokeWorkaroundWhileBugIsOpen = false;
        try {
            String bugId = "800121";
            if (invokeWorkaroundWhileBugIsOpen && BzChecker.getInstance().isBugOpen(bugId)) {
                log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId).toString() + " Bugzilla " + bugId + ".  (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId + ")");
                SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId);
            } else {
                invokeWorkaroundWhileBugIsOpen = false;
            }
        } catch (BugzillaAPIException be) {
        /* ignore exception */
        } catch (RuntimeException re) {
        /* ignore exception */
        }
        if (invokeWorkaroundWhileBugIsOpen) {
            log.warning("If 'NoneType' object message was thrown to stdout during unregister, we will ignore it while this bug is open.");
            Assert.assertTrue(sshCommandResult.getStdout().trim().contains(unregisterSuccessMsg), "The unregister command was a success.");
        } else // END OF WORKAROUND
        if (isPackageVersion("subscription-manager", ">=", "1.19.11-1")) {
            // commit 217c3863448478d06c5008694e327e048cc54f54 Bug 1443101: Provide feedback for force register
            Assert.assertTrue(sshCommandResult.getStdout().trim().startsWith(unregisterFromMsg), "Stdout from an attempt to unregister starts with message '" + unregisterFromMsg + "'.");
            Assert.assertTrue(sshCommandResult.getStdout().trim().endsWith(unregisterSuccessMsg), "Stdout from an attempt to unregister ends with successful message '" + unregisterSuccessMsg + "'.");
        } else {
            Assert.assertTrue(sshCommandResult.getStdout().trim().equals(unregisterSuccessMsg), "Stdout from an attempt to unregister equals successful message '" + unregisterSuccessMsg + "'.");
        }
        Assert.assertEquals(sshCommandResult.getExitCode(), Integer.valueOf(0), "Exit code from an attempt to unregister");
    } else if (sshCommandResult.getExitCode() == 1) {
        if (isPackageVersion("subscription-manager", ">=", "1.13.8-1")) {
            // commit df95529a5edd0be456b3528b74344be283c4d258 bug 1119688
            Assert.assertTrue(sshCommandResult.getStderr().startsWith("This system is currently not registered."), "The unregister command was not necessary.  Stderr indicates it was already unregistered.");
        } else {
            Assert.assertTrue(sshCommandResult.getStdout().startsWith("This system is currently not registered."), "The unregister command was not necessary.  Stdout indicates it was already unregistered.");
        }
    } else {
        Assert.fail("Unexpected exit code '" + sshCommandResult.getExitCode() + "' was returned when attempting to unregister.");
    }
    // assert that the consumer cert and key have been removed
    Assert.assertTrue(!RemoteFileTasks.testExists(sshCommandRunner, this.consumerKeyFile()), "Consumer key file '" + this.consumerKeyFile() + "' does NOT exist after unregister.");
    Assert.assertTrue(!RemoteFileTasks.testExists(sshCommandRunner, this.consumerCertFile()), "Consumer cert file '" + this.consumerCertFile() + " does NOT exist after unregister.");
    // assert that all of the entitlement certs have been removed
    Assert.assertTrue(getCurrentEntitlementCertFiles().size() == 0, "All of the entitlement certificates have been removed after unregister.");
    // from the unregister command
    return sshCommandResult;
}
Also used : SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException)

Example 98 with BugzillaAPIException

use of com.redhat.qe.auto.bugzilla.BugzillaAPIException in project rhsm-qe by RedHatQE.

the class SubscriptionManagerTasks method restart_rhsmcertd.

/**
 * Update the rhsmcertd frequency configurations in /etc/rhsm/rhsm.conf file and restart the rhsmcertd service.
 * @param certFrequency - Frequency of certificate refresh (in minutes) (passing null will not change the current value)
 * @param healFrequency - Frequency of subscription auto healing (in minutes) (passing null will not change the current value)
 * @param assertCertificatesUpdate if NULL, do not assert the status of Certificate updates in rhsmcertd log; if TRUE, assert rhsmcertd logs that Certificate updates succeeded; if FALSE, assert rhsmcertd logs that Certificate updates failed
 * NOTE: Due to the implementation of RFE Bug 1435013, calls to this method could potentially take up to a whole day waiting for the default autoAttachInterval to trigger.
 * To avoid an unfriendly automation delay like this, the splay configuration will be temporarily turned off while restarting rhsmcertd when these frequencies exceed 10 minutes.
 * If you are trying to explicitly test the certFrequency and healFrequency, you should use values less than 10 minutes.
 */
public void restart_rhsmcertd(Integer certFrequency, Integer healFrequency, Boolean assertCertificatesUpdate) {
    // update the configuration for certFrequency and healFrequency
    // updateConfFileParameter(rhsmConfFile, "certFrequency", String.valueOf(certFrequency));
    // updateConfFileParameter(rhsmConfFile, "healFrequency", String.valueOf(healFrequency));
    // save time using the new config module to update the configuration
    List<String[]> listOfSectionNameValues = new ArrayList<String[]>();
    if (certFrequency != null)
        listOfSectionNameValues.add(new String[] { "rhsmcertd", /*"certFrequency" was renamed by bug 882459 to*/
        "certCheckInterval".toLowerCase(), String.valueOf(certFrequency) });
    else
        certFrequency = Integer.valueOf(getConfFileParameter(rhsmConfFile, "rhsmcertd", /*"certFrequency" was renamed by bug 882459 to*/
        "certCheckInterval"));
    if (healFrequency != null)
        listOfSectionNameValues.add(new String[] { "rhsmcertd", /*"healFrequency" was renamed by bug 882459 to*/
        "autoAttachInterval".toLowerCase(), String.valueOf(healFrequency) });
    else
        healFrequency = Integer.valueOf(getConfFileParameter(rhsmConfFile, "rhsmcertd", /*"healFrequency" was renamed by bug 882459 to*/
        "autoAttachInterval"));
    if (listOfSectionNameValues.size() > 0)
        config(null, null, true, listOfSectionNameValues);
    // avoid excessive restart delays by turning off the splay configuration
    String originalSplayConfig = null;
    if (isPackageVersion("subscription-manager", ">=", "1.19.8-1")) {
        // commit e9f8421285fc6541166065a8b55ee89b9a425246 RFE Bug 1435013: Add splay option to rhsmcertd, randomize over interval
        // arbitrarily selected to a small number assuming it is greater than any value tested via the automated our rhsm-qe tests and less than the default frequency values of 240 and 1440.
        int maxSplayDelayMinutes = 10;
        if (healFrequency > maxSplayDelayMinutes || certFrequency > maxSplayDelayMinutes) {
            // get the original rhsmcertd.splay config
            originalSplayConfig = getConfFileParameter(rhsmConfFile, "rhsmcertd", "splay");
            if (originalSplayConfig != null) {
                log.warning("The rhsmcertd.autoAttachInterval (" + healFrequency + ") and/or rhsmcertd.certCheckInterval (" + certFrequency + ") exceed an automation friendly limit of '" + maxSplayDelayMinutes + "'.  Temporarily disabling rhsmcertd.splay to avoid long delays waiting for the next update...");
                try {
                    updateConfFileParameter(rhsmConfFile, "rhsmcertd", "splay", "0");
                } catch (IOException e) {
                    Assert.fail(e.getMessage());
                }
            }
        }
    }
    // mark the rhsmcertd log file before restarting the deamon
    // to ensure the file exists before trying to mark it
    RemoteFileTasks.runCommandAndWait(sshCommandRunner, "touch " + rhsmcertdLogFile, TestRecords.action());
    String rhsmcertdLogMarker = System.currentTimeMillis() + " Testing service rhsmcertd restart...";
    RemoteFileTasks.markFile(sshCommandRunner, rhsmcertdLogFile, rhsmcertdLogMarker);
    // TEMPORARY WORKAROUND FOR BUG
    // Status: 	CLOSED ERRATA
    String bugId = "804227";
    boolean invokeWorkaroundWhileBugIsOpen = false;
    try {
        if (invokeWorkaroundWhileBugIsOpen && BzChecker.getInstance().isBugOpen(bugId)) {
            log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId).toString() + " Bugzilla " + bugId + ".  (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId + ")");
            SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId);
        } else {
            invokeWorkaroundWhileBugIsOpen = false;
        }
    } catch (BugzillaAPIException be) {
    /* ignore exception */
    } catch (RuntimeException re) {
    /* ignore exception */
    }
    if (invokeWorkaroundWhileBugIsOpen) {
        throw new SkipException("Restart rhsmcertd has no workaround for Bugzilla " + bugId + ".");
    }
    // TEMPORARY WORKAROUND FOR BUG
    if (this.arch.equals("s390x") || this.arch.equals("ppc64")) {
        // Status: 	CLOSED ERRATA
        bugId = "691137";
        invokeWorkaroundWhileBugIsOpen = false;
        try {
            if (invokeWorkaroundWhileBugIsOpen && BzChecker.getInstance().isBugOpen(bugId)) {
                log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId).toString() + " Bugzilla " + bugId + ".  (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId + ")");
                SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId);
            } else {
                invokeWorkaroundWhileBugIsOpen = false;
            }
        } catch (BugzillaAPIException be) {
        /* ignore exception */
        } catch (RuntimeException re) {
        /* ignore exception */
        }
        if (invokeWorkaroundWhileBugIsOpen) {
            RemoteFileTasks.runCommandAndWait(sshCommandRunner, "service rhsmcertd restart", TestRecords.action());
        } else {
        /* VALID PRIOR TO BUG 818978:
				 * RemoteFileTasks.runCommandAndAssert(sshCommandRunner,"service rhsmcertd restart",Integer.valueOf(0),"^Starting rhsmcertd "+certFrequency+" "+healFrequency+"\\[  OK  \\]$",null);
				 */
        }
    } else {
    // END OF WORKAROUND
    /* VALID PRIOR TO BUG 818978:
		 * RemoteFileTasks.runCommandAndAssert(sshCommandRunner,"service rhsmcertd restart",Integer.valueOf(0),"^Starting rhsmcertd "+certFrequency+" "+healFrequency+"\\[  OK  \\]$",null);
		 */
    }
    // restart rhsmcertd service
    if (Integer.valueOf(redhatReleaseX) >= 7) {
        // the RHEL7 / F16+ way...
        RemoteFileTasks.runCommandAndAssert(sshCommandRunner, "systemctl restart rhsmcertd.service && systemctl is-active rhsmcertd.service", Integer.valueOf(0), "^active$", null);
    } else {
        // NEW SERVICE RESTART FEEDBACK AFTER IMPLEMENTATION OF Bug 818978 - Missing systemD unit file
        // [root@jsefler-59server ~]# service rhsmcertd restart
        // Stopping rhsmcertd...                                      [  OK  ]
        // Starting rhsmcertd...                                      [  OK  ]
        RemoteFileTasks.runCommandAndAssert(sshCommandRunner, "service rhsmcertd restart", Integer.valueOf(0), "^Starting rhsmcertd\\.\\.\\.\\[  OK  \\]$", null);
        // # service rhsmcertd restart
        // rhsmcertd (pid 10172 10173) is running...
        // RemoteFileTasks.runCommandAndAssert(sshCommandRunner,"service rhsmcertd status",Integer.valueOf(0),"^rhsmcertd \\(pid \\d+ \\d+\\) is running...$",null);	// RHEL62 branch
        // master/RHEL58 branch
        RemoteFileTasks.runCommandAndAssert(sshCommandRunner, "service rhsmcertd status", Integer.valueOf(0), "^rhsmcertd \\(pid \\d+\\) is running...$", null);
    // RemoteFileTasks.runCommandAndAssert(sshCommandRunner,"service rhsmcertd status",Integer.valueOf(0),"^rhsmcertd \\(pid( \\d+){1,2}\\) is running...$",null);	// tolerate 1 or 2 pids for RHEL62 or RHEL58; don't really care which it is since the next assert is really sufficient
    }
    // # tail -f /var/log/rhsm/rhsmcertd.log
    // Wed Nov  9 15:21:54 2011: started: interval = 1440 minutes
    // Wed Nov  9 15:21:54 2011: started: interval = 240 minutes
    // Wed Nov  9 15:21:55 2011: certificates updated
    // Wed Nov  9 15:21:55 2011: certificates updated
    // TEMPORARY WORKAROUND FOR BUG
    /*boolean*/
    // Current bug status is: CLOSED ERRATA; setting invokeWorkaroundWhileBugIsOpen to false to save execution time
    invokeWorkaroundWhileBugIsOpen = false;
    // Status: 	CLOSED ERRATA
    String bugId1 = "752572";
    // Status: 	CLOSED ERRATA
    String bugId2 = "759199";
    invokeWorkaroundWhileBugIsOpen = false;
    try {
        if (invokeWorkaroundWhileBugIsOpen && (BzChecker.getInstance().isBugOpen(bugId1) || BzChecker.getInstance().isBugOpen(bugId2))) {
            log.fine("Invoking workaround for Bugzillas:  https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId1 + " https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId2);
            SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId1);
            SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId2);
        } else {
            invokeWorkaroundWhileBugIsOpen = false;
        }
    } catch (BugzillaAPIException be) {
    /* ignore exception */
    } catch (RuntimeException re) {
    /* ignore exception */
    }
    if (invokeWorkaroundWhileBugIsOpen) {
        log.warning("Skipping assert of the rhsmcertd logging of the started: interval certFrequency and healFrequency while bug " + bugId1 + " or " + bugId2 + " is open.");
    } else {
    // END OF WORKAROUND
    // RemoteFileTasks.runCommandAndAssert(sshCommandRunner,"tail -4 "+rhsmcertdLogFile,Integer.valueOf(0),"(.*started: interval = "+healFrequency+" minutes\n.*started: interval = "+certFrequency+" minutes)|(.*started: interval = "+certFrequency+" minutes\n.*started: interval = "+healFrequency+" minutes)",null);
    // RemoteFileTasks.runCommandAndAssert(sshCommandRunner,"tail -4 "+rhsmcertdLogFile,Integer.valueOf(0),".* healing check started: interval = "+healFrequency+"\n.* cert check started: interval = "+certFrequency,null);
    /* VALID PRIOR TO BUG 818978:
		 * RemoteFileTasks.runCommandAndAssert(sshCommandRunner,"tail -4 "+rhsmcertdLogFile,Integer.valueOf(0),".* healing check started: interval = "+healFrequency+" minute\\(s\\)\n.* cert check started: interval = "+certFrequency+" minute\\(s\\)",null);
		 */
    }
    // give the rhsmcertd time to make its initial check-in with the candlepin server and update the certs
    // I've seen this take 10 to 15 seconds as demonstrated here...
    // when registered...
    // 1334786048260 Testing service rhsmcertd restart...
    // Wed Apr 18 17:54:11 2012: healing check started: interval = 1440
    // Wed Apr 18 17:54:11 2012: cert check started: interval = 240
    // Wed Apr 18 17:54:21 2012: certificates updated
    // Wed Apr 18 17:54:26 2012: certificates updated
    // when not registered...
    // 1341610172422 Testing service rhsmcertd restart...
    // Fri Jul  6 17:30:48 2012: Loading configuration from command line
    // Fri Jul  6 17:30:48 2012: Cert Frequency: 14400 seconds
    // Fri Jul  6 17:30:48 2012: Heal Frequency: 86400 seconds
    // Fri Jul  6 17:30:48 2012: healing check started: interval = 1440 minute(s)
    // Fri Jul  6 17:30:48 2012: cert check started: interval = 240 minute(s)
    // Fri Jul  6 17:30:48 2012: update failed (255), retry will occur on next run
    // Fri Jul  6 17:30:49 2012: update failed (255), retry will occur on next run
    // assert the rhsmcertd log file reflected newly updated certificates...
    /* VALID PRIOR TO BUG 818978:
		int i=0, delay=10;
		String rhsmcertdLogResult,updateRegex;
		if (this.currentlyRegisteredUsername==null)	updateRegex = ".*update failed \\(255\\), retry will occur on next run\\n.*update failed \\(255\\), retry will occur on next run";	// when NOT registered
		else										updateRegex = ".*certificates updated\\n.*certificates updated";
		do {	// retry every 10 seconds (up to a minute) for the expected update certificates regex in the rhsmcertd log
			SubscriptionManagerCLITestScript.sleep(delay*1000);i++;	// wait a few seconds before trying again
			rhsmcertdLogResult = RemoteFileTasks.getTailFromMarkedFile(sshCommandRunner, rhsmcertdLogFile, rhsmcertdLogMarker, "update").trim();
			if (rhsmcertdLogResult.matches(updateRegex)) break;
		} while (delay*i < 60);
		Assert.assertTrue(rhsmcertdLogResult.matches(updateRegex), "Expected certificate update regex '"+updateRegex+"' is being logged to rhsmcertd log during a restart.");
		*/
    // [root@jsefler-59server ~]# tail -f /var/log/rhsm/rhsmcertd.log
    // 1342466941476 Testing service rhsmcertd restart...
    // Mon Jul 16 13:23:56 2012 [INFO] rhsmcertd is shutting down...
    // Mon Jul 16 13:23:56 2012 [INFO] Starting rhsmcertd...
    // Mon Jul 16 13:23:56 2012 [INFO] Healing interval: 1440.0 minute(s) [86400 second(s)]
    // Mon Jul 16 13:23:56 2012 [INFO] Cert check interval: 2.0 minute(s) [120 second(s)]
    // Mon Jul 16 13:23:56 2012 [INFO] Waiting 120 second(s) [2.0 minute(s)] before running updates.
    // Mon Jul 16 13:25:56 2012 [WARN] (Healing) Update failed (255), retry will occur on next run.
    // Mon Jul 16 13:25:57 2012 [WARN] (Cert Check) Update failed (255), retry will occur on next run.
    // Mon Jul 16 13:27:56 2012 [WARN] (Cert Check) Update failed (255), retry will occur on next run.
    // 1342466941944 Testing service rhsmcertd restart...
    // Mon Jul 16 14:30:20 2012 [INFO] rhsmcertd is shutting down...
    // Mon Jul 16 14:30:20 2012 [INFO] Starting rhsmcertd...
    // Mon Jul 16 14:30:20 2012 [INFO] Healing interval: 1440.0 minute(s) [86400 second(s)]
    // Mon Jul 16 14:30:20 2012 [INFO] Cert check interval: 2.0 minute(s) [120 second(s)]
    // Mon Jul 16 14:30:20 2012 [INFO] Waiting 120 second(s) [2.0 minute(s)] before running updates.
    // Mon Jul 16 14:32:25 2012 [INFO] (Healing) Certificates updated.
    // Mon Jul 16 14:32:29 2012 [INFO] (Cert Check) Certificates updated.
    // Mon Jul 16 14:34:22 2012 [INFO] (Cert Check) Certificates updated.
    // this is a dev hard coded wait (seconds) before the first check for updates is attempted  REFERENCE BUG 818978#c2
    Integer waitSecondsForFirstUpdateCheck = 120;
    String rhsmcertdLogExpectedStartingRhsmMsg = String.format(" Starting rhsmcertd...");
    String rhsmcertdLogExpectedHealIntervalMsg = String.format(" Healing interval: %.1f minute(s) [%d second(s)]", healFrequency * 1.0, healFrequency * 60);
    /* msg was changed by bug 882459*/
    rhsmcertdLogExpectedHealIntervalMsg = String.format(" Auto-attach interval: %.1f minute(s) [%d second(s)]", healFrequency * 1.0, healFrequency * 60);
    if (isPackageVersion("subscription-manager", ">=", "1.19.9-1")) {
        // commit e0e1a6b3e80c33e04fe79eaa696a821881f95f35 1443205: Simplify rhsmcertd log message plurality
        rhsmcertdLogExpectedHealIntervalMsg = String.format(" Auto-attach interval: %.1f minutes [%d seconds]", healFrequency * 1.0, healFrequency * 60);
    }
    String rhsmcertdLogExpectedCertIntervalMsg = String.format(" Cert check interval: %.1f minute(s) [%d second(s)]", certFrequency * 1.0, certFrequency * 60);
    if (isPackageVersion("subscription-manager", ">=", "1.19.9-1")) {
        // commit e0e1a6b3e80c33e04fe79eaa696a821881f95f35 1443205: Simplify rhsmcertd log message plurality
        rhsmcertdLogExpectedCertIntervalMsg = String.format(" Cert check interval: %.1f minutes [%d seconds]", certFrequency * 1.0, certFrequency * 60);
    }
    String rhsmcertdLogResult;
    int i = 0, delay = 5;
    do {
        // wait a few seconds before trying again
        if (i > 0)
            SubscriptionManagerCLITestScript.sleep(delay * 1000);
        rhsmcertdLogResult = RemoteFileTasks.getTailFromMarkedFile(sshCommandRunner, rhsmcertdLogFile, rhsmcertdLogMarker, null).trim();
        if (rhsmcertdLogResult.contains(rhsmcertdLogExpectedStartingRhsmMsg))
            break;
    } while (// Note: should wait at least 60+ additional seconds because auto-attach can timeout after 60 seconds.  see bug https://bugzilla.redhat.com/show_bug.cgi?id=964332#c6
    delay * i++ < 20);
    Assert.assertTrue(rhsmcertdLogResult.contains(rhsmcertdLogExpectedStartingRhsmMsg), "Tail of rhsmcertd log contains the expected restart message '" + rhsmcertdLogExpectedStartingRhsmMsg + "'.");
    Assert.assertTrue(rhsmcertdLogResult.contains(rhsmcertdLogExpectedHealIntervalMsg), "Tail of rhsmcertd log contains the expected restart message '" + rhsmcertdLogExpectedHealIntervalMsg + "'.");
    Assert.assertTrue(rhsmcertdLogResult.contains(rhsmcertdLogExpectedCertIntervalMsg), "Tail of rhsmcertd log contains the expected restart message '" + rhsmcertdLogExpectedCertIntervalMsg + "'.");
    if (isPackageVersion("subscription-manager", ">=", "1.19.8-1")) {
        // commit e9f8421285fc6541166065a8b55ee89b9a425246 RFE Bug 1435013: Add splay option to rhsmcertd, randomize over interval
        // The new splay algorithm from RFE Bug 1435013 will wait a hard coded 2 minutes...
        // A. plus a random number of seconds up to a maximum of the configured Auto-attach interval before running /usr/libexec/rhsmcertd-worker --autoheal
        // B. plus a random number of seconds up to a maximum of the configured Cert check interval before running /usr/libexec/rhsmcertd-worker
        // The new splay delay can be turned on/off using the rhsmcertd.splay configuration.
        // When off (splay=0), the splay seconds will be zero which effectively restores the former behavior.
        String splayConfig = getConfFileParameter(rhsmConfFile, "rhsmcertd", "splay");
        // [root@jsefler-rhel7 ~]# tail -f /var/log/rhsm/rhsmcertd.log
        // 1492537756242 Testing service rhsmcertd restart...
        // Tue Apr 18 13:49:16 2017 [INFO] rhsmcertd is shutting down...
        // Tue Apr 18 13:49:16 2017 [INFO] Starting rhsmcertd...
        // Tue Apr 18 13:49:16 2017 [INFO] Auto-attach interval: 4.0 minute(s) [240 second(s)]
        // Tue Apr 18 13:49:16 2017 [INFO] Cert check interval: 3.0 minute(s) [180 second(s)]
        // Tue Apr 18 13:49:16 2017 [INFO] Waiting 2.0 minute(s) plus 129 splay second(s) [249 seconds(s) totals] before performing first auto-attach.
        // Tue Apr 18 13:49:16 2017 [INFO] Waiting 2.0 minute(s) plus 86 splay second(s) [206 seconds(s) totals] before performing first cert check.
        // Tue Apr 18 13:52:43 2017 [INFO] (Cert Check) Certificates updated.
        // Tue Apr 18 13:53:26 2017 [INFO] (Auto-attach) Certificates updated.
        // assert the wait time for auto-attach
        String rhsmcertdLogResultExpectedRegex = String.format(" Waiting %.1f minute\\(s\\) plus (\\d+) splay second\\(s\\) \\[(\\d+) seconds\\(s\\) totals\\] before performing first auto-attach\\.", waitSecondsForFirstUpdateCheck / 60.0);
        if (isPackageVersion("subscription-manager", ">=", "1.19.9-1")) {
            // commit e0e1a6b3e80c33e04fe79eaa696a821881f95f35 1443205: Simplify rhsmcertd log message plurality
            rhsmcertdLogResultExpectedRegex = String.format(" Waiting %.1f minutes plus (\\d+) splay seconds \\[(\\d+) seconds total\\] before performing first auto-attach\\.", waitSecondsForFirstUpdateCheck / 60.0);
        }
        Assert.assertTrue(SubscriptionManagerCLITestScript.doesStringContainMatches(rhsmcertdLogResult, rhsmcertdLogResultExpectedRegex), "Tail of rhsmcertd log contains the expected restart regex message '" + rhsmcertdLogResultExpectedRegex + "'.");
        // 129 splay second(s)
        int splayHealSeconds = Integer.valueOf(SubscriptionManagerCLITestScript.getSubstringMatches(SubscriptionManagerCLITestScript.getSubstringMatches(rhsmcertdLogResult, rhsmcertdLogResultExpectedRegex).get(0), "(\\d+) splay").get(0).split(" ")[0]);
        // 249 seconds(s) totals
        int totalHealSeconds = Integer.valueOf(SubscriptionManagerCLITestScript.getSubstringMatches(SubscriptionManagerCLITestScript.getSubstringMatches(rhsmcertdLogResult, rhsmcertdLogResultExpectedRegex).get(0), "(\\d+) seconds").get(0).split(" ")[0]);
        Assert.assertTrue(0 <= splayHealSeconds && splayHealSeconds <= healFrequency * 60, /*seconds*/
        "The splay (" + splayHealSeconds + ") seconds is greater than or equal to zero and less than or equal to the auto-attach interval (" + healFrequency * 60 + " seconds) ");
        Assert.assertEquals(totalHealSeconds, waitSecondsForFirstUpdateCheck + splayHealSeconds, "The total wait time in seconds for the first auto-attach after restarting rhsmcertd.");
        if (splayConfig.equals("0") || splayConfig.toLowerCase().equals("false"))
            Assert.assertEquals(splayHealSeconds, 0, "When the rhsmcertd.splay configuration in '" + rhsmConfFile + "' is off, the splay seconds for auto-attach should be zero.");
        // assert the wait time for cert check
        rhsmcertdLogResultExpectedRegex = String.format(" Waiting %.1f minute\\(s\\) plus (\\d+) splay second\\(s\\) \\[(\\d+) seconds\\(s\\) totals\\] before performing first cert check\\.", waitSecondsForFirstUpdateCheck / 60.0);
        if (isPackageVersion("subscription-manager", ">=", "1.19.9-1")) {
            // commit e0e1a6b3e80c33e04fe79eaa696a821881f95f35 1443205: Simplify rhsmcertd log message plurality
            rhsmcertdLogResultExpectedRegex = String.format(" Waiting %.1f minutes plus (\\d+) splay seconds \\[(\\d+) seconds total\\] before performing first cert check\\.", waitSecondsForFirstUpdateCheck / 60.0);
        }
        Assert.assertTrue(SubscriptionManagerCLITestScript.doesStringContainMatches(rhsmcertdLogResult, rhsmcertdLogResultExpectedRegex), "Tail of rhsmcertd log contains the expected restart regex message '" + rhsmcertdLogResultExpectedRegex + "'.");
        // 86 splay second(s)
        int splayCertSeconds = Integer.valueOf(SubscriptionManagerCLITestScript.getSubstringMatches(SubscriptionManagerCLITestScript.getSubstringMatches(rhsmcertdLogResult, rhsmcertdLogResultExpectedRegex).get(0), "(\\d+) splay").get(0).split(" ")[0]);
        // 206 seconds(s) totals
        int totalCertSeconds = Integer.valueOf(SubscriptionManagerCLITestScript.getSubstringMatches(SubscriptionManagerCLITestScript.getSubstringMatches(rhsmcertdLogResult, rhsmcertdLogResultExpectedRegex).get(0), "(\\d+) seconds").get(0).split(" ")[0]);
        Assert.assertTrue(0 <= splayCertSeconds && splayCertSeconds <= certFrequency * 60, /*seconds*/
        "The splay (" + splayCertSeconds + ") seconds is greater than or equal to zero and less than or equal to the cert check interval (" + certFrequency * 60 + " seconds) ");
        Assert.assertEquals(totalCertSeconds, waitSecondsForFirstUpdateCheck + splayCertSeconds, "The total wait time in seconds for the first cert check after restarting rhsmcertd.");
        if (splayConfig.equals("0") || splayConfig.toLowerCase().equals("false"))
            Assert.assertEquals(splayCertSeconds, 0, "When the rhsmcertd.splay configuration in '" + rhsmConfFile + "' is off, the splay seconds for cert check should be zero.");
        // Waiting 120 second(s) [2.0 minute(s)] PLUS THE MAXIMUM SPLAY DELAYS before asserting updates.
        SubscriptionManagerCLITestScript.sleep(Math.max(totalHealSeconds, totalCertSeconds) * 1000);
    } else {
        String rhsmcertdLogExpectedWaitMsg = String.format(" Waiting %d second(s) [%.1f minute(s)] before running updates.", waitSecondsForFirstUpdateCheck, waitSecondsForFirstUpdateCheck / 60.0);
        Assert.assertTrue(rhsmcertdLogResult.contains(rhsmcertdLogExpectedWaitMsg), "Tail of rhsmcertd log contains the expected restart message '" + rhsmcertdLogExpectedWaitMsg + "'.");
        // Waiting 120 second(s) [2.0 minute(s)] before running updates.
        SubscriptionManagerCLITestScript.sleep(waitSecondsForFirstUpdateCheck * 1000);
    }
    // assert the rhsmcertd log for messages stating the cert and heal frequencies have be logged
    if (assertCertificatesUpdate != null) {
        // assert these cert and heal update/fail messages are logged (but give the system up to a minute to do it)
        // String healMsg = assertCertificatesUpdate? "(Healing) Certificates updated.":"(Healing) Update failed (255), retry will occur on next run.";	// msg was changed by bug 882459
        String healMsg = assertCertificatesUpdate ? "(Auto-attach) Certificates updated." : "(Auto-attach) Update failed (255), retry will occur on next run.";
        String certMsg = assertCertificatesUpdate ? "(Cert Check) Certificates updated." : "(Cert Check) Update failed (255), retry will occur on next run.";
        /*int*/
        i = 0;
        delay = 10;
        do {
            // wait a few seconds before trying again
            if (i > 0)
                SubscriptionManagerCLITestScript.sleep(delay * 1000);
            // wait a few seconds before trying again
            i++;
            rhsmcertdLogResult = RemoteFileTasks.getTailFromMarkedFile(sshCommandRunner, rhsmcertdLogFile, rhsmcertdLogMarker, null).trim();
            if (rhsmcertdLogResult.contains(healMsg) && rhsmcertdLogResult.contains(certMsg))
                break;
        } while (// Note: should wait at least 60+ additional seconds because auto-attach can timeout after 60 seconds.  see bug https://bugzilla.redhat.com/show_bug.cgi?id=964332#c6
        delay * i++ < 90);
        boolean healMsgAssert = true;
        boolean certMsgAssert = true;
        // TEMPORARY WORKAROUND FOR BUG
        // Bug 1241247 - rhsmcertd-worker throws Traceback "ImportError: cannot import name ga"
        bugId = "1241247";
        invokeWorkaroundWhileBugIsOpen = true;
        try {
            if (assertCertificatesUpdate && invokeWorkaroundWhileBugIsOpen && BzChecker.getInstance().isBugOpen(bugId)) {
                log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId).toString() + " Bugzilla " + bugId + ".  (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId + ")");
                SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId);
            } else {
                invokeWorkaroundWhileBugIsOpen = false;
            }
        } catch (BugzillaAPIException be) {
        /* ignore exception */
        } catch (RuntimeException re) {
        /* ignore exception */
        }
        if (assertCertificatesUpdate && invokeWorkaroundWhileBugIsOpen) {
            throw new SkipException("Restart rhsmcertd has no workaround for Bugzilla " + bugId + ".");
        }
        // END OF WORKAROUND
        // TEMPORARY WORKAROUND FOR BUG
        // Bug 861443 - rhsmcertd logging of Healing shows "Certificates updated." when it should fail.
        bugId = "861443";
        invokeWorkaroundWhileBugIsOpen = true;
        try {
            if (assertCertificatesUpdate && invokeWorkaroundWhileBugIsOpen && BzChecker.getInstance().isBugOpen(bugId)) {
                log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId).toString() + " Bugzilla " + bugId + ".  (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId + ")");
                SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId);
            } else {
                invokeWorkaroundWhileBugIsOpen = false;
            }
        } catch (BugzillaAPIException be) {
        /* ignore exception */
        } catch (RuntimeException re) {
        /* ignore exception */
        }
        if (!assertCertificatesUpdate && invokeWorkaroundWhileBugIsOpen) {
            log.warning("Skipping assertion: " + "Tail of rhsmcertd log contains the expected restart message '" + healMsg + "'.");
            healMsgAssert = false;
        }
        // END OF WORKAROUND
        // TEMPORARY WORKAROUND FOR BUG
        // Bug 1440934 - rhsmcertd is not starting the Auto-attach interval
        bugId = "1440934";
        invokeWorkaroundWhileBugIsOpen = true;
        try {
            if (invokeWorkaroundWhileBugIsOpen && BzChecker.getInstance().isBugOpen(bugId)) {
                log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId).toString() + " Bugzilla " + bugId + ".  (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId + ")");
                SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId);
            } else {
                invokeWorkaroundWhileBugIsOpen = false;
            }
        } catch (BugzillaAPIException be) {
        /* ignore exception */
        } catch (RuntimeException re) {
        /* ignore exception */
        }
        if (invokeWorkaroundWhileBugIsOpen) {
            log.warning("Skipping assertion: " + "Tail of rhsmcertd log contains the expected restart message '" + healMsg + "'.");
            healMsgAssert = false;
        }
        if (healMsgAssert)
            Assert.assertTrue(rhsmcertdLogResult.contains(healMsg), "Tail of rhsmcertd log contains the expected restart message '" + healMsg + "'.");
        if (certMsgAssert)
            Assert.assertTrue(rhsmcertdLogResult.contains(certMsg), "Tail of rhsmcertd log contains the expected restart message '" + certMsg + "'.");
    }
    // restore the original splay configuration
    if (originalSplayConfig != null) {
        log.warning("Restoring the disabled rhsmcertd.splay to it original configuration '" + originalSplayConfig + "' ...");
        try {
            updateConfFileParameter(rhsmConfFile, "rhsmcertd", "splay", originalSplayConfig);
        } catch (IOException e) {
            Assert.fail(e.getMessage());
        }
    }
}
Also used : BigInteger(java.math.BigInteger) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SkipException(org.testng.SkipException) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException)

Example 99 with BugzillaAPIException

use of com.redhat.qe.auto.bugzilla.BugzillaAPIException in project rhsm-qe by RedHatQE.

the class SubscriptionManagerTasks method subscribe_.

/**
 * subscribe WITHOUT asserting results
 * @param noproxy TODO
 */
public SSHCommandResult subscribe_(Boolean auto, String servicelevel, List<String> poolIds, List<String> productIds, List<String> regtokens, String quantity, String email, String locale, String file, String proxy, String proxyuser, String proxypassword, String noproxy) {
    // assemble the command
    String command = subscribeCommand(auto, servicelevel, poolIds, productIds, regtokens, quantity, email, locale, file, proxy, proxyuser, proxypassword, noproxy);
    // run command without asserting results
    SSHCommandResult sshCommandResult = sshCommandRunner.runCommandAndWait(command);
    logRuntimeErrors(sshCommandResult);
    // TEMPORARY WORKAROUND FOR BUG
    // 'SubscribeCommand' object has no attribute 'sorter'
    String bugId = "981689";
    boolean invokeWorkaroundWhileBugIsOpen = true;
    if (sshCommandResult.getStderr().trim().equals("'SubscribeCommand' object has no attribute 'sorter'") || sshCommandResult.getStderr().trim().equals("'AttachCommand' object has no attribute 'sorter'")) {
        try {
            if (invokeWorkaroundWhileBugIsOpen && BzChecker.getInstance().isBugOpen(bugId)) {
                log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId).toString() + " Bugzilla " + bugId + ".  (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId + ")");
                SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId);
            } else {
                invokeWorkaroundWhileBugIsOpen = false;
            }
        } catch (BugzillaAPIException be) {
        /* ignore exception */
        } catch (RuntimeException re) {
        /* ignore exception */
        }
        if (invokeWorkaroundWhileBugIsOpen) {
            throw new SkipException("All tests that attempt to subscribe are blockedByBug '" + bugId + "'.");
        }
    }
    return sshCommandResult;
}
Also used : SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) SkipException(org.testng.SkipException) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException)

Example 100 with BugzillaAPIException

use of com.redhat.qe.auto.bugzilla.BugzillaAPIException in project rhsm-qe by RedHatQE.

the class SubscriptionManagerTasks method registerToRhnClassic_.

/**
 * Call rhnreg_ks without asserting any results
 * @param rhnUsername - rhnreg_ks username
 * @param rhnPassword - rhnreg_ks password
 * @param rhnHostname
 * @return SSHCommandResult containing stdout stderr and exitCode
 */
public SSHCommandResult registerToRhnClassic_(String rhnUsername, String rhnPassword, String rhnHostname) {
    String command;
    String profileName = "rhsm-automation." + hostname;
    // avoid creating a duplicate registration and consequently exhausting orphaned entitlements
    // delete all existing rhn registrations under this profileName
    deleteRhnSystemsRegisteredByName(rhnUsername, rhnPassword, rhnHostname, profileName);
    // register to RHN Classic
    // [root@jsefler-onprem-5server ~]# rhnreg_ks --serverUrl=https://xmlrpc.rhn.code.stage.redhat.com/XMLRPC --username=qa@redhat.com --password=CHANGE-ME --force --norhnsd --nohardware --nopackages --novirtinfo
    // ERROR: refreshing remote package list for System Profile
    String serverUrl = rhnHostname + "/XMLRPC";
    if (!rhnHostname.startsWith("http"))
        serverUrl = "https://xmlrpc." + serverUrl;
    command = String.format("rhnreg_ks --serverUrl=%s --username=%s --password=%s --profilename=%s --force --norhnsd --nohardware --nopackages --novirtinfo", serverUrl, rhnUsername, rhnPassword, profileName);
    SSHCommandResult result = sshCommandRunner.runCommandAndWait(command);
    // ImportError: No module named i18n
    if (result.getStderr().contains("ImportError: No module named i18n")) {
        // Bug 1439363 - ImportError: No module named i18n
        String bugId = "1439363";
        boolean invokeWorkaroundWhileBugIsOpen = true;
        try {
            if (invokeWorkaroundWhileBugIsOpen && BzChecker.getInstance().isBugOpen(bugId)) {
                log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId).toString() + " Bugzilla " + bugId + ".  (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId + ")");
                SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId);
            } else {
                invokeWorkaroundWhileBugIsOpen = false;
            }
        } catch (BugzillaAPIException be) {
        /* ignore exception */
        } catch (RuntimeException re) {
        /* ignore exception */
        }
        if (invokeWorkaroundWhileBugIsOpen) {
            throw new SkipException("The remainder of this test is blocked by bug " + bugId + ".  There is no workaround.");
        }
    }
    // ImportError: No module named tb
    if (result.getStderr().contains("ImportError: No module named tb")) {
        // Bug 1439139 - [RHEL7.4] rhn_check - ImportError: No module named i18n
        String bugId = "1439139";
        boolean invokeWorkaroundWhileBugIsOpen = true;
        try {
            if (invokeWorkaroundWhileBugIsOpen && BzChecker.getInstance().isBugOpen(bugId)) {
                log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId).toString() + " Bugzilla " + bugId + ".  (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId + ")");
                SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId);
            } else {
                invokeWorkaroundWhileBugIsOpen = false;
            }
        } catch (BugzillaAPIException be) {
        /* ignore exception */
        } catch (RuntimeException re) {
        /* ignore exception */
        }
        if (invokeWorkaroundWhileBugIsOpen) {
            throw new SkipException("The remainder of this test is blocked by bug " + bugId + ".  There is no workaround.");
        }
    }
    return result;
}
Also used : SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) SkipException(org.testng.SkipException) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException)

Aggregations

BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)134 Test (org.testng.annotations.Test)91 SkipException (org.testng.SkipException)89 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)88 SSHCommandResult (com.redhat.qe.tools.SSHCommandResult)77 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)55 ArrayList (java.util.ArrayList)44 SubscriptionPool (rhsm.data.SubscriptionPool)28 File (java.io.File)23 ProductSubscription (rhsm.data.ProductSubscription)23 ProductCert (rhsm.data.ProductCert)22 JSONObject (org.json.JSONObject)20 EntitlementCert (rhsm.data.EntitlementCert)16 InstalledProduct (rhsm.data.InstalledProduct)14 BigInteger (java.math.BigInteger)13 List (java.util.List)12 ConsumerCert (rhsm.data.ConsumerCert)11 SyndFeed (com.sun.syndication.feed.synd.SyndFeed)10 Calendar (java.util.Calendar)10 HashMap (java.util.HashMap)10