Search in sources :

Example 1 with ProductSubscription

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

the class ServiceLevelTests method testAutoSubscribeWithServiceLevelIsCaseInsensitive.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-19994", "RHEL7-51026" }, 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: autosubscribe while specifying an valid service level; assert the installed product status is independent of the specified SerViceLeVEL case.", groups = { "Tier1Tests", "blockedByBug-818319", "blockedByBug-859652" }, // dataProvider="getAllAvailableServiceLevelData",	// 06/05/2014 takes too long; rarely reveals a bug
dataProvider = "getRandomSubsetOfAllAvailableServiceLevelData", enabled = true)
// 157226 //157225
@ImplementsNitrateTest(caseId = 157227)
public void testAutoSubscribeWithServiceLevelIsCaseInsensitive(Object bugzilla, String serviceLevel) throws JSONException, Exception {
    // 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) {
            throw new SkipException("This test is blocked by Bugzilla https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId);
        }
    }
    // system was already registered by dataProvider="getSubscribeWithAutoAndServiceLevelData"
    if (clienttasks.getCurrentConsumerId() == null) {
        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);
    }
    // start fresh by returning all entitlements
    clienttasks.unsubscribeFromAllOfTheCurrentlyConsumedProductSubscriptions();
    // autosubscribe specifying a valid service level and get the installed product status
    List<InstalledProduct> installedProductsAfterAutosubscribingWithServiceLevel = InstalledProduct.parse(clienttasks.subscribe(true, serviceLevel, (String) null, (String) null, (String) null, null, null, null, null, null, null, null, null).getStdout());
    // unsubscribe from all entitlements
    clienttasks.unsubscribeFromAllOfTheCurrentlyConsumedProductSubscriptions();
    // autosubscribe specifying a mixed case service level and get the installed product status
    String mixedCaseServiceLevel = randomizeCaseOfCharactersInString(serviceLevel);
    List<InstalledProduct> installedProductsAfterAutosubscribingWithMixedCaseServiceLevel = InstalledProduct.parse(clienttasks.subscribe(true, mixedCaseServiceLevel, (String) null, (String) null, (String) null, null, null, null, null, null, null, null, null).getStdout());
    // assert that the two lists are identical (independent of the serviceLevel case specified during autosubscribe)
    Assert.assertEquals(installedProductsAfterAutosubscribingWithMixedCaseServiceLevel.size(), clienttasks.getCurrentProductIds().size(), "The subscribe output displayed the same number of installed product status's as the current number of installed product certs.");
    Assert.assertTrue(installedProductsAfterAutosubscribingWithServiceLevel.containsAll(installedProductsAfterAutosubscribingWithMixedCaseServiceLevel) && installedProductsAfterAutosubscribingWithMixedCaseServiceLevel.containsAll(installedProductsAfterAutosubscribingWithServiceLevel), "Autosubscribe with serviceLevel '" + mixedCaseServiceLevel + "' yielded the same installed product status as autosubscribe with serviceLevel '" + serviceLevel + "'.");
    // get the current exempt service levels
    List<String> exemptServiceLevels = CandlepinTasks.getServiceLevelsForOrgKey(sm_clientUsername, sm_clientPassword, sm_serverUrl, clienttasks.getCurrentlyRegisteredOwnerKey(), true);
    List<String> exemptServiceLevelsInUpperCase = new ArrayList<String>();
    for (String exemptServiceLevel : exemptServiceLevels) exemptServiceLevelsInUpperCase.add(exemptServiceLevel.toUpperCase());
    // assert that each of the consumed ProductSubscriptions match the specified service level
    List<ProductSubscription> consumedProductSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
    if (consumedProductSubscriptions.isEmpty())
        log.warning("No entitlements were granted after autosubscribing with service level '" + mixedCaseServiceLevel + "'.");
    for (ProductSubscription productSubscription : consumedProductSubscriptions) {
        // tolerate ProductSubscriptions with a null/"" serviceLevel. (result of candlepin Bug 1223560)
        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 (productSubscription.serviceLevel == null || productSubscription.serviceLevel.isEmpty()) {
                log.warning("After autosubscribe with service level '" + mixedCaseServiceLevel + "', this consumed ProductSubscription provides no service level '" + productSubscription.serviceLevel + "'.  (New behavior modification from Bug 1223560)");
                continue;
            }
        }
        // tolerate ProductSubscriptions with exemptServiceLevels
        if (/*sm_*/
        exemptServiceLevelsInUpperCase.contains(productSubscription.serviceLevel.toUpperCase())) {
            log.warning("After autosubscribe with service level '" + mixedCaseServiceLevel + "', this consumed ProductSubscription provides an exempt service level '" + productSubscription.serviceLevel + "'.");
            continue;
        }
        Assert.assertTrue(productSubscription.serviceLevel.equalsIgnoreCase(mixedCaseServiceLevel), "After autosubscribe with service level '" + mixedCaseServiceLevel + "', this consumed ProductSubscription provides a service level '" + productSubscription.serviceLevel + "' that is a case insensitive match to '" + mixedCaseServiceLevel + "'.");
    }
}
Also used : InstalledProduct(rhsm.data.InstalledProduct) ArrayList(java.util.ArrayList) ProductSubscription(rhsm.data.ProductSubscription) SkipException(org.testng.SkipException) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) 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 2 with ProductSubscription

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

