Search in sources :

Example 26 with EntitlementCert

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

the class ContentIntegrationTests method testDownloadRandomPackageFromContentNamespace.

@Test(description = "ensure a random available package can be downloaded from the enabled repo ", groups = { "Tier2Tests" }, dependsOnMethods = { "testRegisterAndSubscribe" }, alwaysRun = true, dependsOnGroups = { "VerifyPackagesAreAvailable" }, dataProvider = "getContentNamespaceData", // disabled in favor of various ContentTests which do not depend on the maintenance of dataProvider="getSubscribeData"
enabled = false)
public // @ImplementsNitrateTest(caseId=) //TODO Find a tcms caseId
void testDownloadRandomPackageFromContentNamespace(String username, String password, ConsumerType type, String productId, Integer sockets, ContentNamespace contentNamespace) {
    EntitlementCert entitlementCert = recallTheEntitlementCertGrantedAfterSubscribing(username, password, type, productId, sockets);
    // register
    registerConsumerWhenNotAlreadyRegistered(username, password, type, sockets);
    // subscribe
    if (!currentlySubscribedProductIds.contains(productId)) {
        // try to save some time by not re-subscribing
        clienttasks.subscribeToProductId(productId);
        currentlySubscribedProductIds.add(productId);
    } else {
        log.info("Saving time by assuming that we are already subscribed to productId='" + productId + "'");
    // clienttasks.list_(null,null,null, Boolean.TRUE, null, null, null, null);
    }
    // make sure that the products required for this repo are installed
    /* not needed anymore since this case is already filtered out by the dataProvider
		if (!clienttasks.areAllRequiredTagsInContentNamespaceProvidedByProductCerts(contentNamespace, currentProductCerts)) {
			throw new SkipException("This contentNamespace has requiredTags '"+contentNamespace.requiredTags+"' that were not found amongst all of the currently installed products.  Therefore we cannot install and remove any package from repo '"+contentNamespace.label+"'.");
		}
		*/
    // make sure there is a positive package count provided by this repo
    /* not needed anymore since this case is already filtered out by the dataProvider
		Integer packageCount = clienttasks.getYumRepolistPackageCount(contentNamespace.label+" --enablerepo="+contentNamespace.label);
		if (packageCount==0) {
			throw new SkipException("Cannot install a package from this repo '"+contentNamespace.label+"' since it is not providing any packages.");
		}
		*/
    // find a random available package provided by this repo
    String pkg = clienttasks.findRandomAvailablePackageFromRepo(contentNamespace.label);
    if (pkg == null) {
        throw new SkipException("Could NOT find a random available package from this repo '" + contentNamespace.label + "' to attempt an install/remove test.");
    }
    // download the package and assert that it is successfully downloaded
    File pkgFile = clienttasks.yumDownloadPackageFromRepo(pkg, contentNamespace.label, "/tmp", null);
    Assert.assertNotNull(pkgFile, "The actual downloaded package file is: " + pkgFile);
    // remove the file since it is not needed anymore
    client.runCommandAndWait("rm -f " + pkgFile);
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) SkipException(org.testng.SkipException) File(java.io.File) Test(org.testng.annotations.Test)

Example 27 with EntitlementCert

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

the class ContentIntegrationTests method getContentNamespaceDataAsListOfLists.

protected List<List<Object>> getContentNamespaceDataAsListOfLists(boolean enabledValue) throws JSONException {
    List<List<Object>> ll = new ArrayList<List<Object>>();
    for (List<Object> row : entitlementCertData) {
        String username = (String) row.get(0);
        String password = (String) row.get(1);
        ConsumerType type = (ConsumerType) row.get(2);
        String productId = (String) row.get(3);
        Integer sockets = (Integer) row.get(4);
        EntitlementCert entitlementCert = (EntitlementCert) row.get(5);
        for (ContentNamespace contentNamespace : entitlementCert.contentNamespaces) {
            if (!contentNamespace.type.equalsIgnoreCase("yum"))
                continue;
            if (contentNamespace.enabled.equals(enabledValue)) {
                // 
                ll.add(Arrays.asList(new Object[] { username, password, type, productId, sockets, contentNamespace }));
            }
        }
    }
    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) ConsumerType(rhsm.base.ConsumerType)

