Search in sources :

Example 91 with EntitlementCert

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

the class RefreshTests method testRefreshEntitlements.

// Test methods ***********************************************************************
@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-20023", "RHEL7-51040" }, 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 = "Tier1")
@Test(description = "subscription-manager-cli: refresh and verify entitlements are updated", groups = { "Tier1Tests", "RefreshEntitlements_Test", "blockedByBug-907638", "blockedByBug-962520", "blockedByBug-1366301" }, enabled = true)
// http://gibson.usersys.redhat.com/agilo/ticket/4022
@ImplementsNitrateTest(caseId = 64182)
public void testRefreshEntitlements() {
    // Start fresh by unregistering and registering...
    log.info("Start fresh by unregistering and registering...");
    clienttasks.unregister(null, null, null, null);
    clienttasks.getCurrentConsumerId(clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, null, false, null, null, null, null));
    // make sure the certFrequency will not affect the results of this test
    log.info("Change the certFrequency to a large value to assure the rhsmcertd does not interfere with this test.");
    clienttasks.restart_rhsmcertd(60, null, true);
    // Subscribe to a randomly available pool...
    log.info("Subscribe to a randomly available pool...");
    List<SubscriptionPool> pools = clienttasks.getCurrentlyAvailableSubscriptionPools();
    if (pools.isEmpty())
        throw new SkipException("There are no available pools at all to get entitlements from.  Cannot attempt this test.");
    // randomly pick a pool
    SubscriptionPool pool = pools.get(randomGenerator.nextInt(pools.size()));
    clienttasks.subscribeToSubscriptionPool(pool);
    // remember the currently consumed product subscriptions (and entitlement certs)
    List<ProductSubscription> consumedProductSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
    List<EntitlementCert> entitlementCerts = clienttasks.getCurrentEntitlementCerts();
    // remove your entitlements
    log.info("Removing the entitlement certs...");
    clienttasks.removeAllCerts(false, true, false);
    Assert.assertEquals(clienttasks.getCurrentEntitlementCerts().size(), 0, "Entitlements have been removed.");
    Assert.assertEquals(clienttasks.getCurrentlyConsumedProductSubscriptions().size(), 0, "Consumed subscription pools do NOT exist after entitlements have been removed.");
    // mark the rhsm.log file
    String rhsmLogMarker = System.currentTimeMillis() + " Testing RefreshEntitlements_Test...";
    RemoteFileTasks.markFile(client, clienttasks.rhsmLogFile, rhsmLogMarker);
    // The following was implemented by to temporarily avoid an IT blocked candlepin end point as described by https://bugzilla.redhat.com/show_bug.cgi?id=1366301#c2
    // python-rhsm-1.17.7-1 commits...
    // python-rhsm RHEL7.3 commit 2debbb619cba05727f44f6823ea60a2aa6b3e269 1366301: Entitlement regeneration no longer propagates server errors
    // python-rhsm RHEL7.3 commit cd43496585d5990500c4b272af9c4fa5e28661aa Update fix to include BadStatusLine responses from the server
    // python-rhsm RHEL7.3 commit c021772a21c34d07542b8e9a01dcfadfc223624b Ensure both cert regen methods succeed despite BadStatusLine from server
    // subscription-manager RHEL7.3 commit a07c9d7b890034a2e8e7e39fe32782b69def1736 1366301: Entitlement regeneration failure no longer aborts refresh
    // 2016-08-30 08:23:19,642 [DEBUG] subscription-manager:20105:MainThread @connection.py:573 - Making request: PUT /subscription/consumers/b29e0643-44b4-4d75-9912-47cf127be7ca/certificates?lazy_regen=true
    // 2016-08-30 08:23:20,070 [DEBUG] subscription-manager:20105:MainThread @connection.py:602 - Response: status=404
    // 2016-08-30 08:23:20,071 [DEBUG] subscription-manager:20105:MainThread @connection.py:1365 - Unable to refresh entitlement certificates: Service currently unsupported.
    // 2016-08-30 08:23:20,071 [DEBUG] subscription-manager:20105:MainThread @connection.py:1366 - Server error attempting a PUT to /subscription/consumers/b29e0643-44b4-4d75-9912-47cf127be7ca/certificates?lazy_regen=true returned status 404
    // 2016-08-30 08:23:20,072 [DEBUG] subscription-manager:20105:MainThread @managercli.py:652 - Warning: Unable to refresh entitlement certificates; service likely unavailable
    // subscription-manager RHEL7.3 commit a07c9d7b890034a2e8e7e39fe32782b69def1736 1366301: Entitlement regeneration failure no longer aborts refresh
    String warningMsg = "Warning: Unable to refresh entitlement certificates; service likely unavailable";
    // "Unable to refresh entitlement certificates: Service currently unsupported."	// python-rhsm RHEL7.3 commit 2debbb619cba05727f44f6823ea60a2aa6b3e269 1366301: Entitlement regeneration no longer propagates server errors
    // refresh
    log.info("Refresh...");
    clienttasks.refresh(null, null, null, null);
    // was subscription-manager "Unable to refresh" as a result of a 404 trying to PUT?
    String rhsmLogTail = RemoteFileTasks.getTailFromMarkedFile(client, clienttasks.rhsmLogFile, rhsmLogMarker, "Unable to refresh");
    boolean unableToRefresh = rhsmLogTail.contains(warningMsg);
    // if yes, then refresh behavior prior to Bug 1360909 will be tested
    if (unableToRefresh)
        log.warning("Due to encountered warning '" + warningMsg + "', the original refresh behavior prior to Bug 1360909 will be asserted...");
    // Assert the entitlement certs are restored after the refresh
    log.info("After running refresh, assert that the entitlement certs are restored...");
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.17.10-1") && !unableToRefresh) {
        // 1360909: Added functionality for regenerating entitlement certificates
        // after the for Bug 1360909 - Clients unable to access newly released content (Satellite 6.2 GA)
        // subscription-manager refresh will grant a new entitlement serial, but the contents are usually identical (unless a content set has been updated)
        // assert nearly the same entitlement was restored (should only differ by serial number)
        List<EntitlementCert> entitlementCertsAfterRefresh = clienttasks.getCurrentEntitlementCerts();
        List<ProductSubscription> consumedProductSubscriptionsAfterRefresh = clienttasks.getCurrentlyConsumedProductSubscriptions();
        Assert.assertEquals(entitlementCertsAfterRefresh.size(), entitlementCerts.size(), "The number of entitlement certs granted after refresh should match the number before refresh.");
        Assert.assertEquals(consumedProductSubscriptionsAfterRefresh.size(), consumedProductSubscriptions.size(), "The number of consumed Product Subscriptions after refresh should match the number before refresh.");
        // The following asserts assume that one one entitlement was granted from a single pool
        Assert.assertEquals(entitlementCertsAfterRefresh.size(), 1, "The remaining assertions in this test assume that an entitlement from only one pool was subscribed.  (If this test fails, then this test requires logic updates.)");
        Assert.assertTrue(!entitlementCertsAfterRefresh.get(0).serialString.equals(entitlementCerts.get(0).serialString), "Serial '" + entitlementCertsAfterRefresh.get(0).serialString + "' in the refreshed entitlement should NOT match serial '" + entitlementCerts.get(0).serialString + "' from the original entitlement.");
        Assert.assertEquals(entitlementCertsAfterRefresh.get(0).version, entitlementCerts.get(0).version, "Version in the refreshed entitlement should match the version from the original entitlement.");
        Assert.assertEquals(entitlementCertsAfterRefresh.get(0).validityNotBefore, entitlementCerts.get(0).validityNotBefore, "ValidityNotBefore in the refreshed entitlement should match the ValidityNotBefore from the original entitlement.");
        Assert.assertEquals(entitlementCertsAfterRefresh.get(0).validityNotAfter, entitlementCerts.get(0).validityNotAfter, "ValidityNotAfter in the refreshed entitlement should match the ValidityNotAfter from the original entitlement.");
        Assert.assertEquals(entitlementCertsAfterRefresh.get(0).orderNamespace, entitlementCerts.get(0).orderNamespace, "Order information in the refreshed entitlement should match the order information from the original entitlement.");
        Assert.assertEquals(entitlementCertsAfterRefresh.get(0).productNamespaces, entitlementCerts.get(0).productNamespaces, "Product information in the refreshed entitlement should match the product information from the original entitlement. (IF THIS FAILS, THEN THERE WAS AN UPSTREAM PROVIDED PRODUCT MODIFICATION LIKE THE SCENARIO IN BUG 1360909. HIGHLY UNLIKELY BETWEEN NOW AND THE START OF THIS TEST.)");
        Assert.assertEquals(entitlementCertsAfterRefresh.get(0).contentNamespaces, entitlementCerts.get(0).contentNamespaces, "Content information in the refreshed entitlement should match the content information from the original entitlement. (IF THIS FAILS, THEN THERE WAS AN UPSTREAM CONTENT MODIFICATION LIKE THE SCENARIO IN BUG 1360909. HIGHLY UNLIKELY BETWEEN NOW AND THE START OF THIS TEST.)");
        Assert.assertEquals(consumedProductSubscriptionsAfterRefresh.size(), 1, "The remaining assertions in this test assume that an only one pool was subscribed.  (If this test fails, then this test requires logic updates.)");
        Assert.assertTrue(!consumedProductSubscriptionsAfterRefresh.get(0).serialNumber.equals(consumedProductSubscriptions.get(0).serialNumber), "Serial Number '" + consumedProductSubscriptionsAfterRefresh.get(0).serialNumber + "' in the refreshed product subscription should NOT match serial number '" + consumedProductSubscriptions.get(0).serialNumber + "' from the original product subscription.");
        Assert.assertEquals(consumedProductSubscriptionsAfterRefresh.get(0).poolId, consumedProductSubscriptions.get(0).poolId, "PoolId in the refreshed consumed product subscription should match the pool id from the original consumed product subscription.");
    // TODO continue asserting equality between fields of the consumedProductSubscriptions (all should be equal except serialNumber which was already asserted above)
    } else {
        // assert the exact same entitlement was restored
        Assert.assertEquals(clienttasks.getCurrentEntitlementCerts(), entitlementCerts, "Original entitlements have been restored.");
        Assert.assertEquals(clienttasks.getCurrentlyConsumedProductSubscriptions(), consumedProductSubscriptions, "Original consumed product subscriptions have been restored.");
    }
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) ProductSubscription(rhsm.data.ProductSubscription) SkipException(org.testng.SkipException) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 92 with EntitlementCert

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

