Search in sources :

Example 11 with YumRepo

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

the class ReposTests method getYumReposDataAsListOfLists.

protected List<List<Object>> getYumReposDataAsListOfLists() throws Exception {
    List<List<Object>> ll = new ArrayList<List<Object>>();
    if (!isSetupBeforeSuiteComplete)
        return ll;
    // register
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, true, false, null, null, null, null);
    // subscribe to all available subscription so as to populate the redhat.repo file
    clienttasks.subscribeToTheCurrentlyAvailableSubscriptionPoolsCollectively();
    // trigger a yum transaction so that subscription-manager plugin will refresh redhat.repo
    clienttasks.getYumRepolist("all");
    for (YumRepo yumRepo : clienttasks.getCurrentlySubscribedYumRepos()) {
        ll.add(Arrays.asList(new Object[] { yumRepo }));
        // minimize the number of dataProvided rows (useful during automated testcase development)
        if (Boolean.valueOf(getProperty("sm.debug.dataProviders.minimize", "false")))
            break;
    }
    return ll;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) YumRepo(rhsm.data.YumRepo)

Example 12 with YumRepo

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

the class ReposTests method testYumRepoListPreservesAdditionalOptionsToRedhatReposUsingRepoOverride.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-19975", "RHEL7-51014" }, 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: add more yum repository options to redhat.repo and assert persistence using repo-override module.", groups = { "Tier1Tests", "blockedByBug-845349", "blockedByBug-834806", "blockedByBug-803746", "blockedByBug-1086316", "blockedByBug-1069230", "blockedByBug-1366301" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testYumRepoListPreservesAdditionalOptionsToRedhatReposUsingRepoOverride() throws JSONException, Exception {
    // register
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, true, false, null, null, null, null);
    clienttasks.subscribeToTheCurrentlyAvailableSubscriptionPoolsCollectively();
    List<YumRepo> subscribedYumRepos = clienttasks.getCurrentlySubscribedYumRepos();
    if (subscribedYumRepos.isEmpty())
        throw new SkipException("There are no entitled yum repos available for this test.");
    // randomly choose one of the YumRepos, set new option values, and manually update the yum repo
    YumRepo yumRepo = subscribedYumRepos.get(randomGenerator.nextInt(subscribedYumRepos.size()));
    // yumRepo = YumRepo.findFirstInstanceWithMatchingFieldFromList("id", "awesomeos-modifier",subscribedYumRepos);	// debugTesting case when yum repo comes from a modifier entitlement
    // yumRepo = YumRepo.findFirstInstanceWithMatchingFieldFromList("id", "content-label-no-gpg",subscribedYumRepos);	// debugTesting case when sslclientcert appears to change.
    yumRepo.exclude = "my-test-pkg my-test-pkg-* my-test-pkgversion-?";
    yumRepo.priority = new Integer(10);
    if (false) {
        // previously supported manual edits to redhat.repos
        clienttasks.updateYumRepo(clienttasks.redhatRepoFile, yumRepo);
    } else {
        // newly supported process for adding redhat.repo edits
        Map<String, String> addNameValueMap = new HashMap<String, String>();
        addNameValueMap.put("exclude", "my-test-pkg my-test-pkg-* my-test-pkgversion-?");
        addNameValueMap.put("priority", "10");
        clienttasks.repo_override(null, null, yumRepo.id, null, addNameValueMap, null, null, null, null);
    }
    // assert that the manually added repository options do not get clobbered by a new yum transaction
    // issue a new yum transaction
    client.runCommandAndWait("yum -q repolist --disableplugin=rhnplugin");
    // getCurrentlySubscribedYumRepos() includes a yum transaction: "yum -q repolist --disableplugin=rhnplugin"	(NOT ANYMORE after bug 1008016)
    YumRepo yumRepoAfterUpdate = YumRepo.findFirstInstanceWithMatchingFieldFromList("id", yumRepo.id, clienttasks.getCurrentlySubscribedYumRepos());
    Assert.assertNotNull(yumRepoAfterUpdate, "Found yum repo [" + yumRepo.id + "] after we manually altered it and issued a yum transaction.");
    Assert.assertEquals(yumRepoAfterUpdate.exclude, yumRepo.exclude, "Yum repo [" + yumRepo.id + "] has persisted the manually added \"exclude\" option and its value.");
    Assert.assertEquals(yumRepoAfterUpdate.priority, yumRepo.priority, "Yum repo [" + yumRepo.id + "] has persisted the manually added \"priority\" option and its value.");
    Assert.assertEquals(yumRepoAfterUpdate, yumRepo, "Yum repo [" + yumRepo.id + "] has persisted all of its repository option values after running a yum transaction.");
    // also assert that the repository values persist even after refresh
    clienttasks.removeAllCerts(false, true, false);
    clienttasks.refresh(null, null, null, null);
    yumRepoAfterUpdate = YumRepo.findFirstInstanceWithMatchingFieldFromList("id", yumRepo.id, clienttasks.getCurrentlySubscribedYumRepos());
    /* temporary idea to figure how why an sslclientcert would change; did not prove to be true; keeping for future
		BigInteger bi = clienttasks.getSerialNumberFromEntitlementCertFile(new File(yumRepoAfterUpdate.sslclientcert));
		SubscriptionPool sp = clienttasks.getSubscriptionPoolFromProductSubscription(ProductSubscription.findFirstInstanceWithMatchingFieldFromList("serialNumber", bi, clienttasks.getCurrentlyConsumedProductSubscriptions()), sm_clientUsername, sm_clientPassword);
		if (CandlepinTasks.isPoolAModifier(sm_clientUsername, sm_clientPassword, sp.poolId, sm_serverUrl)) {
			yumRepoAfterUpdate.sslclientcert = null;
			yumRepoAfterUpdate.sslclientkey = null;
			yumRepo.sslclientcert = null;
			yumRepo.sslclientkey = null;
			Assert.assertEquals(yumRepoAfterUpdate, yumRepo, "Discounting the sslclientcert and sslclientkey, yum repo ["+yumRepo.id+"] still persists all of its repository option values after running refresh and a yum transaction.");
		
		} else {
			Assert.assertEquals(yumRepoAfterUpdate, yumRepo, "Yum repo ["+yumRepo.id+"] still persists all of its repository option values after running refresh and a yum transaction.");
		}
		*/
    // Assert.assertEquals(yumRepoAfterUpdate, yumRepo, "Yum repo ["+yumRepo.id+"] still persists all of its repository option values after running refresh and a yum transaction.");
    yumRepoAfterUpdate.sslclientcert = null;
    yumRepo.sslclientcert = null;
    yumRepoAfterUpdate.sslclientkey = null;
    yumRepo.sslclientkey = null;
    Assert.assertEquals(yumRepoAfterUpdate, yumRepo, "Discounting changes to the sslclientcert and sslclientkey, yum repo [" + yumRepo.id + "] still persists all of its repository option values after running refresh and a yum transaction.");
    // also assert (when possible) that the repository values persist even after setting a release preference
    List<String> releases = clienttasks.getCurrentlyAvailableReleases(null, null, null, null);
    if (!releases.isEmpty()) {
        clienttasks.release(null, null, releases.get(randomGenerator.nextInt(releases.size())), null, null, null, null, null);
        yumRepoAfterUpdate = YumRepo.findFirstInstanceWithMatchingFieldFromList("id", yumRepo.id, clienttasks.getCurrentlySubscribedYumRepos());
        Assert.assertNotNull(yumRepoAfterUpdate, "Found yum repo [" + yumRepo.id + "] after we manually altered it, set a release, and issued a yum transaction.");
        Assert.assertEquals(yumRepoAfterUpdate.exclude, yumRepo.exclude, "Yum repo [" + yumRepo.id + "] has persisted the manually added \"exclude\" option and its value even after setting a release and issuing a yum transaction.");
        Assert.assertEquals(yumRepoAfterUpdate.priority, yumRepo.priority, "Yum repo [" + yumRepo.id + "] has persisted the manually added \"priority\" option and its value even after setting a release and issuing a yum transaction.");
    // THIS WILL LIKELY NOT BE EQUAL WHEN THE yumRepoAfterUpdate.baseurl POINTS TO RHEL CONTENT SINCE IT WILL CONTAIN THE RELEASE PREFERENCE SUBSTITUTED FOR $releasever	//Assert.assertEquals(yumRepoAfterUpdate, yumRepo, "Yum repo ["+yumRepo.id+"] has persisted all of its repository option values even after setting a release and issuing a yum transaction.");
    }
}
Also used : BigInteger(java.math.BigInteger) HashMap(java.util.HashMap) YumRepo(rhsm.data.YumRepo) SkipException(org.testng.SkipException) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 13 with YumRepo

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

