Search in sources :

Example 56 with TestDefinition

use of com.github.redhatqe.polarize.metadata.TestDefinition in project rhsm-qe by RedHatQE.

the class SubscribeTests method testSubscribeWithAutoMoreThanOnce.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36580", "RHEL7-51382" }, 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 = "subscription-manager: autosubscribe consumer more than once and verify we are not duplicately subscribed", groups = { "Tier2Tests", "blockedByBug-723044", "blockedByBug-743082", "blockedByBug-977321" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testSubscribeWithAutoMoreThanOnce() throws Exception {
    // before testing, make sure all the expected subscriptionPoolProductId are available
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, true, false, null, null, null, null);
    // TEMPORARY WORKAROUND
    if (Boolean.valueOf(clienttasks.getFactValue("virt.is_guest"))) {
        boolean invokeWorkaroundWhileBugIsOpen = true;
        // Bug 1198494 - Auto-heal continuously attaches subscriptions to make the system compliant on a guest machine
        String bugId = "1198494";
        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) {
            clienttasks.mapSystemAsAGuestOfItself();
        }
    }
    // END OF WORKAROUND
    // autosubscribe once
    SSHCommandResult result1 = clienttasks.subscribe(Boolean.TRUE, null, (String) null, null, null, null, null, null, null, null, null, null, null);
    List<File> entitlementCertFiles1 = clienttasks.getCurrentEntitlementCertFiles();
    List<InstalledProduct> autosubscribedProductStatusList1 = InstalledProduct.parse(result1.getStdout());
    // autosubscribe twice
    SSHCommandResult result2 = clienttasks.subscribe(Boolean.TRUE, null, (String) null, null, null, null, null, null, null, null, null, null, null);
    List<File> entitlementCertFiles2 = clienttasks.getCurrentEntitlementCertFiles();
    List<InstalledProduct> autosubscribedProductStatusList2 = InstalledProduct.parse(result2.getStdout());
    // assert results
    Assert.assertEquals(entitlementCertFiles2.size(), entitlementCertFiles1.size(), "The number of granted entitlement certs is the same after a second autosubscribe.");
    Assert.assertEquals(autosubscribedProductStatusList2.size(), autosubscribedProductStatusList1.size(), "The stdout from autosubscribe reports the same number of installed product status entries after a second autosubscribe.");
    Assert.assertTrue(autosubscribedProductStatusList1.containsAll(autosubscribedProductStatusList2), "The list of installed product status entries from a second autosubscribe is the same as the first.");
}
Also used : SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) InstalledProduct(rhsm.data.InstalledProduct) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) File(java.io.File) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 57 with TestDefinition

use of com.github.redhatqe.polarize.metadata.TestDefinition in project rhsm-qe by RedHatQE.

