Search in sources :

Example 76 with EntitlementCert

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

the class SubscriptionManagerTasks method unsubscribeFromTheCurrentlyConsumedProductSubscriptionPoolIdsCollectively.

/**
 * Collectively unsubscribe from all of the currently consumed product subscriptions.
 * This will ultimately issue a single call to unsubscribe --pool POOLID1 --pool POOLID2 --pool POOLID3 for each of the product subscriptions being consumed.
 * @throws Exception
 */
public SSHCommandResult unsubscribeFromTheCurrentlyConsumedProductSubscriptionPoolIdsCollectively() throws Exception {
    log.info("Unsubscribing from all of the currently consumed product subscription poolids in one collective call...");
    List<BigInteger> serials = new ArrayList<BigInteger>();
    List<String> poolIds = new ArrayList<String>();
    // THIS AVOIDS PROBLEMS WHEN MODIFIER ENTITLEMENTS ARE BEING CONSUMED
    for (ProductSubscription productSubscription : getCurrentlyConsumedProductSubscriptions()) {
        EntitlementCert entitlementCert = getEntitlementCertCorrespondingToProductSubscription(productSubscription);
        JSONObject jsonEntitlement = CandlepinTasks.getEntitlementUsingRESTfulAPI(this.currentlyRegisteredUsername, this.currentlyRegisteredPassword, candlepinUrl, entitlementCert.id);
        String poolHref = jsonEntitlement.getJSONObject("pool").getString("href");
        JSONObject jsonPool = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(this.currentlyRegisteredUsername, this.currentlyRegisteredPassword, candlepinUrl, poolHref));
        String poolId = jsonPool.getString("id");
        if (CandlepinTasks.isPoolAModifier(this.currentlyRegisteredUsername, this.currentlyRegisteredPassword, poolId, candlepinUrl)) {
            // serials to entitlements that modify others should be at the front of the list to be removed, otherwise they will get re-issued under a new serial number when the modified entitlement is removed first.
            serials.add(0, productSubscription.serialNumber);
            poolIds.add(0, productSubscription.poolId);
        } else {
            serials.add(productSubscription.serialNumber);
            poolIds.add(productSubscription.poolId);
        }
    }
    // unsubscribe from all poolIds collectively
    SSHCommandResult result = unsubscribe(false, null, poolIds, null, null, null, null);
    Assert.assertTrue(getCurrentlyConsumedProductSubscriptions().size() == 0, "Currently no product subscriptions are consumed.");
    Assert.assertTrue(getCurrentEntitlementCertFiles().size() == 0, "This machine has no entitlement certificate files.");
    return result;
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) JSONObject(org.json.JSONObject) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) ArrayList(java.util.ArrayList) ProductSubscription(rhsm.data.ProductSubscription) BigInteger(java.math.BigInteger)

Example 77 with EntitlementCert

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

the class SubscriptionManagerTasks method getEntitlementCertsProvidingProductCert.

public List<EntitlementCert> getEntitlementCertsProvidingProductCert(ProductCert productCert) {
    List<EntitlementCert> correspondingEntitlementCerts = new ArrayList<EntitlementCert>();
    ProductNamespace productNamespaceMatchingProductCert = null;
    for (EntitlementCert entitlementCert : getCurrentEntitlementCerts()) {
        productNamespaceMatchingProductCert = ProductNamespace.findFirstInstanceWithMatchingFieldFromList("id", productCert.productId, entitlementCert.productNamespaces);
        if (productNamespaceMatchingProductCert != null) {
            correspondingEntitlementCerts.add(entitlementCert);
        }
    }
    return correspondingEntitlementCerts;
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) ArrayList(java.util.ArrayList) ProductNamespace(rhsm.data.ProductNamespace)

Example 78 with EntitlementCert

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

