Search in sources :

Example 41 with ProductSubscription

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

the class RHELPersonalTests method testSubPoolIsNotDeletedAfterAllOtherSystemsUnsubscribeFromSubPool.

@Test(description = "subscription-manager-cli: Ensure that after unsubscribing all systems from a subpool, the subpool should not get deleted", groups = { "Tier2Tests", "EnsureSubPoolIsNotDeletedAfterAllOtherSystemsUnsubscribeFromSubPool_Test", "RHELPersonal" }, // dependsOnGroups={"EnsureEntitlementCertForSubPoolIsNotRevokedOnceAnotherSystemUnsubscribesFromSubPool_Test"},
priority = 170, dependsOnMethods = { "testEntitlementCertForSubPoolIsNotRevokedOnceAnotherSystemUnsubscribesFromSubPool" }, // registered consumers type of "person" was originally intended for entitling people to training.  Red Hat Learning Management systems never made use if it, and candlepin has no active requirements for it.  Disabling the personal tests...  Reference CLOSED WONTFIX BUG https://bugzilla.redhat.com/show_bug.cgi?id=967160#c1
enabled = false)
@ImplementsNitrateTest(caseId = 58907)
public // 3) unsubscribe system from subpool as the last system subscribed, make sure the subpool doesn't get deleted (scenario from calfanso@redhat.com)
void testSubPoolIsNotDeletedAfterAllOtherSystemsUnsubscribeFromSubPool() throws JSONException {
    log.info("After having unsubscribed all systems from product subscriptions in the prior testcase , we will now verify that the personal subpool has not been deleted and that all systems can still subscribe to it ...");
    for (String consumerId : systemConsumerIds) {
        // client2tasks.reregister(consumerUsername,consumerPassword,consumerId);
        client2tasks.reregisterToExistingConsumer(username, password, consumerId);
        for (int j = 0; j < sm_personSubscriptionPoolProductData.length(); j++) {
            JSONObject poolProductDataAsJSONObject = (JSONObject) sm_personSubscriptionPoolProductData.get(j);
            String personProductId = poolProductDataAsJSONObject.getString("personProductId");
            JSONObject subpoolProductDataAsJSONObject = poolProductDataAsJSONObject.getJSONObject("subPoolProductData");
            String systemProductId = subpoolProductDataAsJSONObject.getString("systemProductId");
            JSONArray bundledProductData = subpoolProductDataAsJSONObject.getJSONArray("bundledProductData");
            for (int k = 0; k < bundledProductData.length(); k++) {
                JSONObject bundledProductAsJSONObject = (JSONObject) bundledProductData.get(k);
                String systemConsumedProductName = bundledProductAsJSONObject.getString("productName");
                ProductSubscription productSubscription = ProductSubscription.findFirstInstanceWithMatchingFieldFromList("productName", systemConsumedProductName, client2tasks.getCurrentlyConsumedProductSubscriptions());
                Assert.assertNull(productSubscription, systemConsumedProductName + " is not consumed by consumer '" + consumerId + "' (registered as a system under username '" + username + "')");
            }
            SubscriptionPool systemSubscriptionPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", systemProductId, client2tasks.getCurrentlyAvailableSubscriptionPools());
            Assert.assertNotNull(systemSubscriptionPool, "ProductId '" + systemProductId + "' is still available to consumer '" + consumerId + "' (registered as a system under username '" + username + "')");
        }
    }
    log.info("Now that all the subscribers of the personal subpool products have been unsubscribed, the person consumer should be able to unregister without being blocked due to outstanding entitlements...");
    client1tasks.unregister(null, null, null, null);
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ProductSubscription(rhsm.data.ProductSubscription) SubscriptionPool(rhsm.data.SubscriptionPool) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 42 with ProductSubscription

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

the class RegisterTests method testReregisterWithBadIdentityCert.

/**
 * https://tcms.engineering.redhat.com/case/56328/?from_plan=2476
 */
@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36529", "RHEL7-51302" }, 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: bad identity cert\n" + "\t\tActions:\n" + "\n" + "\t \t\t* register a client to candlepin (take note of the uuid returned)\n" + "\t \t\t* take note of your identity cert info using openssl x509\n" + "\t \t\t* subscribe to a pool\n" + "\t \t\t* list consumed\n" + "\t \t\t* ls /etc/pki/entitlement/products\n" + "\t \t\t* Now.. mess up your identity..  mv /etc/pki/consumer/cert.pem /bak\n" + "\t \t\t* run the \"reregister\" command w/ username and passwd AND w/consumerid=<uuid>\n" + "\n" + "\t\tExpected Results:\n" + "\n" + "\t \t\t* after running reregister you should have a new identity cert\n" + "\t \t\t* after registering you should still the same products consumed (list consumed)\n" + "\t \t\t* the entitlement serials should be the same as before the registration", groups = { "Tier2Tests", "blockedByBug-624106", "blockedByBug-844069", "ReregisterWithBadIdentityCert_Test" }, enabled = true)
@ImplementsNitrateTest(caseId = 56328)
public void testReregisterWithBadIdentityCert() {
    // start fresh by unregistering and registering
    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);
    // take note of your identity cert
    ConsumerCert consumerCertBefore = clienttasks.getCurrentConsumerCert();
    // subscribe to a random pool
    List<SubscriptionPool> pools = clienttasks.getCurrentlyAvailableSubscriptionPools();
    if (pools.isEmpty())
        throw new SkipException("Cannot randomly pick a pool for subscribing when there are no available pools for testing.");
    // randomly pick a pool
    SubscriptionPool pool = pools.get(randomGenerator.nextInt(pools.size()));
    clienttasks.subscribeToSubscriptionPool(pool);
    // get a list of the consumed products
    List<ProductSubscription> consumedProductSubscriptionsBefore = clienttasks.getCurrentlyConsumedProductSubscriptions();
    // Now.. mess up your identity..  by borking its content
    log.info("Messing up the identity cert by borking its content...");
    RemoteFileTasks.runCommandAndAssert(client, "openssl x509 -noout -text -in " + clienttasks.consumerCertFile() + " > /tmp/stdout; mv /tmp/stdout -f " + clienttasks.consumerCertFile(), 0);
    // reregister w/ username, password, and consumerid
    // clienttasks.reregister(client1username,client1password,consumerCertBefore.consumerid);
    log.warning("The subscription-manager-cli reregister module has been eliminated and replaced by register --consumerid b3c728183c7259841100eeacb7754c727dc523cd...");
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.16.2-1")) {
        // commit f14d2618ea94c18a0295ae3a5526a2ff252a3f99 Doesnt allow using --force with --consumerid
        // [root@jsefler-6 ~]# subscription-manager register --username=testuser1 --password=password --consumerid=fc1b9613-2793-4017-8b9f-a8ab85c5ba96 --force
        // Error: Can not force registration while attempting to recover registration with consumerid. Please use --force without --consumerid to re-register or use the clean command and try again without --force.
        log.warning("The original point of this test is not really applicable after 1.16.2-1 where registering with --consumerid and --force has been more explicitly divided into two steps... clean and register --consumerid.");
        clienttasks.clean();
        clienttasks.register(sm_clientUsername, sm_clientPassword, null, null, null, null, consumerCertBefore.consumerid, null, null, null, (String) null, null, null, null, Boolean.FALSE, false, null, null, null, null);
    } else {
        clienttasks.register(sm_clientUsername, sm_clientPassword, null, null, null, null, consumerCertBefore.consumerid, null, null, null, (String) null, null, null, null, Boolean.TRUE, false, null, null, null, null);
    }
    // assert that the identity cert has not changed
    ConsumerCert consumerCertAfter = clienttasks.getCurrentConsumerCert();
    Assert.assertEquals(consumerCertBefore, consumerCertAfter, "The consumer identity cert has not changed after reregistering with consumerid.");
    // assert that the user is still consuming the same products
    List<ProductSubscription> consumedProductSubscriptionsAfter = clienttasks.getCurrentlyConsumedProductSubscriptions();
    Assert.assertTrue(consumedProductSubscriptionsAfter.containsAll(consumedProductSubscriptionsBefore) && consumedProductSubscriptionsBefore.size() == consumedProductSubscriptionsAfter.size(), "The list of consumed products after reregistering is identical.");
}
Also used : ProductSubscription(rhsm.data.ProductSubscription) SkipException(org.testng.SkipException) SubscriptionPool(rhsm.data.SubscriptionPool) ConsumerCert(rhsm.data.ConsumerCert) 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 43 with ProductSubscription

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

