Search in sources :

Example 16 with ContentNamespace

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

the class ReposTests method testReposListReportsGrantedContentNamespacesAfterSubscribingToPool.

// 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-19972", "RHEL7-51011" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier1")
@Test(description = "subscription-manager: subscribe to a pool and verify that the newly entitled content namespaces are represented in the repos list", groups = { "Tier1Tests", "blockedByBug-807407", "blockedByBug-962520", "blockedByBug-1034649" }, // dataProvider="getAvailableSubscriptionPoolsData",	// very thorough, but takes too long to execute and rarely finds more bugs
dataProvider = "getRandomSubsetOfAvailableSubscriptionPoolsData", enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testReposListReportsGrantedContentNamespacesAfterSubscribingToPool(SubscriptionPool pool) throws JSONException, Exception {
    log.info("Following is a list of previously subscribed repos...");
    List<Repo> priorRepos = clienttasks.getCurrentlySubscribedRepos();
    // choose a quantity before subscribing to avoid Stdout: Quantity '1' is not a multiple of instance multiplier '2'
    String quantity = null;
    /*if (clienttasks.isPackageVersion("subscription-manager",">=","1.10.3-1"))*/
    if (pool.suggested != null) {
        // when the Suggested quantity is 0, let's specify a quantity to avoid Stdout: Quantity '1' is not a multiple of instance multiplier '2'
        if (pool.suggested < 1)
            quantity = CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "instance_multiplier");
        if (pool.suggested > 1 && quantity == null)
            quantity = pool.suggested.toString();
    }
    // subscribe and get the granted entitlement
    // File entitlementCertFile = clienttasks.subscribeToSubscriptionPool(pool);	// for this test, we can skip the exhaustive asserts done by this call to clienttasks.subscribeToSubscriptionPool(pool)
    File entitlementCertFile = clienttasks.subscribeToSubscriptionPool_(pool, quantity);
    Assert.assertTrue(RemoteFileTasks.testExists(client, entitlementCertFile.getPath()), "Found the EntitlementCert file (" + entitlementCertFile + ") that was granted after subscribing to pool id '" + pool.poolId + "'.");
    EntitlementCert entitlementCert = clienttasks.getEntitlementCertFromEntitlementCertFile(entitlementCertFile);
    // check the modifierSubscriptionData for SubscriptionPools that may already have been subscribed too and will modify this pool thereby enabling more repos than expected
    for (List<Object> row : modifierSubscriptionData) {
        // ll.add(Arrays.asList(new Object[]{modifierPool, label, modifiedProductIds, requiredTags, providingPools}));
        SubscriptionPool modifierPool = (SubscriptionPool) row.get(0);
        String label = (String) row.get(1);
        List<String> modifiedProductIds = (List<String>) row.get(2);
        String requiredTags = (String) row.get(3);
        List<SubscriptionPool> poolsModified = (List<SubscriptionPool>) row.get(4);
        if (poolsModified.contains(pool)) {
            if (priorSubscribedPoolIds.contains(modifierPool.poolId)) {
                // the modifier's content should now be available in the repos too
                EntitlementCert modifierEntitlementCert = clienttasks.getEntitlementCertCorrespondingToSubscribedPool(modifierPool);
                // simply add the contentNamespaces (if not already there) from the modifier to the entitlement cert's contentNamespaces so they will be accounted for in the repos list test below
                for (ContentNamespace contentNamespace : modifierEntitlementCert.contentNamespaces) {
                    if (!contentNamespace.type.equalsIgnoreCase("yum"))
                        continue;
                    if (!entitlementCert.contentNamespaces.contains(contentNamespace)) {
                        log.warning("Due to a previously subscribed modifier subscription pool (" + modifierPool.subscriptionName + "), the new repos listed should also include ContentNamespace: " + contentNamespace);
                        entitlementCert.contentNamespaces.add(contentNamespace);
                    }
                }
            }
        }
    }
    priorSubscribedPoolIds.add(pool.poolId);
    log.info("Following is the new list of subscribed repos after subscribing to pool: " + pool);
    List<Repo> actualRepos = clienttasks.getCurrentlySubscribedRepos();
    // assert that the new contentNamespaces from the entitlementCert are listed in repos
    int numNewRepos = 0;
    for (ContentNamespace contentNamespace : entitlementCert.contentNamespaces) {
        if (!contentNamespace.type.equalsIgnoreCase("yum"))
            continue;
        // instantiate the expected Repo that represents this contentNamespace
        // the expected RepoUrl is set by joining the rhsm.conf baseurl with the downloadUrl in the contentNamespace which is usually a relative path.  When it is already a full path, leave it!
        String expectedRepoUrl;
        if (contentNamespace.downloadUrl.contains("://")) {
            expectedRepoUrl = contentNamespace.downloadUrl;
        } else {
            // join baseurl to downloadUrl with "/"
            expectedRepoUrl = clienttasks.baseurl.replaceFirst("//+$", "//") + contentNamespace.downloadUrl.replaceFirst("^//+", "");
        }
        Repo expectedRepo = new Repo(contentNamespace.name, contentNamespace.label, expectedRepoUrl, contentNamespace.enabled);
        // assert the subscription-manager repos --list reports the expectedRepo (unless it requires tags that are not found in the installed product certs)
        if (clienttasks.areAllRequiredTagsInContentNamespaceProvidedByProductCerts(contentNamespace, currentProductCerts)) {
            // TEMPORARY WORKAROUND FOR Bug 1246636 - an expected entitled content set is not reflected in subscription-manager repos --list
            if (expectedRepo.repoName.equals("content") && !actualRepos.contains(expectedRepo)) {
                boolean invokeWorkaroundWhileBugIsOpen = true;
                String bugId = "1246636";
                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) {
                    log.warning("The newly entitled contentNamespace '" + contentNamespace + "' is NOT represented in the subscription-manager repos --list by: " + expectedRepo);
                    continue;
                }
            }
            // END OF WORKAROUND
            Assert.assertTrue(actualRepos.contains(expectedRepo), "The newly entitled contentNamespace '" + contentNamespace + "' is represented in the subscription-manager repos --list by: " + expectedRepo);
            // also count the number of NEW contentNamespaces
            if (!priorRepos.contains(expectedRepo))
                numNewRepos++;
        } else {
            Assert.assertFalse(actualRepos.contains(expectedRepo), "The newly entitled contentNamespace '" + contentNamespace + "' is NOT represented in the subscription-manager repos --list because it requires tags (" + contentNamespace.requiredTags + ") that are not provided by the currently installed product certs.");
        }
    }
    // assert that the number of repos reported has increased by the number of contentNamespaces in the new entitlementCert (unless the
    Assert.assertEquals(actualRepos.size(), priorRepos.size() + numNewRepos, "The number of entitled repos has increased by the number of NEW contentNamespaces (" + numNewRepos + ") from the newly granted entitlementCert (including applicable contentNamespaces from a previously subscribed modifier pool).");