the class SubscribeTests method testNormalAvailablePoolsFromSubscriptionsPassTheHardwareRulesCheck.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-19982", "RHEL7-51016" }, 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: make sure the normal available pools come from subscriptions that pass the hardware rules for availability.", groups = { "Tier1Tests" }, dependsOnGroups = {}, enabled = true)
public // Note: The objective if this test is essentially the same as ListTests.EnsureHardwareMatchingSubscriptionsAreListedAsAvailable_Test() and ListTests.EnsureNonHardwareMatchingSubscriptionsAreNotListedAsAvailable_Test(), but its implementation is slightly different
void testNormalAvailablePoolsFromSubscriptionsPassTheHardwareRulesCheck() throws Exception {
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, true, false, null, null, null, null);
    // let's pretend that this system is a host consumer and simulate virt-who by mapping this virtual system as a guest of itself
    if (Boolean.valueOf(clienttasks.getFactValue("virt.is_guest")))
        clienttasks.mapSystemAsAGuestOfItself();
    subscriptionPoolProductData = getSystemSubscriptionPoolProductDataAsListOfLists(true, false);
    List<SubscriptionPool> availableSubscriptionPools = clienttasks.getCurrentlyAvailableSubscriptionPools();
    for (List<Object> subscriptionPoolProductDatum : subscriptionPoolProductData) {
        String productId = (String) subscriptionPoolProductDatum.get(0);
        SubscriptionPool subscriptionPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", productId, availableSubscriptionPools);
        // special case...
        if (subscriptionPool == null) {
            // when pool is null, another likely cause is that all of the available subscriptions from the pools are being consumed, let's check...
            for (String poolId : CandlepinTasks.getPoolIdsForProductId(sm_clientUsername, sm_clientPassword, sm_serverUrl, clienttasks.getCurrentlyRegisteredOwnerKey(), productId)) {
                int quantity = (Integer) CandlepinTasks.getPoolValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, poolId, "quantity");
                int consumed = (Integer) CandlepinTasks.getPoolValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, poolId, "consumed");
                if (consumed >= quantity) {
                    throw new SkipException("The total quantity '" + quantity + "' of subscriptions from poolId '" + poolId + "' for product '" + productId + "' are being consumed; hence this pool is appropriately not available despite a match in hardware");
                }
            }
            // another possible cause is that the pool.productAttributes.arch list on the pool is older than the subscription.product.attributes.arch
            SubscriptionPool poolFromAllAvailable = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", productId, clienttasks.getCurrentlyAllAvailableSubscriptionPools());
            if (poolFromAllAvailable != null) {
                String poolArch = (String) CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, poolFromAllAvailable.poolId, "arch");
                // Note: the arch attribute can be a comma separated list of values
                List<String> poolArches = new ArrayList<String>();
                // Note: the arch attribute can be a comma separated list of values
                poolArches.addAll(Arrays.asList(poolArch.trim().split(" *, *")));
                String subscriptionId = CandlepinTasks.getSubscriptionIdForPoolId(sm_clientUsername, sm_clientPassword, sm_serverUrl, poolFromAllAvailable.poolId);
                JSONObject jsonSubscription = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, "/subscriptions/" + subscriptionId));
                String subscriptionArch = CandlepinTasks.getResourceAttributeValue(jsonSubscription.getJSONObject("product"), "arch");
                // Note: the arch attribute can be a comma separated list of values
                List<String> subscriptionArches = new ArrayList<String>();
                // Note: the arch attribute can be a comma separated list of values
                subscriptionArches.addAll(Arrays.asList(subscriptionArch.trim().split(" *, *")));
                if (!poolArches.containsAll(subscriptionArches) || !subscriptionArches.containsAll(poolArches)) {
                    log.warning("There is an all available pool for product '" + productId + "' whose arch " + poolArches + " does not match its corresponding subscription arch " + subscriptionArches + ".  Likely, there was an upstream SKU change by dev-ops that requires an org level pool refresh.");
                }
            }
        }
        Assert.assertNotNull(subscriptionPool, "Expecting SubscriptionPool with ProductId '" + productId + "' to be available to registered user '" + sm_clientUsername + "'. (Look for warnings above to explain a failure. A pool refresh may also fix a failure.)");
    }
    for (SubscriptionPool availableSubscriptionPool : availableSubscriptionPools) {
        // skip pools that are not NORMAL (eg. BONUS, ENTITLEMENT_DERIVED, STACK_DERIVED)
        String poolType = (String) CandlepinTasks.getPoolValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, availableSubscriptionPool.poolId, "type");
        if (!poolType.equals("NORMAL")) {
            log.warning("Skipping '" + poolType + "' pool: " + availableSubscriptionPool);
            continue;
        }
        boolean productIdFound = false;
        for (List<Object> subscriptionPoolProductDatum : subscriptionPoolProductData) {
            if (availableSubscriptionPool.productId.equals((String) subscriptionPoolProductDatum.get(0))) {
                productIdFound = true;
                break;
            }
        }
        Assert.assertTrue(productIdFound, "Available SubscriptionPool '" + availableSubscriptionPool.productId + "' poolId='" + availableSubscriptionPool.poolId + "' passes the hardware rules check.");
    }
}
Also used : BigInteger(java.math.BigInteger) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) JSONObject(org.json.JSONObject) 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)

Example 58 with TestDefinition

use of com.github.redhatqe.polarize.metadata.TestDefinition in project rhsm-qe by RedHatQE.

