Search in sources :

Example 71 with EntitlementCert

use of rhsm.data.EntitlementCert in project rhsm-qe by RedHatQE.

the class EventTests method testPoolModifiedAndEntitlementModified.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-26757", "RHEL7-52091" }, 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 = "subscription-manager: events: Pool Modified and Entitlement Modified is sent over an RSS atom feed.", groups = { "Tier3Tests", "blockedByBug-721141", "PoolModifiedAndEntitlementModified_Test", "blockedByBug-645597", "blockedByBug-1303242", "blockedByBug-1500837", "blockedByBug-1500843" }, dependsOnGroups = { "EntitlementCreated_Test" }, enabled = true)
public // @ImplementsTCMS(id="")
void testPoolModifiedAndEntitlementModified() throws Exception {
    if (server == null)
        throw new SkipException("This test requires an SSH connection to the candlepin server.");
    // get the owner and consumer feeds before we test the firing of a new event
    ConsumerCert consumerCert = clienttasks.getCurrentConsumerCert();
    String ownerKey = CandlepinTasks.getOwnerKeyOfConsumerId(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, consumerCert.consumerid);
    // get the number of subscriptions this owner owns
    // JSONArray jsonSubscriptions = new JSONArray(CandlepinTasks.getResourceUsingRESTfulAPI(serverHostname,serverPort,serverPrefix,clientusername,clientpassword,"/owners/"+ownerKey+"/subscriptions"));
    // find the first pool id of a currently consumed product
    List<ProductSubscription> consumedProductSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
    ProductSubscription originalConsumedProductSubscription = consumedProductSubscriptions.get(0);
    testPool = clienttasks.getSubscriptionPoolFromProductSubscription(originalConsumedProductSubscription, sm_clientUsername, sm_clientPassword);
    Calendar originalStartDate = (Calendar) originalConsumedProductSubscription.startDate.clone();
    EntitlementCert originalEntitlementCert = clienttasks.getEntitlementCertCorrespondingToProductSubscription(originalConsumedProductSubscription);
    originalStartDate = (Calendar) originalEntitlementCert.validityNotBefore.clone();
    SyndFeed oldFeed = CandlepinTasks.getSyndFeed(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl);
    SyndFeed oldOwnerFeed = CandlepinTasks.getSyndFeedForOwner(ownerKey, sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl);
    SyndFeed oldConsumerFeed = CandlepinTasks.getSyndFeedForConsumer(/*ownerKey,*/
    consumerCert.consumerid, sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl);
    // fire an modified pool event (and subsequently a modified entitlement event because the pool was modified thereby requiring an entitlement update dropped to the consumer)
    log.info("To fire a modified pool event (and subsequently a modified entitlement event because the pool is already subscribed too), we will modify pool '" + testPool.poolId + "' by subtracting one month from startdate...");
    Calendar newStartDate = (Calendar) originalStartDate.clone();
    newStartDate.add(Calendar.MONTH, -1);
    if (false) {
        // the following block was used prior to candlepin-2.0.0 and replaced by CandlepinTasks.updateSubscriptionAndRefreshPoolsUsingRESTfulAPI which I think will also work for pre candlepin-2.0.0, but is untested.  <== TODO
        updateSubscriptionPoolDatesOnDatabase(testPool, newStartDate, null);
        log.info("Now let's refresh the subscription pools to expose the POOL MODIFIED event...");
        JSONObject jobDetail = CandlepinTasks.refreshPoolsUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, ownerKey);
        jobDetail = CandlepinTasks.waitForJobDetailStateUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, jobDetail, "FINISHED", 10 * 1000, 3);
    } else
        /*OLD*/
        CandlepinTasks.updateSubscriptionDatesAndRefreshPoolsUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, CandlepinTasks.getSubscriptionIdForPoolId(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, testPool.poolId), newStartDate, null);
    // NEW TODO CandlepinTasks.updateSubscriptionPoolDatesUsingRESTfulAPI(sm_serverAdminUsername,sm_serverAdminPassword,sm_serverUrl, testPool.poolId,newStartDate,null);
    // assert the consumer feed...
    List<String> newEventTitles = new ArrayList<String>();
    // newEventTitles.add("ENTITLEMENT MODIFIED");
    assertTheNewConsumerFeed(ownerKey, consumerCert.consumerid, oldConsumerFeed, newEventTitles);
    // assert the owner feed...
    // //assertTheNewOwnerFeed(ownerKey, oldOwnerFeed, new String[]{"ENTITLEMENT MODIFIED", "POOL MODIFIED"});
    // for (int s=0; s<jsonSubscriptions.length(); s++) newEventTitles.add("POOL MODIFIED");		// NOTE: This is troublesome because the number of POOL MODIFIED events is not this predictable especially when the pool (which is randomly chosen) is a virt pool
    // assertTheNewOwnerFeed(ownerKey, oldOwnerFeed, newEventTitles);
    newEventTitles.add("POOL MODIFIED");
    assertTheNewOwnerFeedContains(ownerKey, oldOwnerFeed, newEventTitles);
    // assert the feed...
    // //assertTheNewFeed(oldFeed, new String[]{"ENTITLEMENT MODIFIED", "POOL MODIFIED"});
    // assertTheNewFeed(oldFeed, newEventTitles);
    assertTheNewFeedContains(oldFeed, newEventTitles);
    log.info("Now let's refresh the client's entitlements to expose the ENTITLEMENT MODIFIED event...");
    clienttasks.refresh(null, null, null, null);
    // COMPLIANCE CREATED events were added to support gutterball
    newEventTitles.add("COMPLIANCE CREATED");
    newEventTitles.add("ENTITLEMENT MODIFIED");
    // assert the feed...
    assertTheNewFeedContains(oldFeed, newEventTitles);
    // assert the owner feed...
    assertTheNewOwnerFeedContains(ownerKey, oldOwnerFeed, newEventTitles);
    // assert the consumer feed...
    newEventTitles.remove("POOL MODIFIED");
    // assertTheNewConsumerFeed(ownerKey, consumerCert.consumerid, oldConsumerFeed, newEventTitles);
    assertTheNewConsumerFeedIgnoringEventTitles(ownerKey, consumerCert.consumerid, oldConsumerFeed, newEventTitles.toArray(new String[] {}), new HashSet<String>() {

        {
            add("COMPLIANCE CREATED");
        }
    });
    // TEMPORARY WORKAROUND FOR BUG
    boolean invokeWorkaroundWhileBugIsOpen = true;
    Calendar now = Calendar.getInstance();
    try {
        String bugId = "883486";
        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("The workaround while this bug is open is to compensate the expected consumed product subscription start date for daylight savings.");
        // adjust the expected entitlement dates for daylight savings time (changed by https://github.com/candlepin/subscription-manager/pull/385)
        // now.get(Calendar.DST_OFFSET) will equal 0 in the winter StandardTime; will equal 1000*60*60 in the summer DaylightSavingsTime (when the local time zone observes DST)
        newStartDate.add(Calendar.MILLISECOND, now.get(Calendar.DST_OFFSET) - newStartDate.get(Calendar.DST_OFFSET));
        newStartDate.add(Calendar.MILLISECOND, now.get(Calendar.DST_OFFSET) - newStartDate.get(Calendar.DST_OFFSET));
    }
    // END OF WORKAROUND
    // ProductSubscription newConsumedProductSubscription = ProductSubscription.findFirstInstanceWithMatchingFieldFromList("serialNumber", originalConsumedProductSubscription.serialNumber, clienttasks.getCurrentlyConsumedProductSubscriptions());	// can't do this because the serialNumber changes after the pool and entitlement have been modified
    ProductSubscription newConsumedProductSubscription = ProductSubscription.findFirstInstanceWithMatchingFieldFromList("productId", originalConsumedProductSubscription.productId, clienttasks.getCurrentlyConsumedProductSubscriptions());
    // AN org.xmlpull.v1.XmlPullParserException IS THROWN WHEN THIS FAILS: Assert.assertEquals(newConsumedProductSubscription.startDate, newStartDate, "After modifying pool '"+testPool.poolId+"' by subtracting one month from startdate and refreshing entitlements, the consumed product subscription now reflects the modified field.");
    Assert.assertEquals(ProductSubscription.formatDateString(newConsumedProductSubscription.startDate), ProductSubscription.formatDateString(newStartDate), "After modifying pool '" + testPool.poolId + "' by subtracting one month from startdate and refreshing entitlements, the consumed product subscription now reflects the modified field.");
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) Calendar(java.util.Calendar) ProductSubscription(rhsm.data.ProductSubscription) ArrayList(java.util.ArrayList) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) JSONObject(org.json.JSONObject) SkipException(org.testng.SkipException) ConsumerCert(rhsm.data.ConsumerCert) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 72 with EntitlementCert

