Search in sources :

Example 6 with SubscriptionPool

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

the class VirtualizationTests method testHostAndGuestPoolQuantities.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-22223", "RHEL7-59439" }, 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 Tier2")
@Test(description = "Verify host and guest pools quantities generated from a virtualization-aware subscription", // "blockedByBug-679617" indirectly when this script is run as part of the full TestNG suite since this is influenced by other scripts calling refresh pools
groups = { "Tier1Tests", "Tier2Tests", "VerifyHostAndGuestPoolQuantities_Test" }, dependsOnGroups = {}, dataProvider = "getVirtSubscriptionData", enabled = true)
public void testHostAndGuestPoolQuantities(String subscriptionId, String productName, String productId, int quantity, String virtLimit, String hostPoolId, String guestPoolId, Boolean physicalOnly) throws JSONException, Exception {
    if (hostPoolId == null && guestPoolId == null)
        throw new SkipException("Failed to find expected host and guest pools derived from virtualization-aware subscription id '" + subscriptionId + "' (" + productName + ").");
    // if (!productId.equals("awesomeos-virt-unlimited")) throw new SkipException("debugTesting VerifyHostAndGuestPoolQuantities_Test");
    JSONObject jsonHostPool = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/pools/" + hostPoolId));
    int jsonHostPoolQuantity = jsonHostPool.getInt("quantity");
    int jsonHostPoolQuantityConsumed = jsonHostPool.getInt("consumed");
    int jsonHostPoolQuantityExported = jsonHostPool.getInt("exported");
    JSONObject jsonGuestPool = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/pools/" + guestPoolId));
    int jsonGuestPoolQuantity = jsonGuestPool.getInt("quantity");
    int jsonGuestPoolQuantityConsumed = jsonGuestPool.getInt("consumed");
    int jsonGuestPoolQuantityExported = jsonGuestPool.getInt("exported");
    // trick this system into believing it is a virt guest
    forceVirtWhatToReturnGuest("kvm");
    // get the available pools
    List<SubscriptionPool> allAvailablePools = clienttasks.getCurrentlyAllAvailableSubscriptionPools();
    // get the hostPool
    SubscriptionPool hostPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", hostPoolId, allAvailablePools);
    // determine the availability of the hostPool
    if (jsonHostPoolQuantityConsumed > jsonHostPoolQuantity) {
        Assert.fail("Host pool id '" + hostPoolId + "' has a consumed attribute value '" + jsonHostPoolQuantityConsumed + "' that exceeds its total quantity '" + jsonHostPoolQuantity + "'.  This does NOT make sense.");
    } else if (jsonHostPoolQuantityConsumed == jsonHostPoolQuantity) {
        Assert.assertNull(hostPool, "Host pool id '" + hostPoolId + "', derived from the virtualization-aware subscription id '" + subscriptionId + "', is NOT listed in all available subscriptions since all of its quantity are already being consumed by other systems.");
    } else {
        Assert.assertNotNull(hostPool, "Host pool id '" + hostPoolId + "', derived from the virtualization-aware subscription id '" + subscriptionId + "', is listed in all available subscriptions: " + hostPool);
        // Assert.assertEquals(Integer.valueOf(hostPool.quantity), Integer.valueOf(quantity-jsonHostPoolQuantityConsumed), "Assuming '"+jsonHostPoolQuantityConsumed+"' entitlements are currently being consumed from this host pool '"+hostPool.poolId+"', the quantity of available entitlements should be '"+quantity+"' minus '"+jsonHostPoolQuantityConsumed+"' (COULD BE DIFFERENT IF ANOTHER PHYSICAL HOST SYSTEM IS SIMULTANEOUSLY SUBSCRIBING TO THE SAME POOL OR JUST RETURNED AN ENTITLEMENT TO THE SAME POOL).");
        if (!Integer.valueOf(hostPool.quantity).equals(Integer.valueOf(quantity - jsonHostPoolQuantityConsumed))) {
            log.warning("Assuming '" + jsonHostPoolQuantityConsumed + "' entitlements are currently being consumed from this host pool '" + hostPool.poolId + "', the quantity of available entitlements should be '" + quantity + "' minus '" + jsonHostPoolQuantityConsumed + "' (COULD BE DIFFERENT IF ANOTHER PHYSICAL HOST SYSTEM IS SIMULTANEOUSLY SUBSCRIBING TO THE SAME POOL OR JUST RETURNED AN ENTITLEMENT TO THE SAME POOL).");
        }
        if (!CandlepinType.hosted.equals(sm_serverType)) {
            // too many false negatives occur on hosted due to simultaneous client consumption from the same pool
            Assert.assertEquals(Integer.valueOf(hostPool.quantity), Integer.valueOf(quantity - jsonHostPoolQuantityConsumed), "Assuming '" + jsonHostPoolQuantityConsumed + "' entitlements are currently being consumed from this host pool '" + hostPool.poolId + "', the quantity of available entitlements should be '" + quantity + "' minus '" + jsonHostPoolQuantityConsumed + "' (COULD BE DIFFERENT IF ANOTHER PHYSICAL HOST SYSTEM IS SIMULTANEOUSLY SUBSCRIBING TO THE SAME POOL OR JUST RETURNED AN ENTITLEMENT TO THE SAME POOL).");
        }
    }
    // get the guestPool
    SubscriptionPool guestPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", guestPoolId, allAvailablePools);
    // determine the availability of the guestPool
    if (jsonGuestPoolQuantity == -1) {
        Assert.assertNotNull(guestPool, "Guest pool id '" + guestPoolId + "', derived from the virtualization-aware subscription id '" + subscriptionId + "', is listed in all available subscriptions: " + guestPool);
        // assert guestPoolId quantity is unlimited
        // altered after Bug 862885 - String Update: Capitalize unlimited in the All Available Subscriptions tab
        Assert.assertEquals(guestPool.quantity, "Unlimited", "When the subscription product has a quantity attribute of '-1', then the guest pool's quantity viewed by within the list --all --available should be 'Unlimited'.");
        Assert.assertEquals(virtLimit, "unlimited", "When the subscription product has a quantity attribute of '-1', then the guest pool's virt_limit attribute should be 'unlimited'.");
    } else if (jsonGuestPoolQuantityConsumed > jsonGuestPoolQuantity) {
        Assert.fail("Guest pool id '" + guestPoolId + "' has a consumed attribute value '" + jsonGuestPoolQuantityConsumed + "' that exceeds its total quantity '" + jsonGuestPoolQuantity + "'.  This does NOT make sense.");
    } else if (jsonGuestPoolQuantityConsumed == jsonGuestPoolQuantity) {
        Assert.assertNull(guestPool, "Guest pool id '" + guestPoolId + "', derived from the virtualization-aware subscription id '" + subscriptionId + "', is NOT listed in all available subscriptions since all of its quantity are already being consumed by other systems.");
    } else {
        Assert.assertNotNull(guestPool, "Guest pool id '" + guestPoolId + "', derived from the virtualization-aware subscription id '" + subscriptionId + "', is listed in all available subscriptions: " + guestPool);
        // Assert.assertEquals(Integer.valueOf(guestPool.quantity), Integer.valueOf((quantity-jsonHostPoolQuantityExported)*Integer.valueOf(virtLimit)-jsonGuestPoolQuantityConsumed), "Assuming '"+jsonGuestPoolQuantityConsumed+"' entitlements are currently being consumed from guest pool '"+guestPool.poolId+"', the quantity of available entitlements for this guest pool should be the host pool's virt_limit of '"+virtLimit+"' times (the host's total quantity '"+quantity+"' minus those exported '"+jsonHostPoolQuantityExported+"') minus the number of already consumed from the pool '"+jsonGuestPoolQuantityConsumed+"'  (COULD BE DIFFERENT IF ANOTHER VIRTUAL GUEST SYSTEM IS SIMULTANEOUSLY SUBSCRIBING TO THE SAME POOL).");
        if (!Integer.valueOf(guestPool.quantity).equals(Integer.valueOf((quantity - jsonHostPoolQuantityExported) * Integer.valueOf(virtLimit) - jsonGuestPoolQuantityConsumed))) {
            log.warning("Assuming '" + jsonGuestPoolQuantityConsumed + "' entitlements are currently being consumed from guest pool '" + guestPool.poolId + "', the quantity of available entitlements for this guest pool should be the host pool's virt_limit of '" + virtLimit + "' times (the host's total quantity '" + quantity + "' minus those exported '" + jsonHostPoolQuantityExported + "') minus the number of already consumed from the pool '" + jsonGuestPoolQuantityConsumed + "'  (COULD BE DIFFERENT IF ANOTHER VIRTUAL GUEST SYSTEM IS SIMULTANEOUSLY SUBSCRIBING TO THE SAME POOL).");
        }
        if (!CandlepinType.hosted.equals(sm_serverType)) {
            // too many false negatives occur on hosted due to simultaneous client consumption from the same pool
            Assert.assertEquals(Integer.valueOf(guestPool.quantity), Integer.valueOf((quantity - jsonHostPoolQuantityExported) * Integer.valueOf(virtLimit) - jsonGuestPoolQuantityConsumed), "Assuming '" + jsonGuestPoolQuantityConsumed + "' entitlements are currently being consumed from guest pool '" + guestPool.poolId + "', the quantity of available entitlements for this guest pool should be the host pool's virt_limit of '" + virtLimit + "' times (the host's total quantity '" + quantity + "' minus those exported '" + jsonHostPoolQuantityExported + "') minus the number of already consumed from the pool '" + jsonGuestPoolQuantityConsumed + "'  (COULD BE DIFFERENT IF ANOTHER VIRTUAL GUEST SYSTEM IS SIMULTANEOUSLY SUBSCRIBING TO THE SAME POOL).");
        }
    }
}
Also used : 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 7 with SubscriptionPool

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

