Search in sources :

Example 56 with SubscriptionPool

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

the class ComplianceTests method getSubscriptionPoolProvidingProductIdOnArchDataAsListOfLists.

protected List<List<Object>> getSubscriptionPoolProvidingProductIdOnArchDataAsListOfLists() throws JSONException, Exception {
    List<List<Object>> ll = new ArrayList<List<Object>>();
    if (!isSetupBeforeSuiteComplete)
        return ll;
    // configureProductCertDirAfterClass(); is not needed since the priority of this test is implied as 0 and run first before the other tests alter the productCertDir
    List<ProductCert> productCerts = clienttasks.getCurrentProductCerts();
    List<String> productIdArchTested = new ArrayList<String>();
    boolean isSystemVirtual = Boolean.valueOf(clienttasks.getFactValue("virt.is_guest"));
    for (List<Object> allAvailableSubscriptionPoolsDataList : getAllAvailableSubscriptionPoolsDataAsListOfLists()) {
        SubscriptionPool availableSubscriptionPool = (SubscriptionPool) allAvailableSubscriptionPoolsDataList.get(0);
        // for the purpose of this test, skip unmapped_guests_only pools when system is virtual otherwise the subscribe will fail with "Pool is restricted to unmapped virtual guests: '8a9087e34bdb9471014bdb9573e60af6'."
        if (isSystemVirtual && CandlepinTasks.isPoolRestrictedToUnmappedVirtualSystems(sm_clientUsername, sm_clientPassword, sm_serverUrl, availableSubscriptionPool.poolId))
            continue;
        // for the purpose of this test, skip physical_only pools when system is virtual otherwise the subscribe will fail with "Pool is restricted to physical systems: '8a9086d344549b0c0144549bf9ae0dd4'."
        if (isSystemVirtual && CandlepinTasks.isPoolRestrictedToPhysicalSystems(sm_clientUsername, sm_clientPassword, sm_serverUrl, availableSubscriptionPool.poolId))
            continue;
        // for the purpose of this test, skip virt_only pools when system is physical otherwise the subscribe will fail with "Pool is restricted to virtual guests: '8a9086d344549b0c0144549bf9ae0dd4'."
        if (!isSystemVirtual && CandlepinTasks.isPoolRestrictedToVirtualSystems(sm_clientUsername, sm_clientPassword, sm_serverUrl, availableSubscriptionPool.poolId))
            continue;
        List<String> providedProductIds = CandlepinTasks.getPoolProvidedProductIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, availableSubscriptionPool.poolId);
        String poolProductArch = CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, availableSubscriptionPool.poolId, "arch");
        for (ProductCert productCert : productCerts) {
            if (providedProductIds.contains(productCert.productId)) {
                BlockedByBzBug blockedByBzBug = null;
                // if a row has already been added for this productId+arch combination, skip it since adding it would be redundant testing
                if (productIdArchTested.contains(productCert.productId + poolProductArch))
                    continue;
                // Bug 951633 - installed product with comma separated arch attribute fails to go green
                if (productCert.productNamespace.arch.contains(","))
                    blockedByBzBug = new BlockedByBzBug("951633");
                ll.add(Arrays.asList(new Object[] { blockedByBzBug, availableSubscriptionPool, productCert.productId, poolProductArch }));
                productIdArchTested.add(productCert.productId + poolProductArch);
            }
        }
    }
    return ll;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ProductCert(rhsm.data.ProductCert) SubscriptionPool(rhsm.data.SubscriptionPool) BlockedByBzBug(com.redhat.qe.auto.bugzilla.BlockedByBzBug)

Example 57 with SubscriptionPool

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

the class ComplianceTests method setupProductCertDirsBeforeClass.

