Search in sources :

Example 11 with SubscriptionPool

use of rhsm.data.SubscriptionPool 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 12 with SubscriptionPool

use of rhsm.data.SubscriptionPool 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 13 with SubscriptionPool

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

the class SubscribeTests method testNormalAvailablePoolsFromSubscriptionsPassTheHardwareRulesCheck.

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

Example 14 with SubscriptionPool

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

the class TemporaryPoolTests method getAvailableUnmappedGuestsOnlySubscriptionPoolsDataAsListOfLists.

protected List<List<Object>> getAvailableUnmappedGuestsOnlySubscriptionPoolsDataAsListOfLists() throws JSONException, Exception {
    List<List<Object>> ll = new ArrayList<List<Object>>();
    if (!isSetupBeforeSuiteComplete)
        return ll;
    // instrument the system to be a Virtual guest
    factsMap.clear();
    factsMap.put("virt.is_guest", String.valueOf(true));
    factsMap.put("virt.uuid", "1234-5678-ABCD-EFGH");
    // set system facts that will always make the subscription available
    // ram
    factsMap.put("memory.memtotal", "1");
    // sockets
    factsMap.put("cpu.cpu_socket(s)", "1");
    // cores
    factsMap.put("cpu.core(s)_per_socket", "1");
    clienttasks.createFactsFileWithOverridingValues(factsMap);
    // note: getAvailableSubscriptionPoolsDataAsListOfLists(...) will ensure the system is newly registered
    for (List<Object> list : getAvailableSubscriptionPoolsDataAsListOfLists(false)) {
        SubscriptionPool pool = (SubscriptionPool) (list.get(0));
        if (CandlepinTasks.isPoolRestrictedToUnmappedVirtualSystems(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId)) {
            // Object bugzilla,	SubscriptionPool unmappedGuestsOnlyPool
            ll.add(Arrays.asList(new Object[] { null, pool }));
        }
    }
    return ll;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SubscriptionPool(rhsm.data.SubscriptionPool)

Example 15 with SubscriptionPool

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

the class TemporaryPoolTests method testAvailabilityOfUnmappedGuestsOnlySubpool.

// Test methods ***********************************************************************
@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-20093", "RHEL7-51735" }, 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, assert that it is available only to virtual systems whose host consumer has not yet mapped its virt.uuid as a guestId onto the host consumer.  Moreover, assert that once mapped, the pool is no longer available.", groups = { "Tier1Tests" }, dataProvider = "getAvailableUnmappedGuestsOnlySubscriptionPoolsData", enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testAvailabilityOfUnmappedGuestsOnlySubpool(Object bugzilla, SubscriptionPool unmappedGuestsOnlyPool) throws JSONException, Exception {
    // system facts were overridden in dataProvider with factsMap to fake this system as a guest
    // make sure we are freshly registered (to discard a consumer from a former data provided iteration that has mapped guests)
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, true, false, null, null, null, null);
    // verify the unmapped_guests_only pool is available for consumption
    List<SubscriptionPool> availableSubscriptionPools = clienttasks.getCurrentlyAvailableSubscriptionPools();
    Assert.assertNotNull(SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", unmappedGuestsOnlyPool.poolId, availableSubscriptionPools), "Temporary pool '" + unmappedGuestsOnlyPool.subscriptionName + "' poolId='" + unmappedGuestsOnlyPool.poolId + "' (for virtual systems whose host consumer has not yet reported this system's virt.uuid as a guest) is available for consumption.");
    // verify that it is for Virtual systems
    Assert.assertEquals(unmappedGuestsOnlyPool.machineType, "Virtual", "Temporary pools intended for unmapped guests only should indicate that it is for machine type Virtual.");
    // verify that the Subscription Type indicates it is temporary
    if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "0.9.47-1")) {
        // commit dfd7e68ae83642f77c80590439353a0d66fe2961	// Bug 1201520 - [RFE] Usability suggestions to better identify a temporary (aka 24 hour) entitlement
        String temporarySuffix = " (Temporary)";
        Assert.assertTrue(unmappedGuestsOnlyPool.subscriptionType.endsWith(temporarySuffix), "The Subscription Type for a temporary pool intended for unmapped guests only should end in suffix '" + temporarySuffix + "' (actual='" + unmappedGuestsOnlyPool.subscriptionType + "').");
    }
    // verify that the corresponding Physical pool is also available (when not physical_only)
    String parentPhysicalPoolId = getParentPoolIdCorrespondingToDerivedPoolId(sm_clientUsername, sm_clientPassword, sm_serverUrl, clienttasks.getCurrentlyRegisteredOwnerKey(), unmappedGuestsOnlyPool.poolId);
    Assert.assertNotNull(parentPhysicalPoolId, "Found parent Physical poolId corresponding to temporary unmapped guests only poolId '" + unmappedGuestsOnlyPool.poolId + "'.");
    SubscriptionPool parentPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", parentPhysicalPoolId, availableSubscriptionPools);
    if (CandlepinTasks.isPoolRestrictedToPhysicalSystems(sm_clientUsername, sm_clientPassword, sm_serverUrl, parentPhysicalPoolId)) {
        Assert.assertNull(parentPool, "Should NOT found parent pool corresponding to temporary unmapped guests only poolId '" + unmappedGuestsOnlyPool.poolId + "' among available pools since it is Physical only.");
    } else {
        Assert.assertNotNull(parentPool, "Found parent Physical pool corresponding to temporary unmapped guests only poolId '" + unmappedGuestsOnlyPool.poolId + "' among available pools.");
        Assert.assertEquals(parentPool.machineType, "Physical", "The machine type for the parent pool corresponding to temporary unmapped guests only poolId '" + unmappedGuestsOnlyPool.poolId + "'.");
    }
    // simulate the actions of virt-who my mapping the virt.uuid as a guestID onto a host consumer
    clienttasks.mapSystemAsAGuestOfItself();
    // verify that the unmapped_guests_only pool is no longer available
    Assert.assertNull(SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", unmappedGuestsOnlyPool.poolId, clienttasks.getCurrentlyAvailableSubscriptionPools()), "Temporary pool '" + unmappedGuestsOnlyPool.subscriptionName + "' poolId='" + unmappedGuestsOnlyPool.poolId + "' (for virtual systems whose host consumer has not yet reported this system's virt.uuid as a guest) is NO LONGER available for consumption after it's virt.uuid has been mapped to a consumer's guestId list.");
    // assert that we are blocked from attempt to attach the temporary pool
    // 201503191231:11.346 - FINE: ssh root@jsefler-os6.usersys.redhat.com subscription-manager subscribe --pool=8a9087e34c2f214a014c2f22a7d11ad0
    // 201503191231:16.011 - FINE: Stdout: Pool is restricted to unmapped virtual guests: '8a9087e34c2f214a014c2f22a7d11ad0'
    // 201503191231:16.014 - FINE: Stderr:
    // 201503191231:16.016 - FINE: ExitCode: 1
    SSHCommandResult result = clienttasks.subscribe_(null, null, unmappedGuestsOnlyPool.poolId, null, null, null, null, null, null, null, null, null, null);
    String expectedStdout = String.format("Pool is restricted to unmapped virtual guests: '%s'", unmappedGuestsOnlyPool.poolId);
    if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.3.1-1")) {
        // commit 0d5fefcfa8c1c2485921d2dee6633879b1e06931 Correct incorrect punctuation in user messages
        expectedStdout = String.format("Pool is restricted to unmapped virtual guests: \"%s\".", unmappedGuestsOnlyPool.poolId);
    }
    String expectedStderr = "";
    Assert.assertEquals(result.getStdout().trim(), expectedStdout, "Stdout from an attempt to attach a temporary pool to a virtual guest that has already been mapped.");
    Assert.assertEquals(result.getStderr().trim(), expectedStderr, "Stderr from an attempt to attach a temporary pool to a virtual guest that has already been mapped.");
    Assert.assertEquals(result.getExitCode(), Integer.valueOf(1), "Exit code from an attempt to attach a temporary pool to a virtual guest that has already been mapped.");
}
Also used : SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Aggregations

SubscriptionPool (rhsm.data.SubscriptionPool)195 Test (org.testng.annotations.Test)155 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)137 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)112 SkipException (org.testng.SkipException)90 ArrayList (java.util.ArrayList)87 JSONObject (org.json.JSONObject)66 SSHCommandResult (com.redhat.qe.tools.SSHCommandResult)53 ProductSubscription (rhsm.data.ProductSubscription)38 BigInteger (java.math.BigInteger)37 File (java.io.File)34 List (java.util.List)33 EntitlementCert (rhsm.data.EntitlementCert)33 HashMap (java.util.HashMap)32 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)28 InstalledProduct (rhsm.data.InstalledProduct)25 ProductCert (rhsm.data.ProductCert)24 JSONArray (org.json.JSONArray)22 Calendar (java.util.Calendar)12 GregorianCalendar (java.util.GregorianCalendar)11