the class ReposTests method testReposEnableDisableReposInOrder.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-20387", "RHEL7-51679" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier3")
@Test(description = "subscription-manager: attempt enable/disable/enable/disable repos in an order", groups = { "Tier3Tests", "blockedByBug-1115499" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testReposEnableDisableReposInOrder() throws JSONException, Exception {
    if (clienttasks.isPackageVersion("subscription-manager", "<", "1.12.8-1"))
        throw new SkipException("Bugzilla 1115499 was not implemented in this version of subscription-manager.");
    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);
    clienttasks.subscribeToTheCurrentlyAvailableSubscriptionPoolsCollectively();
    // List<Repo> subscribedRepos = clienttasks.getCurrentlySubscribedRepos();
    List<Repo> subscribedRepos = getRandomSubsetOfList(clienttasks.getCurrentlySubscribedRepos(), 5);
    String expectedStdoutMsgFormat = "Repo %s is %s for this system.";
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.10.7-1"))
        expectedStdoutMsgFormat = "Repo '%s' is %sd for this system.";
    // bug 1122530 commit add5a9b746f9f2af147a7e4622b897a46b5ef132
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.13.6-1"))
        expectedStdoutMsgFormat = "Repository '%s' is %sd for this system.";
    String command = clienttasks.reposCommand(null, null, null, null, null, null, null, null, null);
    Map<String, String> repoEnablements = new HashMap<String, String>();
    List<String> enablements = Arrays.asList("enable", "disable");
    for (Repo subscribedRepo : subscribedRepos) {
        for (int i = 0; i < 4; i++) {
            // enable or disable
            String enablement = (getRandomListItem(enablements));
            command += String.format(" --%s=%s", enablement, subscribedRepo.repoId);
            repoEnablements.put(subscribedRepo.repoId, enablement);
        }
    }
    SSHCommandResult sshCommandResult = client.runCommandAndWait(command);
    Assert.assertEquals(sshCommandResult.getExitCode(), new Integer(0), "ExitCode from an attempt to enable/disable multiple valid repos.");
    for (Repo subscribedRepo : subscribedRepos) {
        String expectedEnableStdoutMsg = String.format(expectedStdoutMsgFormat, subscribedRepo.repoId, repoEnablements.get(subscribedRepo.repoId));
        Assert.assertTrue(sshCommandResult.getStdout().contains(expectedEnableStdoutMsg), "Stdout from an attempt to enable/disable repos in order contains expected message: " + expectedEnableStdoutMsg);
    }
    List<YumRepo> currentlySubscribedYumRepos = clienttasks.getCurrentlySubscribedYumRepos();
    for (Repo subscribedRepo : subscribedRepos) {
        YumRepo yumRepo = YumRepo.findFirstInstanceWithMatchingFieldFromList("id", subscribedRepo.repoId, currentlySubscribedYumRepos);
        if (repoEnablements.get(subscribedRepo.repoId).equals("enable")) {
            Assert.assertTrue(yumRepo.enabled, "Enablement of yum repo " + yumRepo.id);
        } else {
            Assert.assertFalse(yumRepo.enabled, "Enablement of yum repo " + yumRepo.id);
        }
    }
}
Also used : BigInteger(java.math.BigInteger) Repo(rhsm.data.Repo) YumRepo(rhsm.data.YumRepo) HashMap(java.util.HashMap) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) SkipException(org.testng.SkipException) YumRepo(rhsm.data.YumRepo) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 14 with YumRepo

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