the class SubscribeTests method testAttemptToSubscribeToAnAlreadySubscribedPool.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-27123", "RHEL7-51392" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.NEGATIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier2")
@Test(description = "Subscribed for Already subscribed Entitlement.", groups = { "Tier2Tests", "blockedByBug-584137", "blockedByBug-979492" }, // dataProvider="getAvailableSubscriptionPoolsData", TAKES TOO LONG AND RARELY REVEALS A BUG - changing to getRandomSubsetOfAvailableSubscriptionPoolsData
dataProvider = "getRandomSubsetOfAvailableSubscriptionPoolsData", enabled = true)
@ImplementsNitrateTest(caseId = 41897)
public void testAttemptToSubscribeToAnAlreadySubscribedPool(SubscriptionPool pool) throws JSONException, Exception {
    String consumerId = clienttasks.getCurrentConsumerId();
    Assert.assertNull(CandlepinTasks.getConsumersNewestEntitlementSerialCorrespondingToSubscribedPoolId(sm_clientUsername, sm_clientPassword, sm_serverUrl, consumerId, pool.poolId), "The current consumer has not been granted any entitlements from pool '" + pool.poolId + "'.");
    Assert.assertNotNull(clienttasks.subscribeToSubscriptionPool_(pool), "Authenticator '" + sm_clientUsername + "' has been granted an entitlement from pool '" + pool.poolId + "' under organization '" + sm_clientOrg + "'.");
    BigInteger serial1 = CandlepinTasks.getConsumersNewestEntitlementSerialCorrespondingToSubscribedPoolId(sm_clientUsername, sm_clientPassword, sm_serverUrl, consumerId, pool.poolId);
    SSHCommandResult subscribeResult = clienttasks.subscribe_(null, null, pool.poolId, null, null, null, null, null, null, null, null, null, null);
    String subscribeStdout = subscribeResult.getStdout().trim();
    subscribeStdout = clienttasks.workaroundForBug906550(subscribeStdout);
    if (CandlepinTasks.isPoolProductMultiEntitlement(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId)) {
        // Assert.assertEquals(subscribeStdout, String.format("Successfully consumed a subscription from the pool with id %s.",pool.poolId),	// Bug 812410 - Subscription-manager subscribe CLI feedback
        // Assert.assertEquals(subscribeStdout, String.format("Successfully consumed a subscription for: %s",pool.subscriptionName),	// changed by Bug 874804 Subscribe -> Attach
        Assert.assertEquals(subscribeStdout, String.format("Successfully attached a subscription for: %s", pool.subscriptionName), "subscribe command allows multi-entitlement pools to be subscribed to by the same consumer more than once.");
        BigInteger serial2 = CandlepinTasks.getConsumersNewestEntitlementSerialCorrespondingToSubscribedPoolId(sm_clientUsername, sm_clientPassword, sm_serverUrl, consumerId, pool.poolId);
        Assert.assertNotSame(serial1, serial2, "Upon subscribing to a multi-entitlement pool '" + pool.poolId + "' for the second time, the newly granted entilement's serial '" + serial2 + "' number differs from the first '" + serial1 + "'.");
        Assert.assertTrue(RemoteFileTasks.testExists(client, clienttasks.entitlementCertDir + File.separator + serial1 + ".pem"), "After subscribing to multi-entitlement pool '" + pool.poolId + "' for the second time, the first granted entilement cert file still exists.");
        Assert.assertTrue(RemoteFileTasks.testExists(client, clienttasks.entitlementCertDir + File.separator + serial2 + ".pem"), "After subscribing to multi-entitlement pool '" + pool.poolId + "' for the second time, the second granted entilement cert file exists.");
    } else {
        String expectedStdout = String.format("This consumer is already subscribed to the product matching pool with id '%s'.", pool.poolId);
        if (!clienttasks.workaroundForBug876764(sm_serverType))
            expectedStdout = String.format("This unit has already had the subscription matching pool ID '%s' attached.", pool.poolId);
        if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.3.1-1")) {
            // commit 0d5fefcfa8c1c2485921d2dee6633879b1e06931 Correct incorrect punctuation in user messages
            expectedStdout = String.format("This unit has already had the subscription matching pool ID \"%s\" attached.", pool.poolId);
        }
        Assert.assertEquals(subscribeStdout, expectedStdout, "subscribe command returns proper message when the same consumer attempts to subscribe to a non-multi-entitlement pool more than once.");
        Assert.assertTrue(RemoteFileTasks.testExists(client, clienttasks.entitlementCertDir + File.separator + serial1 + ".pem"), "After attempting to subscribe to pool '" + pool.poolId + "' for the second time, the first granted entilement cert file still exists.");
    }
}
Also used : SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) BigInteger(java.math.BigInteger) 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 59 with TestDefinition

use of com.github.redhatqe.polarize.metadata.TestDefinition in project rhsm-qe by RedHatQE.