the class VirtualizationTests method testGuestPoolQuantityIsNotClobberedByRefreshPools.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-47928", "RHEL7-97327" }, linkedWorkItems = { @LinkedItem(// RHSM-REQ : Host-limited Guest Subscriptions
workitemId = "RHEL6-28576", project = Project.RHEL6, role = DefTypes.Role.RELATES_TO), @LinkedItem(// RHSM-REQ : Host-limited Guest Subscriptions
workitemId = "RHEL7-84958", project = Project.RedHatEnterpriseLinux7, role = DefTypes.Role.RELATES_TO) }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier2")
@Test(description = "Verify the virt_limit multiplier on guest pool quantity is not clobbered by refresh pools", groups = { "Tier2Tests", "blockedByBug-679617" }, dependsOnGroups = {}, dependsOnMethods = { "testHostAndGuestPoolQuantities" }, dataProvider = "getVirtSubscriptionData", enabled = true)
public void testGuestPoolQuantityIsNotClobberedByRefreshPools(String subscriptionId, String productName, String productId, int quantity, String virtLimit, String hostPoolId, String guestPoolId, Boolean physicalOnly) throws JSONException, Exception {
    if (hostPoolId == null && guestPoolId == null)
        throw new SkipException("Failed to find expected host and guest pools derived from virtualization-aware subscription id '" + subscriptionId + "' (" + productName + ").");
    if (servertasks.dbConnection == null)
        throw new SkipException("This testcase requires a connection to the candlepin database so that it can updateSubscriptionDatesOnDatabase.");
    // get the hostPool
    List<SubscriptionPool> allAvailablePools = clienttasks.getCurrentlyAllAvailableSubscriptionPools();
    SubscriptionPool hostPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", hostPoolId, allAvailablePools);
    Assert.assertNotNull(hostPool, "A host pool derived from the virtualization-aware subscription id '" + subscriptionId + "' is listed in all available subscriptions: " + hostPool);
    // remember the hostPool quantity before calling refresh pools
    String hostPoolQuantityBefore = hostPool.quantity;
    // get the guestPool
    SubscriptionPool guestPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", guestPoolId, allAvailablePools);
    Assert.assertNotNull(guestPool, "A guest pool derived from the virtualization-aware subscription id '" + subscriptionId + "' is listed in all available subscriptions: " + guestPool);
    // remember the hostPool quantity before calling refresh pools
    String guestPoolQuantityBefore = guestPool.quantity;
    log.info("Now let's modify the start date of the virtualization-aware subscription id '" + subscriptionId + "'...");
    /* 7/10/2015 devel consciously decided to drop @Verify(value = Owner.class, subResource = SubResource.SUBSCRIPTIONS) on this GET method starting with candlepin-2.0.
		 * 7/10/2015 modifying this testware to simply raise the authentication credentials to admin
		JSONArray jsonSubscriptions = new JSONArray(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername,sm_clientPassword,sm_serverUrl,"/owners/"+ownerKey+"/subscriptions"));	
		 */
    JSONArray jsonSubscriptions = new JSONArray(CandlepinTasks.getResourceUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, "/owners/" + ownerKey + "/subscriptions"));
    JSONObject jsonSubscription = null;
    for (int i = 0; i < jsonSubscriptions.length(); i++) {
        jsonSubscription = (JSONObject) jsonSubscriptions.get(i);
        if (jsonSubscription.getString("id").equals(subscriptionId)) {
            break;
        } else {
            jsonSubscription = null;
        }
    }
    // "startDate":"2012-02-08T00:00:00.000+0000"
    Calendar startDate = parseISO8601DateString(jsonSubscription.getString("startDate"), "GMT");
    // subtract a month
    Calendar newStartDate = (Calendar) startDate.clone();
    // subtract a month
    newStartDate.add(Calendar.MONTH, -1);
    updateSubscriptionDatesOnDatabase(subscriptionId, newStartDate, null);
    log.info("Now let's refresh the subscription pools...");
    JSONObject jobDetail = CandlepinTasks.refreshPoolsUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, ownerKey);
    jobDetail = CandlepinTasks.waitForJobDetailStateUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, jobDetail, "FINISHED", 10 * 1000, 3);
    allAvailablePools = clienttasks.getCurrentlyAllAvailableSubscriptionPools();
    // retrieve the host pool again and assert the quantity has not changed
    hostPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", hostPoolId, allAvailablePools);
    Assert.assertEquals(hostPool.quantity, hostPoolQuantityBefore, "The quantity of entitlements available from the host pool has NOT changed after refreshing pools.");
    // retrieve the guest pool again and assert the quantity has not changed
    guestPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", guestPoolId, allAvailablePools);
    Assert.assertEquals(guestPool.quantity, guestPoolQuantityBefore, "The quantity of entitlements available from the guest pool has NOT changed after refreshing pools.");
}
Also used : JSONObject(org.json.JSONObject) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) JSONArray(org.json.JSONArray) 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 8 with SubscriptionPool

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