// randomly decide to unsubscribe from the pool only for the purpose of saving on accumulated logging and avoid a java heap memory error
// if (randomGenerator.nextInt(2)==1) clienttasks.unsubscribe(null, entitlementCert.serialNumber, null, null, null); AND ALSO REMOVE pool FROM priorSubscribedPools
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) ContentNamespace(rhsm.data.ContentNamespace) Repo(rhsm.data.Repo) YumRepo(rhsm.data.YumRepo) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 17 with ContentNamespace

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

the class RHUITests method testDownloadRHUIISOFromFileRepo.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-22305", "RHEL7-55202" }, 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 = "download an expected RHUI iso from an expected file repoUrl", // RHEL-6-RHUI-2-LATEST-Server-x86_64-DVD.iso ERROR 404: Not Found. https://projects.engineering.redhat.com/browse/RCMPROJ-6571
groups = { "Tier1Tests", "blockedByBug-860516", "blockedByBug-894184", "blockedByBug-1427516" }, dependsOnMethods = { "testConsumeRHUISubscriptionProduct" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testDownloadRHUIISOFromFileRepo() {
    if (sm_rhuiDownloadIso.equals(""))
        throw new SkipException("Skipping this test when no value was given for the RHUI Download ISO");
    File downloadedIsoFile = new File("/tmp/" + sm_rhuiDownloadIso);
    RemoteFileTasks.runCommandAndAssert(client, "rm -rf " + downloadedIsoFile, 0);
    // find the repo for the isos
    ContentNamespace contentNamespaceForIso = null;
    for (EntitlementCert entitlementCert : clienttasks.getCurrentEntitlementCerts()) {
        for (ContentNamespace contentNamespace : entitlementCert.contentNamespaces) {
            if (contentNamespace.label.equals(sm_rhuiRepoIdForIsos)) {
                contentNamespaceForIso = contentNamespace;
                break;
            }
        }
    }
    Assert.assertNotNull(contentNamespaceForIso, "Found expected ContentNamespace to repoId '" + sm_rhuiRepoIdForIsos + "' for rhui isos after subscribe to '" + sm_rhuiSubscriptionProductId + "'.");
    String repoUrl = clienttasks.baseurl + contentNamespaceForIso.downloadUrl;
    // assert available repos for "Red Hat Enterprise Linux Server from RHUI" (when not a server, no content should exist)
    List<Repo> repos = clienttasks.getCurrentlySubscribedRepos();
    if (clienttasks.releasever.contains("Server")) {
        Assert.assertMore(repos.size(), 0, "When consuming RHUI Product ID '" + sm_rhuiSubscriptionProductId + "' on a Server '" + clienttasks.releasever + "' system, repo content should be available.");
    } else {
        Assert.assertEquals(repos.size(), 0, "When consuming RHUI Product ID '" + sm_rhuiSubscriptionProductId + "' on a non-Server '" + clienttasks.releasever + "' system, repo content should NOT be available.");
        // RHEL-6.1-RHUI-2.0-LATEST-Server-x86_64-DVD.iso
        throw new SkipException("This system release is '" + clienttasks.releasever + "'.  RHUI ISO '" + sm_rhuiDownloadIso + "' requires Server for downloading.");
    }
    // substitute the yum vars
    // http://www.centos.org/docs/5/html/5.2/Deployment_Guide/s1-yum-useful-variables.html
    // http://www.centos.org/docs/5/html/5.2/Deployment_Guide/s1-yum-useful-variables.html
    String arch = Arrays.asList("i686", "i486", "i386").contains(clienttasks.arch) ? "i386" : clienttasks.arch;
    // RHEL-6.1-RHUI-2.0-LATEST-Server-x86_64-DVD.iso
    if (!sm_rhuiDownloadIso.contains(arch))
        throw new SkipException("When this system's arch (" + arch + ") is substituted into the repoUrl (" + repoUrl + "), it will not find RHUI ISO (" + sm_rhuiDownloadIso + ") for downloading.");
    repoUrl = repoUrl.replaceFirst("\\$releasever", clienttasks.releasever);
    repoUrl = repoUrl.replaceFirst("\\$basearch", arch);
    File entitlementKeyFile = clienttasks.getEntitlementCertKeyFileCorrespondingToEntitlementCertFile(entitlementCertFile);
    // $ wget  --certificate=<Content Certificate>	https://cdn.redhat.com/content/dist/rhel/rhui/server/6/6Server/x86_64/rhui/2.0/iso/RHEL-6.1-RHUI-2.0-LATEST-Server-x86_64-DVD.iso
    // wget --no-check-certificate --certificate=/etc/pki/entitlement/7658526340059785943.pem --private-key=/etc/pki/entitlement/7658526340059785943-key.pem --output-document=/tmp/RHEL-6.1-RHUI-2.0-LATEST-Server-x86_64-DVD.iso -- https://cdn.redhat.com/content/dist/rhel/rhui/server/6/6Server/x86_64/rhui/2.0/iso/RHEL-6.1-RHUI-2.0-LATEST-Server-x86_64-DVD.iso
    RemoteFileTasks.runCommandAndAssert(client, "wget --no-check-certificate --certificate=" + entitlementCertFile + " --private-key=" + entitlementKeyFile + " --output-document=" + downloadedIsoFile + " -- " + repoUrl + "/" + sm_rhuiDownloadIso, 0);
    Assert.assertTrue(RemoteFileTasks.testExists(client, downloadedIsoFile.getPath()), "Expected RHUI Download ISO was downloaded.");
}
Also used : ContentNamespace(rhsm.data.ContentNamespace) EntitlementCert(rhsm.data.EntitlementCert) Repo(rhsm.data.Repo) SkipException(org.testng.SkipException) File(java.io.File) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 18 with ContentNamespace

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

the class ContentTests method testContentSetsEntitledFromSubscriptionPoolSatisfyTheSystemArch.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-20081", "RHEL7-50720" }, 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 that all content sets granted from a subscription pool satisfy the system arch and subset the provided product's arch", groups = { "Tier1Tests", "blockedByBug-706187", "blockedByBug-975520" }, // "getAvailableSubscriptionPoolsData",
dataProvider = "getAllAvailableSubscriptionPoolsProvidingArchBasedContentData", enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testContentSetsEntitledFromSubscriptionPoolSatisfyTheSystemArch(SubscriptionPool pool) throws JSONException, Exception {
    List<String> providedProductIds = CandlepinTasks.getPoolProvidedProductIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId);
    if (providedProductIds.isEmpty())
        throw new SkipException("This test is not applicable for a pool that provides no products.");
    JSONObject jsonStatus = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(/*authenticator*/
    null, /*password*/
    null, sm_serverUrl, "/status"));
    JSONObject jsonPool = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/pools/" + pool.poolId));
    // maintain a list of expected content sets
    Set<ContentNamespace> expectedContentNamespaceSet = new HashSet<ContentNamespace>();
    // maintain a list of unexpected content sets
    Set<ContentNamespace> unexpectedContentNamespaceSet = new HashSet<ContentNamespace>();
    for (String providedProductId : providedProductIds) {
        // get the product
        String path = "/products/" + providedProductId;
        // starting with candlepin-2.0.11 /products/<ID> are requested by /owners/<KEY>/products/<ID> OR /products/<UUID>
        if (SubscriptionManagerTasks.isVersion(jsonStatus.getString("version"), ">=", "2.0.11"))
            path = jsonPool.getJSONObject("owner").getString("href") + path;
        JSONObject jsonProduct = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, path));
        // get the product supported arches
        JSONArray jsonProductAttributes = jsonProduct.getJSONArray("attributes");
        List<String> productSupportedArches = new ArrayList<String>();
        for (int j = 0; j < jsonProductAttributes.length(); j++) {
            JSONObject jsonProductAttribute = (JSONObject) jsonProductAttributes.get(j);
            String attributeName = jsonProductAttribute.getString("name");
            String attributeValue = jsonProductAttribute.isNull("value") ? null : jsonProductAttribute.getString("value");
            if (attributeName.equals("arch")) {
                // Note: the arch attribute can be a comma separated list of values
                productSupportedArches.addAll(Arrays.asList(attributeValue.trim().split("\\s*,\\s*")));
                // Note: x86 is a general arch to cover all 32-bit intel microprocessors
                if (productSupportedArches.contains("x86")) {
                    productSupportedArches.addAll(Arrays.asList("i386", "i486", "i586", "i686"));
                }
            }
        }
        // get the provided product contents
        JSONArray jsonProductContents = jsonProduct.getJSONArray("productContent");
        for (int j = 0; j < jsonProductContents.length(); j++) {
            JSONObject jsonProductContent = (JSONObject) jsonProductContents.get(j);
            JSONObject jsonContent = jsonProductContent.getJSONObject("content");
            Map<String, String> certData = new HashMap<String, String>();
            // certData.put("", jsonContent.getString("id"));
            if (jsonContent.has("type") && !jsonContent.isNull("type"))
                certData.put("type", jsonContent.getString("type"));
            if (jsonContent.has("label") && !jsonContent.isNull("label"))
                certData.put("label", jsonContent.getString("label"));
            if (jsonContent.has("name") && !jsonContent.isNull("name"))
                certData.put("name", jsonContent.getString("name"));
            if (jsonContent.has("vendorId") && !jsonContent.isNull("vendorId"))
                certData.put("vendorId", jsonContent.getString("vendor"));
            if (jsonContent.has("downloadUrl") && !jsonContent.isNull("downloadUrl"))
                certData.put("downloadUrl", jsonContent.getString("contentUrl"));
            if (jsonContent.has("requiredTags") && !jsonContent.isNull("requiredTags"))
                certData.put("requiredTags", jsonContent.getString("requiredTags"));
            // certData.put("", jsonContent.getString("releaseVer"));
            if (jsonContent.has("gpgKeyUrl") && !jsonContent.isNull("gpgKeyUrl"))
                certData.put("gpgKeyUrl", jsonContent.getString("gpgUrl"));
            if (jsonContent.has("metadataExpire") && !jsonContent.isNull("metadataExpire"))
                certData.put("metadataExpire", String.valueOf(jsonContent.getInt("metadataExpire")));
            // certData.put("", jsonContent.getString("modifiedProductIds"));
            if (jsonContent.has("arches") && !jsonContent.isNull("arches"))
                certData.put("arches", jsonContent.getString("arches"));
            ContentNamespace contentNamespace = new ContentNamespace(certData);
            // // get modifiedProductIds for each of the productContents
            // JSONArray jsonModifiedProductIds = jsonContent.getJSONArray("modifiedProductIds");
            // for (int k = 0; k < jsonModifiedProductIds.length(); k++) {
            // String modifiedProductId = (String) jsonModifiedProductIds.get(k);
            // }
            // get this content supported arches
            Set<String> contentSupportedArches = new HashSet<String>();
            String jsonContentArches = null;
            if (jsonContent.has("arches") && !jsonContent.isNull("arches") && !jsonContent.getString("arches").isEmpty()) {
                jsonContentArches = jsonContent.getString("arches");
                contentSupportedArches.addAll(Arrays.asList(jsonContentArches.split("\\s*,\\s*")));
                // Note: x86 is a general arch to cover all 32-bit intel microprocessors
                if (contentSupportedArches.contains("x86"))
                    contentSupportedArches.addAll(Arrays.asList("i386", "i486", "i586", "i686"));
                // it contains an arch that matches the system
                if (contentSupportedArches.contains("ALL") || contentSupportedArches.contains("noarch") || contentSupportedArches.contains(clienttasks.arch)) {
                    expectedContentNamespaceSet.add(contentNamespace);
                } else {
                    unexpectedContentNamespaceSet.add(contentNamespace);
                }
            } else {
                // TODO: NOT SURE HOW TOLERANT WE WANT TO BE FOR CONTENT SETS THAT INHERIT FROM THEIR PRODUCTS
                if (productSupportedArches.contains("ALL") || productSupportedArches.contains(clienttasks.arch)) {
                    expectedContentNamespaceSet.add(contentNamespace);
                } else {
                    unexpectedContentNamespaceSet.add(contentNamespace);
                }
            }
        }
    }
    // conflict situation: if a subscription provides more than one product that both provide the same content but whose product's arch differs, then it is possible to have the content in both expectedContentLabels and unexpectedContentLabels; expectedContentLabels wins!
    for (ContentNamespace expectedContentNamespace : expectedContentNamespaceSet) {
        List<ContentNamespace> unexpectedContentNamespaceList = new ArrayList<ContentNamespace>();
        unexpectedContentNamespaceList.addAll(unexpectedContentNamespaceSet);
        ContentNamespace unexpectedContentNamespace = ContentNamespace.findFirstInstanceWithMatchingFieldFromList("label", expectedContentNamespace.label, unexpectedContentNamespaceList);
        if (unexpectedContentNamespace != null) {
            log.warning("Based on multiple products '" + providedProductIds + "' from subscription '" + pool.subscriptionName + "' with conflicting arches, content label '" + expectedContentNamespace.label + "' defined for arches '" + expectedContentNamespace.arches + "' will be provided.");
            unexpectedContentNamespaceSet.remove(unexpectedContentNamespace);
        }
    }
    if (expectedContentNamespaceSet.isEmpty() && unexpectedContentNamespaceSet.isEmpty())
        throw new SkipException("This test is not applicable for a pool whose provided products have no content sets.");
    // avoid throttling RateLimitExceededException from IT-Candlepin
    if (!poolIds.contains(pool.poolId) && 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);
    }
    poolIds.add(pool.poolId);
    clienttasks.unsubscribe(true, (BigInteger) null, null, null, null, null, null);
    EntitlementCert entitlementCert = clienttasks.getEntitlementCertFromEntitlementCertFile(clienttasks.subscribeToSubscriptionPool(pool, /*sm_serverAdminUsername*/
    sm_clientUsername, /*sm_serverAdminPassword*/
    sm_clientPassword, sm_serverUrl));
    // adjust the expectedContentNamespaces for modified product ids that are not installed
    // List<ProductCert> installedProductCerts = clienttasks.getCurrentProductCerts();
    List<ProductSubscription> consumedProductSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
    for (String providedProductId : providedProductIds) {
        // get the product
        String path = "/products/" + providedProductId;
        // starting with candlepin-2.0.11 /products/<ID> are requested by /owners/<KEY>/products/<ID> OR /products/<UUID>
        if (SubscriptionManagerTasks.isVersion(jsonStatus.getString("version"), ">=", "2.0.11"))
            path = jsonPool.getJSONObject("owner").getString("href") + path;
        JSONObject jsonProduct = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, path));
        // get the provided product contents
        JSONArray jsonProductContents = jsonProduct.getJSONArray("productContent");
        for (int j = 0; j < jsonProductContents.length(); j++) {
            JSONObject jsonProductContent = (JSONObject) jsonProductContents.get(j);
            JSONObject jsonContent = jsonProductContent.getJSONObject("content");
            // get modifiedProductIds for each of the productContents
            JSONArray jsonModifiedProductIds = jsonContent.getJSONArray("modifiedProductIds");
            for (int k = 0; k < jsonModifiedProductIds.length(); k++) {
                String modifiedProductId = (String) jsonModifiedProductIds.get(k);
                String contentLabel = jsonContent.getString("label");
                // TODO: I do not believe this should check the installed products or all the current subscriptions' providedProductIds for this modifiedProductId
                // // if modifiedProductId is not installed, then the modifier jsonContent should NOT be among the expectedContentNamespaceSet
                // if (InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productId", modifiedProductId, installedProductCerts)==null) {
                // ContentNamespace contentNamespace = ContentNamespace.findFirstInstanceWithMatchingFieldFromList("label", jsonContent.getString("label"), new ArrayList<ContentNamespace>(expectedContentNamespaceSet));
                // if (contentNamespace!=null) {
                // log.warning("ContentNamespace label '"+contentNamespace.label+"' modifies product id '"+modifiedProductId+"' which is NOT installed and should therefore not be among the entitled content namespaces no matter what its arch ("+contentNamespace.arches+") may be.");
                // unexpectedContentNamespaceSet.add(contentNamespace);
                // expectedContentNamespaceSet.remove(contentNamespace);
                // }
                // }
                // DONE: Implemented the second thought by the following test block
                // if modifiedProductId is not provided by the currently consumed subscriptions, then the modifier jsonContent should NOT be among the expectedContentNamespaceSet
                Set<String> providedProductIdsByCurrentlyConsumedProductSubscriptions = new HashSet<String>();
                for (ProductSubscription productSubscription : consumedProductSubscriptions) {
                    for (String providedProductIdByCurrentlyConsumedProductSubscription : CandlepinTasks.getPoolProvidedProductIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId)) {
                        providedProductIdsByCurrentlyConsumedProductSubscriptions.add(providedProductIdByCurrentlyConsumedProductSubscription);
                    }
                }
                if (!providedProductIdsByCurrentlyConsumedProductSubscriptions.contains(modifiedProductId)) {
                    ContentNamespace contentNamespace = ContentNamespace.findFirstInstanceWithMatchingFieldFromList("label", jsonContent.getString("label"), new ArrayList<ContentNamespace>(expectedContentNamespaceSet));
                    if (contentNamespace != null) {
                        log.warning("ContentNamespace label '" + contentNamespace.label + "' modifies product id '" + modifiedProductId + "' which is NOT provided by the currently consumed subscriptions and should therefore not be among the entitled content namespaces no matter what its arch (" + contentNamespace.arches + ") may be.");
                        unexpectedContentNamespaceSet.add(contentNamespace);
                        expectedContentNamespaceSet.remove(contentNamespace);
                        // to the next contentNamespace/jsonProductContent/jsonContent
                        break;
                    }
                }
            }
        }
    }
    // entitlement asserts
    List<String> actualEntitledContentLabels = new ArrayList<String>();
    for (ContentNamespace contentNamespace : entitlementCert.contentNamespaces) actualEntitledContentLabels.add(contentNamespace.label);
    for (ContentNamespace contentNamespace : expectedContentNamespaceSet) {
        Assert.assertTrue(actualEntitledContentLabels.contains(contentNamespace.label), "As expected, contentNamespace label '" + contentNamespace.label + "' defined for arches '" + contentNamespace.arches + "' requiredTags '" + contentNamespace.requiredTags + "' is included in the entitlement after subscribing to '" + pool.subscriptionName + "' on a '" + clienttasks.arch + "' system.");
    }
    for (ContentNamespace contentNamespace : unexpectedContentNamespaceSet) {
        Assert.assertTrue(!actualEntitledContentLabels.contains(contentNamespace.label), "As expected, contentNamespace label '" + contentNamespace.label + "' defined for arches '" + contentNamespace.arches + "' requiredTags '" + contentNamespace.requiredTags + "' is NOT included in the entitlement after subscribing to '" + pool.subscriptionName + "' on a '" + clienttasks.arch + "' system.");
    }
    // adjust the expectedContentNamespaces for requiredTags that are not provided by the installed productCerts' providedTags before checking the YumRepos
    List<ProductCert> installedProductCerts = clienttasks.getCurrentProductCerts();
    for (ContentNamespace contentNamespace : new HashSet<ContentNamespace>(expectedContentNamespaceSet)) {
        if (!clienttasks.areAllRequiredTagsProvidedByProductCerts(contentNamespace.requiredTags, installedProductCerts)) {
            log.warning("Entitled contentNamespace label '" + contentNamespace.label + "' defined for arches '" + contentNamespace.arches + "' has requiredTags '" + contentNamespace.requiredTags + "' that are NOT provided by the currently installed product certs.  This expected contentNamespace will be moved to the unexpected list when asserting the YumRepos next.");
            unexpectedContentNamespaceSet.add(contentNamespace);
            expectedContentNamespaceSet.remove(contentNamespace);
        }
    }
    // adjust the expectedContentNamespaces for type that does not equal "yum" before checking the YumRepos
    for (ContentNamespace contentNamespace : new HashSet<ContentNamespace>(expectedContentNamespaceSet)) {
        if (!contentNamespace.type.equals("yum")) {
            // "file", "kickstart"
            log.warning("Entitled contentNamespace label '" + contentNamespace.label + "' defined for arches '" + contentNamespace.arches + "' has type '" + contentNamespace.type + "'.  This expected contentNamespace will be moved to the unexpected list when asserting the YumRepos next.");
            unexpectedContentNamespaceSet.add(contentNamespace);
            expectedContentNamespaceSet.remove(contentNamespace);
        }
    }
    // YumRepo asserts
    List<String> actualYumRepoLabels = new ArrayList<String>();
    for (YumRepo yumRepo : clienttasks.getCurrentlySubscribedYumRepos()) actualYumRepoLabels.add(yumRepo.id);
    for (ContentNamespace contentNamespace : expectedContentNamespaceSet) {
        Assert.assertTrue(actualYumRepoLabels.contains(contentNamespace.label), "As expected, yum repo label '" + contentNamespace.label + "' defined for arches '" + contentNamespace.arches + "' requiredTags '" + contentNamespace.requiredTags + "' is included in " + clienttasks.redhatRepoFile + " after subscribing to '" + pool.subscriptionName + "' on a '" + clienttasks.arch + "' system.");
    }
    for (ContentNamespace contentNamespace : unexpectedContentNamespaceSet) {
        Assert.assertTrue(!actualYumRepoLabels.contains(contentNamespace.label), "As expected, yum repo label '" + contentNamespace.label + "' defined for arches '" + contentNamespace.arches + "' requiredTags '" + contentNamespace.requiredTags + "' is NOT included in in " + clienttasks.redhatRepoFile + " after subscribing to '" + pool.subscriptionName + "' on a '" + clienttasks.arch + "' system.");
    }
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) HashMap(java.util.HashMap) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) ProductSubscription(rhsm.data.ProductSubscription) ProductCert(rhsm.data.ProductCert) ContentNamespace(rhsm.data.ContentNamespace) JSONObject(org.json.JSONObject) SkipException(org.testng.SkipException) YumRepo(rhsm.data.YumRepo) HashSet(java.util.HashSet) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 19 with ContentNamespace

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