the class ServiceLevelTests method testRegisterWithServiceLevelIsCaseInsensitive.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-19995", "RHEL7-51028" }, 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: register with autosubscribe while specifying an valid random case SeRviCEleVel; assert the installed product status is independent of the specified service level case.", groups = { "Tier1Tests", "blockedByBug-859652", "blockedByBug-859652", "blockedByBug-919700" }, // dataProvider="getAllAvailableServiceLevelData",	// 06/05/2014 takes too long; rarely reveals a bug
dataProvider = "getRandomSubsetOfAllAvailableServiceLevelData", enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testRegisterWithServiceLevelIsCaseInsensitive(Object bugzilla, String 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) {
            throw new SkipException("Hosted candlepin server '" + sm_serverHostname + "' does not yet support this test execution.");
        }
    }
    // END OF WORKAROUND
    // register with autosubscribe specifying a valid service level and get the installed product status
    List<InstalledProduct> installedProductsAfterAutosubscribedRegisterWithServiceLevel = InstalledProduct.parse(clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, true, serviceLevel, null, (String) null, null, null, null, true, null, null, null, null, null).getStdout());
    // register with autosubscribe specifying a mixed case service level and get the installed product status
    String mixedCaseServiceLevel = randomizeCaseOfCharactersInString(serviceLevel);
    List<InstalledProduct> installedProductsAfterAutosubscribedRegisterWithMixedCaseServiceLevel = InstalledProduct.parse(clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, true, mixedCaseServiceLevel, null, (String) null, null, null, null, true, null, null, null, null, null).getStdout());
    // assert that the two lists are identical (independent of the serviceLevel case specified during registration)
    Assert.assertEquals(installedProductsAfterAutosubscribedRegisterWithMixedCaseServiceLevel.size(), clienttasks.getCurrentProductIds().size(), "The registration output displayed the same number of installed product status's as the number of installed product certs.");
    Assert.assertTrue(installedProductsAfterAutosubscribedRegisterWithServiceLevel.containsAll(installedProductsAfterAutosubscribedRegisterWithMixedCaseServiceLevel) && installedProductsAfterAutosubscribedRegisterWithMixedCaseServiceLevel.containsAll(installedProductsAfterAutosubscribedRegisterWithServiceLevel), "Autosubscribed registration with serviceLevel '" + mixedCaseServiceLevel + "' yielded the same installed product status as autosubscribed registration with serviceLevel '" + serviceLevel + "'.");
    // assert that each of the consumed ProductSubscriptions match the specified service level
    List<ProductSubscription> consumedProductSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
    if (consumedProductSubscriptions.isEmpty())
        log.warning("No entitlements were granted after registering with autosubscribe and service level '" + mixedCaseServiceLevel + "'.");
    for (ProductSubscription productSubscription : consumedProductSubscriptions) {
        // tolerate ProductSubscriptions with a null/"" serviceLevel. (result of candlepin Bug 1223560)
        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 (productSubscription.serviceLevel == null || productSubscription.serviceLevel.isEmpty()) {
                log.warning("After autosubscribed registration with service level '" + mixedCaseServiceLevel + "', this consumed ProductSubscription provides no service level '" + productSubscription.serviceLevel + "'.  (New behavior modification from Bug 1223560)");
                continue;
            }
        }
        // tolerate exemptServiceLevels
        if (sm_exemptServiceLevelsInUpperCase.contains(productSubscription.serviceLevel.toUpperCase())) {
            log.warning("After autosubscribed registration with service level '" + mixedCaseServiceLevel + "', this consumed ProductSubscription provides an exempt service level '" + productSubscription.serviceLevel + "'.");
            continue;
        }
        Assert.assertTrue(productSubscription.serviceLevel.equalsIgnoreCase(mixedCaseServiceLevel), "After autosubscribed registration with service level '" + mixedCaseServiceLevel + "', this consumed ProductSubscription provides a service level '" + productSubscription.serviceLevel + "' that is a case insensitive match to '" + mixedCaseServiceLevel + "'.");
    }
}
Also used : InstalledProduct(rhsm.data.InstalledProduct) ProductSubscription(rhsm.data.ProductSubscription) SkipException(org.testng.SkipException) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 3 with ProductSubscription

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