the class OverconsumptionTests method testConcurrentAttemptToSubscribe.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-37718", "RHEL7-51496" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.NEGATIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier2")
@Test(description = "subscription-manager: Concurrent attempt to subscribe", groups = { "Tier2Tests" }, dependsOnMethods = { "testBasicAttemptToOversubscribe" }, enabled = true)
public // @ImplementsTCMS(id="")
void testConcurrentAttemptToSubscribe() throws JSONException, Exception {
    if (client1 == null || client2 == null)
        throw new SkipException("This test requires two clients.");
    // reregister the first systemConsumerId and unsubscribe from the test pool
    client1tasks.clean();
    client1tasks.register(sm_clientUsername, sm_clientPassword, null, null, null, registereeName, systemConsumerIds.get(0), null, null, null, (String) null, null, null, null, null, false, null, null, null, null);
    client1tasks.unsubscribeFromAllOfTheCurrentlyConsumedProductSubscriptions();
    // reregister the second systemConsumerId and unsubscribe from the test pool
    client2tasks.clean();
    client2tasks.register(sm_clientUsername, sm_clientPassword, null, null, null, registereeName, systemConsumerIds.get(1), null, null, null, (String) null, null, null, null, null, false, null, null, null, null);
    client2tasks.unsubscribeFromAllOfTheCurrentlyConsumedProductSubscriptions();
    // assert that each client has no entitlements
    List<File> client1EntitlementCerts = client1tasks.getCurrentEntitlementCertFiles();
    Assert.assertEquals(client1EntitlementCerts.size(), 0, "Registered client on '" + client1tasks.hostname + "' should have NO entitlements.");
    List<File> client2EntitlementCerts = client2tasks.getCurrentEntitlementCertFiles();
    Assert.assertEquals(client2EntitlementCerts.size(), 0, "Registered client on '" + client2tasks.hostname + "' should have NO entitlements.");
    // assert that the test pool now has a quantity of 2 available
    SubscriptionPool pool;
    pool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", testPool.poolId, client1tasks.getCurrentlyAvailableSubscriptionPools());
    Assert.assertNotNull(pool, "Found the test pool after having consumed available subscriptions.");
    Assert.assertEquals(pool.quantity, "2", "Asserting the test pool quantity after having consumed almost all of its available subscriptions.");
    pool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", testPool.poolId, client2tasks.getCurrentlyAvailableSubscriptionPools());
    Assert.assertNotNull(pool, "Found the test pool after having consumed available subscriptions.");
    Assert.assertEquals(pool.quantity, "2", "Asserting the test pool quantity after having consumed almost all of its available subscriptions.");
    // attempt to concurrently subscribe to the test pool
    log.info("Now we will attempt to subscribe both clients concurrently to pool: " + pool);
    String client1command = String.format("%s subscribe --pool=%s", client1tasks.command, pool.poolId);
    String client2command = String.format("%s subscribe --pool=%s", client2tasks.command, pool.poolId);
    client1.runCommand(client1command, TestRecords.action());
    client2.runCommand(client2command, TestRecords.action());
    // timeout after 10 min
    client1.waitForWithTimeout(new Long(10 * 60 * 1000));
    // timeout after 10 min
    client2.waitForWithTimeout(new Long(10 * 60 * 1000));
    SSHCommandResult result1 = client1.getSSHCommandResult();
    SSHCommandResult result2 = client2.getSSHCommandResult();
    // assert the results
    log.info("SSHCommandResult from '" + client1tasks.hostname + "': " + result1);
    // Assert.assertEquals(result1.getStdout().trim(), "","The lack of information in stdout from the subscribe command on '"+client1tasks.hostname+"' indicates that it successfully subscribed to poolid: "+testPool.poolId);
    // Assert.assertEquals(result1.getStdout().trim(), String.format("Successfully consumed a subscription from the pool with id %s.",testPool.poolId),"On '"+client1tasks.hostname+"' we successfully subscribed to poolid: "+testPool.poolId);	// Bug 812410 - Subscription-manager subscribe CLI feedback
    // Assert.assertEquals(result1.getStdout().trim(), String.format("Successfully consumed a subscription for: %s",testPool.subscriptionName),"On '"+client1tasks.hostname+"' we successfully subscribed to poolid: "+testPool.poolId);	// changed by Bug 874804 Subscribe -> Attach
    Assert.assertEquals(result1.getStdout().trim(), String.format("Successfully attached a subscription for: %s", testPool.subscriptionName), "On '" + client1tasks.hostname + "' we successfully subscribed to poolid: " + testPool.poolId);
    Assert.assertEquals(result1.getStderr().trim(), "", "No stderr information is expected on '" + client1tasks.hostname + "'.");
    Assert.assertEquals(result1.getExitCode(), Integer.valueOf(0), "The exit code from the subscribe command on '" + client1tasks.hostname + "' indicates the subscribe attempt was handled gracefully.");
    log.info("SSHCommandResult from '" + client2tasks.hostname + "': " + result2);
    // Assert.assertEquals(result2.getStdout().trim(), "","The lack of information in stdout from the subscribe command on '"+client2tasks.hostname+"' indicates that it successfully subscribed to poolid: "+testPool.poolId);
    // Assert.assertEquals(result2.getStdout().trim(), String.format("Successfully consumed a subscription from the pool with id %s.",testPool.poolId),"On '"+client2tasks.hostname+"' we successfully subscribed to poolid: "+testPool.poolId);	// Bug 812410 - Subscription-manager subscribe CLI feedback
    // Assert.assertEquals(result2.getStdout().trim(), String.format("Successfully consumed a subscription for: %s",testPool.subscriptionName),"On '"+client2tasks.hostname+"' we successfully subscribed to poolid: "+testPool.poolId);	// changed by Bug 874804 Subscribe -> Attach
    Assert.assertEquals(result2.getStdout().trim(), String.format("Successfully attached a subscription for: %s", testPool.subscriptionName), "On '" + client2tasks.hostname + "' we successfully subscribed to poolid: " + testPool.poolId);
    Assert.assertEquals(result2.getStderr().trim(), "", "No stderr information is expected on '" + client2tasks.hostname + "'.");
    Assert.assertEquals(result2.getExitCode(), Integer.valueOf(0), "The exit code from the subscribe command on '" + client2tasks.hostname + "' indicates the subscribe attempt was handled gracefully.");
    // assert that the test pool has dropped by 2
    // pool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", testPool.poolId, client1tasks.getCurrentlyAllAvailableSubscriptionPools());
    // Assert.assertNotNull(pool, "Found the test pool amongst --all --available after having consumed all of its available entitlements.");
    // Assert.assertEquals(pool.quantity, "0", "Asserting the test pool quantity has dropped by 2 due to the concurrent call to subscribe.");
    // pool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", testPool.poolId, client2tasks.getCurrentlyAllAvailableSubscriptionPools());
    // Assert.assertNotNull(pool, "Found the test pool amongst --all --available after having consumed all of its available entitlements.");
    // Assert.assertEquals(pool.quantity, "0", "Asserting the test pool quantity has dropped by 2 due to the concurrent call to subscribe.");
    pool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", testPool.poolId, client1tasks.getCurrentlyAllAvailableSubscriptionPools());
    Assert.assertNull(pool, "The test pool is no longer in the --all --available list after having consumed all of its available subscriptions.");
    pool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", testPool.poolId, client2tasks.getCurrentlyAllAvailableSubscriptionPools());
    Assert.assertNull(pool, "The test pool is no longer in the --all --available list after having consumed all of its available subscriptions.");
    JSONObject jsonTestPool = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/pools/" + testPool.poolId));
    Assert.assertEquals(jsonTestPool.getInt("consumed"), jsonTestPool.getInt("quantity"), "Asserting the test pool's consumed attribute matches it's original total quantity after having consumed all of its available entitlements.");
    // make sure both clients got individualized entitlement certs
    client1EntitlementCerts = client1tasks.getCurrentEntitlementCertFiles();
    Assert.assertEquals(client1EntitlementCerts.size(), 1, "Registered client on '" + client1tasks.hostname + "' should have 1 entitlement from the attempt to subscribe to poolid: " + testPool.poolId);
    client2EntitlementCerts = client2tasks.getCurrentEntitlementCertFiles();
    Assert.assertEquals(client2EntitlementCerts.size(), 1, "Registered client on '" + client2tasks.hostname + "' should have 1 entitlement from the attempt to subscribe to poolid: " + testPool.poolId);
    EntitlementCert client1EntitlementCert = client1tasks.getEntitlementCertFromEntitlementCertFile(client1EntitlementCerts.get(0));
    EntitlementCert client2EntitlementCert = client2tasks.getEntitlementCertFromEntitlementCertFile(client2EntitlementCerts.get(0));
    Assert.assertFalse(client1EntitlementCert.serialNumber.equals(client2EntitlementCert.serialNumber), "Asserting that the entitlement serials granted to each of the concurent subscribers are unique to each other.");
}
Also used : JSONObject(org.json.JSONObject) EntitlementCert(rhsm.data.EntitlementCert) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) SkipException(org.testng.SkipException) File(java.io.File) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 79 with EntitlementCert

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