the class ContentTests method getYumGroupFromEnabledRepoAndSubscriptionPoolDataAsListOfLists.

protected List<List<Object>> getYumGroupFromEnabledRepoAndSubscriptionPoolDataAsListOfLists() throws JSONException, Exception {
    List<List<Object>> ll = new ArrayList<List<Object>>();
    if (!isSetupBeforeSuiteComplete)
        return ll;
    if (clienttasks == null)
        return ll;
    if (sm_clientUsername == null)
        return ll;
    if (sm_clientPassword == null)
        return ll;
    // get the currently installed product certs to be used when checking for conditional content tagging
    List<ProductCert> currentProductCerts = clienttasks.getCurrentProductCerts();
    // assure we are freshly registered and process all available subscription pools
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, ConsumerType.system, null, null, null, null, null, (String) null, null, null, null, Boolean.TRUE, false, null, null, null, null);
    for (SubscriptionPool pool : clienttasks.getCurrentlyAvailableSubscriptionPools()) {
        // avoid throttling RateLimitExceededException from IT-Candlepin
        if (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, ConsumerType.system, null, null, null, null, null, (String) null, null, null, null, Boolean.TRUE, false, null, null, null, null);
        }
        File entitlementCertFile = clienttasks.subscribeToSubscriptionPool_(pool);
        Assert.assertNotNull(entitlementCertFile, "Found the entitlement cert file that was granted after subscribing to pool: " + pool);
        EntitlementCert entitlementCert = clienttasks.getEntitlementCertFromEntitlementCertFile(entitlementCertFile);
        for (ContentNamespace contentNamespace : entitlementCert.contentNamespaces) {
            if (!contentNamespace.type.equalsIgnoreCase("yum"))
                continue;
            if (contentNamespace.enabled && clienttasks.areAllRequiredTagsInContentNamespaceProvidedByProductCerts(contentNamespace, currentProductCerts)) {
                String repoLabel = contentNamespace.label;
                // find first available group provided by this repo
                String availableGroup = clienttasks.findAnAvailableGroupFromRepo(repoLabel);
                // find first installed group provided by this repo
                String installedGroup = clienttasks.findAnInstalledGroupFromRepo(repoLabel);
                // String availableGroup, String installedGroup, String repoLabel, SubscriptionPool pool
                ll.add(Arrays.asList(new Object[] { availableGroup, installedGroup, repoLabel, pool }));
            }
        }
        clienttasks.unsubscribeFromSerialNumber(clienttasks.getSerialNumberFromEntitlementCertFile(entitlementCertFile));
        // minimize the number of dataProvided rows (useful during automated testcase development)
        if (Boolean.valueOf(getProperty("sm.debug.dataProviders.minimize", "false")) && !ll.isEmpty())
            break;
    }
    return ll;
}
Also used : ContentNamespace(rhsm.data.ContentNamespace) EntitlementCert(rhsm.data.EntitlementCert) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) JSONObject(org.json.JSONObject) ProductCert(rhsm.data.ProductCert) SubscriptionPool(rhsm.data.SubscriptionPool) File(java.io.File)