@BeforeClass(groups = { "setup" }, dependsOnMethods = { "moveOriginalProductCertDefaultDirFilesBeforeClass" })
public void setupProductCertDirsBeforeClass() throws JSONException, Exception {
    // clean out the productCertDirs
    for (String productCertDir : new String[] { productCertDirForSomeProductsSubscribable, productCertDirForAllProductsSubscribable, productCertDirForNoProductsSubscribable, productCertDirForNoProductsinstalled, productCertDirForAllProductsSubscribableInTheFuture, productCertDirForAllProductsSubscribableByOneCommonServiceLevel, productCertDirForAllProductsSubscribableByMoreThanOneCommonServiceLevel }) {
        RemoteFileTasks.runCommandAndAssert(client, "rm -rf " + productCertDir, 0);
        RemoteFileTasks.runCommandAndAssert(client, "mkdir " + productCertDir, 0);
    }
    // register and subscribe to all available subscriptions
    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);
    // to avoid unmapped_guests_only pools
    if (Boolean.valueOf(clienttasks.getFactValue("virt.is_guest")))
        clienttasks.mapSystemAsAGuestOfItself();
    clienttasks.subscribeToTheCurrentlyAvailableSubscriptionPoolsCollectively();
    // get the current certs
    List<EntitlementCert> currentEntitlementCerts = clienttasks.getCurrentEntitlementCerts();
    List<ProductCert> currentProductCerts = clienttasks.getCurrentProductCerts();
    List<InstalledProduct> installedProducts = clienttasks.getCurrentlyInstalledProducts();
    // distribute a copy of the product certs amongst the productCertDirs based on their status
    for (ProductCert productCert : currentProductCerts) {
        InstalledProduct installedProduct = clienttasks.getInstalledProductCorrespondingToProductCert(productCert, installedProducts);
        if (installedProduct.status.equals("Not Subscribed")) {
            // "Not Subscribed" case...
            RemoteFileTasks.runCommandAndAssert(client, "cp " + productCert.file + " " + productCertDirForNoProductsSubscribable, 0);
            RemoteFileTasks.runCommandAndAssert(client, "cp " + productCert.file + " " + productCertDirForSomeProductsSubscribable, 0);
        } else if (installedProduct.status.equals("Subscribed")) {
            // "Subscribed" case...
            RemoteFileTasks.runCommandAndAssert(client, "cp " + productCert.file + " " + productCertDirForAllProductsSubscribable, 0);
            RemoteFileTasks.runCommandAndAssert(client, "cp " + productCert.file + " " + productCertDirForSomeProductsSubscribable, 0);
        } else {
        // TODO "Partially Subscribed" case
        // InstalledProduct installedProduct = clienttasks.getInstalledProductCorrespondingToEntitlementCert(correspondingEntitlementCert);
        }
    }
    // setup for productCertDirForAllProductsSubscribableInTheFuture
    // clienttasks.unsubscribeFromAllOfTheCurrentlyConsumedProductSubscriptions();
    List<File> productCertFilesCopied = new ArrayList<File>();
    futureSystemSubscriptionPools = new ArrayList<SubscriptionPool>();
    for (List<Object> futureSystemSubscriptionPoolsDataRow : getAllFutureSystemSubscriptionPoolsDataAsListOfLists()) {
        SubscriptionPool futureSystemSubscriptionPool = (SubscriptionPool) futureSystemSubscriptionPoolsDataRow.get(0);
        // for (ProductCert productCert : clienttasks.getCurrentProductCertsProvidedBySubscriptionPool(futureSystemSubscriptionPool)) {	// TODO not efficient; testing fix on next line
        for (ProductCert productCert : clienttasks.getProductCertsProvidedBySubscriptionPool(currentProductCerts, futureSystemSubscriptionPool)) {
            if (!productCertFilesCopied.contains(productCert.file)) {
                // RemoteFileTasks.runCommandAndAssert(client, "cp -n "+productCert.file+" "+productCertDirForAllProductsSubscribableInTheFuture, 0);	// RHEL5 does not understand cp -n
                // no clobber copy for both RHEL5 ad RHEL6
                RemoteFileTasks.runCommandAndAssert(client, "if [ ! -e " + productCertDirForAllProductsSubscribableInTheFuture + File.separator + productCert.file.getName() + " ]; then cp " + productCert.file + " " + productCertDirForAllProductsSubscribableInTheFuture + "; fi;", 0);
                productCertFilesCopied.add(productCert.file);
                if (!futureSystemSubscriptionPools.contains(futureSystemSubscriptionPool)) {
                    futureSystemSubscriptionPools.add(futureSystemSubscriptionPool);
                }
            }
        }
    }
    // determine the serviceLevel and all the products that are subscribable by one common service level
    // Map<String,Set<String>> serviceLevelToProductIdsMap = getServiceLevelToProductIdsMapFromEntitlementCerts(clienttasks.getCurrentEntitlementCerts());	// TODO not efficient; testing fix on next line
    Map<String, Set<String>> serviceLevelToProductIdsMap = getServiceLevelToProductIdsMapFromEntitlementCerts(currentEntitlementCerts);
    // /*debugTesting*/ serviceLevelToProductIdsMap.get("Premium").add("17000");
    Map<String, Set<String>> productIdsToServiceLevelsMap = getInvertedMap(serviceLevelToProductIdsMap);
    Set<String> allProductsSubscribableByOneCommonServiceLevelCandidates = productIdsToServiceLevelsMap.keySet();
    boolean allProductsSubscribableByOneCommonServiceLevelDeterminable = true;
    OUT: do {
        String serviceLevelCandidate = getKeyToLongestMap(serviceLevelToProductIdsMap);
        Assert.assertNotNull(serviceLevelCandidate, "If the key to the longest map of serviceLevel to ProductIds is null, then there are probably no subscriptions available.");
        // does this candidate have all candidate products?
        if (serviceLevelToProductIdsMap.get(serviceLevelCandidate).containsAll(allProductsSubscribableByOneCommonServiceLevelCandidates)) {
            // is there another serviceLevel that has all candidate products?
            for (String serviceLevel : serviceLevelToProductIdsMap.keySet()) {
                if (serviceLevel.equals(serviceLevelCandidate))
                    continue;
                if (serviceLevelToProductIdsMap.get(serviceLevel).size() == serviceLevelToProductIdsMap.get(serviceLevelCandidate).size()) {
                    allProductsSubscribableByOneCommonServiceLevelDeterminable = false;
                    break OUT;
                }
            }
            allProductsSubscribableByOneCommonServiceLevelValue = serviceLevelCandidate;
        } else {
            // pluck the first candidate product that is not in the serviceLevelCandidate map of products
            for (String productId : (String[]) allProductsSubscribableByOneCommonServiceLevelCandidates.toArray(new String[] {})) {
                if (!serviceLevelToProductIdsMap.get(serviceLevelCandidate).contains(productId)) {
                    allProductsSubscribableByOneCommonServiceLevelCandidates.remove(productId);
                    for (String serviceLevel : serviceLevelToProductIdsMap.keySet()) {
                        serviceLevelToProductIdsMap.get(serviceLevel).remove(productId);
                    }
                    break;
                }
            }
        }
    } while (allProductsSubscribableByOneCommonServiceLevelValue == null && allProductsSubscribableByOneCommonServiceLevelDeterminable);
    // copy the products to productCertDirForAllProductsSubscribableByOneCommonServiceLevel
    if (allProductsSubscribableByOneCommonServiceLevelDeterminable) {
        // for (ProductCert productCert : clienttasks.getCurrentProductCerts()) {	// TODO not efficient; testing fix on next line
        for (ProductCert productCert : currentProductCerts) {
            if (allProductsSubscribableByOneCommonServiceLevelCandidates.contains(productCert.productId)) {
                RemoteFileTasks.runCommandAndAssert(client, "cp " + productCert.file + " " + productCertDirForAllProductsSubscribableByOneCommonServiceLevel, 0);
            }
        }
    } else {
        log.warning("Cannot determine a set of products where allProductsSubscribableByOneCommonServiceLevel.");
    }
    // determine the serviceLevels and all the products that are subscribable by more than one common service level
    // serviceLevelToProductIdsMap = getServiceLevelToProductIdsMapFromEntitlementCerts(clienttasks.getCurrentEntitlementCerts());	// TODO not efficient; testing fix on next line
    serviceLevelToProductIdsMap = getServiceLevelToProductIdsMapFromEntitlementCerts(currentEntitlementCerts);
    productIdsToServiceLevelsMap = getInvertedMap(serviceLevelToProductIdsMap);
    List<String> allProductsSubscribableByMoreThanOneCommonServiceLevelCandidates = new ArrayList<String>();
    for (String productId : productIdsToServiceLevelsMap.keySet()) {
        if (productIdsToServiceLevelsMap.get(productId).size() > 1)
            allProductsSubscribableByMoreThanOneCommonServiceLevelCandidates.add(productId);
    }
    if (!allProductsSubscribableByMoreThanOneCommonServiceLevelCandidates.isEmpty()) {
        // randomly choose the service levels from the candidates
        // allProductsSubscribableByMoreThanOneCommonServiceLevelValues = Arrays.asList(productIdsToServiceLevelsMap.get(allProductsSubscribableByMoreThanOneCommonServiceLevelCandidates.get(randomGenerator.nextInt(allProductsSubscribableByMoreThanOneCommonServiceLevelCandidates.size()))).toArray(new String[]{}));
        allProductsSubscribableByMoreThanOneCommonServiceLevelValues.addAll(productIdsToServiceLevelsMap.get(allProductsSubscribableByMoreThanOneCommonServiceLevelCandidates.get(randomGenerator.nextInt(allProductsSubscribableByMoreThanOneCommonServiceLevelCandidates.size()))));
        // pluck out the productIds that do not map to all of the values in allProductsSubscribableByMoreThanOneCommonServiceLevelValues
        for (String productId : productIdsToServiceLevelsMap.keySet()) {
            if (!productIdsToServiceLevelsMap.get(productId).containsAll(allProductsSubscribableByMoreThanOneCommonServiceLevelValues)) {
                allProductsSubscribableByMoreThanOneCommonServiceLevelCandidates.remove(productId);
            }
        }
        // for (ProductCert productCert : clienttasks.getCurrentProductCerts()) {	// TODO not efficient; testing fix on next line
        for (ProductCert productCert : currentProductCerts) {
            if (allProductsSubscribableByMoreThanOneCommonServiceLevelCandidates.contains(productCert.productId)) {
                RemoteFileTasks.runCommandAndAssert(client, "cp " + productCert.file + " " + productCertDirForAllProductsSubscribableByMoreThanOneCommonServiceLevel, 0);
            }
        }
    } else {
        log.warning("Cannot determine a set of products where allProductsSubscribableByMoreThanOneCommonServiceLevel.");
    }
    // remember the originally configured productCertDir
    this.originalProductCertDir = clienttasks.productCertDir;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) EntitlementCert(rhsm.data.EntitlementCert) ArrayList(java.util.ArrayList) ProductCert(rhsm.data.ProductCert) InstalledProduct(rhsm.data.InstalledProduct) File(java.io.File) SubscriptionPool(rhsm.data.SubscriptionPool) BeforeClass(org.testng.annotations.BeforeClass)