the class UnsubscribeTests method testUnsubscribeFromAllSerials.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36596", "RHEL7-51401" }, linkedWorkItems = { @LinkedItem(// RHSM-REQ : subscription-manager cli attaching and removing subscriptions
workitemId = "RHEL6-28489", project = Project.RHEL6, role = DefTypes.Role.VERIFIES), @LinkedItem(// RHSM-REQ : subscription-manager cli attaching and removing subscriptions
workitemId = "RHEL7-84911", 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 = "Tier2")
@Test(description = "Verify the feedback after unsubscribing from all consumed subscriptions using unsubscribe --serial SERIAL1 --serial SERIAL2 --serial SERIAL3 etc.", groups = { "Tier2Tests", "blockedByBug-867766" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testUnsubscribeFromAllSerials() throws Exception {
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (List<String>) null, null, null, null, true, false, null, null, null, null);
    List<SubscriptionPool> pools = clienttasks.subscribeToTheCurrentlyAllAvailableSubscriptionPoolsCollectively();
    if (pools.isEmpty())
        throw new SkipException("This test requires multiple available pools.");
    // unsubscribe from all serials in one call and assert the feedback
    List<ProductSubscription> productSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
    String expectedStdoutMsgLabel;
    expectedStdoutMsgLabel = "Successfully unsubscribed serial numbers:";
    // changed by bug 874749
    expectedStdoutMsgLabel = "Successfully removed serial numbers:";
    // changed by bug 895447 subscription-manager commit 8e10e76fb5951e0b5d6c867c6c7209d8ec80dead
    expectedStdoutMsgLabel = "Serial numbers successfully removed at the server:";
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.17.8-1")) {
        // commit f64d5a6b012f49bb4d6d6653441d4de9bf373660  1319678: Alter the return message for removing entitlements at server
        expectedStdoutMsgLabel = "The entitlement server successfully removed these serial numbers:";
    }
    String expectedStdoutMsg = expectedStdoutMsgLabel;
    for (ProductSubscription productSubscription : productSubscriptions) expectedStdoutMsg += "\n   " + productSubscription.serialNumber;
    SSHCommandResult result = clienttasks.unsubscribeFromTheCurrentlyConsumedProductSubscriptionSerialsCollectively();
    // 201512041150:31.105 - FINE: ssh root@jsefler-6.usersys.redhat.com subscription-manager unsubscribe --serial=4651043328648416651 --serial=2129955862705896392 --serial=6036987963107037829 --serial=6517055606227995394 --serial=2413511261042915625 --serial=926011418395876185 --serial=8453228344236558779 --serial=5066796542261309304 --serial=3293732479098570905 --serial=5415112579595928189 --serial=9157726701938581232 --serial=6182970514936389843 --serial=2260599158127862401 --serial=4271127926386632804 --serial=5634936969630756863 --serial=7207476634289399667 --serial=2228491462979865207 --serial=2386453852224823924 --serial=7223061298534444815 --serial=5297175478219818300 --serial=3982095574288257352 --serial=5040485111524274578 --serial=3366381999267298553 --serial=2205964533240272738 --serial=2009203577428614683 --serial=2151906114081820015 --serial=3936210531886609574 --serial=4672997312714367813 --serial=7537851805340427070 --serial=4060809784799304042 --serial=3484999197148046565 --serial=803523513343380611 --serial=7191534188916803249 --serial=1978078461069342056 --serial=3112667572957043871 --serial=8477444878208748895 --serial=4389608640436010689 --serial=2216833362015010963 --serial=1813156641027923146 --serial=6235363562528759967 --serial=8254500161982005905 --serial=8635854683836611062 --serial=2837535867304046524 --serial=6672137066369518129 --serial=6702191060241838270 --serial=695479724906271580 (com.redhat.qe.tools.SSHCommandRunner.run)
    // 201512041151:20.262 - FINE: Stdout:
    // Serial numbers successfully removed at the server:
    // 4651043328648416651
    // 2129955862705896392
    // 6036987963107037829
    // 6517055606227995394
    // 2413511261042915625
    // 926011418395876185
    // 8453228344236558779
    // 5066796542261309304
    // 3293732479098570905
    // 5415112579595928189
    // 9157726701938581232
    // 6182970514936389843
    // 2260599158127862401
    // 4271127926386632804
    // 5634936969630756863
    // 7207476634289399667
    // 2228491462979865207
    // 2386453852224823924
    // 7223061298534444815
    // 5297175478219818300
    // 3982095574288257352
    // 5040485111524274578
    // 3366381999267298553
    // 2205964533240272738
    // 2009203577428614683
    // 2151906114081820015
    // 3936210531886609574
    // 4672997312714367813
    // 7537851805340427070
    // 4060809784799304042
    // 3484999197148046565
    // 803523513343380611
    // 7191534188916803249
    // 1978078461069342056
    // 3112667572957043871
    // 8477444878208748895
    // 4389608640436010689
    // 2216833362015010963
    // 1813156641027923146
    // 6235363562528759967
    // 8254500161982005905
    // 8635854683836611062
    // 2837535867304046524
    // 6672137066369518129
    // 6702191060241838270
    // 695479724906271580
    // 46 local certificates have been deleted.
    // 201512041151:20.283 - FINE: Stderr:
    String actualStdoutMsg = result.getStdout().trim();
    actualStdoutMsg = clienttasks.workaroundForBug906550(actualStdoutMsg);
    // NOTE: This expectedStdoutMsg makes a huge assumption about the order of the unsubscribed serial numbers printed to stdout
    // NOTE: TIME TO FIX THIS ASSERTION... Assert.assertEquals(result.getStdout().trim(), expectedStdoutMsg, "Stdout feedback when unsubscribing from all the currently consumed subscriptions.");
    List<String> expectedStdoutMsgAsList = new ArrayList<String>(Arrays.asList(expectedStdoutMsg.split("\n")));
    expectedStdoutMsgAsList.remove(expectedStdoutMsgLabel);
    List<String> actualStdoutMsgAsList = new ArrayList<String>(Arrays.asList(actualStdoutMsg.split("\n")));
    actualStdoutMsgAsList.remove(expectedStdoutMsgLabel);
    Assert.assertTrue(expectedStdoutMsgAsList.containsAll(actualStdoutMsgAsList) && actualStdoutMsgAsList.containsAll(expectedStdoutMsgAsList), "Stdout feedback when unsubscribing from all the currently consumed subscriptions contains all the expected serial numbers:" + expectedStdoutMsg.replace(expectedStdoutMsgLabel, ""));
}
Also used : SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) ProductSubscription(rhsm.data.ProductSubscription) ArrayList(java.util.ArrayList) 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 4 with ProductSubscription

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