the class StackingTests method getAvailableStackableAttributeSubscriptionPoolsDataAsListOfLists.

protected List<List<Object>> getAvailableStackableAttributeSubscriptionPoolsDataAsListOfLists() throws JSONException, Exception {
    List<List<Object>> ll = new ArrayList<List<Object>>();
    if (!isSetupBeforeSuiteComplete)
        return ll;
    Map<String, List<SubscriptionPool>> stackableSubscriptionPoolsMap = new HashMap<String, List<SubscriptionPool>>();
    // find all the SubscriptionPools with the same stacking_id
    for (List<Object> l : getAvailableSubscriptionPoolsDataAsListOfLists()) {
        SubscriptionPool pool = (SubscriptionPool) l.get(0);
        String stacking_id = CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "stacking_id");
        // skip non-stackable pools
        if (stacking_id == null)
            continue;
        // skip instance-based pools (these are covered in InstanceTests.java)
        if (CandlepinTasks.isPoolProductInstanceBased(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId))
            continue;
        // add this available stackable pool to the stackableSubscriptionPoolsMap
        if (!stackableSubscriptionPoolsMap.containsKey(stacking_id))
            stackableSubscriptionPoolsMap.put(stacking_id, new ArrayList<SubscriptionPool>());
        stackableSubscriptionPoolsMap.get(stacking_id).add(pool);
    }
    // assemble the rows of data
    for (String stacking_id : stackableSubscriptionPoolsMap.keySet()) {
        List<SubscriptionPool> stackableSubscriptionPools = stackableSubscriptionPoolsMap.get(stacking_id);
        for (String attribute : new String[] { "sockets", "cores", "ram", "vcpu" }) {
            List<SubscriptionPool> stackableAttributeSubscriptionPools = new ArrayList<SubscriptionPool>();
            for (SubscriptionPool stackableSubscriptionPool : stackableSubscriptionPools) {
                if (CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, stackableSubscriptionPool.poolId, attribute) != null) {
                    stackableAttributeSubscriptionPools.add(stackableSubscriptionPool);
                }
            }
            if (!stackableAttributeSubscriptionPools.isEmpty()) {
                BlockedByBzBug blockedByBzBug = null;
                // Bug 871602 - [RFE] Virtual Architecture Independence  HAS EFFECTIVELY BEEN FIXED AS A DUP OF Bug 885785 - [RFE] Subscription Manager should alert a user if subscription vcpu limits are lower than system vcpu allocation
                if (attribute.equals("vcpu"))
                    blockedByBzBug = new BlockedByBzBug(new String[] { "885785", "871602" });
                // Object bugzilla, String attribute, String systemIsGuest, List<SubscriptionPool> stackableAttributeSubscriptionPools
                ll.add(Arrays.asList(new Object[] { blockedByBzBug, attribute, true, stackableAttributeSubscriptionPools }));
                ll.add(Arrays.asList(new Object[] { blockedByBzBug, attribute, false, stackableAttributeSubscriptionPools }));
            }
        }
    }
    return ll;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) JSONObject(org.json.JSONObject) SubscriptionPool(rhsm.data.SubscriptionPool) BlockedByBzBug(com.redhat.qe.auto.bugzilla.BlockedByBzBug)