Example 28 with EntitlementCert

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

the class ContentIntegrationTests method testPackagesAreAvailableForDefaultEnabledContentNamespace.

@Test(description = "verify the CDN provides packages for the default enabled content set after subscribing to a product subscription", groups = { "Tier2Tests", "VerifyPackagesAreAvailable", "blockedByBug-905546" }, dependsOnMethods = { "testRegisterAndSubscribe" }, alwaysRun = true, dataProvider = "getDefaultEnabledContentNamespaceData", // disabled in favor of various ContentTests which do not depend on the maintenance of dataProvider="getSubscribeData"
enabled = false)
public // @ImplementsNitrateTest(caseId=) //TODO Find a tcms caseId
void testPackagesAreAvailableForDefaultEnabledContentNamespace(String username, String password, ConsumerType type, String productId, Integer sockets, ContentNamespace contentNamespace) {
    // is this an enabled or disabled test?
    String abled = contentNamespace.enabled ? "enabled" : "disabled";
    EntitlementCert entitlementCert = recallTheEntitlementCertGrantedAfterSubscribing(username, password, type, productId, sockets);
    Integer packageCount = null;
    // if(true) throw new SkipException("debugging");
    // register a new consumer
    registerConsumerWhenNotAlreadyRegistered(username, password, type, sockets);
    // subscribe
    if (!currentlySubscribedProductIds.contains(productId)) {
        // try to save some time by not re-subscribing
        clienttasks.subscribeToProductId(productId);
        currentlySubscribedProductIds.add(productId);
    } else {
        log.info("Saving time by assuming that we are already subscribed to productId='" + productId + "'");
    // clienttasks.list_(null,null,null, Boolean.TRUE, null, null, null, null);
    }
    // Assert that after subscribing, the default enabled/disabled repo is now included in yum repolist
    ArrayList<String> repolist = clienttasks.getYumRepolist(abled);
    if (clienttasks.areAllRequiredTagsInContentNamespaceProvidedByProductCerts(contentNamespace, currentProductCerts)) {
        Assert.assertTrue(repolist.contains(contentNamespace.label), "Yum repolist " + abled + " includes " + abled + " repo id/label '" + contentNamespace.label + "' after having subscribed to Subscription ProductId '" + productId + "'.");
    } else {
        log.warning("Did not find all the requiredTags '" + contentNamespace.requiredTags + "' for this content namespace amongst the currently installed products.");
        Assert.assertFalse(repolist.contains(contentNamespace.label), "Yum repolist " + abled + " excludes " + abled + " repo id/label '" + contentNamespace.label + "' after having subscribed to Subscription ProductId '" + productId + "' because not all requiredTags '" + contentNamespace.requiredTags + "' in the contentNamespace are provided by the currently installed productCerts.");
        throw new SkipException("This contentNamespace has requiredTags '" + contentNamespace.requiredTags + "' that were not found amongst all of the currently installed products.  Therefore we cannot verify that the CDN is providing packages for repo '" + contentNamespace.label + "'.");
    }
    // verify the yum repolist contentNamespace.label returns more than 0 packages
    String options = contentNamespace.enabled ? contentNamespace.label : contentNamespace.label + " --enablerepo=" + contentNamespace.label;
    packageCount = clienttasks.getYumRepolistPackageCount(options);
    Assert.assertTrue(packageCount > 0, "After subscribing to product subscription '" + productId + "', the number of available packages from the default " + abled + " repo '" + contentNamespace.label + "' is greater than zero (actual packageCount is '" + packageCount + "').");
    // TODO populate data for subsequent calls to InstallAndRemoveAnyPackageFromContentNamespace_Test
    contentNamespaceData.add(Arrays.asList(new Object[] { username, password, type, productId, sockets, contentNamespace, entitlementCert }));
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) JSONObject(org.json.JSONObject) SkipException(org.testng.SkipException) Test(org.testng.annotations.Test)

Example 29 with EntitlementCert

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

the class ContentIntegrationTests method testRegisterAndSubscribe.

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

Example 30 with EntitlementCert

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

the class ModifierTests method testContentLabelForModifierSubscriptionIsOnlyAvailableInYumRepoListAfterTheModifiesPoolIsSubscribed.

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

Aggregations

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