the class ImportTests method testImportACertificateForAFutureEntitlement.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36632", "RHEL7-51442" }, 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: import a certificate for a future entitlement", groups = { "Tier2Tests", "blockedByBug-860344", "blockedByBug-1440180" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testImportACertificateForAFutureEntitlement() throws Exception {
    if (futureEntitlementCertFile == null)
        throw new SkipException("Could not generate an entitlement certificate for a future subscription.");
    // create a import file for the future entitlement
    File importEntitlementCertFile = futureEntitlementCertFile;
    File importEntitlementKeyFile = clienttasks.getEntitlementCertKeyFileCorrespondingToEntitlementCertFile(importEntitlementCertFile);
    File importCertificateFile = new File(importCertificatesDir + File.separator + importEntitlementCertFile.getName());
    client.runCommandAndWait("cat " + importEntitlementCertFile + " " + importEntitlementKeyFile + " > " + importCertificateFile);
    // once imported, what should the entitlement cert file be?
    File expectedEntitlementCertFile = new File(clienttasks.entitlementCertDir + File.separator + importCertificateFile.getName());
    File expectedEntitlementKeyFile = clienttasks.getEntitlementCertKeyFileCorrespondingToEntitlementCertFile(expectedEntitlementCertFile);
    // make sure the expected entitlement files do not exist before our test and that no subscriptions are consumed
    Assert.assertEquals(RemoteFileTasks.testFileExists(client, expectedEntitlementCertFile.getPath()), 0, "Before attempting the import, asserting that expected destination for the entitlement cert file does NOT yet exist (" + expectedEntitlementCertFile + ").");
    Assert.assertEquals(RemoteFileTasks.testFileExists(client, expectedEntitlementKeyFile.getPath()), 0, "Before attempting the import, asserting that expected destination for the entitlement key file does NOT yet exist (" + expectedEntitlementKeyFile + ").");
    Assert.assertEquals(clienttasks.getCurrentlyConsumedProductSubscriptions().size(), 0, "Should not be consuming any subscriptions before the import.");
    // show the contents of the file about to be imported
    log.info("Following is the contents of the certificate file about to be imported...");
    client.runCommandAndWait("cat " + importCertificateFile);
    // attempt an entitlement cert import from a valid bundled file
    clienttasks.importCertificate(importCertificateFile.getPath());
    // verify that the expectedEntitlementCertFile now exists
    Assert.assertEquals(RemoteFileTasks.testFileExists(client, expectedEntitlementCertFile.getPath()), 1, "After attempting the import, the expected destination for the entitlement cert file should now exist (" + expectedEntitlementCertFile + ").");
    // verify that the expectedEntitlementKeyFile also exists
    Assert.assertEquals(RemoteFileTasks.testFileExists(client, expectedEntitlementKeyFile.getPath()), 1, "After attempting the import, the expected destination for the entitlement key file should now exist (" + expectedEntitlementKeyFile + ").");
    // assert that the contents of the imported files match the originals
    log.info("Asserting that the imported entitlement cert file contents match the original...");
    RemoteFileTasks.runCommandAndAssert(client, "diff -w " + expectedEntitlementCertFile + " " + importEntitlementCertFile, 0);
    log.info("Asserting that the imported entitlement key file contents match the original...");
    RemoteFileTasks.runCommandAndAssert(client, "diff -w " + expectedEntitlementKeyFile + " " + importEntitlementKeyFile, 0);
    // finally verify that we are now consuming subscriptions
    List<ProductSubscription> consumedProductSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
    Assert.assertTrue(consumedProductSubscriptions.size() > 0, "After importing a valid certificate, we should be consuming subscriptions.");
    // assert that the consumed subscriptions begin in the future
    Calendar now = new GregorianCalendar();
    now.setTimeInMillis(System.currentTimeMillis());
    for (ProductSubscription productSubscription : consumedProductSubscriptions) {
        Assert.assertTrue(productSubscription.startDate.after(now), "The product subscription consumed from the imported future entitlement certificate begins in the future.  ProductSubscription: " + productSubscription);
    }
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) ProductSubscription(rhsm.data.ProductSubscription) GregorianCalendar(java.util.GregorianCalendar) SkipException(org.testng.SkipException) File(java.io.File) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 44 with ProductSubscription

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

the class InstanceBasedTests method testHealingOfInstanceBasedSubscriptions.

/**
 * @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-36688", "RHEL7-51533" }, 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 healing of Instance-Based subscriptions", groups = { "Tier2Tests", "HealingOfInstanceBasedSubscription", "blockedByBug-907638" }, enabled = true)
public void testHealingOfInstanceBasedSubscriptions() throws JSONException, Exception {
    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);
    // to avoid unmapped_guests_only pools
    if (Boolean.valueOf(clienttasks.getFactValue("virt.is_guest")))
        clienttasks.mapSystemAsAGuestOfItself();
    clienttasks.subscribe_(true, null, (String) null, null, null, null, null, null, null, null, null, null, null);
    int healFrequency = 2;
    if (clienttasks.getFactValue("virt.is_guest").equalsIgnoreCase("false")) {
        Integer sockets = 4;
        factsMap.put("cpu.cpu_socket(s)", String.valueOf(sockets));
        clienttasks.createFactsFileWithOverridingValues(factsMap);
        clienttasks.facts(null, true, null, null, null, null);
        for (SubscriptionPool availList : clienttasks.getCurrentlyAllAvailableSubscriptionPools()) {
            if (CandlepinTasks.isPoolProductInstanceBased(sm_clientUsername, sm_clientPassword, sm_serverUrl, availList.poolId)) {
                clienttasks.subscribe(null, null, availList.poolId, null, null, "2", null, null, null, null, null, null, null);
            }
        }
        String messageDetails = "Only covers 2 of " + sockets + " sockets.";
        for (InstalledProduct installed : clienttasks.getCurrentlyInstalledProducts()) {
            if (installed.productId.contains("Instance Server")) {
                Assert.assertEquals(installed.status.trim(), "Partially Subscribed");
                Assert.assertEquals(installed.statusDetails, messageDetails);
            }
        }
    }
    /* replacing call to restart_rhsmcertd with a faster call to run_rhsmcertd_worker	
		clienttasks.restart_rhsmcertd(null, healFrequency, true);
		SubscriptionManagerCLITestScript.sleep(healFrequency * 60 * 1000);
*/
    clienttasks.run_rhsmcertd_worker(true);
    for (InstalledProduct installed : clienttasks.getCurrentlyInstalledProducts()) {
        if (installed.productName.contains("Instance Server")) {
            Assert.assertEquals(installed.status.trim(), "Subscribed");
        }
    }
    if (clienttasks.getFactValue("virt.is_guest").equals("True")) {
        Integer sockets = 4;
        factsMap.put("cpu.cpu_socket(s)", String.valueOf(sockets));
        clienttasks.createFactsFileWithOverridingValues(factsMap);
        clienttasks.facts(null, true, null, null, null, null);
        /* replacing call to restart_rhsmcertd with a faster call to run_rhsmcertd_worker	
			clienttasks.restart_rhsmcertd(null, healFrequency, true);
			SubscriptionManagerCLITestScript.sleep(healFrequency * 60 * 1000);
*/
        clienttasks.run_rhsmcertd_worker(true);
        for (InstalledProduct installed : clienttasks.getCurrentlyInstalledProducts()) {
            if (installed.productName.contains("Instance Server")) {
                Assert.assertEquals(installed.status.trim(), "Subscribed");
            }
        }
        for (ProductSubscription consumed : clienttasks.getCurrentlyConsumedProductSubscriptions()) {
            if (consumed.productName.contains("Instance Based")) {
                Integer quantity = 1;
                Assert.assertEquals(consumed.quantityUsed, quantity);
            }
        }
    }
}
Also used : InstalledProduct(rhsm.data.InstalledProduct) ProductSubscription(rhsm.data.ProductSubscription) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 45 with ProductSubscription

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