Example 58 with SubscriptionPool

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

the class ContentIntegrationTests method testRegisterAndSubscribe.

// Test Methods ***********************************************************************
@Test(description = "register and subscribe to expected product subscription", groups = { "Tier1Tests" }, dataProvider = "getSubscribeData", // disabled in favor of various ContentTests which do not depend on the maintenance of dataProvider="getSubscribeData"
enabled = false)
public // @ImplementsNitrateTest(caseId=) //TODO Find a tcms caseId
void testRegisterAndSubscribe(String username, String password, ConsumerType type, String productId, String variant, String arch, Integer sockets, String engProductId) {
    // register a new consumer
    registerConsumerWhenNotAlreadyRegistered(username, password, type, sockets);
    // assert non-availability based on sockets
    if (sockets != null) {
        // set client's sockets value one higher than subscription supports
        Map<String, String> factsMap = new HashMap<String, String>();
        Integer moreSockets = sockets + 1;
        factsMap.put("cpu.cpu_socket(s)", String.valueOf(moreSockets));
        // factsMap.put("lscpu.cpu_socket(s)", String.valueOf(moreSockets));
        clienttasks.createFactsFileWithOverridingValues(factsMap);
        clienttasks.facts(null, true, null, null, null, null);
        SubscriptionPool pool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", productId, clienttasks.getCurrentlyAvailableSubscriptionPools());
        Assert.assertNull(pool, "Subscription pool for product '" + productId + "' is NOT available when the client's sockets (simulated cpu.cpu_socket(s)='" + moreSockets + "') exceed '" + sockets + "'.");
        factsMap.put("cpu.cpu_socket(s)", String.valueOf(sockets));
        // factsMap.put("lscpu.cpu_socket(s)", String.valueOf(sockets));
        clienttasks.createFactsFileWithOverridingValues(factsMap);
        clienttasks.facts(null, true, null, null, null, null);
    }
    // get the pools available to this registered consumer
    List<SubscriptionPool> availablePools = clienttasks.getCurrentlyAvailableSubscriptionPools();
    // assert non-availability based on arch
    if (arch != null) {
        // Note: the arch attribute can be a comma separated list of values
        List<String> arches = new ArrayList<String>(Arrays.asList(arch.trim().toUpperCase().split(" *, *")));
        // Note: x86 is a general term to cover all 32-bit intel microprocessors
        if (arches.contains("X86")) {
            arches.addAll(Arrays.asList("I386", "I486", "I586", "I686"));
        }
        if (!arches.contains(clienttasks.arch.toUpperCase())) {
            SubscriptionPool pool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", productId, availablePools);
            Assert.assertNull(pool, "Subscription pool for product '" + productId + "' is NOT available when the client arch (actual='" + clienttasks.arch + "') is not contained in '" + arches + "'.");
            pool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", productId, clienttasks.getCurrentlyAllAvailableSubscriptionPools());
            Assert.assertNotNull(pool, "Subscription pool for product '" + productId + "' is only listed in --all --available when the client arch (actual='" + clienttasks.arch + "') is not contained in '" + arches + "'.");
            File entitlementCertFile = clienttasks.subscribeToSubscriptionPool(pool, /*sm_serverAdminUsername*/
            username, /*sm_serverAdminPassword*/
            password, sm_serverUrl);
            currentlySubscribedProductIds.add(productId);
            EntitlementCert entitlementCert = clienttasks.getEntitlementCertFromEntitlementCertFile(entitlementCertFile);
            assertEngProductsAreProvidedInEntitlementCert(engProductId, entitlementCert);
            log.warning("No need for further testing of subscription productId '" + productId + "' on this hardware since the providing pool is not normally available.");
            return;
        }
    }
    // subscribe to the first available pool providing the productId
    SubscriptionPool pool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", productId, availablePools);
    Assert.assertNotNull(pool, "Found first available pool to subscribe to productId '" + productId + "'.");
    File entitlementCertFile = clienttasks.subscribeToSubscriptionPool(pool, /*sm_serverAdminUsername*/
    username, /*sm_serverAdminPassword*/
    password, sm_serverUrl);
    currentlySubscribedProductIds.add(productId);
    // setup data for subsequent tests
    // TODO MAYBE WE SHOULD ONLY DO THIS WHEN variants.contains(clienttasks.variant)) OR WHEN SUBSCRIPTION IS AVAILABLE?
    EntitlementCert entitlementCert = clienttasks.getEntitlementCertFromEntitlementCertFile(entitlementCertFile);
    entitlementCertData.add(Arrays.asList(new Object[] { username, password, type, productId, sockets, entitlementCert }));
    // assert that the entitlementCert contains productNamespaces for the engProductId(s)
    if (engProductId != null) {
        assertEngProductsAreProvidedInEntitlementCert(engProductId, entitlementCert);
    }
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONObject(org.json.JSONObject) SubscriptionPool(rhsm.data.SubscriptionPool) File(java.io.File) Test(org.testng.annotations.Test)

Example 59 with SubscriptionPool

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

the class MigrationTests method testRhnMigrateClassicToRhsmWithActivationKey.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-20109", "RHEL7-51742" }, 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 = "Execute migration tool rhn-migrate-classic-to-rhsm with a valid activation-key (and a good org)", groups = { "Tier1Tests", "blockedByBug-1154375", "blockedByBug-1512948", "blockedByBug-1516832" }, enabled = true)
@ImplementsNitrateTest(caseId = 130765)
public void testRhnMigrateClassicToRhsmWithActivationKey() throws Exception {
    if (clienttasks.isPackageVersion("subscription-manager", "<", "1.14.1-1"))
        throw new SkipException("The --activation-key option was not implemented in this version of subscription-manager.");
    // create a valid activation key
    // randomly choose a valid available pool for this key
    SubscriptionPool pool = getRandomListItem(availableSubscriptionPools);
    // choose an activationKey name
    String activationKeyName = String.format("activationKeyForOrg_%s_Pool_%s", clientOrgKey, pool.productId);
    JSONObject jsonActivationKey = CandlepinTasks.createActivationKeyUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, clientOrgKey, activationKeyName, Arrays.asList(pool.poolId), null);
    // register with the activation key
    if (false) {
        // debugTesting
        clienttasks.register_(null, null, clientOrgKey, null, null, null, null, null, null, null, activationKeyName, null, null, null, true, null, null, null, null, null);
        clienttasks.unregister_(null, null, null, null);
    }
    // TEMPORARY WORKAROUND FOR BUG
    // Bug 1196416 - rhn-migrate-classic-to-rhsm with --activation-key option should not prompt for destination credentials
    String bugId = "1196416";
    boolean invokeWorkaroundWhileBugIsOpen = true;
    try {
        if (invokeWorkaroundWhileBugIsOpen && BzChecker.getInstance().isBugOpen(bugId)) {
            log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId).toString() + " Bugzilla " + bugId + ".  (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId + ")");
            SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId);
        } else {
            invokeWorkaroundWhileBugIsOpen = false;
        }
    } catch (BugzillaAPIException be) {
    /* ignore exception */
    } catch (RuntimeException re) {
    /* ignore exception */
    }
    if (invokeWorkaroundWhileBugIsOpen) {
        testRhnMigrateClassicToRhsm(null, sm_rhnUsername, sm_rhnPassword, sm_rhnHostname, new ArrayList<String>(), "--activation-key=" + activationKeyName + " " + "--org=" + clientOrgKey, sm_rhnUsername, sm_rhnPassword, sm_clientUsername, sm_clientPassword, null, null, null);
    } else
        // call RhnMigrateClassicToRhsm_Test with rhsmUsername=null and rhsmPassword=null
        // END OF WORKAROUND
        // migrate from RHN Classic to RHSM using the activation key
        testRhnMigrateClassicToRhsm(null, sm_rhnUsername, sm_rhnPassword, sm_rhnHostname, new ArrayList<String>(), "--activation-key=" + activationKeyName + " " + "--org=" + clientOrgKey, sm_rhnUsername, sm_rhnPassword, null, null, null, null, null);
    // assert that the system is consuming the pool from the activation key.
    List<ProductSubscription> consumedProductSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
    Assert.assertEquals(consumedProductSubscriptions.size(), 1, "Number of consumed subscriptions after migrating from RHN Classic to RHSM with activation key '" + activationKeyName + "'.");
    Assert.assertEquals(consumedProductSubscriptions.get(0).poolId, pool.poolId, "The sole consumed subscription poolId after migrating from RHN Classic to RHSM with activation key '" + activationKeyName + "'.");
}
Also used : JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) ProductSubscription(rhsm.data.ProductSubscription) SkipException(org.testng.SkipException) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) 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)

