Search in sources :

Example 36 with SSHCommandResult

use of com.redhat.qe.tools.SSHCommandResult in project rhsm-qe by RedHatQE.

the class SubscribeTests method testSubscribeWithQuantityToMultiplePools.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36585", "RHEL7-51388" }, 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: subscribe to multiple pools using --quantity that exceeds some pools and is under other pools.", groups = { "Tier2Tests", "blockedByBug-722975" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testSubscribeWithQuantityToMultiplePools() throws JSONException, Exception {
    // is this system virtual
    boolean isSystemVirtual = Boolean.valueOf(clienttasks.getFactValue("virt.is_guest"));
    // register
    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);
    // get all the available pools
    List<SubscriptionPool> pools = clienttasks.getCurrentlyAllAvailableSubscriptionPools();
    List<String> poolIds = new ArrayList<String>();
    // find the poolIds and their quantities
    List<Integer> quantities = new ArrayList<Integer>();
    for (SubscriptionPool pool : pools) {
        poolIds.add(pool.poolId);
        // ignore  "unlimited" pools
        try {
            Integer.valueOf(pool.quantity);
        } catch (NumberFormatException e) {
            continue;
        }
        quantities.add(Integer.valueOf(pool.quantity));
    }
    Collections.sort(quantities);
    // choose the median as the quantity to subscribe with
    int quantity = quantities.get(quantities.size() / 2);
    // collectively subscribe to all pools with --quantity
    SSHCommandResult subscribeResult = clienttasks.subscribe_(null, null, poolIds, null, null, String.valueOf(quantity), null, null, null, null, null, null, null);
    /*
		Multi-entitlement not supported for pool with id '8a90f8c6320e9a4401320e9be0e20480'.
		Successfully subscribed the system to Pool 8a90f8c6320e9a4401320e9be196049e
		No free entitlements are available for the pool with id '8a90f8c6320e9a4401320e9be1d404a8'.
		Multi-entitlement not supported for pool with id '8a90f8c6320e9a4401320e9be24004be'.
		Successfully subscribed the system to Pool 8a90f8c6320e9a4401320e9be2e304dd
		No free entitlements are available for the pool with id '8a90f8c6320e9a4401320e9be30c04e8'.
		Multi-entitlement not supported for pool with id '8a90f8c6320e9a4401320e9be3b80505'.
		Multi-entitlement not supported for pool with id '8a90f8c6320e9a4401320e9be4660520'.
		Pool is restricted to physical systems: '8a9086d34470376901447038624d0f87'.
		Pool is restricted to virtual guests: '8a9086d344549b0c0144549bf9ae0dd4'.
		*/
    // assert that the expected pools were subscribed to based on quantity
    Assert.assertEquals(subscribeResult.getExitCode(), Integer.valueOf(0), "The exit code from the subscribe command indicates a success.");
    String expectedSubscribeResultStdoutSubString = null;
    for (SubscriptionPool pool : pools) {
        if (quantity > 1 && !CandlepinTasks.isPoolProductMultiEntitlement(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId)) {
            expectedSubscribeResultStdoutSubString = String.format("Multi-entitlement not supported for pool with id '%s'.", pool.poolId);
            if (!clienttasks.workaroundForBug876764(sm_serverType))
                expectedSubscribeResultStdoutSubString = String.format("Multi-entitlement not supported for pool with ID '%s'.", pool.poolId);
            if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.3.1-1")) {
                // commit 0d5fefcfa8c1c2485921d2dee6633879b1e06931 Correct incorrect punctuation in user messages
                expectedSubscribeResultStdoutSubString = String.format("Multi-entitlement not supported for pool with ID \"%s\".", pool.poolId);
            }
            Assert.assertTrue(subscribeResult.getStdout().contains(expectedSubscribeResultStdoutSubString), "Subscribe attempt to non-multi-entitlement pool '" + pool.poolId + "' was NOT successful when subscribing with --quantity greater than one.");
        } else if (isSystemVirtual && CandlepinTasks.isPoolRestrictedToPhysicalSystems(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId)) {
            // Note: the "Multi-entitlement not supported" restriction is thrown before "Pool is restricted to physical systems"
            expectedSubscribeResultStdoutSubString = String.format("Pool is restricted to physical systems: '%s'.", pool.poolId);
            if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.3.1-1")) {
                // commit 0d5fefcfa8c1c2485921d2dee6633879b1e06931 Correct incorrect punctuation in user messages
                expectedSubscribeResultStdoutSubString = String.format("Pool is restricted to physical systems: \"%s\".", pool.poolId);
            }
            Assert.assertTrue(subscribeResult.getStdout().contains(expectedSubscribeResultStdoutSubString), "Subscribe attempt to physical_only pool '" + pool.poolId + "' was NOT successful when system is virtual.");
        } else if (!isSystemVirtual && CandlepinTasks.isPoolRestrictedToVirtualSystems(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId)) {
            // Note: the "Multi-entitlement not supported" restriction is thrown before "Pool is restricted to virtual systems"
            expectedSubscribeResultStdoutSubString = String.format("Pool is restricted to virtual guests: '%s'.", pool.poolId);
            if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.3.1-1")) {
                // commit 0d5fefcfa8c1c2485921d2dee6633879b1e06931 Correct incorrect punctuation in user messages
                expectedSubscribeResultStdoutSubString = String.format("Pool is restricted to virtual guests: \"%s\".", pool.poolId);
            }
            Assert.assertTrue(subscribeResult.getStdout().contains(expectedSubscribeResultStdoutSubString), "Subscribe attempt to virt_only pool '" + pool.poolId + "' was NOT successful when system is physical.");
        } else if (pool.quantity.equalsIgnoreCase("unlimited") || quantity <= Integer.valueOf(pool.quantity)) {
            // Assert.assertTrue(subscribeResult.getStdout().contains(String.format("Successfully consumed a subscription from the pool with id %s.",pool.poolId)),"Subscribe to pool '"+pool.poolId+"' was successful when subscribing with --quantity less than or equal to the pool's availability.");	// Bug 812410 - Subscription-manager subscribe CLI feedback
            // Assert.assertTrue(subscribeResult.getStdout().contains(String.format("Successfully consumed a subscription for: %s",pool.subscriptionName)),"Subscribe to pool '"+pool.poolId+"' was successful when subscribing with --quantity less than or equal to the pool's availability.");	// changed by Bug 874804 Subscribe -> Attach
            Assert.assertTrue(subscribeResult.getStdout().contains(String.format("Successfully attached a subscription for: %s", pool.subscriptionName)), "Subscribe to pool '" + pool.poolId + "' was successful when subscribing with --quantity less than or equal to the pool's availability.");
        } else {
            // expected string changed by bug 876758
            expectedSubscribeResultStdoutSubString = String.format("No entitlements are available from the pool with id '%s'.", pool.poolId);
            expectedSubscribeResultStdoutSubString = String.format("No subscriptions are available from the pool with id '%s'.", pool.poolId);
            if (!clienttasks.workaroundForBug876764(sm_serverType))
                expectedSubscribeResultStdoutSubString = String.format("No subscriptions are available from the pool with ID '%s'.", pool.poolId);
            if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.3.1-1")) {
                // commit 0d5fefcfa8c1c2485921d2dee6633879b1e06931 Correct incorrect punctuation in user messages
                expectedSubscribeResultStdoutSubString = String.format("No subscriptions are available from the pool with ID \"%s\".", pool.poolId);
            }
            Assert.assertTrue(subscribeResult.getStdout().contains(expectedSubscribeResultStdoutSubString), "Subscribe to pool '" + pool.poolId + "' was NOT successful when subscribing with --quantity greater than the pool's availability.");
        }
    }
}
Also used : BigInteger(java.math.BigInteger) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) ArrayList(java.util.ArrayList) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 37 with SSHCommandResult