the class ReposTests method testReposListEnabledReportsOnlyEnabledContentNamespaces.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-20385", "RHEL7-51686" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier3")
@Test(description = "subscription-manager: subscribe to a pool and verify that repos list --list-enabled reports only the enabled repos from the newly entitled content namespaces", groups = { "Tier3Tests", "blockedByBug-1119648" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testReposListEnabledReportsOnlyEnabledContentNamespaces() throws JSONException, Exception {
    if (clienttasks.isPackageVersion("subscription-manager", "<", "1.13.4-1"))
        throw new SkipException("The repos --list-enabled function was not implemented until version subscription-manager-1.13.4-1");
    // register
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, true, false, null, null, null, null);
    clienttasks.subscribeToTheCurrentlyAvailableSubscriptionPoolsCollectively();
    List<YumRepo> subscribedYumRepos = clienttasks.getCurrentlySubscribedYumRepos();
    if (subscribedYumRepos.isEmpty())
        throw new SkipException("There are no entitled yum repos available for this test.");
    List<YumRepo> enabledYumRepos = YumRepo.findAllInstancesWithMatchingFieldFromList("enabled", Boolean.TRUE, subscribedYumRepos);
    // get the list of currently enabled repos
    SSHCommandResult sshCommandResult = clienttasks.repos(null, true, null, (String) null, (String) null, null, null, null, null);
    List<Repo> listEnabledRepos = Repo.parse(sshCommandResult.getStdout());
    // verify that the enabledYumRepos are all present in the listEnabledRepos
    for (YumRepo yumRepo : enabledYumRepos) {
        Repo enabledRepo = Repo.findFirstInstanceWithMatchingFieldFromList("repoId", yumRepo.id, listEnabledRepos);
        Assert.assertNotNull(enabledRepo, "Enabled yum repo [" + yumRepo.id + "] is included in the report of repos --list-enabled.");
    }
    Assert.assertEquals(listEnabledRepos.size(), enabledYumRepos.size(), "The number of --list-enabled repos matches the number of enabled yum repos in '" + clienttasks.redhatRepoFile + "'.");
}
Also used : Repo(rhsm.data.Repo) YumRepo(rhsm.data.YumRepo) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) SkipException(org.testng.SkipException) YumRepo(rhsm.data.YumRepo) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 15 with YumRepo

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

Aggregations

YumRepo (rhsm.data.YumRepo)29 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)23 Test (org.testng.annotations.Test)23 SkipException (org.testng.SkipException)17 SSHCommandResult (com.redhat.qe.tools.SSHCommandResult)12 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 Repo (rhsm.data.Repo)8 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)4 Map (java.util.Map)4 BigInteger (java.math.BigInteger)3 ContentNamespace (rhsm.data.ContentNamespace)3 EntitlementCert (rhsm.data.EntitlementCert)3 ProductSubscription (rhsm.data.ProductSubscription)3 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)2 ProductCert (rhsm.data.ProductCert)2 HashSet (java.util.HashSet)1 List (java.util.List)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1