the class RegisterTests method testReregisterWithConsumerIdShouldAutomaticallyRefreshEntitlements.

/**
 * https://tcms.engineering.redhat.com/case/72845/?from_plan=2476
 *
 * @throws Exception
 * @throws JSONException
 */
@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36530", "RHEL7-51303" }, 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 = "Tier2")
@Test(description = "register with existing consumerid should automatically refresh entitlements\n" + "Actions:\n" + "\n" + "    * register with username and password and remember the consumerid\n" + "    * subscribe to one or more subscriptions\n" + "    * list the consumed subscriptions and remember them\n" + "    * clean system\n" + "    * assert that there are no entitlements on the system\n" + "    * register with same username, password and existing consumerid\n" + "    * assert that originally consumed subscriptions are once again being consumed\n" + "\n" + "\t\n" + "Expected Results:\n" + "\n" + "    * when registering a new system to an already existing consumer, all of the existing consumers entitlement certs should be downloaded to the new system", groups = { "Tier2Tests" }, enabled = true)
@ImplementsNitrateTest(caseId = 72845)
public void testReregisterWithConsumerIdShouldAutomaticallyRefreshEntitlements() throws JSONException, Exception {
    // register with username and password and remember the consumerid
    clienttasks.unregister(null, null, null, null);
    String consumerId = clienttasks.getCurrentConsumerId(clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, null, false, null, null, null, null));
    // subscribe to one or more subscriptions
    // // subscribe to a random pool
    // List<SubscriptionPool> pools = clienttasks.getCurrentlyAvailableSubscriptionPools();
    // SubscriptionPool pool = pools.get(randomGenerator.nextInt(pools.size())); // randomly pick a pool
    // clienttasks.subscribeToSubscriptionPoolUsingPoolId(pool);
    clienttasks.subscribeToTheCurrentlyAvailableSubscriptionPoolsCollectively();
    // list the consumed subscriptions and remember them
    List<ProductSubscription> originalConsumedProductSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
    // also remember the current entitlement certs
    List<EntitlementCert> originalEntitlementCerts = clienttasks.getCurrentEntitlementCerts();
    // clean system
    clienttasks.clean();
    // assert that there are no entitlements on the system
    // Assert.assertTrue(clienttasks.getCurrentlyConsumedProductSubscriptions().isEmpty(),"There are NO consumed Product Subscriptions on this system after running clean");
    Assert.assertTrue(clienttasks.getCurrentEntitlementCerts().isEmpty(), "There are NO Entitlement Certs on this system after running clean");
    // register with same username, password and existing consumerid
    // Note: no need to register with force as running clean wipes system of all local registration data
    clienttasks.register(sm_clientUsername, sm_clientPassword, null, null, null, null, consumerId, null, null, null, (String) null, null, null, null, null, false, null, null, null, null);
    // assert that originally consumed subscriptions are once again being consumed
    List<ProductSubscription> consumedProductSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
    Assert.assertEquals(consumedProductSubscriptions.size(), originalConsumedProductSubscriptions.size(), "The number of consumed Product Subscriptions after registering to an existing consumerid matches his original count.");
    for (ProductSubscription productSubscription : consumedProductSubscriptions) {
        Assert.assertContains(originalConsumedProductSubscriptions, productSubscription);
    }
    // assert that original entitlement certs are once on the system
    List<EntitlementCert> entitlementCerts = clienttasks.getCurrentEntitlementCerts();
    Assert.assertEquals(entitlementCerts.size(), originalEntitlementCerts.size(), "The number of Entitlement Certs on the system after registering to an existing consumerid matches his original count.");
    for (EntitlementCert entitlementCert : entitlementCerts) {
        Assert.assertContains(originalEntitlementCerts, entitlementCert);
    }
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) ProductSubscription(rhsm.data.ProductSubscription) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 93 with EntitlementCert

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