use of rhsm.data.EntitlementCert 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 73 with EntitlementCert

use of rhsm.data.EntitlementCert in project rhsm-qe by RedHatQE.

the class GoldenTicketTests method testRevokingContentAccessModeOnOwnerRemovesEntitlement.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-47905", "RHEL7-96743" }, 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 revoking contentAccessMode set on the owner removes extra entitlement", groups = { "Tier3Tests", "blockedByBug-1448855" }, enabled = true)
public void testRevokingContentAccessModeOnOwnerRemovesEntitlement() 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);
    }
    SSHCommandResult repoResult = clienttasks.repos(false, false, true, (String) null, null, null, null, null, null);
    Assert.assertNotEquals(repoResult.getStdout().toString().trim(), ExpectedRepoMsg);
    // 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");
    // now revoke the contentAccessMode set on the owner
    CandlepinTasks.setAttributeForOrg(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, org, attributeName, "entitlement");
    clienttasks.refresh(null, null, null, null);
    repoResult = clienttasks.repos(false, false, true, (String) null, null, null, null, null, null);
    String ExpectedRepoMsgAfterRevoke = "This system has no repositories available through subscriptions.";
    Assert.assertEquals(repoResult.getStdout().toString().trim(), ExpectedRepoMsgAfterRevoke);
    List<EntitlementCert> entitlementCertsAfterRevoke = clienttasks.getCurrentEntitlementCerts();
    // assert that extra entitlement is now revoked
    Assert.assertTrue(entitlementCertsAfterRevoke.size() == 0, "No extra entitlement granted by the org/environment is present");
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 74 with EntitlementCert