the class TemporaryPoolTests method testAutoHealingIsStableAfterAttachingUnmappedGuestsOnlySubpool.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-20092", "RHEL7-59320" }, 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 = "given an available unmapped_guests_only pool, attach it and attempt to auto-heal - repeated attempts to auto-heal should NOT add more and more entitlements", groups = { "Tier1Tests", "blockedByBug-1198494" }, dataProvider = "getAvailableUnmappedGuestsOnlySubscriptionPoolsData", enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testAutoHealingIsStableAfterAttachingUnmappedGuestsOnlySubpool(Object bugzilla, SubscriptionPool unmappedGuestsOnlyPool) throws JSONException, Exception {
    // system facts were overridden in dataProvider with factsMap to fake this system as a guest
    // make sure we are freshly registered (to discard a consumer from a former data provided iteration that has mapped guests) and auto-subscribed
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, true, null, null, (String) null, null, null, null, true, false, null, null, null, null);
    // attach the unmapped guests only pool
    clienttasks.subscribe_(null, null, unmappedGuestsOnlyPool.poolId, null, null, null, null, null, null, null, null, null, null);
    // assert that the temporary subscription appears in the status report
    SSHCommandResult statusResult = clienttasks.status(null, null, null, null, null);
    // [root@jsefler-os6 ~]# subscription-manager status
    // +-------------------------------------------+
    // System Status Details
    // +-------------------------------------------+
    // Overall Status: Invalid
    // 
    // Awesome OS Instance Server Bits:
    // - Guest has not been reported on any host and is using a temporary unmapped guest subscription.
    // 
    // UNABLE_TO_GET_NAME:
    // - Guest has not been reported on any host and is using a temporary unmapped guest subscription.
    // 
    Map<String, String> statusMap = StatusTests.getProductStatusMapFromStatusResult(statusResult);
    // occurred in candlepin 0.9.45-1 // TODO block by a bug
    Assert.assertTrue(!statusMap.containsKey("UNABLE_TO_GET_NAME"), "The status module should NOT report 'UNABLE_TO_GET_NAME'.");
    Assert.assertTrue(statusMap.containsKey(unmappedGuestsOnlyPool.subscriptionName), "The status module reports an incompliance from temporary subscription '" + unmappedGuestsOnlyPool.subscriptionName + "'.");
    // get a list of the current entitlements
    List<File> entitlementCertFileAfterSubscribed = clienttasks.getCurrentEntitlementCertFiles();
    // trigger an auto-heal event
    clienttasks.autoheal(null, true, null, null, null, null, null);
    clienttasks.run_rhsmcertd_worker(true);
    // get a list of the entitlements after auto-heal
    List<File> entitlementCertFileAfterAutoHeal1 = clienttasks.getCurrentEntitlementCertFiles();
    // assert that no additional entitlements were added (test for Bug 1198494 - Auto-heal continuously attaches subscriptions to make the system compliant on a guest machine)
    Assert.assertTrue(entitlementCertFileAfterSubscribed.containsAll(entitlementCertFileAfterAutoHeal1) && entitlementCertFileAfterAutoHeal1.containsAll(entitlementCertFileAfterSubscribed), "The entitlement certs remained the same after first attempt to auto-heal despite the attached temporary pool. (Assuming that the initial registration with autosubcribe provided as much coverage as possible for the installed products from subscriptions with plenty of available quantity, repeated attempts to auto-heal should not consume more entitlements.)");
    // trigger a second auto-heal event
    clienttasks.autoheal(null, true, null, null, null, null, null);
    clienttasks.run_rhsmcertd_worker(true);
    // get a list of the entitlements after second auto-heal event
    List<File> entitlementCertFileAfterAutoHeal2 = clienttasks.getCurrentEntitlementCertFiles();
    // assert that no additional entitlements were added (test for Bug 1198494 - Auto-heal continuously attaches subscriptions to make the system compliant on a guest machine)
    Assert.assertTrue(entitlementCertFileAfterSubscribed.containsAll(entitlementCertFileAfterAutoHeal2) && entitlementCertFileAfterAutoHeal2.containsAll(entitlementCertFileAfterSubscribed), "The entitlement certs remained the same after a second attempt to auto-heal despite the attached temporary pool. (Assuming that the initial registration with autosubcribe provided as much coverage as possible for the installed products from subscriptions with plenty of available quantity, repeated attempts to auto-heal should not consume more entitlements.)");
}
Also used : SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) File(java.io.File) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 60 with TestDefinition

use of com.github.redhatqe.polarize.metadata.TestDefinition in project rhsm-qe by RedHatQE.