the class UnsubscribeTests method testUnsubscribeFromAllPoolIds.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36594", "RHEL7-51399" }, linkedWorkItems = { @LinkedItem(// RHSM-REQ : subscription-manager cli attaching and removing subscriptions
workitemId = "RHEL6-28489", project = Project.RHEL6, role = DefTypes.Role.VERIFIES), @LinkedItem(// RHSM-REQ : subscription-manager cli attaching and removing subscriptions
workitemId = "RHEL7-84911", 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 = "Tier2")
@Test(description = "Verify the feedback after unsubscribing from all consumed subscriptions using unsubscribe --pool POOLID1 --pool POOLID2 --pool POOLID3 etc.", groups = { "Tier2Tests", "blockedByBug-1198178", "blockedByBug-1288626" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testUnsubscribeFromAllPoolIds() throws Exception {
    if (clienttasks.isPackageVersion("subscription-manager", "<", "1.16.5-1"))
        throw new SkipException("The unsubscribe --pool function was not implemented in this version of subscription-manager.  See RFE Bug 1198178");
    if (!servertasks.statusCapabilities.contains("remove_by_pool_id"))
        throw new SkipException("The registered entitlement server does not support remove --pool");
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (List<String>) null, null, null, null, true, false, null, null, null, null);
    List<SubscriptionPool> pools = clienttasks.subscribeToTheCurrentlyAllAvailableSubscriptionPoolsCollectively();
    if (pools.isEmpty())
        throw new SkipException("This test requires multiple available pools.");
    List<String> poolIds = new ArrayList<String>();
    for (SubscriptionPool pool : pools) poolIds.add(pool.poolId);
    // add more serials from multi-entitlement pools (ignoring failures)
    clienttasks.subscribe_(null, null, poolIds, null, null, null, null, null, null, null, null, null, null);
    // unsubscribe from all pool in one call and assert the feedback
    List<ProductSubscription> productSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
    String successfulStdoutSerialsMsgLabel;
    successfulStdoutSerialsMsgLabel = "Successfully unsubscribed serial numbers:";
    // changed by bug 874749
    successfulStdoutSerialsMsgLabel = "Successfully removed serial numbers:";
    // changed by bug 895447 subscription-manager commit 8e10e76fb5951e0b5d6c867c6c7209d8ec80dead
    successfulStdoutSerialsMsgLabel = "Serial numbers successfully removed at the server:";
    // commit f64d5a6b012f49bb4d6d6653441d4de9bf373660  1319678: Alter the return message for removing entitlements at server
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.17.8-1"))
        successfulStdoutSerialsMsgLabel = "The entitlement server successfully removed these serial numbers:";
    String successfulStdoutPoolIdsMsgLabel;
    successfulStdoutPoolIdsMsgLabel = "Pools successfully removed at the server:";
    // commit f64d5a6b012f49bb4d6d6653441d4de9bf373660  1319678: Alter the return message for removing entitlements at server
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.17.8-1"))
        successfulStdoutPoolIdsMsgLabel = "The entitlement server successfully removed these pools:";
    String unsuccessfulStdoutSerialsMsgLabel;
    unsuccessfulStdoutSerialsMsgLabel = "Serial numbers unsuccessfully removed at the server:";
    // commit f64d5a6b012f49bb4d6d6653441d4de9bf373660  1319678: Alter the return message for removing entitlements at server
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.17.8-1"))
        unsuccessfulStdoutSerialsMsgLabel = "The entitlement server failed to remove these serial numbers:";
    String unsuccessfulStdoutPoolsMsgLabel;
    unsuccessfulStdoutPoolsMsgLabel = "Pools unsuccessfully removed at the server:";
    // commit f64d5a6b012f49bb4d6d6653441d4de9bf373660  1319678: Alter the return message for removing entitlements at server
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.17.8-1"))
        unsuccessfulStdoutPoolsMsgLabel = "The entitlement server failed to remove these pools:";
    Set<String> expectedPoolIds = new HashSet<String>();
    Set<String> expectedSerials = new HashSet<String>();
    for (ProductSubscription productSubscription : productSubscriptions) {
        expectedPoolIds.add(productSubscription.poolId);
        expectedSerials.add(productSubscription.serialNumber.toString());
    }
    SSHCommandResult result = clienttasks.unsubscribeFromTheCurrentlyConsumedProductSubscriptionPoolIdsCollectively();
    // 201511231656:37.570 - FINE: ssh root@jsefler-6.usersys.redhat.com subscription-manager unsubscribe --pool=8a9087905136504801513651940f049a --pool=8a90879051365048015136519c0d055b --pool=8a9087905136504801513651946b04a7 --pool=8a9087905136504801513651ad77079b --pool=8a9087905136504801513651aa620721 --pool=8a9087905136504801513651ac43076c --pool=8a9087905136504801513651bc6e09aa --pool=8a90879051365048015136519a7c0529 --pool=8a9087905136504801513651a1b1061d --pool=8a9087905136504801513651b9a3094c --pool=8a90879051365048015136519b730556 --pool=8a9087905136504801513651ab5f0741 --pool=8a9087905136504801513651a06705ef --pool=8a9087905136504801513651a51b0689 --pool=8a9087905136504801513651ae9907d4 --pool=8a9087905136504801513651ad370790 --pool=8a9087905136504801513651a86906ed --pool=8a9087905136504801513651b7960927 --pool=8a90879051365048015136519c4c056a --pool=8a9087905136504801513651b4cc08cd --pool=8a9087905136504801513651940f0498 --pool=8a9087905136504801513651a2b7063a --pool=8a9087905136504801513651a79306d5 --pool=8a9087905136504801513651ae6007b9 --pool=8a9087905136504801513651a03305d5 --pool=8a9087905136504801513651b7cf0936 --pool=8a9087905136504801513651a74b06c9 --pool=8a9087905136504801513651946504a4 --pool=8a9087905136504801513651ae8c07c2 --pool=8a9087905136504801513651b56908d7 --pool=8a90879051365048015136519c65056e --pool=8a9087905136504801513651ab860744 --pool=8a90879051365048015136519b510553 --pool=8a90879051365048015136519c7e0572 --pool=8a90879051365048015136519c0c055a --pool=8a9087905136504801513651b21f0872 --pool=8a9087905136504801513651a2430630 --pool=8a9087905136504801513651ae6b07bf --pool=8a9087905136504801513651a222062d --pool=8a9087905136504801513651953b04aa --pool=8a9087905136504801513651bb9f0987 --pool=8a9087905136504801513651b4d708cf --pool=8a9087905136504801513651b892093c --pool=8a9087905136504801513651b3b708bb --pool=8a9087905136504801513651bd1b09b2 --pool=8a9087905136504801513651a88b06f6 --pool=8a9087905136504801513651945604a1 --pool=8a9087905136504801513651940f0499 --pool=8a9087905136504801513651b1320855 --pool=8a9087905136504801513651ba510960 (com.redhat.qe.tools.SSHCommandRunner.run)
    // 201511231657:33.946 - FINE: Stdout:
    // Pools successfully removed at the server:
    // 8a9087905136504801513651940f049a
    // 8a90879051365048015136519c0d055b
    // 8a9087905136504801513651946b04a7
    // Serial numbers successfully removed at the server:
    // 8865613847264050544
    // 8937932663056862717
    // 3352861400531049008
    // 8107962814745856003
    // 8514271782573332949
    // 3379403338434026844
    // 2230666936775183579
    // 7 local certificates have been deleted.
    // 201511231657:33.989 - FINE: Stderr:
    // 201512041343:44.111 - FINE: ssh root@jsefler-6.usersys.redhat.com subscription-manager unsubscribe --pool=8a908790516a011001516a02508b049b --pool=8a908790516a011001516a025891054a --pool=8a908790516a011001516a025dbc05ec --pool=8a908790516a011001516a026b970797 --pool=8a908790516a011001516a0250a1049e --pool=8a908790516a011001516a0264a006d3 --pool=8a908790516a011001516a02646b06c3 --pool=8a908790516a011001516a02511e04a4 --pool=8a908790516a011001516a02762e0904 --pool=8a908790516a011001516a0261720680 --pool=8a908790516a011001516a0265b906e1 --pool=8a908790516a011001516a02714d089b --pool=8a908790516a011001516a0261720680 --pool=8a908790516a011001516a0259dd056e --pool=8a908790516a011001516a02588b0547 --pool=8a908790516a011001516a025a490575 --pool=8a908790516a011001516a02646b06c3 --pool=8a908790516a011001516a0263ac06bb --pool=8a908790516a011001516a026168067d --pool=8a908790516a011001516a025e0e05f9 --pool=8a908790516a011001516a027e6b09db --pool=8a908790516a011001516a0251b504aa --pool=8a908790516a011001516a0274dd08e0 --pool=8a908790516a011001516a026919073f --pool=8a908790516a011001516a02662606f4 --pool=8a908790516a011001516a0278a70937 --pool=8a908790516a011001516a027b7f0984 --pool=8a908790516a011001516a0250650498 --pool=8a908790516a011001516a0264a106d6 --pool=8a908790516a011001516a026b030786 --pool=8a908790516a011001516a0278aa0939 --pool=8a908790516a011001516a0265b906e1 --pool=8a908790516a011001516a02714d089b --pool=8a908790516a011001516a025d6005e8 --pool=8a908790516a011001516a0278a70937 --pool=8a908790516a011001516a0258030542 --pool=8a908790516a011001516a0278aa0939 --pool=8a908790516a011001516a02510504a1 --pool=8a908790516a011001516a0264a106d6 --pool=8a908790516a011001516a02762e0904 --pool=8a908790516a011001516a02588b0547 --pool=8a908790516a011001516a027b930986 --pool=8a908790516a011001516a0260e5066a --pool=8a908790516a011001516a0258e20560 --pool=8a908790516a011001516a025a490575 --pool=8a908790516a011001516a025e0e05f9 --pool=8a908790516a011001516a0269940747 --pool=8a908790516a011001516a026acf0781 --pool=8a908790516a011001516a0251b504aa --pool=8a908790516a011001516a026910073c --pool=8a908790516a011001516a0274c608de --pool=8a908790516a011001516a02710c0899 --pool=8a908790516a011001516a02516304a7 --pool=8a908790516a011001516a0269940747 --pool=8a908790516a011001516a0259b60569 --pool=8a908790516a011001516a0274dd08e0 --pool=8a908790516a011001516a0259dd056e --pool=8a908790516a011001516a02516304a7 --pool=8a908790516a011001516a0269bf074b --pool=8a908790516a011001516a0263ac06bb --pool=8a908790516a011001516a0269bf074b --pool=8a908790516a011001516a026b33078f --pool=8a908790516a011001516a026b030786 --pool=8a908790516a011001516a026acf0781 --pool=8a908790516a011001516a026f8d0869 --pool=8a908790516a011001516a0257ab0529 --pool=8a908790516a011001516a025dbc05ec --pool=8a908790516a011001516a0264a006d3 --pool=8a908790516a011001516a027b930986 (com.redhat.qe.tools.SSHCommandRunner.run)
    // 201512041344:51.518 - FINE: Stdout:
    // Pools successfully removed at the server:
    // 8a908790516a011001516a0269bf074b
    // 8a908790516a011001516a026b33078f
    // 8a908790516a011001516a026f8d0869
    // 8a908790516a011001516a0257ab0529
    // Pools unsuccessfully removed at the server:
    // 8a908790516a011001516a0261720680
    // 8a908790516a011001516a02646b06c3
    // Serial numbers successfully removed at the server:
    // 6147826158890249653
    // 2710596911835822689
    // 8362938208950031094
    // 130483993634735580
    // 2732609281506598523
    // Serial numbers unsuccessfully removed at the server:
    // 8a908790516a011001516a0261720680   <=== Bug 1288626
    // 8a908790516a011001516a02646b06c3   <=== Bug 1288626
    // 5 local certificates have been deleted.
    // 201512041344:51.520 - FINE: Stderr:  (com.redhat.qe.tools.SSHCommandRunner.runCommandAndWait)
    String actualStdoutMsg = result.getStdout().trim();
    actualStdoutMsg = clienttasks.workaroundForBug906550(actualStdoutMsg);
    Assert.assertTrue(actualStdoutMsg.contains(successfulStdoutPoolIdsMsgLabel), "Stdout from unsubscribing many pool ids contains expected label '" + successfulStdoutPoolIdsMsgLabel + "'.");
    Assert.assertTrue(actualStdoutMsg.contains(successfulStdoutSerialsMsgLabel), "Stdout from unsubscribing many pool ids contains expected label '" + successfulStdoutSerialsMsgLabel + "'.");
    String actualStdoutPoolIdsMsg = actualStdoutMsg.split(successfulStdoutSerialsMsgLabel)[0];
    actualStdoutPoolIdsMsg = actualStdoutPoolIdsMsg.replace(successfulStdoutPoolIdsMsgLabel + "\n", "").replace(unsuccessfulStdoutPoolsMsgLabel + "\n", "");
    String actualStdoutSerialsMsg = actualStdoutMsg.split(successfulStdoutSerialsMsgLabel)[1];
    actualStdoutSerialsMsg = actualStdoutSerialsMsg.replace(successfulStdoutSerialsMsgLabel + "\n", "").replace(unsuccessfulStdoutSerialsMsgLabel + "\n", "");
    Set<String> actualStdoutPoolIds = new HashSet<String>();
    actualStdoutPoolIds.addAll(Arrays.asList(actualStdoutPoolIdsMsg.trim().split("\\s*\n\\s*")));
    Set<String> actualStdoutSerials = new HashSet<String>();
    actualStdoutSerials.addAll(Arrays.asList(actualStdoutSerialsMsg.trim().split("\\s*\n\\s*")));
    // Note: these assertions will pass regardless if the pools/serial removed were successful or unsuccessful
    Assert.assertTrue(actualStdoutPoolIds.containsAll(expectedPoolIds) && expectedPoolIds.containsAll(actualStdoutPoolIds), "Stdout feedback when unsubscribing from all the currently consumed subscriptions pool ids contains all the expected pool ids from the list of consumed Product Subscriptions.");
    Assert.assertTrue(actualStdoutSerials.containsAll(expectedSerials) && expectedSerials.containsAll(actualStdoutSerials), "Stdout feedback when unsubscribing from all the currently consumed subscriptions pool ids contains all the expected serials from the list of consumed Product Subscriptions.");
}
Also used : SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) ArrayList(java.util.ArrayList) ProductSubscription(rhsm.data.ProductSubscription) SkipException(org.testng.SkipException) SubscriptionPool(rhsm.data.SubscriptionPool) HashSet(java.util.HashSet) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 5 with ProductSubscription

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