Example 20 with ContentNamespace

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

the class ContentTests method getPackageFromEnabledRepoAndPersonalSubscriptionSubPoolDataAsListOfLists.

protected List<List<Object>> getPackageFromEnabledRepoAndPersonalSubscriptionSubPoolDataAsListOfLists() throws Exception {
    List<List<Object>> ll = new ArrayList<List<Object>>();
    if (!isSetupBeforeSuiteComplete)
        return ll;
    if (client1tasks == null)
        return ll;
    if (client2tasks == null)
        return ll;
    // assure we are registered (as a person on client2 and a system on client1)
    // register client1 as a system under rhpersonalUsername
    client1tasks.register(sm_rhpersonalUsername, sm_rhpersonalPassword, sm_rhpersonalOrg, null, ConsumerType.system, null, null, null, null, null, (String) null, null, null, null, Boolean.TRUE, false, null, null, null, null);
    // register client2 as a person under rhpersonalUsername
    client2tasks.register(sm_rhpersonalUsername, sm_rhpersonalPassword, sm_rhpersonalOrg, null, ConsumerType.person, null, null, null, null, null, (String) null, null, null, null, Boolean.TRUE, false, null, null, null, null);
    // subscribe to the personal subscription pool to unlock the subpool
    personalConsumerId = client2tasks.getCurrentConsumerId();
    for (int j = 0; j < sm_personSubscriptionPoolProductData.length(); j++) {
        JSONObject poolProductDataAsJSONObject = (JSONObject) sm_personSubscriptionPoolProductData.get(j);
        String personProductId = poolProductDataAsJSONObject.getString("personProductId");
        JSONObject subpoolProductDataAsJSONObject = poolProductDataAsJSONObject.getJSONObject("subPoolProductData");
        String systemProductId = subpoolProductDataAsJSONObject.getString("systemProductId");
        SubscriptionPool personPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", personProductId, client2tasks.getCurrentlyAvailableSubscriptionPools());
        Assert.assertNotNull(personPool, "Personal productId '" + personProductId + "' is available to user '" + sm_rhpersonalUsername + "' registered as a person.");
        File entitlementCertFile = client2tasks.subscribeToSubscriptionPool_(personPool);
        Assert.assertNotNull(entitlementCertFile, "Found the entitlement cert file that was granted after subscribing to personal pool: " + personPool);
        // now the subpool is available to the system
        SubscriptionPool systemPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", systemProductId, client1tasks.getCurrentlyAvailableSubscriptionPools());
        Assert.assertNotNull(systemPool, "Personal subPool productId'" + systemProductId + "' is available to user '" + sm_rhpersonalUsername + "' registered as a system.");
        // client1tasks.subscribeToSubscriptionPool(systemPool);
        entitlementCertFile = client1tasks.subscribeToSubscriptionPool_(systemPool);
        Assert.assertNotNull(entitlementCertFile, "Found the entitlement cert file that was granted after subscribing to system pool: " + systemPool);
        EntitlementCert entitlementCert = client1tasks.getEntitlementCertFromEntitlementCertFile(entitlementCertFile);
        for (ContentNamespace contentNamespace : entitlementCert.contentNamespaces) {
            if (!contentNamespace.type.equalsIgnoreCase("yum"))
                continue;
            if (contentNamespace.enabled) {
                String repoLabel = contentNamespace.label;
                // find an available package that is uniquely provided by repo
                String pkg = client1tasks.findUniqueAvailablePackageFromRepo(repoLabel);
                if (pkg == null) {
                    log.warning("Could NOT find a unique available package from repo '" + repoLabel + "' after subscribing to SubscriptionSubPool: " + systemPool);
                }
                // String availableGroup, String installedGroup, String repoLabel, SubscriptionPool pool
                ll.add(Arrays.asList(new Object[] { pkg, repoLabel, systemPool }));
            }
        }
        client1tasks.unsubscribeFromSerialNumber(client1tasks.getSerialNumberFromEntitlementCertFile(entitlementCertFile));
    }
    return ll;
}
Also used : ContentNamespace(rhsm.data.ContentNamespace) JSONObject(org.json.JSONObject) EntitlementCert(rhsm.data.EntitlementCert) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) JSONObject(org.json.JSONObject) SubscriptionPool(rhsm.data.SubscriptionPool) File(java.io.File)

Aggregations

ContentNamespace (rhsm.data.ContentNamespace)26 EntitlementCert (rhsm.data.EntitlementCert)26 ProductCert (rhsm.data.ProductCert)15 ArrayList (java.util.ArrayList)14 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)13 Test (org.testng.annotations.Test)13 File (java.io.File)12 SkipException (org.testng.SkipException)11 JSONObject (org.json.JSONObject)10 List (java.util.List)9 SSHCommandResult (com.redhat.qe.tools.SSHCommandResult)7 SubscriptionPool (rhsm.data.SubscriptionPool)7 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)6 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)4 BigInteger (java.math.BigInteger)4 HashSet (java.util.HashSet)4 YumRepo (rhsm.data.YumRepo)4 HashMap (java.util.HashMap)3 ProductNamespace (rhsm.data.ProductNamespace)3 Calendar (java.util.Calendar)2