use of rhsm.data.EntitlementCert in project rhsm-qe by RedHatQE.

the class SubscriptionManagerTasks method getEntitlementCertCorrespondingToSubscribedPool.

public EntitlementCert getEntitlementCertCorrespondingToSubscribedPool(SubscriptionPool subscribedPool) {
    for (File entitlementCertFile : getCurrentEntitlementCertFiles("-t")) {
        EntitlementCert entitlementCert = getEntitlementCertFromEntitlementCertFile(entitlementCertFile);
        try {
            JSONObject jsonEntitlement = CandlepinTasks.getEntitlementUsingRESTfulAPI(this.currentlyRegisteredUsername, this.currentlyRegisteredPassword, candlepinUrl, entitlementCert.id);
            JSONObject jsonPool = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(this.currentlyRegisteredUsername, this.currentlyRegisteredPassword, candlepinUrl, jsonEntitlement.getJSONObject("pool").getString("href")));
            if (jsonPool.getString("id").equals(subscribedPool.poolId)) {
                return entitlementCert;
            }
        } catch (Exception e) {
            e.printStackTrace();
            Assert.fail(e.getMessage());
        }
    }
    // not found
    return null;
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) JSONObject(org.json.JSONObject) File(java.io.File) SkipException(org.testng.SkipException) JSONException(org.json.JSONException) IOException(java.io.IOException) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException)

Example 75 with EntitlementCert

use of rhsm.data.EntitlementCert in project rhsm-qe by RedHatQE.

the class SubscriptionManagerTasks method getCurrentSerialMapToSubscriptionPools.

/**
 * @return a map of serialNumber to SubscriptionPool pairs.  The SubscriptionPool is the source from where the serialNumber for the currentlyConsumedProductSubscriptions came from.
 * @throws Exception
 */
// public Map<Long, SubscriptionPool> getCurrentSerialMapToSubscriptionPools() {
// sshCommandRunner.runCommandAndWait("find "+entitlementCertDir+" -name '*.pem' | xargs -I '{}' openssl x509 -in '{}' -noout -text");
// String certificates = sshCommandRunner.getStdout();
// return SubscriptionPool.parseCerts(certificates);
// }
public Map<BigInteger, SubscriptionPool> getCurrentSerialMapToSubscriptionPools(String username, String password) throws Exception {
    Map<BigInteger, SubscriptionPool> serialMapToSubscriptionPools = new HashMap<BigInteger, SubscriptionPool>();
    // String prefix = getConfFileParameter(rhsmConfFile, "prefix");
    for (EntitlementCert entitlementCert : getCurrentEntitlementCerts()) {
        JSONObject jsonEntitlement = CandlepinTasks.getEntitlementUsingRESTfulAPI(username, password, candlepinUrl, entitlementCert.id);
        String poolHref = jsonEntitlement.getJSONObject("pool").getString("href");
        JSONObject jsonPool = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(username, password, candlepinUrl, poolHref));
        String subscriptionName = jsonPool.getString("productName");
        String productId = jsonPool.getString("productId");
        String poolId = jsonPool.getString("id");
        // = jsonPool.getString("quantity");
        String quantity = Integer.toString(jsonPool.getInt("quantity"));
        // a pool quantity of -1 provided unlimited entitlements
        if (jsonPool.getInt("quantity") < 0)
            quantity = "Unlimited";
        String endDate = jsonPool.getString("endDate");
        Boolean multiEntitlement = CandlepinTasks.isPoolProductMultiEntitlement(username, password, candlepinUrl, poolId);
        SubscriptionPool fromPool = new SubscriptionPool(subscriptionName, productId, poolId, quantity, null, multiEntitlement, endDate);
        serialMapToSubscriptionPools.put(entitlementCert.serialNumber, fromPool);
    }
    return serialMapToSubscriptionPools;
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) BigInteger(java.math.BigInteger) SubscriptionPool(rhsm.data.SubscriptionPool)

Aggregations

EntitlementCert (rhsm.data.EntitlementCert)94 Test (org.testng.annotations.Test)63 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)58 SkipException (org.testng.SkipException)39 ArrayList (java.util.ArrayList)38 File (java.io.File)36 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)35 SubscriptionPool (rhsm.data.SubscriptionPool)33 SSHCommandResult (com.redhat.qe.tools.SSHCommandResult)30 JSONObject (org.json.JSONObject)29 ContentNamespace (rhsm.data.ContentNamespace)26 ProductCert (rhsm.data.ProductCert)23 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)17 BigInteger (java.math.BigInteger)17 ProductSubscription (rhsm.data.ProductSubscription)17 List (java.util.List)16 Calendar (java.util.Calendar)11 HashMap (java.util.HashMap)11 ProductNamespace (rhsm.data.ProductNamespace)11 HashSet (java.util.HashSet)8