the class ServiceLevelTests method testInstalledProductsProvidedByAvailablePoolsWithExemptServiceLevelAreAutoSubscribedRegardlessOfServiceLevel.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-21703", "RHEL7-51027" }, 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 = "Tier1")
@Test(description = "installed products provided by available pools with an exempt service level should be auto-subscribed regardless of what service level is specified (or is not specified)", groups = { "Tier1Tests", "blockedByBug-818319", "blockedByBug-859652", "blockedByBug-919700" }, dataProvider = "getExemptInstalledProductAndServiceLevelData", enabled = true)
@ImplementsNitrateTest(caseId = 157229)
public void testInstalledProductsProvidedByAvailablePoolsWithExemptServiceLevelAreAutoSubscribedRegardlessOfServiceLevel(Object bugzilla, String installedProductId, String serviceLevel) {
    // randomize the case of the service level
    String seRvICElevEl = randomizeCaseOfCharactersInString(serviceLevel);
    log.info("This test will be conducted with a randomized serviceLevel value: " + seRvICElevEl);
    // TEMPORARY WORKAROUND FOR BUG
    if (sm_serverType.equals(CandlepinType.hosted)) {
        String bugId = "818319";
        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) {
            seRvICElevEl = serviceLevel;
            log.warning("This test will NOT be conducted with a randomized serviceLevel value.  Testing with serviceLevel: " + seRvICElevEl);
        }
    }
    // END OF WORKAROUND
    // register with autosubscribe and a randomize case serviceLevel
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, true, seRvICElevEl, null, (List<String>) null, null, null, null, true, false, null, null, null, null);
    // assert that the installed ProductId is "Subscribed"
    InstalledProduct installedProduct = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productId", installedProductId, clienttasks.getCurrentlyInstalledProducts());
    Assert.assertEquals(installedProduct.status, "Subscribed", "After registering with autosubscribe and serviceLevel '" + seRvICElevEl + "' the following installed exempt product should be subscribed: " + installedProduct);
    // EXTRA CREDIT: assert that the consumed ProductSubscription that provides the installed exempt product is among the known exempt service levels.
    // WARNING: THIS MAY NOT BE AN APPROPRIATE ASSERTION WHEN THE EXEMPT PRODUCT HAPPENS TO ALSO BE PROVIDED BY A SUBSCRIPTION THAT COINCIDENTY PROVIDES ANOTHER INSTALLED PRODUCT
    List<ProductSubscription> productSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
    for (EntitlementCert entitlementCert : clienttasks.getCurrentEntitlementCerts()) {
        for (ProductNamespace productNamespace : entitlementCert.productNamespaces) {
            if (productNamespace.id.equals(installedProductId)) {
                BigInteger serialNumber = clienttasks.getSerialNumberFromEntitlementCertFile(entitlementCert.file);
                ProductSubscription productSubscription = ProductSubscription.findFirstInstanceWithMatchingFieldFromList("serialNumber", serialNumber, productSubscriptions);
                Assert.assertTrue(sm_exemptServiceLevelsInUpperCase.contains(productSubscription.serviceLevel.toUpperCase()), "Installed exempt product '" + installedProduct + "' is entitled by consumed productSubscription '" + productSubscription + "' that provides one of the exempt service levels '" + sm_exemptServiceLevelsInUpperCase + "'.");
            }
        }
    }
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) InstalledProduct(rhsm.data.InstalledProduct) ProductSubscription(rhsm.data.ProductSubscription) BigInteger(java.math.BigInteger) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) ProductNamespace(rhsm.data.ProductNamespace) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 94 with EntitlementCert

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

