Search in sources :

Example 51 with TestDefinition

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

the class SubscribeTests method testMultiConsumerSubscribeWithQuantity.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36578", "RHEL7-51379" }, 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 using --quantity option and assert the available quantity is properly decremented/incremeneted as multiple consumers subscribe/unsubscribe.", groups = { "Tier2Tests", "blockedByBug-979492" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testMultiConsumerSubscribeWithQuantity() throws NumberFormatException, JSONException, Exception {
    // start by calling SubscribeWithQuantity_Test with the row from the dataProvider where quantity=2
    SubscriptionPool consumer1Pool = null;
    int consumer1Quantity = 0;
    int totalPoolQuantity = 0;
    for (List<Object> row : getSubscribeWithQuantityDataAsListOfLists()) {
        // find the row where quantity.equals("2")
        if (((String) (row.get(2)) != null) && ((String) (row.get(4)) != null)) {
            if (((String) (row.get(2))).equals("2") && ((String) (row.get(4))).startsWith("^Successful")) {
                consumer1Pool = (SubscriptionPool) row.get(1);
                totalPoolQuantity = Integer.valueOf(consumer1Pool.quantity);
                consumer1Quantity = Integer.valueOf((String) row.get(2));
                testSubscribeWithQuantity(row.get(0), (SubscriptionPool) row.get(1), (String) row.get(2), (Integer) row.get(3), (String) row.get(4), (String) row.get(5));
                break;
            }
        }
    }
    if (consumer1Pool == null)
        Assert.fail("Failed to initiate the first consumer for this test.");
    // remember the current consumerId
    String consumer1Id = clienttasks.getCurrentConsumerId();
    systemConsumerIds.add(consumer1Id);
    // clean the client and register a second consumer
    clienttasks.clean();
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, "SubscriptionQuantityConsumer2", null, null, null, null, (String) null, null, null, null, false, false, null, null, null, null);
    // remember the second consumerId
    String consumer2Id = clienttasks.getCurrentConsumerId();
    systemConsumerIds.add(consumer2Id);
    // find the pool among the available pools
    SubscriptionPool consumer2Pool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", consumer1Pool.poolId, clienttasks.getCurrentlyAvailableSubscriptionPools());
    Assert.assertNotNull(consumer2Pool, "Consumer2 found the same pool from which consumer1 subscribed a quantity of " + consumer1Quantity);
    // assert that the quantity available to consumer2 is correct
    int consumer2Quantity = totalPoolQuantity - consumer1Quantity;
    Assert.assertEquals(consumer2Pool.quantity, String.valueOf(consumer2Quantity), "The pool quantity available to consumer2 has been decremented by the quantity consumer1 consumed.");
    // assert that consumer2 can NOT oversubscribe
    Assert.assertTrue(!clienttasks.subscribe(null, null, consumer2Pool.poolId, null, null, String.valueOf(consumer2Quantity + 1), null, null, null, null, null, null, null).getStdout().startsWith("Success"), "An attempt by consumer2 to oversubscribe using the remaining pool quantity+1 should NOT succeed.");
    // assert that consumer2 can successfully consume all the remaining pool quantity
    Assert.assertTrue(clienttasks.subscribe(null, null, consumer2Pool.poolId, null, null, String.valueOf(consumer2Quantity), null, null, null, null, null, null, null).getStdout().startsWith("Success"), "An attempt by consumer2 to exactly consume the remaining pool quantity should succeed.");
    // start rolling back the subscribes
    clienttasks.clean();
    // restore consumer1, unsubscribe, and assert remaining quantities
    clienttasks.register(sm_clientUsername, sm_clientPassword, null, null, null, null, consumer1Id, null, null, null, (String) null, null, null, null, false, false, null, null, null, null);
    Assert.assertNull(SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", consumer1Pool.poolId, clienttasks.getCurrentlyAvailableSubscriptionPools()), "SubscriptionPool '" + consumer1Pool.poolId + "' should NOT be available (because consumer1 is already subscribed to it).");
    clienttasks.unsubscribe(null, clienttasks.getCurrentlyConsumedProductSubscriptions().get(0).serialNumber, null, null, null, null, null);
    consumer1Pool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", consumer1Pool.poolId, clienttasks.getCurrentlyAvailableSubscriptionPools());
    Assert.assertEquals(consumer1Pool.quantity, String.valueOf(totalPoolQuantity - consumer2Quantity), "The pool quantity available to consumer1 has incremented by the quantity consumer1 consumed.");
    clienttasks.unregister(null, null, null, null);
    // restore consumer2, unsubscribe, and assert remaining quantities
    clienttasks.register(sm_clientUsername, sm_clientPassword, null, null, null, null, consumer2Id, null, null, null, (String) null, null, null, null, false, false, null, null, null, null);
    consumer2Pool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", consumer2Pool.poolId, clienttasks.getCurrentlyAvailableSubscriptionPools());
    // Assert.assertNull(consumer2Pool,"SubscriptionPool '"+consumer2Pool.poolId+"' should NOT be available (because consumer2 is already subscribed to it).");
    Assert.assertNotNull(consumer2Pool, "SubscriptionPool '" + consumer2Pool.poolId + "' should be available even though consumer2 is already subscribed to it because it is multi-entitleable.");
    Assert.assertEquals(consumer2Pool.quantity, String.valueOf(totalPoolQuantity - consumer2Quantity), "The pool quantity available to consumer2 is still decremented by the quantity consumer2 consumed.");
    clienttasks.unsubscribe(null, clienttasks.getCurrentlyConsumedProductSubscriptions().get(0).serialNumber, null, null, null, null, null);
    consumer2Pool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", consumer2Pool.poolId, clienttasks.getCurrentlyAvailableSubscriptionPools());
    Assert.assertEquals(consumer2Pool.quantity, String.valueOf(totalPoolQuantity), "The pool quantity available to consumer2 has been restored to its original total quantity");
    clienttasks.unregister(null, null, null, null);
}
Also used : JSONObject(org.json.JSONObject) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 52 with TestDefinition

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

the class SubscribeTests method testSubscribeToMultipleDuplicateAndBadPools.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36587", "RHEL7-51390" }, 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-cli: subscribe consumer to multiple/duplicate/bad pools in one call", groups = { "Tier2Tests", "blockedByBug-622851", "blockedByBug-995597" }, enabled = true)
public void testSubscribeToMultipleDuplicateAndBadPools() throws JSONException, Exception {
    // begin the test with a cleanly registered system
    clienttasks.unregister(null, null, null, 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);
    // assemble a list of all the available SubscriptionPool ids with duplicates and bad ids
    List<String> poolIds = new ArrayList<String>();
    Map<String, String> poolNames = new HashMap<String, String>();
    for (SubscriptionPool pool : clienttasks.getCurrentlyAvailableSubscriptionPools()) {
        poolIds.add(pool.poolId);
        // add a duplicate poolid
        poolIds.add(pool.poolId);
        poolNames.put(pool.poolId, pool.subscriptionName);
    }
    String badPoolId1 = "bad123", badPoolId2 = "bad_POOLID";
    // insert a bad poolid
    poolIds.add(0, badPoolId1);
    // append a bad poolid
    poolIds.add(badPoolId2);
    // subscribe to all pool ids
    log.info("Attempting to subscribe to multiple pools with duplicate and bad pool ids...");
    SSHCommandResult subscribeResult = clienttasks.subscribe_(null, null, poolIds, null, null, null, null, null, null, null, null, null, null);
    /*
		No such entitlement pool: bad123
		Successfully subscribed the system to Pool 8a90f8c63159ce55013159cfd6c40303
		This consumer is already subscribed to the product matching pool with id '8a90f8c63159ce55013159cfd6c40303'.
		Successfully subscribed the system to Pool 8a90f8c63159ce55013159cfea7a06ac
		Successfully subscribed the system to Pool 8a90f8c63159ce55013159cfea7a06ac
		No such entitlement pool: bad_POOLID
		*/
    // assert the results...
    Assert.assertEquals(subscribeResult.getExitCode(), Integer.valueOf(0), "The exit code from the subscribe command indicates a success.");
    for (String poolId : poolIds) {
        String subscribeResultMessage;
        if (poolId.equals(badPoolId1) || poolId.equals(badPoolId2)) {
            subscribeResultMessage = String.format("No such entitlement pool: %s", poolId);
            subscribeResultMessage = String.format("Subscription pool %s does not exist.", poolId);
            subscribeResultMessage = String.format("Pool with id %s could not be found.", poolId);
            Assert.assertTrue(subscribeResult.getStdout().contains(subscribeResultMessage), "The subscribe result for an invalid pool '" + poolId + "' contains: " + subscribeResultMessage);
        } else if (CandlepinTasks.isPoolProductMultiEntitlement(sm_clientUsername, sm_clientPassword, sm_serverUrl, poolId)) {
            // Bug 812410 - Subscription-manager subscribe CLI feedback
            subscribeResultMessage = String.format("Successfully consumed a subscription from the pool with id %s.", poolId);
            // changed by Bug 874804 Subscribe -> Attach
            subscribeResultMessage = String.format("Successfully consumed a subscription for: %s", poolNames.get(poolId));
            subscribeResultMessage = String.format("Successfully attached a subscription for: %s", poolNames.get(poolId));
            subscribeResultMessage += "\n" + subscribeResultMessage;
            Assert.assertTrue(subscribeResult.getStdout().contains(subscribeResultMessage), "The duplicate subscribe result for a multi-entitlement pool '" + poolId + "' contains: " + subscribeResultMessage);
        } else if (false) {
        // TODO case when there are no entitlements remaining for the duplicate subscribe
        } else {
            // Bug 812410 - Subscription-manager subscribe CLI feedback
            subscribeResultMessage = String.format("Successfully consumed a subscription from the pool with id %s.", poolId);
            // changed by Bug 874804 Subscribe -> Attach
            subscribeResultMessage = String.format("Successfully consumed a subscription for: %s", poolNames.get(poolId));
            subscribeResultMessage = String.format("Successfully attached a subscription for: %s", poolNames.get(poolId));
            String subscribeResultSubMessage = String.format("This consumer is already subscribed to the product matching pool with id '%s'.", poolId);
            if (!clienttasks.workaroundForBug876764(sm_serverType))
                subscribeResultSubMessage = String.format("This unit has already had the subscription matching pool ID '%s' attached.", poolId);
            if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.3.1-1")) {
                // commit 0d5fefcfa8c1c2485921d2dee6633879b1e06931 Correct incorrect punctuation in user messages
                subscribeResultSubMessage = String.format("This unit has already had the subscription matching pool ID \"%s\" attached.", poolId);
            }
            subscribeResultMessage += "\n" + subscribeResultSubMessage;
            Assert.assertTrue(subscribeResult.getStdout().contains(subscribeResultMessage), "The duplicate subscribe result for pool '" + poolId + "' contains: " + subscribeResultMessage);
        }
    }
}
Also used : HashMap(java.util.HashMap) 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 53 with TestDefinition

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