the class TemporaryPoolTests method testAutomaticRemovalOfAnAttachedUnmappedGuestsOnlySubpoolOnceGuestIsMapped.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-22237", "RHEL7-59322" }, 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 = "Once a guest is mapped, while consuming a temporary pool entitlement, the entitlement should be removed at the next checkin.  Verify this while autoheal is disabled.", groups = { "Tier1Tests", "blockedByBug-1198494" }, dataProvider = "getAvailableUnmappedGuestsOnlySubscriptionPoolsData", enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testAutomaticRemovalOfAnAttachedUnmappedGuestsOnlySubpoolOnceGuestIsMapped(Object bugzilla, SubscriptionPool unmappedGuestsOnlyPool) throws JSONException, Exception {
    // system facts were overridden in dataProvider with factsMap to fake this system as a guest
    // make sure we are freshly registered (to discard a consumer from a former data provided iteration that has mapped guests)
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, true, null, null, null, null, null);
    // ensure that auto-healing is off
    clienttasks.autoheal(null, null, true, null, null, null, null);
    // attach the unmapped guests only pool
    clienttasks.subscribe_(null, null, unmappedGuestsOnlyPool.poolId, null, null, null, null, null, null, null, null, null, null);
    ProductSubscription consumedUnmappedGuestsOnlyProductSubscription = ProductSubscription.findFirstInstanceWithMatchingFieldFromList("poolId", unmappedGuestsOnlyPool.poolId, clienttasks.getCurrentlyConsumedProductSubscriptions());
    Assert.assertNotNull(consumedUnmappedGuestsOnlyProductSubscription, "Successfully found the consumed product subscription after attaching temporary pool '" + unmappedGuestsOnlyPool.subscriptionName + "' (poolId='" + unmappedGuestsOnlyPool.poolId + "').");
    // map the guest
    clienttasks.mapSystemAsAGuestOfItself();
    // trigger a rhsmcertd checkin (either of these calls are valid - randomly choose)
    // TEMPORARY WORKAROUND FOR BUG
    // Bug 1366301 - Server error attempting a PUT to /subscription/consumers/<UUID>/certificates?lazy_regen=true returned status 404
    String bugId = "1366301";
    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 && CandlepinType.hosted.equals(sm_serverType)) {
        log.warning("Skipping a random call to refresh local certificates while bug '" + bugId + "' is open.");
        // no need to pass autoheal option because it is already set true on the consumer
        clienttasks.run_rhsmcertd_worker(null);
    } else // END OF WORKAROUND
    if (getRandomListItem(Arrays.asList(true, false)))
        clienttasks.refresh(null, null, null, null);
    else
        // no need to pass autoheal option because it is already set true on the consumer
        clienttasks.run_rhsmcertd_worker(null);
    // verify that the attached temporary subscription has automatically been removed
    List<ProductSubscription> currentlyConsumedProductSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
    Assert.assertTrue(ProductSubscription.findAllInstancesWithMatchingFieldFromList("poolId", unmappedGuestsOnlyPool.poolId, currentlyConsumedProductSubscriptions).isEmpty(), "Now that the guest is mapped, the consumed entitlements from the temporary pool '" + unmappedGuestsOnlyPool.subscriptionName + "' (poolId='" + unmappedGuestsOnlyPool.poolId + "') have automatically been removed.");
    Assert.assertTrue(currentlyConsumedProductSubscriptions.isEmpty(), "Now that the guest is mapped (and autoheal was off at the instant the guest was mapped), not only is the temporary entitlement removed, but no new entitlements are granted.");
}
Also used : ProductSubscription(rhsm.data.ProductSubscription) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Aggregations

TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)687 Test (org.testng.annotations.Test)687 SSHCommandResult (com.redhat.qe.tools.SSHCommandResult)401 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)366 SkipException (org.testng.SkipException)328 ArrayList (java.util.ArrayList)144 SubscriptionPool (rhsm.data.SubscriptionPool)137 JSONObject (org.json.JSONObject)95 BigInteger (java.math.BigInteger)90 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)88 HashMap (java.util.HashMap)78 File (java.io.File)74 ProductSubscription (rhsm.data.ProductSubscription)72 InstalledProduct (rhsm.data.InstalledProduct)66 EntitlementCert (rhsm.data.EntitlementCert)58 ProductCert (rhsm.data.ProductCert)54 YumRepo (rhsm.data.YumRepo)34 Repo (rhsm.data.Repo)26 Calendar (java.util.Calendar)25 List (java.util.List)24