the class ListTests method testConsumedEntitlementsListed.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-27118", "RHEL7-51350" }, 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 = "subscription-manager-cli: list consumed entitlements", groups = { "Tier2Tests" }, dataProvider = "getAllSystemSubscriptionPoolProductData", enabled = true)
@ImplementsNitrateTest(caseId = 41679)
public void testConsumedEntitlementsListed(String productId, JSONArray bundledProductDataAsJSONArray) throws JSONException, Exception {
    // if (!productId.equals("awesomeos-virt-unlmtd-phys")) throw new SkipException("debugTesting productId="+productId);
    clienttasks.unregister(null, null, null, null);
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, null, false, null, null, null, null);
    SubscriptionPool pool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", productId, clienttasks.getCurrentlyAllAvailableSubscriptionPools());
    Assert.assertNotNull(pool, "SubscriptionPool with ProductId '" + productId + "' is available for subscribing.");
    EntitlementCert entitlementCert = clienttasks.getEntitlementCertFromEntitlementCertFile(clienttasks.subscribeToSubscriptionPool_(pool));
    List<ProductSubscription> consumedProductSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
    Assert.assertTrue(!consumedProductSubscriptions.isEmpty(), "The list of Consumed Product Subscription is NOT empty after subscribing to a pool with ProductId '" + productId + "'.");
    for (ProductSubscription productSubscription : consumedProductSubscriptions) {
        Assert.assertEquals(productSubscription.serialNumber, entitlementCert.serialNumber, "SerialNumber of Consumed Product Subscription matches the serial number from the current entitlement certificate.");
    }
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) ProductSubscription(rhsm.data.ProductSubscription) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 80 with EntitlementCert

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

the class ManagementAddOnTests method testManagementAddOnEntitlementsContainNoProductNamespace.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-27128", "RHEL7-51413" }, 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 product namespace.", groups = { "Tier2Tests" }, dependsOnGroups = {}, dataProvider = "getAddOnSubscriptionData", enabled = true)
public void testManagementAddOnEntitlementsContainNoProductNamespace(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 product namespaces contained within the granted entitlement cert
    Assert.assertTrue(entitlementCert.productNamespaces.isEmpty(), "There are no product 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)

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