the class SubscribeTests method testSubscribeToFutureSubscriptionPool.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-27122", "RHEL7-51945" }, 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 future subscription pool", groups = { "Tier2Tests", "blockedByBug-979492", "blockedByBug-1440180" }, // dataProvider="getAllFutureSystemSubscriptionPoolsData",	// 06/04/2014 takes too long; rarely reveals a bug
dataProvider = "getRandomSubsetOfFutureSystemSubscriptionPoolsData", enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testSubscribeToFutureSubscriptionPool(SubscriptionPool pool) throws Exception {
    // if (!pool.productId.equals("awesomeos-virt-unlmtd-phys")) throw new SkipException("debugTesting pool productId="+pool.productId);
    Calendar now = new GregorianCalendar();
    now.setTimeInMillis(System.currentTimeMillis());
    // subscribe to the future subscription pool
    SSHCommandResult subscribeResult = clienttasks.subscribe(null, null, pool.poolId, null, null, null, null, null, null, null, null, null, null);
    // Pool is restricted to physical systems: '8a9086d3443c043501443c052aec1298'.
    if (subscribeResult.getStdout().startsWith("Pool is restricted")) {
        throw new SkipException("Subscribing to this future subscription is not applicable to this test: " + pool);
    }
    // assert that the granted entitlement cert begins in the future
    EntitlementCert entitlementCert = clienttasks.getEntitlementCertCorrespondingToSubscribedPool(pool);
    Assert.assertNotNull(entitlementCert, "Found the newly granted EntitlementCert on the client after subscribing to future subscription pool '" + pool.poolId + "'.");
    Assert.assertTrue(entitlementCert.validityNotBefore.after(now), "The newly granted EntitlementCert is not valid until the future.  EntitlementCert: " + entitlementCert);
    Assert.assertTrue(entitlementCert.orderNamespace.startDate.after(now), "The newly granted EntitlementCert's OrderNamespace starts in the future.  OrderNamespace: " + entitlementCert.orderNamespace);
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) SkipException(org.testng.SkipException) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 54 with TestDefinition

use of com.github.redhatqe.polarize.metadata.TestDefinition 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 55 with TestDefinition

use of com.github.redhatqe.polarize.metadata.TestDefinition 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)

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