the class StatusTests method testStatusWhileRegisteredWithEntitlements.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-19968", "RHEL7-51007" }, 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 = "run subscription-manager status when registered with entitlements", groups = { "Tier1Tests", "blockedByBug-958827", "StatusWhileRegisteredWithEntitlements_Test" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testStatusWhileRegisteredWithEntitlements() throws JSONException, Exception {
    SSHCommandResult statusResult;
    // override the system facts setting the attribute count to a value for which all the stackable subscriptions are needed to achieve compliance
    Map<String, String> factsMap = new HashMap<String, String>();
    factsMap.put("memory.memtotal", "75");
    factsMap.put("cpu.cpu_socket(s)", "100");
    factsMap.put("cpu.core(s)_per_socket", "2");
    clienttasks.createFactsFileWithOverridingValues(factsMap);
    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);
    clienttasks.subscribeToTheCurrentlyAvailableSubscriptionPoolsCollectively();
    String systemEntitlementsValid = clienttasks.getFactValue("system.entitlements_valid");
    statusResult = clienttasks.status(null, null, null, null, null);
    // [root@jsefler-5 ~]# subscription-manager status
    // +-------------------------------------------+
    // System Status Details
    // +-------------------------------------------+
    // Overall Status: Invalid
    // 
    // Large File Support Bits:
    // - Not covered by a valid subscription.
    // 
    // Awesome OS for x86 Bits:
    // - Not covered by a valid subscription.
    // 
    // Stackable Cores Package (8 cores)/Stackable Cores Package (8 cores):
    // - Only covers 16 of 200 cores.
    // 
    // Awesome OS for S390X Bits:
    // - Not covered by a valid subscription.
    // 
    // Awesome OS for S390 Bits:
    // - Not covered by a valid subscription.
    // 
    // Load Balancing Bits:
    // - Not covered by a valid subscription.
    // 
    // Awesome OS Workstation Bits:
    // - Not covered by a valid subscription.
    // 
    // Clustering Bits:
    // - Not covered by a valid subscription.
    // 
    // Awesome OS for i386 Bits:
    // - Not covered by a valid subscription.
    // 
    // Stackable with Awesome OS for x86_64/Awesome OS for x86_64/Stackable with Awesome OS for x86_64/Awesome OS for x86_64:
    // - Only covers 4 of 100 sockets.
    // 
    // Multi-Attribute (non-stackable) (6 cores, 8GB):
    // - Only covers 6 of 200 cores.
    // 
    // Awesome OS for ia64 Bits:
    // - Not covered by a valid subscription.
    // 
    // Awesome OS Developer Basic:
    // - Not covered by a valid subscription.
    // 
    // Multi-Attribute (multi-entitlement only) (8 cores, 4GB):
    // - Only covers 8 of 200 cores.
    // 
    // Cores Package (26 cores):
    // - Only covers 26 of 200 cores.
    // 
    // Multiplier Product Bits:
    // - Not covered by a valid subscription.
    // 
    // RAM/Cores Package (8GB, 4 cores):
    // - Only covers 4 of 200 cores.
    // 
    // Shared Storage Bits:
    // - Not covered by a valid subscription.
    // 
    // Awesome OS for ppc64 Bits:
    // - Not covered by a valid subscription.
    // 
    // Awesome OS for i686 Bits:
    // - Not covered by a valid subscription.
    // 
    // Awesome OS Premium Architecture Bits:
    // - Not covered by a valid subscription.
    // 
    // Multi-Attribute Stackable (4 cores)/Multi-Attribute Stackable (2 GB, 2 Cores)/Multi-Attribute Stackable (4 cores)/Multi-Attribute Stackable (2 GB, 2 Cores)/Multi-Attribute Stackable (16
    // cores, 4 sockets, 8GB RAM)/Multi-Attribute Stackable (2 sockets)/Multi-Attribute Stackable (2 GB)/Multi-Attribute Stackable (2 sockets)/Multi-Attribute Stackable (16 cores, 4 sockets, 8GB
    // RAM)/Multi-Attribute Stackable (2 GB):
    // - Only covers 44 of 200 cores.
    // - Only covers 12 of 100 sockets.
    // 
    // Management Bits:
    // - Not covered by a valid subscription.
    // 
    // Virt Only Awesome OS for i386 Bits:
    // - Not covered by a valid subscription.
    // 
    // Awesome OS Developer Bits:
    // - Not covered by a valid subscription.
    // 
    // Awesome OS for x86_64/i686/ia64/ppc/ppc64/s390x/s390 Bits:
    // - Not covered by a valid subscription.
    // Awesome OS Server Bits:
    // - Guest has not been reported on any host and is using a temporary unmapped guest subscription.
    // assert the overall status
    String expectedStatus = null;
    if (systemEntitlementsValid.equals("valid")) {
        // translation for "valid"
        expectedStatus = "Overall Status: Current";
    } else if (systemEntitlementsValid.equals("invalid")) {
        // translation for "invalid"
        expectedStatus = "Overall Status: Invalid";
    } else if (systemEntitlementsValid.equals("partial")) {
        // translation for "partial"	// Bug 959124 - "Compliant status" of the system set to "Insufficient" if any partial subscription is attached to a product (which is not exsiting )
        expectedStatus = "Overall Status: Insufficient";
    } else if (systemEntitlementsValid.equals("unknown")) {
        // translation for "unknown"
        expectedStatus = "Overall Status: Unknown";
    } else {
        Assert.fail("Encountered an unexpected value for systemEntitlementsValid '" + systemEntitlementsValid + "'.");
    }
    Assert.assertTrue(statusResult.getStdout().contains(expectedStatus), "Expecting '" + expectedStatus + "'.");
    // if (clienttasks.isPackageVersion("subscription-manager",">=","1.13.8-1")) {		// post commit 7957b8df95c575e6e8713c2f1a0f8f754e32aed3 bug 1119688
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.13.10-1")) {
        // exit code of 0 indicates valid compliance, otherwise exit code is 1
        if (systemEntitlementsValid.equals("valid")) {
            Assert.assertEquals(statusResult.getExitCode(), new Integer(0), "When the system's overall status is valid, an exit code of 0 should be returned.");
        } else {
            Assert.assertEquals(statusResult.getExitCode(), new Integer(1), "When the system's overall status is NOT valid, an exit code of 1 should be returned.");
        }
    }
    // assert the individual installed product status details
    for (InstalledProduct installedProduct : clienttasks.getCurrentlyInstalledProducts()) {
        // status details from the individual installed products is only included in the status report when the product is Not Subscribed
        if (installedProduct.status.equals("Not Subscribed")) {
            // expectedDetails "Not covered by a valid subscription."
            if (installedProduct.statusDetails.isEmpty())
                log.warning("Status Details appears empty.  Is your candlepin server older than 0.8.6?");
            Assert.assertTrue(!getSubstringMatches(statusResult.getStdout(), "^" + installedProduct.productName.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)") + ":").isEmpty(), "Installed product '" + installedProduct.productName + "' should be included in the overall status details report when its own status is Not Subscribed.");
            for (String statusDetail : installedProduct.statusDetails) {
                Assert.assertTrue(!getSubstringMatches(statusResult.getStdout(), "^" + installedProduct.productName.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)") + ":(\\n- .*)*?\\n- " + statusDetail.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)")).isEmpty(), "Expecting the status detail '" + statusDetail + "' of installed product '" + installedProduct.productName + "' to appear in the list of overall status details.");
                // Assert.assertTrue(!doesStringContainMatches(listStatusResult.getStdout(), "(\\n^- "+statusDetail+"){2,}"),
                // "Status detail '"+statusDetail+"' of installed product '"+installedProduct.productName+"' should NOT appear in duplicate.");
                Assert.assertTrue(!doesStringContainMatches(statusResult.getStdout(), statusDetail.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)") + "(\\n- .*)*?\\n- " + statusDetail.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)")), "Status detail '" + statusDetail + "' of installed product '" + installedProduct.productName + "' should not appear in duplicate.");
            }
        } else {
            // TEMPORARY WORKAROUND FOR BUG:
            boolean invokeWorkaroundWhileBugIsOpen = true;
            // Bug 1197897 - subscription-manager status is yellow due to 24-hour subscription despite redundant coverage from a green subscription
            String bugId = "1197897";
            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 && !getSubstringMatches(statusResult.getStdout(), "^" + installedProduct.productName.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)") + ":").isEmpty()) {
                String expectedReason = "Guest has not been reported on any host and is using a temporary unmapped guest subscription.";
                log.warning("Verifying that the reason product '" + installedProduct.productName + "' appears in the status report is because a temporary 24 hour subscription has been attached since '" + expectedReason + "'.");
                Assert.assertTrue(!getSubstringMatches(statusResult.getStdout(), "^" + installedProduct.productName.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)") + ":" + "\n- " + expectedReason).isEmpty(), "Installed product '" + installedProduct.productName + "' appears to be covered by a temporary 24 hours entitlement because the status module reports '" + expectedReason + "'");
            } else
                // assert
                // END OF WORKAROUND
                Assert.assertTrue(getSubstringMatches(statusResult.getStdout(), "^" + installedProduct.productName.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)") + ":").isEmpty(), "Installed product '" + installedProduct.productName + "' should NOT be included in the overall status details report when its own status '" + installedProduct.status + "' is something other than Not Subscribed.");
        }
    }
    // assert the individual consumed subscription status details
    List<ProductSubscription> currentlyConsumedProductSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
    for (ProductSubscription productSubscription : currentlyConsumedProductSubscriptions) {
        // if (productSubscription.statusDetails.isEmpty()) {	// is not sufficient after bug 1180400 implementation
        if (productSubscription.statusDetails.isEmpty() && clienttasks.isPackageVersion("subscription-manager", "<", "1.13.13-1")) {
            // since this productSubscription is empty, it should NOT be reported in the Status report
            Assert.assertTrue(getSubstringMatches(statusResult.getStdout(), "(^|/)" + productSubscription.productName.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)") + "(|/.+):").isEmpty(), "Expecting the empty status details " + productSubscription.statusDetails + " of consumed subscription '" + productSubscription.productName + "' to NOT appear in the list of overall status details of the installed products.");
        } else if (productSubscription.statusDetails.size() == 1 && productSubscription.statusDetails.get(0).trim().equals("Subscription is current") && clienttasks.isPackageVersion("subscription-manager", ">=", "1.13.13-1")) {
            // commit 252ec4520fb6272b00ae379703cd004f558aac63	// bug 1180400: "Status Details" are now populated on CLI
            // since this productSubscription appears to be current, it should NOT be reported in the Status report, UNLESS there is another overconsumed subscription by the same name that is not current.
            // assume
            boolean allOtherConsumedProductSubscriptionsWithThisProductNameAreCurrent = true;
            for (ProductSubscription otherConsumedProductSubscription : currentlyConsumedProductSubscriptions) {
                if (otherConsumedProductSubscription.productName.equals(productSubscription.productName) && !otherConsumedProductSubscription.poolId.equals(productSubscription.poolId) && !otherConsumedProductSubscription.statusDetails.isEmpty() && !otherConsumedProductSubscription.statusDetails.get(0).equals("Subscription is current")) {
                    allOtherConsumedProductSubscriptionsWithThisProductNameAreCurrent = false;
                    log.warning("There are multiple consumed subscriptions for '" + productSubscription.productName + "'.  Not all of them are current.");
                }
            }
            boolean statusReportIncludesProductSubscriptionProductName = getSubstringMatches(statusResult.getStdout(), "(^|/)" + productSubscription.productName.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)") + "(|/.+):").isEmpty();
            if (allOtherConsumedProductSubscriptionsWithThisProductNameAreCurrent) {
                Assert.assertTrue(statusReportIncludesProductSubscriptionProductName, "Since the status details of consumed subscription '" + productSubscription.productName + "' states Subscription is current, product '" + productSubscription.productName + "' should NOT appear in the list of overall status details of the installed products.");
            }
        // else the actual status report will be asserted when the outer for loop hits the otherConsumedProductSubscriptionsWithThisProductName
        } else {
            // since this productSubscription is not current, its status details should be reported in the Status report under the subscription's name.
            for (String statusDetail : productSubscription.statusDetails) {
                Assert.assertTrue(!getSubstringMatches(statusResult.getStdout(), "(^|/)" + productSubscription.productName.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)") + "(|/.+):(\\n- .*)*?\\n- " + statusDetail.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)")).isEmpty(), "Expecting the status detail '" + statusDetail + "' of consumed subscription '" + productSubscription.productName + "' to appear in the list of overall status details.");
                // Assert.assertTrue(!doesStringContainMatches(listStatusResult.getStdout(), "(\\n^- "+statusDetail+"){2,}"),
                // "Status detail '"+statusDetail+"' of consumed subscription '"+productSubscription+"' should NOT appear in duplicate.");
                Assert.assertTrue(!doesStringContainMatches(statusResult.getStdout(), statusDetail.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)") + "(\\n- .*)*?\\n- " + statusDetail.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)")), "Status detail '" + statusDetail + "' of consumed subscription '" + productSubscription.productName + "' should not appear in duplicate.");
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) InstalledProduct(rhsm.data.InstalledProduct) ProductSubscription(rhsm.data.ProductSubscription) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Aggregations

ProductSubscription (rhsm.data.ProductSubscription)90 Test (org.testng.annotations.Test)82 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)72 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)56 SkipException (org.testng.SkipException)46 ArrayList (java.util.ArrayList)41 SubscriptionPool (rhsm.data.SubscriptionPool)38 SSHCommandResult (com.redhat.qe.tools.SSHCommandResult)31 JSONObject (org.json.JSONObject)31 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)23 HashMap (java.util.HashMap)22 BigInteger (java.math.BigInteger)20 EntitlementCert (rhsm.data.EntitlementCert)17 InstalledProduct (rhsm.data.InstalledProduct)16 Calendar (java.util.Calendar)15 JSONArray (org.json.JSONArray)13 File (java.io.File)10 GregorianCalendar (java.util.GregorianCalendar)10 HashSet (java.util.HashSet)6 ConsumerCert (rhsm.data.ConsumerCert)6