Search in sources :

Example 81 with SubscriptionPool

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

the class ListTests method testListAvailableReportsContract.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36550", "RHEL7-51327" }, 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: list of available subscriptions should include contract number", groups = { "Tier2Tests", "blockedByBug-1007580", "blockedByBug-1088507" }, enabled = true)
public // @ImplementsNitrateTest(caseId=, fromPlan=)
void testListAvailableReportsContract() {
    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);
    // assert the contract value in all available pools
    boolean availableSubscriptionPoolsDisplayContract = false;
    for (SubscriptionPool pool : clienttasks.getCurrentlyAllAvailableSubscriptionPools()) {
        String none = "None";
        if (pool.contract != null) {
            Assert.assertTrue(!pool.contract.equalsIgnoreCase(none), "The contract '" + pool.contract + "' for subscription pool '" + pool.poolId + "' should not be reported as '" + none + "'.");
            availableSubscriptionPoolsDisplayContract = true;
        }
    }
    Assert.assertTrue(availableSubscriptionPoolsDisplayContract, "Successfully encountered contracts reported in the list of available subscription pools.");
}
Also used : SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 82 with SubscriptionPool

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

the class ListTests method testListAvailableWithNoOverlap.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36565", "RHEL7-51349" }, 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: subcription manager list all with --match-installed option", groups = { "Tier2Tests", "blockedByBug-654501", "blockedByBug-1022622", /*rhel7*/
"blockedByBug-1114717", /*rhel6*/
"blockedByBug-1493711" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testListAvailableWithNoOverlap() throws JSONException, Exception {
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, false, null, null, null, null, null);
    clienttasks.autoheal(null, null, true, null, null, null, null);
    // assemble a list of currently installed product ids
    List<ProductCert> installedProductCerts = clienttasks.getCurrentProductCerts();
    List<String> installedProductIds = new ArrayList<String>();
    for (ProductCert productCert : installedProductCerts) installedProductIds.add(productCert.productId);
    // get the available subscription pools
    List<SubscriptionPool> availableSubscriptionPools = SubscriptionPool.parse(clienttasks.list(null, true, null, null, null, null, null, false, null, null, null, null, null, null).getStdout());
    // randomly attach a positive subset of available subscriptions
    List<SubscriptionPool> randomAvailableSubscriptionPools = getRandomSubsetOfList(availableSubscriptionPools, randomGenerator.nextInt(availableSubscriptionPools.size() - 1) + 1);
    List<String> poolIds = new ArrayList<String>();
    for (SubscriptionPool subscriptionPool : randomAvailableSubscriptionPools) poolIds.add(subscriptionPool.poolId);
    if (false) {
        // debugTesting will cause test to fail due to bugzilla https://bugzilla.redhat.com/show_bug.cgi?id=1022622#c0
        poolIds.clear();
        poolIds.add(SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("subscriptionName", "Awesome OS Server Basic", availableSubscriptionPools).poolId);
        poolIds.add(SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("subscriptionName", "Awesome OS for All Arch (excpt for x86_64 content)", availableSubscriptionPools).poolId);
        poolIds.add(SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("subscriptionName", "Awesome OS with unlimited virtual guests", availableSubscriptionPools).poolId);
        poolIds.add(SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("subscriptionName", "Multi-Attribute Stackable (2 GB, 2 Cores)", availableSubscriptionPools).poolId);
        poolIds.add(SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("subscriptionName", "Awesome OS Server Basic (data center)", availableSubscriptionPools).poolId);
        poolIds.add(SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("subscriptionName", "Multi-Attribute Stackable (2 sockets)", availableSubscriptionPools).poolId);
        poolIds.add(SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("subscriptionName", "Awesome OS for systems with no sockets", availableSubscriptionPools).poolId);
        poolIds.add(SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("subscriptionName", "Awesome OS Server Basic (multi-entitlement)", availableSubscriptionPools).poolId);
        poolIds.add(SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("subscriptionName", "Awesome OS Modifier", availableSubscriptionPools).poolId);
    }
    clienttasks.subscribe(null, null, poolIds, null, null, "1", null, null, null, null, null, null, null);
    List<InstalledProduct> installedProducts = InstalledProduct.parse(clienttasks.list(null, null, null, true, null, null, null, null, null, null, null, null, null, null).getStdout());
    List<SubscriptionPool> availableSubscriptionPoolsWithoutOverlap = SubscriptionPool.parse(clienttasks.list(null, true, null, null, null, null, null, true, null, null, null, null, null, null).getStdout());
    // loop through the list of available subscription pools without overlap and assert that at least one of pool's provided products is not fully subscribed.
    for (SubscriptionPool subscriptionPool : availableSubscriptionPoolsWithoutOverlap) {
        boolean noOverlapFound = false;
        List<String> providedProductIds = CandlepinTasks.getPoolProvidedProductIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, subscriptionPool.poolId);
        if (providedProductIds.isEmpty()) {
            Assert.assertTrue(providedProductIds.isEmpty(), "Subscription '" + subscriptionPool.subscriptionName + "' provides=" + subscriptionPool.provides + " reported in the list available with no-overlap provides no products and therefore does not overlap an already covered product.");
            noOverlapFound = true;
        }
        for (String providedProductId : providedProductIds) {
            InstalledProduct installedProduct = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productId", providedProductId, installedProducts);
            if (installedProduct != null) {
                if (!installedProduct.status.equalsIgnoreCase("Subscribed")) {
                    Assert.assertTrue(!installedProduct.status.equalsIgnoreCase("Subscribed"), "Subscription '" + subscriptionPool.subscriptionName + "' provides=" + subscriptionPool.provides + " reported in the list available with no-overlap provides product id '" + providedProductId + "' which is installed with status '" + installedProduct.status + "' and therefore does not overlap an already covered product.");
                    noOverlapFound = true;
                } else {
                    log.warning("Subscription '" + subscriptionPool.subscriptionName + "' provides=" + subscriptionPool.provides + " reported in the list available with no-overlap provides product id '" + providedProductId + "' which is installed with status '" + installedProduct.status + "'.");
                }
            } else {
                Assert.assertTrue(installedProduct == null, "Subscription '" + subscriptionPool.subscriptionName + "' provides=" + subscriptionPool.provides + " reported in the list available with no-overlap provides product id '" + providedProductId + "' which is not installed and therefore does not overlap an already covered product.");
                noOverlapFound = true;
            }
        }
        Assert.assertTrue(noOverlapFound, "Subscription '" + subscriptionPool.subscriptionName + "' provides=" + subscriptionPool.provides + " that is reported in the list available with no-overlap provides at least one product that is not fully Subscribed.");
    }
    // the remainder of this --no-overlap test has been fixed in subscription-manager-1.12.6-1 and newer; otherwise skip it.
    if (clienttasks.isPackageVersion("subscription-manager", "<", "1.12.6-1"))
        throw new SkipException("The installed version of subscription-manager does not contain the fix for https://bugzilla.redhat.com/show_bug.cgi?id=1022622#c3");
    // assert that availableSubscriptionPools that are not filtered out of the availableSubscriptionPoolsWithoutOverlap provide products that are all fully Subscribed
    availableSubscriptionPools = SubscriptionPool.parse(clienttasks.list(null, true, null, null, null, null, null, false, null, null, null, null, null, null).getStdout());
    for (SubscriptionPool availableSubscriptionPool : availableSubscriptionPools) {
        if (!availableSubscriptionPoolsWithoutOverlap.contains(availableSubscriptionPool)) {
            for (String providedProductId : CandlepinTasks.getPoolProvidedProductIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, availableSubscriptionPool.poolId)) {
                InstalledProduct installedProduct = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productId", providedProductId, installedProducts);
                if (installedProduct != null) {
                    Assert.assertEquals(installedProduct.status, "Subscribed", "Subscription '" + availableSubscriptionPool.subscriptionName + "' provides=" + availableSubscriptionPool.provides + " is excluded from the list available with no-overlap.  It provides product id '" + providedProductId + "' which is installed and covered by an active subscription.");
                } else {
                // skip the providedProductId when not installed
                }
            }
        }
    }
}
Also used : InstalledProduct(rhsm.data.InstalledProduct) ArrayList(java.util.ArrayList) ProductCert(rhsm.data.ProductCert) 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 83 with SubscriptionPool

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