the class ServiceLevelTests method testAutoSubscribeWithServiceLevel.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-19990", "RHEL7-51022" }, 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 = "Tier1")
@Test(description = "subscription-manager: subscribe with auto while specifying an valid service level; assert the entitlements granted match the requested service level", groups = { "Tier1Tests", "blockedByBug-859652", "blockedByBug-977321" }, // dataProvider="getAllAvailableServiceLevelData",	// 06/05/2014 takes too long; rarely reveals a bug
dataProvider = "getRandomSubsetOfAllAvailableServiceLevelData", enabled = true)
// 147971
@ImplementsNitrateTest(caseId = 157229)
public void testAutoSubscribeWithServiceLevel(Object bugzilla, String serviceLevel) throws JSONException, Exception {
    // ensure system is registered
    if (clienttasks.getCurrentConsumerId() == null)
        clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, "AutoSubscribeWithServiceLevelConsumer", null, null, null, null, (String) null, null, null, null, null, false, null, null, null, null);
    // are any products installed?
    boolean noInstalledProducts = clienttasks.getCurrentlyInstalledProducts().isEmpty();
    // remember this initial service level preference for this consumer
    String initialConsumerServiceLevel = clienttasks.getCurrentServiceLevel();
    // start fresh by returning all entitlements
    // clienttasks.unsubscribeFromAllOfTheCurrentlyConsumedProductSubscriptions();
    // may help avoid: Runtime Error No row with the given identifier exists: [org.candlepin.model.PoolAttribute#8a99f98146b4fa9d0146b7e4d5d34375] at org.hibernate.UnresolvableObjectException.throwIfNull:64
    clienttasks.unsubscribeFromTheCurrentlyConsumedSerialsCollectively();
    // autosubscribe with a valid service level
    SSHCommandResult subscribeResult = clienttasks.subscribe(true, serviceLevel, (String) null, (String) null, (String) null, null, null, null, null, null, null, null, null);
    // get the current consumer object and assert that the serviceLevel persisted
    JSONObject jsonConsumer = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/consumers/" + clienttasks.getCurrentConsumerId()));
    if (serviceLevel == null) {
        Assert.assertEquals(jsonConsumer.get("serviceLevel"), initialConsumerServiceLevel, "The consumer's serviceLevel preference should remain unchanged when calling subscribe with auto and a servicelevel of null.");
    } else if (noInstalledProducts) {
        Assert.assertEquals(jsonConsumer.get("serviceLevel"), initialConsumerServiceLevel, "The consumer's serviceLevel preference should remain unchanged when calling subscribe with auto when no products are installed because the autosubscribe process should abort thereby not attenpting a service level change.");
    } else {
        Assert.assertEquals(jsonConsumer.get("serviceLevel"), serviceLevel, "The call to subscribe with auto and a servicelevel of '" + serviceLevel + "' persisted the servicelevel setting on the current consumer object.");
    }
    // assert that each of the autosubscribed entitlements come from a pool that supports the specified service level
    List<EntitlementCert> entitlementCerts = clienttasks.getCurrentEntitlementCerts();
    if (subscribeResult.getExitCode().intValue() == 1)
        Assert.assertEquals(entitlementCerts.size(), 0, "When subscribe --auto returns an exitCode of 1, then no entitlements should have been granted.");
    for (EntitlementCert entitlementCert : entitlementCerts) {
        // tolerate entitlements granted from pools with null/no support_level regardless of the specified service level
        if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", /*TODO ">" is technically correct*/
        "2.0.2-1")) {
            // commit 9cefb6e23baefcc4ee2e14423f205edd37eecf22	// Bug 1223560 - Service levels on an activation key prevent custom products from attaching at registration if auto-attach enabled
            if (entitlementCert.orderNamespace.supportLevel == null || entitlementCert.orderNamespace.supportLevel.isEmpty()) {
                log.warning("Regardless of the consumer's service-level preference '" + initialConsumerServiceLevel + "' or the requested service-level '" + serviceLevel + "', this EntitlementCert provides a support_level of '" + entitlementCert.orderNamespace.supportLevel + "'. (New behavior modification from Bug 1223560)");
                continue;
            }
        }
        // tolerate exemptServiceLevels
        if (entitlementCert.orderNamespace.supportLevel != null && sm_exemptServiceLevelsInUpperCase.contains(entitlementCert.orderNamespace.supportLevel.toUpperCase())) {
            log.warning("After autosubscribing, this EntitlementCert provides an exempt service level '" + entitlementCert.orderNamespace.supportLevel + "'.");
            continue;
        }
        if ("".equals(serviceLevel) || (serviceLevel == null && initialConsumerServiceLevel.equals(""))) {
            log.info("When specifying a servicelevel of \"\" during an autosubscribe (or specifying a servicelevel of null and the current consumer's has no servicelevel preference), then the servicelevel of the granted entitlement certs can be anything.  This one is '" + entitlementCert.orderNamespace.supportLevel + "'.");
        } else if (serviceLevel == null && !initialConsumerServiceLevel.equals("")) {
            Assert.assertTrue(initialConsumerServiceLevel.equalsIgnoreCase(entitlementCert.orderNamespace.supportLevel), "When specifying a servicelevel of null during an autosubscribe and the current consumer has a servicelevel preference set, then the servicelevel from the orderNamespace of this granted entitlement cert (" + entitlementCert.orderNamespace.supportLevel + ") must match the current consumer's service level preference (" + initialConsumerServiceLevel + ").");
        } else {
            Assert.assertTrue(serviceLevel.equalsIgnoreCase(entitlementCert.orderNamespace.supportLevel), "Ignoring case, this autosubscribed entitlement was filled from a subscription order that provides the requested service level '" + serviceLevel + "': " + entitlementCert.orderNamespace);
        }
    }
}
Also used : JSONObject(org.json.JSONObject) EntitlementCert(rhsm.data.EntitlementCert) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

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