the class SubscriptionManagerCLITestScript method getAllConsumedProductSubscriptionsDataAsListOfLists.

/**
 * @return List of [ProductSubscription productSubscription]
 */
protected List<List<Object>> getAllConsumedProductSubscriptionsDataAsListOfLists() throws JSONException, Exception {
    List<List<Object>> ll = new ArrayList<List<Object>>();
    if (!isSetupBeforeSuiteComplete)
        return ll;
    if (clienttasks == null)
        return ll;
    if (sm_clientUsername == null)
        return ll;
    if (sm_clientPassword == null)
        return ll;
    // first make sure we are subscribed to all pools
    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);
    clienttasks.subscribeToTheCurrentlyAvailableSubscriptionPoolsCollectively();
    // then assemble a list of all consumed ProductSubscriptions
    for (ProductSubscription productSubscription : clienttasks.getCurrentlyConsumedProductSubscriptions()) {
        ll.add(Arrays.asList(new Object[] { productSubscription }));
        // 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) ProductSubscription(rhsm.data.ProductSubscription) List(java.util.List) ArrayList(java.util.ArrayList) JSONObject(org.json.JSONObject)

Aggregations

ProductSubscription (rhsm.data.ProductSubscription)90 Test (org.testng.annotations.Test)82 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)72 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)56 SkipException (org.testng.SkipException)46 ArrayList (java.util.ArrayList)41 SubscriptionPool (rhsm.data.SubscriptionPool)38 SSHCommandResult (com.redhat.qe.tools.SSHCommandResult)31 JSONObject (org.json.JSONObject)31 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)23 HashMap (java.util.HashMap)22 BigInteger (java.math.BigInteger)20 EntitlementCert (rhsm.data.EntitlementCert)17 InstalledProduct (rhsm.data.InstalledProduct)16 Calendar (java.util.Calendar)15 JSONArray (org.json.JSONArray)13 File (java.io.File)10 GregorianCalendar (java.util.GregorianCalendar)10 HashSet (java.util.HashSet)6 ConsumerCert (rhsm.data.ConsumerCert)6