the class ListTests method assertActualResultOfListAvailableWithMatches.

protected void assertActualResultOfListAvailableWithMatches(String matchesString, List<SubscriptionPool> actualSubscriptionPoolsMatches, List<SubscriptionPool> availableSubscriptionPools) throws JSONException, Exception {
    // translate matchesString into a regexString
    // escape parentheses
    String regexString = matchesString.toLowerCase().replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)");
    // splat wildcards match any zero or more chars
    regexString = regexString.replaceAll("\\*", ".*");
    // question mark wildcards match any one char
    regexString = regexString.replaceAll("\\?", ".");
    // search through the available availableSubscriptionPools for expected matches on the matchesString
    // <crog> --matches looks at the following: product name, product id, pool/sub contract number, pool order number, provided product id, provided product name, provided product content name, provided product content label
    // NOTE: exact matches means no wildcards and is case insensitive
    List<SubscriptionPool> expectedSubscriptionPoolMatches = new ArrayList<SubscriptionPool>();
    availableSubscriptionPoolsLoop: for (SubscriptionPool subscriptionPool : availableSubscriptionPools) {
        // Test for match on Subscription Name:
        if (subscriptionPool.subscriptionName.toLowerCase().matches(regexString)) {
            log.info("Found a hit on matches '" + matchesString + "' against the available subscription '" + subscriptionPool.subscriptionName + "' SKU '" + subscriptionPool.productId + "'.  The match is in Subscription Name: " + subscriptionPool.subscriptionName);
            if (!expectedSubscriptionPoolMatches.contains(subscriptionPool)) {
                expectedSubscriptionPoolMatches.add(subscriptionPool);
                continue availableSubscriptionPoolsLoop;
            }
        }
        // Test for match on Provides:
        for (String providesName : subscriptionPool.provides) {
            if (providesName.toLowerCase().matches(regexString)) {
                log.info("Found a hit on matches '" + matchesString + "' against the available subscription '" + subscriptionPool.subscriptionName + "' SKU '" + subscriptionPool.productId + "'.  The match is in Provides: " + subscriptionPool.provides);
                if (!expectedSubscriptionPoolMatches.contains(subscriptionPool)) {
                    expectedSubscriptionPoolMatches.add(subscriptionPool);
                    continue availableSubscriptionPoolsLoop;
                }
            }
        }
        // Test for match on SKU:
        if (subscriptionPool.productId.toLowerCase().matches(regexString)) {
            log.info("Found a hit on matches '" + matchesString + "' against the available subscription '" + subscriptionPool.subscriptionName + "' SKU '" + subscriptionPool.productId + "'.  The match is in SKU: " + subscriptionPool.productId);
            if (!expectedSubscriptionPoolMatches.contains(subscriptionPool)) {
                expectedSubscriptionPoolMatches.add(subscriptionPool);
                continue availableSubscriptionPoolsLoop;
            }
        }
        // Test for match on Contract:
        if (subscriptionPool.contract.toLowerCase().matches(regexString)) {
            log.info("Found a hit on matches '" + matchesString + "' against the available subscription '" + subscriptionPool.subscriptionName + "' SKU '" + subscriptionPool.productId + "'.  The match is in Contract: " + subscriptionPool.contract);
            if (!expectedSubscriptionPoolMatches.contains(subscriptionPool)) {
                expectedSubscriptionPoolMatches.add(subscriptionPool);
                continue availableSubscriptionPoolsLoop;
            }
        }
        // Test for match on Service Level:
        if (subscriptionPool.serviceLevel.toLowerCase().matches(regexString)) {
            log.info("Found a hit on matches '" + matchesString + "' against the available subscription '" + subscriptionPool.subscriptionName + "' SKU '" + subscriptionPool.productId + "'.  The match is in Service Level: " + subscriptionPool.serviceLevel);
            if (!expectedSubscriptionPoolMatches.contains(subscriptionPool)) {
                expectedSubscriptionPoolMatches.add(subscriptionPool);
                continue availableSubscriptionPoolsLoop;
            }
        }
        // Test for match on Provided ProductId:
        for (String providedProductId : CandlepinTasks.getPoolProvidedProductIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, subscriptionPool.poolId)) {
            if (providedProductId.toLowerCase().matches(regexString)) {
                log.info("Found a hit on matches '" + matchesString + "' against the available subscription '" + subscriptionPool.subscriptionName + "' SKU '" + subscriptionPool.productId + "'.  The match is in Provided Product ID: " + providedProductId);
                if (!expectedSubscriptionPoolMatches.contains(subscriptionPool)) {
                    expectedSubscriptionPoolMatches.add(subscriptionPool);
                    continue availableSubscriptionPoolsLoop;
                }
            }
        }
        // Test for match on Provided ProductId Content Names and Labels:
        for (String providedProductId : CandlepinTasks.getPoolProvidedProductIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, subscriptionPool.poolId)) {
            JSONArray jsonProductContents = CandlepinTasks.getPoolProvidedProductContent(sm_clientUsername, sm_clientPassword, sm_serverUrl, subscriptionPool.poolId, providedProductId);
            for (int j = 0; j < jsonProductContents.length(); j++) {
                JSONObject jsonProductContent = (JSONObject) jsonProductContents.get(j);
                JSONObject jsonContent = jsonProductContent.getJSONObject("content");
                boolean enabled = jsonProductContent.getBoolean("enabled");
                String name = jsonContent.getString("name");
                String label = jsonContent.getString("label");
                // does the content name match the regexString
                if (name.toLowerCase().matches(regexString)) {
                    log.info("Found a hit on matches '" + matchesString + "' against the available subscription '" + subscriptionPool.subscriptionName + "' SKU '" + subscriptionPool.productId + "'.  The match is in Provided Product ID '" + providedProductId + "' Content Name: " + name);
                    if (!expectedSubscriptionPoolMatches.contains(subscriptionPool)) {
                        expectedSubscriptionPoolMatches.add(subscriptionPool);
                        continue availableSubscriptionPoolsLoop;
                    }
                }
                // does the content label match the regexString
                if (label.toLowerCase().matches(regexString)) {
                    log.info("Found a hit on matches '" + matchesString + "' against the available subscription '" + subscriptionPool.subscriptionName + "' SKU '" + subscriptionPool.productId + "'.  The match is in Provided Product ID '" + providedProductId + "' Content Label: " + label);
                    if (!expectedSubscriptionPoolMatches.contains(subscriptionPool)) {
                        expectedSubscriptionPoolMatches.add(subscriptionPool);
                        continue availableSubscriptionPoolsLoop;
                    }
                }
            }
        }
    // TODO May want to open an RFE to also search on these other available subscription fields
    // See https://bugzilla.redhat.com/show_bug.cgi?id=1146125#c7
    // Pool ID:           2c90af8b49435579014943591343172c
    // Available:         10
    // Suggested:         1
    // Service Type:
    // Subscription Type: Standard
    // Ends:              10/23/2015
    // System Type:       Physical
    }
    // assert that all of the expectedSubscriptionPoolMatches is identical to the actualSubscriptionPoolsMatches
    for (SubscriptionPool expectedSubscriptionPool : expectedSubscriptionPoolMatches) {
        if (!actualSubscriptionPoolsMatches.contains(expectedSubscriptionPool)) {
            log.warning("The actual list of subscription pools does NOT include this expected pool that matches '" + matchesString + "': " + expectedSubscriptionPool);
        }
    }
    for (SubscriptionPool actualSubscriptionPool : actualSubscriptionPoolsMatches) {
        if (!expectedSubscriptionPoolMatches.contains(actualSubscriptionPool)) {
            log.warning("The actual list of subscription pools includes this extraneous pool that should not match '" + matchesString + "': " + actualSubscriptionPool);
        }
    }
    Assert.assertTrue(expectedSubscriptionPoolMatches.containsAll(actualSubscriptionPoolsMatches) && actualSubscriptionPoolsMatches.containsAll(expectedSubscriptionPoolMatches), "All of the expected available pools with an exact match (ignoring case) on '" + matchesString + "' were returned with the list --available --matches option.");
}
Also used : JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) SubscriptionPool(rhsm.data.SubscriptionPool)

