Search in sources :

Example 41 with EntitlementCert

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

the class DockerTests method testContainerConfigurationsAreSetAfterAutoSubscribingAndUnsubscribing.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-26770", "RHEL7-51758" }, 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 entitlements providing containerimage content are copied to relevant directories when attached via auto-subscribe (as governed by the subscription-manager-plugin-container package)", groups = { "Tier1Tests" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testContainerConfigurationsAreSetAfterAutoSubscribingAndUnsubscribing() {
    // get the list of registry_hostnames from /etc/rhsm/pluginconf.d/container_content.ContainerContentPlugin.conf
    String registry_hostnames = clienttasks.getConfFileParameter(containerContentPluginFile.getPath(), "registry_hostnames");
    List<String> registryHostnames = Arrays.asList(registry_hostnames.split(" *, *"));
    // rhsm-test.redhat.com does NOT appear to come from a redhat.com CDN
    if (!registryHostnames.contains("rhsm-test.redhat.com"))
        clienttasks.updateConfFileParameter(containerContentPluginFile.getPath(), "registry_hostnames", registry_hostnames + "," + "rhsm-test.redhat.com");
    // cdn.rhsm-test.redhat.com DOES appear to come from a redhat.com CDN because it matches regex ^cdn\.(?:.*\.)?redhat\.com$
    if (!registryHostnames.contains("cdn.rhsm-test.redhat.com"))
        clienttasks.updateConfFileParameter(containerContentPluginFile.getPath(), "registry_hostnames", registry_hostnames + "," + "cdn.rhsm-test.redhat.com");
    registry_hostnames = clienttasks.getConfFileParameter(containerContentPluginFile.getPath(), "registry_hostnames");
    registryHostnames = Arrays.asList(registry_hostnames.split(" *, *"));
    // register the host, autosubscribe, and get the granted entitlements
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, true, null, null, (String) null, null, null, null, true, false, null, null, null, null);
    List<EntitlementCert> entitlementCerts = clienttasks.getCurrentEntitlementCerts();
    // 5109020365795659852.cert  5109020365795659852.key  redhat-uep.crt
    if (!verifyEntitlementsProvidingContainerImageContentAreCopiedToRegistryHostnames(entitlementCerts, registryHostnames))
        throw new SkipException("None of the auto-attached subscriptions for this system provide content of type \"containerimage\".");
    // individually unsubscribe from entitlements and assert the entitlement bearing a containerimage is also removed from registry_hostnames
    for (EntitlementCert entitlementCert : entitlementCerts) {
        List<ContentNamespace> containerImageContentNamespaces = ContentNamespace.findAllInstancesWithCaseInsensitiveMatchingFieldFromList("type", "containerimage", entitlementCert.contentNamespaces);
        BigInteger serialNumber = clienttasks.getSerialNumberFromEntitlementCertFile(entitlementCert.file);
        clienttasks.unsubscribeFromSerialNumber(serialNumber);
        if (!containerImageContentNamespaces.isEmpty()) {
            // after unsubscribing, assert that the entitlementCert was removed from the directory of registry_hostnames
            for (String registryHostname : registryHostnames) {
                File certFile = getRegistryHostnameCertFileFromEntitlementCert(registryHostname, entitlementCert);
                File keyFile = getRegistryHostnameCertKeyFileFromEntitlementCert(registryHostname, entitlementCert);
                Assert.assertTrue(!RemoteFileTasks.testExists(client, certFile.getPath()), "Entitlement cert '" + entitlementCert.orderNamespace.productName + "' providing a 'containerimage' (case insensitive) was removed from '" + certFile.getPath() + "' after unsubscribing.");
                Assert.assertTrue(!RemoteFileTasks.testExists(client, keyFile.getPath()), "Corresponding entitlement key providing a 'containerimage' (case insensitive) was removed from '" + keyFile.getPath() + "' after unsubscribing.");
            }
        }
    }
}
Also used : ContentNamespace(rhsm.data.ContentNamespace) EntitlementCert(rhsm.data.EntitlementCert) BigInteger(java.math.BigInteger) SkipException(org.testng.SkipException) File(java.io.File) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 42 with EntitlementCert

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

the class ManagementAddOnTests method testManagementAddOnEntitlementsContainNoContentNamespace.