use of com.redhat.qe.tools.SSHCommandResult in project rhsm-qe by RedHatQE.

the class SubscribeTests method testSubscribeWithQuantity.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-19981", "RHEL7-33098" }, 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 using various good and bad values for the --quantity option", groups = { "Tier1Tests", "blockedByBug-962520" }, dataProvider = "getSubscribeWithQuantityData", enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testSubscribeWithQuantity(Object meta, SubscriptionPool pool, String quantity, Integer expectedExitCode, String expectedStdoutRegex, String expectedStderrRegex) {
    log.info("Testing subscription-manager subscribe using various good and bad values for the --quantity option.");
    // special case in the dataProvider to identify when a test pool was not available; expectedStderrRegex contains a message for what kind of test pool was being searched for.
    if (pool == null)
        throw new SkipException(expectedStderrRegex);
    // start fresh by returning all entitlements
    clienttasks.unsubscribeFromAllOfTheCurrentlyConsumedProductSubscriptions();
    // for debugging purposes, list what is currently available so we can see the available quantity before we attempt to attach
    clienttasks.list_(null, true, null, null, null, null, null, null, null, null, null, null, null, null);
    // subscribe with quantity
    SSHCommandResult sshCommandResult = clienttasks.subscribe_(null, null, pool.poolId, null, null, quantity, null, null, null, null, null, null, null);
    // assert the sshCommandResult here
    if (expectedExitCode != null)
        Assert.assertEquals(sshCommandResult.getExitCode(), expectedExitCode, "ExitCode after subscribe with quantity=\"" + quantity + "\" option:");
    if (expectedStdoutRegex != null)
        Assert.assertContainsMatch(sshCommandResult.getStdout().trim(), expectedStdoutRegex, "Stdout after subscribe with --quantity=\"" + quantity + "\" option:");
    if (expectedStderrRegex != null)
        Assert.assertContainsMatch(sshCommandResult.getStderr().trim(), expectedStderrRegex, "Stderr after subscribe with --quantity=\"" + quantity + "\" option:");
    // when successful, assert that the quantity is correctly reported in the list of consumed subscriptions
    List<ProductSubscription> subscriptionsConsumed = client1tasks.getCurrentlyConsumedProductSubscriptions();
    List<EntitlementCert> entitlementCerts = client1tasks.getCurrentEntitlementCerts();
    if (expectedExitCode == 0 && expectedStdoutRegex != null && expectedStdoutRegex.contains("Successful")) {
        Assert.assertEquals(entitlementCerts.size(), 1, "One EntitlementCert should have been downloaded to " + client1tasks.hostname + " when the attempt to subscribe is successful.");
        Assert.assertEquals(entitlementCerts.get(0).orderNamespace.quantityUsed, quantity.replaceFirst("^\\+", ""), "The quantityUsed in the OrderNamespace of the downloaded EntitlementCert should match the quantity requested when we subscribed to pool '" + pool.poolId + "'.  OrderNamespace: " + entitlementCerts.get(0).orderNamespace);
        for (ProductSubscription productSubscription : subscriptionsConsumed) {
            Assert.assertEquals(productSubscription.quantityUsed, Integer.valueOf(quantity.replaceFirst("^\\+", "")), "The quantityUsed reported in each consumed ProductSubscription should match the quantity requested when we subscribed to pool '" + pool.poolId + "'.  ProductSubscription: " + productSubscription);
        }
    } else {
        Assert.assertEquals(subscriptionsConsumed.size(), 0, "No subscriptions should be consumed when the attempt to subscribe is not successful.");
    }
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) ProductSubscription(rhsm.data.ProductSubscription) SkipException(org.testng.SkipException) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 38 with SSHCommandResult

use of com.redhat.qe.tools.SSHCommandResult 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 39 with SSHCommandResult

use of com.redhat.qe.tools.SSHCommandResult 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 40 with SSHCommandResult

use of com.redhat.qe.tools.SSHCommandResult 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)

Aggregations

SSHCommandResult (com.redhat.qe.tools.SSHCommandResult)553 Test (org.testng.annotations.Test)416 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)401 SkipException (org.testng.SkipException)219 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)201 ArrayList (java.util.ArrayList)101 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)79 BigInteger (java.math.BigInteger)68 File (java.io.File)58 SubscriptionPool (rhsm.data.SubscriptionPool)53 JSONObject (org.json.JSONObject)47 HashMap (java.util.HashMap)42 ProductSubscription (rhsm.data.ProductSubscription)31 EntitlementCert (rhsm.data.EntitlementCert)30 List (java.util.List)21 YumRepo (rhsm.data.YumRepo)18 ProductCert (rhsm.data.ProductCert)17 Repo (rhsm.data.Repo)16 InstalledProduct (rhsm.data.InstalledProduct)15 Calendar (java.util.Calendar)13