Example 84 with SubscriptionPool

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

the class ListTests method testListAvailableWithWildcardMatches.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-19965", "RHEL7-33095" }, 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: subcription manager list --available with wildcard --matches on Subscription Name, Provided Product Name, Contract Number, SKU, Service Level, Provided Product ID.  Note: wildcard match means * matches zero or more char and ? matches one char and is case insensitive.", groups = { "Tier1Tests", "blockedByBug-1146125", "blockedByBug-1301696", "blockedByBug-1493711" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testListAvailableWithWildcardMatches() throws JSONException, Exception {
    if (clienttasks.isPackageVersion("subscription-manager", "<", "1.13.6-1"))
        throw new SkipException("The list --matches function was not implemented in this version of subscription-manager.");
    // candlepin commit e5b6c24f2322b79a7ea8bb1e8c85a8cb86733471
    if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, "<", "0.9.33-1"))
        throw new SkipException("Candlepin support for list --available --matches function was not implemented in server version '" + servertasks.statusVersion + "'.");
    String matchesString;
    List<SubscriptionPool> expectedPools, actualSubscriptionPoolMatches;
    Boolean all = getRandomBoolean();
    Boolean matchInstalled = getRandomBoolean();
    Boolean noOverlap = getRandomBoolean();
    // /*debugTesting*/ all=true; noOverlap=true; matchInstalled=false;	//  Bug 1301696 - getting unexpected hits on TESTDATA from subscription-manager list --available --matches=*os*
    // /*debugTesting*/ all=true; noOverlap=false; matchInstalled=false;
    log.info("Testing with all=" + all);
    log.info("Testing with matchInstalled=" + matchInstalled);
    log.info("Testing with noOverlap=" + noOverlap);
    if (clienttasks.getCurrentlyRegisteredOwnerKey() == null) {
        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);
        clienttasks.autoheal(null, null, true, null, null, null, null);
    } else
        clienttasks.unsubscribe_(true, (BigInteger) null, null, null, null, null, null);
    // get all the available subscription pools
    SSHCommandResult listResult = clienttasks.list(all, true, null, null, null, null, matchInstalled, noOverlap, null, null, null, null, null, null);
    if (matchInstalled && clienttasks.getCurrentlyInstalledProducts().isEmpty()) {
        String skipCase = "No available subscription pools to list";
        Assert.assertEquals(listResult.getStdout().trim(), skipCase);
        throw new SkipException("Skipping this test when: " + skipCase);
    }
    List<SubscriptionPool> availableSubscriptionPools = SubscriptionPool.parse(listResult.getStdout());
    // randomly choose an available pool
    SubscriptionPool randomAvailablePool = getRandomListItem(availableSubscriptionPools);
    // /*debugTesting*/ randomAvailablePool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", "awesomeos-ostree", availableSubscriptionPools);	//  Bug 1301696 - getting unexpected hits on TESTDATA from subscription-manager list --available --matches=*os*
    // /*debugTesting*/ randomAvailablePool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", "RH0380468", availableSubscriptionPools);	//  Bug 1301696 - getting unexpected hits on TESTDATA from subscription-manager list --available --matches=*os*
    log.info("Testing with randomAvailablePool=" + randomAvailablePool);
    // +-------------------------------------------+
    // Available Subscriptions
    // +-------------------------------------------+
    // Subscription Name: Awesome OS OSTree
    // Provides:          Awesome OS OStree Bits
    // SKU:               awesomeos-ostree
    // Contract:          3
    // Pool ID:           2c90af8b49435579014943591343172c
    // Available:         10
    // Suggested:         1
    // Service Level:
    // Service Type:
    // Subscription Type: Standard
    // Ends:              10/23/2015
    // System Type:       Physical
    // Test 1: test wildcard --matches on Subscription Name:
    matchesString = randomAvailablePool.subscriptionName;
    // drop first word
    matchesString = matchesString.replaceFirst("^\\S+\\s+", "*");
    actualSubscriptionPoolMatches = SubscriptionPool.parse(clienttasks.list(all, true, null, null, null, null, matchInstalled, noOverlap, matchesString, null, null, null, null, null).getStdout());
    assertActualResultOfListAvailableWithMatches(matchesString, actualSubscriptionPoolMatches, availableSubscriptionPools);
    // also test case insensitivity
    matchesString = randomizeCaseOfCharactersInString(matchesString);
    // and drop last word
    matchesString = matchesString.replaceFirst("\\s+\\S+$", "*");
    actualSubscriptionPoolMatches = SubscriptionPool.parse(clienttasks.list(all, true, null, null, null, null, matchInstalled, noOverlap, matchesString, null, null, null, null, null).getStdout());
    assertActualResultOfListAvailableWithMatches(matchesString, actualSubscriptionPoolMatches, availableSubscriptionPools);
    // Test 2: test wildcard --matches on Provides:
    if (!randomAvailablePool.provides.isEmpty()) {
        matchesString = getRandomListItem(randomAvailablePool.provides);
        // drop last word
        matchesString = matchesString.replaceFirst("\\s+\\S+$", "*");
        actualSubscriptionPoolMatches = SubscriptionPool.parse(clienttasks.list(all, true, null, null, null, null, matchInstalled, noOverlap, matchesString, null, null, null, null, null).getStdout());
        assertActualResultOfListAvailableWithMatches(matchesString, actualSubscriptionPoolMatches, availableSubscriptionPools);
        // also test case insensitivity
        matchesString = randomizeCaseOfCharactersInString(matchesString);
        // and drop first word
        matchesString = matchesString.replaceFirst("^\\S+\\s+", "*");
        actualSubscriptionPoolMatches = SubscriptionPool.parse(clienttasks.list(all, true, null, null, null, null, matchInstalled, noOverlap, matchesString, null, null, null, null, null).getStdout());
        assertActualResultOfListAvailableWithMatches(matchesString, actualSubscriptionPoolMatches, availableSubscriptionPools);
    } else
        log.warning("Skipping list --available --matches test on a Provides item since the provides list is empty on our random available subscription: " + randomAvailablePool);
    // Test 3: test wildcard --matches on SKU:
    matchesString = randomAvailablePool.productId;
    // drop first char
    matchesString = matchesString.replaceFirst("^.", "?");
    actualSubscriptionPoolMatches = SubscriptionPool.parse(clienttasks.list(all, true, null, null, null, null, matchInstalled, noOverlap, matchesString, null, null, null, null, null).getStdout());
    assertActualResultOfListAvailableWithMatches(matchesString, actualSubscriptionPoolMatches, availableSubscriptionPools);
    // also test case insensitivity
    matchesString = randomizeCaseOfCharactersInString(matchesString);
    // and drop last char
    matchesString = matchesString.replaceFirst(".$", "?");
    actualSubscriptionPoolMatches = SubscriptionPool.parse(clienttasks.list(all, true, null, null, null, null, matchInstalled, noOverlap, matchesString, null, null, null, null, null).getStdout());
    assertActualResultOfListAvailableWithMatches(matchesString, actualSubscriptionPoolMatches, availableSubscriptionPools);
    // Test 4: test wildcard --matches on Contract:
    if (randomAvailablePool.contract != null && !randomAvailablePool.contract.isEmpty()) {
        matchesString = randomAvailablePool.contract;
        // drop the last char and replace it with a '?' wildcard
        matchesString = matchesString.replaceFirst(".$", "?");
        actualSubscriptionPoolMatches = SubscriptionPool.parse(clienttasks.list(all, true, null, null, null, null, matchInstalled, noOverlap, matchesString, null, null, null, null, null).getStdout());
        assertActualResultOfListAvailableWithMatches(matchesString, actualSubscriptionPoolMatches, availableSubscriptionPools);
        // also test case insensitivity
        matchesString = randomizeCaseOfCharactersInString(matchesString);
        // also drop the first char and replace it with a '?' wildcard
        matchesString = matchesString.replaceFirst("^.", "?");
        actualSubscriptionPoolMatches = SubscriptionPool.parse(clienttasks.list(all, true, null, null, null, null, matchInstalled, noOverlap, matchesString, null, null, null, null, null).getStdout());
        assertActualResultOfListAvailableWithMatches(matchesString, actualSubscriptionPoolMatches, availableSubscriptionPools);
    } else
        log.warning("Skipping list --available --matches test on a Contract item since it is null or empty on our random available subscription: " + randomAvailablePool);
    // Test 5: test wildcard --matches on Service Level:
    if (randomAvailablePool.serviceLevel != null && !randomAvailablePool.serviceLevel.isEmpty()) {
        matchesString = randomAvailablePool.serviceLevel;
        // drop first char
        matchesString = matchesString.replaceFirst("^.", "*");
        // drop last char
        matchesString = matchesString.replaceFirst(".$", "?");
        actualSubscriptionPoolMatches = SubscriptionPool.parse(clienttasks.list(all, true, null, null, null, null, matchInstalled, noOverlap, matchesString, null, null, null, null, null).getStdout());
        assertActualResultOfListAvailableWithMatches(matchesString, actualSubscriptionPoolMatches, availableSubscriptionPools);
        // also test case insensitivity
        matchesString = randomizeCaseOfCharactersInString(matchesString);
        actualSubscriptionPoolMatches = SubscriptionPool.parse(clienttasks.list(all, true, null, null, null, null, matchInstalled, noOverlap, matchesString, null, null, null, null, null).getStdout());
        assertActualResultOfListAvailableWithMatches(matchesString, actualSubscriptionPoolMatches, availableSubscriptionPools);
    } else
        log.warning("Skipping list --available --matches test on a Service Level item since it is null or empty on our random available subscription: " + randomAvailablePool);
    // Test 6: test wildcard --matches on Provided ProductId:
    if (!randomAvailablePool.provides.isEmpty()) {
        matchesString = getRandomListItem(CandlepinTasks.getPoolProvidedProductIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, randomAvailablePool.poolId));
        int i = randomGenerator.nextInt(matchesString.length());
        matchesString = matchesString.replaceAll(String.valueOf(matchesString.charAt(i)), "?");
        actualSubscriptionPoolMatches = SubscriptionPool.parse(clienttasks.list(all, true, null, null, null, null, matchInstalled, noOverlap, matchesString, null, null, null, null, null).getStdout());
        assertActualResultOfListAvailableWithMatches(matchesString, actualSubscriptionPoolMatches, availableSubscriptionPools);
    } else
        log.warning("Skipping list --available --matches test on a Provides ProductId item since the provides list is empty on our random available subscription: " + randomAvailablePool);