Example 60 with SubscriptionPool

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

the class ModifierTests method testContentLabelForModifierSubscriptionIsOnlyAvailableInYumRepoListAfterTheModifiesPoolIsSubscribed.

// 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-21728", "RHEL7-51102" }, 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 = "verify content label for modifier subscriptions (e.g. EUS Subscriptions) is only available in yum repolist after providing subscriptions are entitled", groups = { "Tier1Tests", "blockedByBug-804227", "blockedByBug-871146", "blockedByBug-905546", "blockedByBug-958182" }, dependsOnGroups = {}, dataProvider = "getModifierSubscriptionData", enabled = true)
public void testContentLabelForModifierSubscriptionIsOnlyAvailableInYumRepoListAfterTheModifiesPoolIsSubscribed(SubscriptionPool modifierPool, String label, List<String> modifiedProductIds, String requiredTags, List<SubscriptionPool> poolsModified) throws JSONException, Exception {
    // avoid throttling RateLimitExceededException from IT-Candlepin
    if (/*!modifierPoolIds.contains(modifierPool.poolId) && WAS NOT AGRESSIVE ENOUGH*/
    CandlepinType.hosted.equals(sm_serverType)) {
        // strategically get a new consumer to avoid 60 repeated API calls from the same consumer
        // re-register as a new consumer
        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);
    }
    modifierPoolIds.add(modifierPool.poolId);
    // remove selected pools from the poolsModified list that are not consumable by this system to avoid: Pool is restricted to physical systems: '8a9086d344549b0c0144549bf9ae0dd4'.
    boolean isSystemVirtual = Boolean.valueOf(clienttasks.getFactValue("virt.is_guest"));
    for (SubscriptionPool subscriptionPool : new ArrayList<SubscriptionPool>(poolsModified)) {
        if (isSystemVirtual && CandlepinTasks.isPoolRestrictedToPhysicalSystems(sm_clientUsername, sm_clientPassword, sm_serverUrl, subscriptionPool.poolId)) {
            poolsModified.remove(subscriptionPool);
        } else if (!isSystemVirtual && CandlepinTasks.isPoolRestrictedToVirtualSystems(sm_clientUsername, sm_clientPassword, sm_serverUrl, subscriptionPool.poolId)) {
            poolsModified.remove(subscriptionPool);
        }
    }
    // make sure we are not subscribed to anything
    clienttasks.unsubscribeFromAllOfTheCurrentlyConsumedProductSubscriptions();
    boolean areAllRequiredTagsProvided = clienttasks.areAllRequiredTagsProvidedByProductCerts(requiredTags, clienttasks.getCurrentProductCerts());
    log.info("Before subscribing to anything, assert that the label (repo id) '" + label + "' is not available.");
    Assert.assertFalse(clienttasks.getYumRepolist("all").contains(label), "Before beginning our test, yum repolist all excludes label (repo id) '" + label + "'.");
    log.info("Now subscribe to the modifier pool and assert that the label (repo id) '" + label + "' is still not available.");
    // clienttasks.subscribeToSubscriptionPool(modifierPool);	// fails on systems that have no available pools, replacing with the next call that passed credentials
    // FIXME, this call assumes that  sm_clientUsername, sm_clientPassword is the currently registered consumer.  TODO I should query clienttasks to get the currently registered credentials
    clienttasks.subscribeToSubscriptionPool(modifierPool, sm_clientUsername, sm_clientPassword, sm_serverUrl);
    if (poolsModified.contains(modifierPool)) {
        // catch corner case when the modifierPool actually modifies itself
        log.warning("Modifier Subscription Pool '" + modifierPool.subscriptionName + "' appears to modify itself. That means that one of the modifiedProductIds " + modifiedProductIds + " from repo '" + label + "' is among this subscription's providedProducts " + modifierPool.provides + ".");
        if (areAllRequiredTagsProvided) {
            Assert.assertTrue(clienttasks.getYumRepolist("all").contains(label), "After subscribing only to modifier pool for productId '" + modifierPool.productId + "', yum repolist all DOES include (repo id) '" + label + "' because this subscription pool appears to modify itself and all of the requiredTags '" + requiredTags + "' are provided by the installed product certs.  See warning above.");
        } else {
            Assert.assertTrue(!clienttasks.getYumRepolist("all").contains(label), "After subscribing only to modifier pool for productId '" + modifierPool.productId + "', yum repolist all does NOT include (repo id) '" + label + "' because all of the requiredTags '" + requiredTags + "' are NOT provided by the installed product certs despite the facts that this subscription pool appears to modify itself.  See warning above.");
        }
        return;
    }
    Assert.assertTrue(!clienttasks.getYumRepolist("all").contains(label), "After subscribing to modifier pool for productId '" + modifierPool.productId + "', yum repolist all does NOT include (repo id) '" + label + "' because at least one of the providing product subscription(s) being modified is not yet subscribed to.");
    log.info("Now individually subscribe to each of the subscribing products being modified and assert that once both the modifier pool and product subscription being modified are both subscribed, then the modifier (repo id) '" + label + "' will become available.");
    for (SubscriptionPool pool : poolsModified) {
        EntitlementCert entitlementCert = clienttasks.getEntitlementCertFromEntitlementCertFile(clienttasks.subscribeToSubscriptionPool(pool, /*sm_serverAdminUsername*/
        sm_clientUsername, /*sm_serverAdminPassword*/
        sm_clientPassword, sm_serverUrl));
        if (areAllRequiredTagsProvided) {
            Assert.assertTrue(clienttasks.getYumRepolist("all").contains(label), "Having subscribed to both the modifier pool and the pool it modifies for productId '" + pool.productId + "', now the modifier pool's (repo id) '" + label + "' is available in yum repolist all.");
        } else {
            Assert.assertTrue(!clienttasks.getYumRepolist("all").contains(label), "Because not all of the requiredTags '" + requiredTags + "' for content label '" + label + "' are not 100% provided by the currently installed product certs, we are blocked from seeing the repo id label '" + label + "' in yum repolist all.");
        }
        clienttasks.unsubscribeFromSerialNumber(entitlementCert.serialNumber);
        Assert.assertTrue(!clienttasks.getYumRepolist("all").contains(label), "After unsubscribing from the modified pool for productId '" + pool.productId + "', yum repolist all no longer includes (repo id) '" + label + "' from modifier productId '" + modifierPool.productId + "'.");
    }
    log.info("Now let's subscribe to the pool being modified first before subscribing to the modifier.");
    clienttasks.unsubscribeFromAllOfTheCurrentlyConsumedProductSubscriptions();
    Assert.assertFalse(clienttasks.getYumRepolist("all").contains(label), "Yum repolist now excludes label (repo id) '" + label + "' since we are not subscribed to anything.");
    List<String> modifiedPoolIds = new ArrayList<String>();
    if (poolsModified.isEmpty())
        throw new SkipException("Cannot complete this test because it appears that there are no modifiable pools (providing products " + modifiedProductIds + ") available to this consumer that can be modified by the modifier pool '" + modifierPool.subscriptionName + "'.");
    for (SubscriptionPool pool : poolsModified) modifiedPoolIds.add(pool.poolId);
    clienttasks.subscribe(null, null, modifiedPoolIds, null, null, null, null, null, null, null, null, null, null);
    EntitlementCert entitlementCert = clienttasks.getEntitlementCertFromEntitlementCertFile(clienttasks.subscribeToSubscriptionPool(modifierPool, sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl));
    if (areAllRequiredTagsProvided) {
        Assert.assertTrue(clienttasks.getYumRepolist("all").contains(label), "Having subscribed to all of the pools modified and the modifier pool, the modifier pool's (repo id) '" + label + "' is immediately be available in yum repolist all.");
    } else {
        Assert.assertTrue(!clienttasks.getYumRepolist("all").contains(label), "Because not all of the requiredTags '" + requiredTags + "' for content label '" + label + "' are not 100% provided by the currently installed product certs, we are blocked from seeing the repo id label '" + label + "' in yum repolist all.");
    }
    clienttasks.unsubscribeFromSerialNumber(entitlementCert.serialNumber);
    Assert.assertTrue(!clienttasks.getYumRepolist("all").contains(label), "After unsubscribing from the modifier pool, yum repolist all no longer includes (repo id) '" + label + "' from modifier productId '" + modifierPool.productId + "'.");
    if (!areAllRequiredTagsProvided) {
        throw new SkipException("We cannot claim success on this test because 100% of the requiredTags '" + requiredTags + "' are not provided by the currently install products.");
    }
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) ArrayList(java.util.ArrayList) SkipException(org.testng.SkipException) 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