Example 9 with SubscriptionPool

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

the class StorageBandTests method testAutoHealStorageBandSubscription.

/**
 * @author skallesh
 * @throws Exception
 * @throws JSONException
 */
@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-21461", "RHEL7-51710" }, 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 = "Tier3")
@Test(description = "verify if you auto-heal a system using 300TB of storage, installed storage product is fully subscribed from multiple pools that provide 256TB of coverage.", groups = { "Tier3Tests", "AutoHealStorageBandSubscription" }, dataProvider = "getStorageBandSubscriptions", enabled = true)
public void testAutoHealStorageBandSubscription(Object Bugzilla, SubscriptionPool storagebandpool) throws JSONException, Exception {
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, true, null, null, null, null, null);
    log.info("To auto-heal this system for '" + bandStorageUsage + "'TB of storage, there must be more than one stackable pool for product SKU '" + storagebandpool.productId + "'.");
    // to troubleshoot the existance of multiple pools
    SSHCommandResult listResult = clienttasks.list(null, true, null, null, null, null, null, null, storagebandpool.productId, null, null, null, null, null);
    List<SubscriptionPool> availableStorageBandPools = SubscriptionPool.parse(listResult.getStdout());
    String expectedStatus = availableStorageBandPools.size() > 1 ? "Subscribed" : "Not Subscribed";
    clienttasks.autoheal(null, true, null, null, null, null, null);
    clienttasks.run_rhsmcertd_worker(true);
    List<String> providedProductIds = CandlepinTasks.getPoolProvidedProductIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, storagebandpool.poolId);
    List<InstalledProduct> installedProducts = clienttasks.getCurrentlyInstalledProducts();
    for (String providedProductId : providedProductIds) {
        InstalledProduct installedProduct = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productId", providedProductId, installedProducts);
        if (installedProduct != null) {
            Assert.assertEquals(installedProduct.status.trim(), expectedStatus, "Status of installed product '" + installedProduct.productName + "' provided for by Storage Band entitlement pools that covers only 256TB on a system using '" + bandStorageUsage + "'TBs (that has been autohealed with '" + availableStorageBandPools.size() + "' available '" + storagebandpool.productId + "' pools)");
        }
    }
}
Also used : SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) InstalledProduct(rhsm.data.InstalledProduct) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 10 with SubscriptionPool

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

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