// 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-27127", "RHEL7-51412" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier2")
@Test(description = "verify that the entitlement cert granted by subscribing to a management add-on product does not contain a content namespace.", groups = { "Tier2Tests" }, dependsOnGroups = {}, dataProvider = "getAddOnSubscriptionData", enabled = true)
public void testManagementAddOnEntitlementsContainNoContentNamespace(Object bugzilla, SubscriptionPool managementAddOnPool) {
    // subscribe to a management add-on pool
    EntitlementCert entitlementCert = clienttasks.getEntitlementCertFromEntitlementCertFile(clienttasks.subscribeToSubscriptionPool(managementAddOnPool, sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl));
    // assert that there are no content namespaces in the granted entitlement cert
    Assert.assertTrue(entitlementCert.contentNamespaces.isEmpty(), "There are no content namespaces in the entitlement cert granted after subscribing to management add-on subscription pool: " + managementAddOnPool);
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 43 with EntitlementCert

use of rhsm.data.EntitlementCert 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 44 with EntitlementCert

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

the class ReposTests method testReposListReportsNoContentNamespacesAfterSubscribingToFuturePool.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-20295", "RHEL7-51691" }, 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 future pool and verify that NO content namespaces are represented in the repos list", groups = { "Tier3Tests", "blockedByBug-768983", "blockedByBug-1440180", "testReposListReportsNoContentNamespacesAfterSubscribingToFuturePool" }, dataProvider = "getAllFutureSystemSubscriptionPoolsData", enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testReposListReportsNoContentNamespacesAfterSubscribingToFuturePool(SubscriptionPool pool) throws Exception {
    // if (!pool.productId.equals("awesomeos-virt-unlmtd-phys")) throw new SkipException("debugTesting productId="+pool.productId);
    // subscribe to the future SubscriptionPool
    SSHCommandResult subscribeResult = clienttasks.subscribe(null, null, pool.poolId, null, null, null, null, null, null, null, null, null, null);
    // Pool is restricted to physical systems: '8a9086d3443c043501443c052aec1298'.
    if (subscribeResult.getStdout().startsWith("Pool is restricted")) {
        throw new SkipException("Subscribing to this future subscription is not applicable to this test: " + pool);
    }
    // assert that the granted EntitlementCert and its corresponding key exist
    EntitlementCert entitlementCert = clienttasks.getEntitlementCertCorrespondingToSubscribedPool(pool);
    File entitlementCertFile = clienttasks.getEntitlementCertFileFromEntitlementCert(entitlementCert);
    File entitlementCertKeyFile = clienttasks.getEntitlementCertKeyFileFromEntitlementCert(entitlementCert);
    Assert.assertTrue(RemoteFileTasks.testExists(client, entitlementCertFile.getPath()), "EntitlementCert file exists after subscribing to future SubscriptionPool.");
    Assert.assertTrue(RemoteFileTasks.testExists(client, entitlementCertKeyFile.getPath()), "EntitlementCert key file exists after subscribing to future SubscriptionPool.");
    // assuming that we are not subscribed to a non-future subscription pool, assert that there are NO subscribed repos
    Assert.assertEquals(clienttasks.getCurrentlySubscribedRepos().size(), 0, "Assuming that we are not currently subscribed to a non-future subscription pool, then there should NOT be any repos reported after subscribing to future subscription pool '" + pool.poolId + "'.");
// TODO we may want to randomly unsubscribe from serial number without asserting to save some computation of the accumulating entitlement certs
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) SkipException(org.testng.SkipException) File(java.io.File) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 45 with EntitlementCert

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

the class RAMTests method testRamBasedSubscriptionInfoInEntitlementCert.

/**
 * @author skallesh
 * @throws Exception
 * @throws JSONException
 */
@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36685", "RHEL7-51530" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier2")
@Test(description = "verify Ram info in product and entitlement certificate", groups = { "Tier2Tests", "RamBasedSubscriptionInfoInEntitlementCert" }, enabled = true)
public void testRamBasedSubscriptionInfoInEntitlementCert() throws JSONException, Exception {
    factsMap.clear();
    factsMap.put("uname.machine", "x86_64");
    factsMap.put("cpu.core(s)_per_socket", "1");
    clienttasks.createFactsFileWithOverridingValues(factsMap);
    clienttasks.register_(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, false, null, null, (String) null, null, null, null, true, null, null, null, null, null);
    for (SubscriptionPool pool : getRamBasedSubscriptions()) {
        clienttasks.subscribe_(null, null, pool.poolId, null, null, null, null, null, null, null, null, null, null);
    }
    List<EntitlementCert> ramEntitlements = clienttasks.getCurrentEntitlementCerts();
    for (EntitlementCert ramEntitlement : ramEntitlements) {
        Assert.assertTrue(!ramEntitlement.orderNamespace.ramLimit.isEmpty(), "A ram-based entitlement cert contains a non-empty Ram Limit (actual='" + ramEntitlement.orderNamespace.ramLimit + "').");
    }
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Aggregations

EntitlementCert (rhsm.data.EntitlementCert)94 Test (org.testng.annotations.Test)63 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)58 SkipException (org.testng.SkipException)39 ArrayList (java.util.ArrayList)38 File (java.io.File)36 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)35 SubscriptionPool (rhsm.data.SubscriptionPool)33 SSHCommandResult (com.redhat.qe.tools.SSHCommandResult)30 JSONObject (org.json.JSONObject)29 ContentNamespace (rhsm.data.ContentNamespace)26 ProductCert (rhsm.data.ProductCert)23 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)17 BigInteger (java.math.BigInteger)17 ProductSubscription (rhsm.data.ProductSubscription)17 List (java.util.List)16 Calendar (java.util.Calendar)11 HashMap (java.util.HashMap)11 ProductNamespace (rhsm.data.ProductNamespace)11 HashSet (java.util.HashSet)8