// TODO Test 7: test exact --matches on a Content Name provided by a Provided ProductId
// see ListAvailableWithExactMatches_Test()
// TODO Test 8: test exact --matches on a Content Label provided by a Provided ProductId
// see ListAvailableWithExactMatches_Test()
}
Also used : SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) BigInteger(java.math.BigInteger) 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 85 with SubscriptionPool

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

the class ListTests method testHardwareMatchingSubscriptionsAreListedAsAvailable.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-19963", "RHEL7-33104" }, 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-cli: list available subscriptions - verify that among all the subscriptions available to this consumer, those that satisfy the system hardware are listed as available", groups = { "Tier1Tests", "blockedByBug-712502", "unsubscribeBeforeGroup" }, dataProvider = "getAvailableSystemSubscriptionPoolProductData", enabled = true)
@ImplementsNitrateTest(caseId = 41678)
public void testHardwareMatchingSubscriptionsAreListedAsAvailable(String productId, JSONArray bundledProductDataAsJSONArray) throws JSONException, Exception {
    // /*debugTesting*/if (!productId.equals("awesomeos-virt-unlmtd-phys")) throw new SkipException("debugTesting productId="+productId);
    // /*debugTesting*/if (!productId.equals("MCT3115")) throw new SkipException("debugTesting productId="+productId);
    // implicitly registered in dataProvider; no need to register with force; saves time
    // clienttasks.register(clientusername, clientpassword, null, null, null, null, true, null, null, null);
    SubscriptionPool pool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", productId, clienttasks.getCurrentlyAvailableSubscriptionPools());
    // special case...
    if (pool == 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(pool, "Expected SubscriptionPool with ProductId '" + productId + "' is listed as available for subscribing.  (Look for warnings above to explain a failure. A pool refresh may also fix a failure.)");
}
Also used : BigInteger(java.math.BigInteger) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) SkipException(org.testng.SkipException) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest) 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