Search in sources :

Example 66 with TestDefinition

use of com.github.redhatqe.polarize.metadata.TestDefinition in project rhsm-qe by RedHatQE.

the class ActivationKeyTests method testRegisterWithListOfCommaSeparatedActivationKeys.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-21802", "RHEL7-51619" }, 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 = "create many activation keys with one added pool per key and then register with --activationkey=comma_separated_string_of_keys asserting all the pools get consumed", groups = { "Tier3Tests", "blockedByBug-878986", "blockedByBug-979492", "blockedByBug-1040101" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testRegisterWithListOfCommaSeparatedActivationKeys() throws JSONException, Exception {
    // get all of the pools belonging to ownerKey
    JSONArray jsonPools = new JSONArray(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/owners/" + sm_clientOrg + "/pools?listall=true"));
    if (!(jsonPools.length() > 1))
        throw new SkipException("This test requires more than one pool for org '" + sm_clientOrg + "'.");
    jsonPools = clienttasks.workaroundForBug1040101(jsonPools);
    // process each of the pools adding them to an individual activation key
    List<String> activationKeyNames = new ArrayList<String>();
    Integer addQuantity = null;
    JSONArray jsonPoolsAddedToActivationKey = new JSONArray();
    boolean isSystemVirtual = Boolean.valueOf(clienttasks.getFactValue("virt.is_guest"));
    for (int i = 0; i < jsonPools.length(); i++) {
        JSONObject jsonPool = (JSONObject) jsonPools.get(i);
        // for the purpose of this test, skip pools with no available entitlements (consumed>=quantity) (quantity=-1 is unlimited)
        if (jsonPool.getInt("quantity") > 0 && jsonPool.getInt("consumed") >= jsonPool.getInt("quantity"))
            continue;
        // for the purpose of this test, skip non-system pools otherwise the register will fail with "Consumers of this type are not allowed to subscribe to the pool with id '8a90f8c631ab7ccc0131ab7e46ca0619'."
        if (!CandlepinTasks.isPoolProductConsumableByConsumerType(sm_clientUsername, sm_clientPassword, sm_serverUrl, jsonPool.getString("id"), ConsumerType.system))
            continue;
        // for the purpose of this test, skip physical_only pools when system is virtual otherwise the register will fail with "Pool is restricted to physical systems: '8a9086d344549b0c0144549bf9ae0dd4'."
        if (isSystemVirtual && CandlepinTasks.isPoolRestrictedToPhysicalSystems(sm_clientUsername, sm_clientPassword, sm_serverUrl, jsonPool.getString("id")))
            continue;
        // for the purpose of this test, skip virt_only pools when system is physical otherwise the register will fail with "Pool is restricted to virtual guests: '8a9086d344549b0c0144549bf9ae0dd4'."
        if (!isSystemVirtual && CandlepinTasks.isPoolRestrictedToVirtualSystems(sm_clientUsername, sm_clientPassword, sm_serverUrl, jsonPool.getString("id")))
            continue;
        /* skipping pools that are not NORMAL is more reliable than this...
			// for the purpose of this test, skip virt_only derived_pool when server is standalone otherwise the register will fail with "Unable to entitle consumer to the pool with id '8a90f85733d86b130133d88c09410e5e'.: virt.guest.host.does.not.match.pool.owner"
			//if (servertasks.statusStandalone) {	// 5/29/2014 removed this check, I can't remember why I originally set it 
			// for the purpose of this test, skip virt_only derived_pool when otherwise the register will fail with "Guest's host does not match owner of pool: '8a908775463fef2301464072ee68496e'."
			if (true) {
				String pool_derived = CandlepinTasks.getPoolAttributeValue(jsonPool, "pool_derived");
				String virt_only = CandlepinTasks.getPoolAttributeValue(jsonPool, "virt_only");
				if (pool_derived!=null && virt_only!=null && Boolean.valueOf(pool_derived) && Boolean.valueOf(virt_only)) {
					continue;
				}
			}
			*/
        // for the purpose of this test, skip pools that are not NORMAL (eg. BONUS, ENTITLEMENT_DERIVED, STACK_DERIVED)
        String poolType = (String) CandlepinTasks.getPoolValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, jsonPool.getString("id"), "type");
        if (!poolType.equals("NORMAL"))
            continue;
        // create an activation key
        String activationKeyName = String.format("ActivationKey%sWithPool%sForOrg_%s", System.currentTimeMillis(), jsonPool.getString("id"), sm_clientOrg);
        Map<String, String> mapActivationKeyRequest = new HashMap<String, String>();
        mapActivationKeyRequest.put("name", activationKeyName);
        JSONObject jsonActivationKeyRequest = new JSONObject(mapActivationKeyRequest);
        JSONObject jsonActivationKey = new JSONObject(CandlepinTasks.postResourceUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, "/owners/" + sm_clientOrg + "/activation_keys", jsonActivationKeyRequest.toString()));
        // add the pool to the activation key
        JSONObject jsonResult = new JSONObject(CandlepinTasks.postResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/activation_keys/" + jsonActivationKey.getString("id") + "/pools/" + jsonPool.getString("id") + (addQuantity == null ? "" : "?quantity=" + addQuantity), null));
        // if (clienttasks.isVersion(servertasks.statusVersion, ">", "0.9.30-1")) the POST now returns the jsonActivationKey and formerly returned the jsonPoolAddedToActivationKey	// candlepin commit 82b9af5dc2c63b58447366e680fcf6f156c6049f
        if (jsonResult.has("displayMessage")) {
            Assert.fail("Failed to add pool '" + jsonPool.getString("productId") + "' '" + jsonPool.getString("id") + "' to activation key '" + jsonActivationKey.getString("id") + "'.  DisplayMessage: " + jsonResult.getString("displayMessage"));
        }
        jsonPoolsAddedToActivationKey.put(jsonPool);
        activationKeyNames.add(activationKeyName);
    }
    if (addQuantity == null)
        addQuantity = 1;
    // assemble the comma separated list of activation key names
    String commaSeparatedActivationKeyNames = "";
    for (String activationKeyName : activationKeyNames) commaSeparatedActivationKeyNames += activationKeyName + ",";
    // strip off trailing comma
    commaSeparatedActivationKeyNames = commaSeparatedActivationKeyNames.replaceFirst(",$", "");
    // register with the activation key specified as a single string
    SSHCommandResult registerResult = clienttasks.register(null, null, sm_clientOrg, null, null, null, null, null, null, null, commaSeparatedActivationKeyNames, null, null, null, true, null, null, null, null, null);
    // assert that all the pools were consumed
    List<ProductSubscription> consumedProductSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
    for (int i = 0; i < jsonPoolsAddedToActivationKey.length(); i++) {
        JSONObject jsonPoolAdded = (JSONObject) jsonPoolsAddedToActivationKey.get(i);
        // assert that the pool's providedProducts (excluding type=MKT products) are consumed (unless it is a ManagementAddOn product - indicated by no providedProducts)
        assertProvidedProductsFromPoolAreWithinConsumedProductSubscriptionsUsingQuantity(jsonPoolAdded, consumedProductSubscriptions, addQuantity, false);
    }
    Assert.assertEquals(clienttasks.getCurrentEntitlementCertFiles().size(), activationKeyNames.size(), "Expecting a new entitlement cert file in '" + clienttasks.entitlementCertDir + "' for each of the single pooled activation keys used during register.");
}
Also used : HashMap(java.util.HashMap) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) ProductSubscription(rhsm.data.ProductSubscription) JSONObject(org.json.JSONObject) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) SkipException(org.testng.SkipException) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 67 with TestDefinition

use of com.github.redhatqe.polarize.metadata.TestDefinition in project rhsm-qe by RedHatQE.

the class ActivationKeyTests method testRegisterWithActivationKeyContainingPoolForWhichNotEnoughQuantityRemains.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-21796", "RHEL7-51613" }, 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 = "Tier3")
@Test(description = "create an activation key with a valid quantity and attempt to register with it when not enough entitlements remain", groups = { "Tier3Tests" }, dataProvider = "getAllMultiEntitlementJSONPoolsData", enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testRegisterWithActivationKeyContainingPoolForWhichNotEnoughQuantityRemains(Object blockedByBug, String keyName, JSONObject jsonPool) throws JSONException, Exception {
    // first, figure out how many entitlements remain
    int quantityAvail = jsonPool.getInt("quantity") - jsonPool.getInt("consumed");
    if (quantityAvail < 1)
        throw new SkipException("Cannot do this test until there is an available entitlement for pool '" + jsonPool.getString("id") + "'.");
    // skip this pool when our candlepin is standalone and this is a pool_derived virt_only pool (for which we have not registered our host system)
    if (servertasks.statusStandalone) {
        String pool_derived = CandlepinTasks.getPoolAttributeValue(jsonPool, "pool_derived");
        String virt_only = CandlepinTasks.getPoolAttributeValue(jsonPool, "virt_only");
        if (pool_derived != null && virt_only != null && Boolean.valueOf(pool_derived) && Boolean.valueOf(virt_only)) {
            throw new SkipException("Skipping this virt_only derived_pool '" + jsonPool.getString("id") + "' on a standalone candlepin server since our system's host is not registered.");
        }
    }
    // now consume an entitlement from the pool
    String requires_consumer_type = CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, jsonPool.getString("id"), "requires_consumer_type");
    if (requires_consumer_type != null) {
        if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.20.2-1")) {
            // post commit e0c34a729e9e347ab1e0f4f5fa656c8b20205fdf RFE Bug 1461003: Deprecate --type option on register command
            throw new SkipException("Due to RFE Bug 1461003, subscription-manager can no longer register with --type which prevents registration using an --activationkey for a pool that has attribute \"requires_consumer_type\":\"" + requires_consumer_type + "\"");
        }
    }
    ConsumerType consumerType = requires_consumer_type == null ? null : ConsumerType.valueOf(requires_consumer_type);
    String consumer1Id = clienttasks.getCurrentConsumerId(clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, consumerType, null, null, null, null, null, (String) null, null, null, null, true, null, null, null, null, null));
    SubscriptionPool subscriptionPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", jsonPool.getString("id"), clienttasks.getCurrentlyAllAvailableSubscriptionPools());
    clienttasks.subscribe(null, null, jsonPool.getString("id"), null, null, null, null, null, null, null, null, null, null);
    // remember the consuming consumerId
    // String consumer1Id = clienttasks.getCurrentConsumerId();
    systemConsumerIds.add(consumer1Id);
    // clean the system of all data (will not return the consumed entitlement)
    clienttasks.clean();
    // assert that the current pool recognizes an increment in consumption
    JSONObject jsonCurrentPool = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/pools/" + jsonPool.getString("id")));
    // Assert.assertEquals(jsonCurrentPool.getInt("consumed"),jsonPool.getInt("consumed")+1,"The consumed entitlement from Pool '"+jsonPool.getString("id")+"' has incremented by one to an expected total of '"+(jsonPool.getInt("consumed")+1)+"' consumed.");	// valid before Bug 1008557 and Bug 1008647
    // when subscriptionPool.suggested is zero, subscribe should still attach 1.
    Integer suggested = subscriptionPool.suggested;
    // when subscriptionPool.suggested is zero, subscribe should still attach 1.
    Integer expectedIncrement = suggested > 0 ? suggested : 1;
    Assert.assertEquals(jsonCurrentPool.getInt("consumed"), jsonPool.getInt("consumed") + expectedIncrement, "The consumed entitlement from Pool '" + jsonPool.getString("id") + "' has incremented by the suggested quantity '" + subscriptionPool.suggested + "' to an expected total of '" + (jsonPool.getInt("consumed") + expectedIncrement) + "' consumed (Except when suggested quantity is zero, then subscribe should still attach one entitlement).");
    // finally do the test...
    // create an activation key, add the current pool to the activation key with this valid quantity, and attempt to register with it.
    SSHCommandResult registerResult = testRegisterWithActivationKeyContainingPoolWithQuantity(blockedByBug, keyName, jsonCurrentPool, quantityAvail);
    String expectedStderr = String.format("No entitlements are available from the pool with id '%s'.", jsonCurrentPool.getString("id"));
    // string changed by bug 876758
    expectedStderr = String.format("No subscriptions are available from the pool with id '%s'.", jsonCurrentPool.getString("id"));
    if (!clienttasks.workaroundForBug876764(sm_serverType))
        expectedStderr = String.format("No subscriptions are available from the pool with ID '%s'.", jsonCurrentPool.getString("id"));
    if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.3.1-1")) {
        // commit 0d5fefcfa8c1c2485921d2dee6633879b1e06931 Correct incorrect punctuation in user messages
        expectedStderr = String.format("No subscriptions are available from the pool with ID \"%s\".", jsonCurrentPool.getString("id"));
    }
    if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">", "0.9.30-1")) {
        log.info("Prior to candlepin version 0.9.30-1, the expected feedback was: " + expectedStderr);
        // Follows: candlepin-0.9.30-1	// https://github.com/candlepin/candlepin/commit/bcb4b8fd8ee009e86fc9a1a20b25f19b3dbe6b2a
        expectedStderr = "No activation key was applied successfully.";
    }
    if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.2.0-1")) {
        // candlepin commit 08bcd6829cb4c89f737b8b77cbfdb85600a47933   bug 1440924: Adjust message when activation key registration fails
        log.info("Prior to candlepin version 2.2.0-1 , the expected feedback was: " + expectedStderr);
        expectedStderr = "None of the subscriptions on the activation key were available for attaching.";
    }
    Integer expectedExitCode = new Integer(255);
    // EX_SOFTWARE	// post commit df95529a5edd0be456b3528b74344be283c4d258 bug 1119688
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.13.8-1"))
        expectedExitCode = new Integer(70);
    Assert.assertEquals(registerResult.getStderr().trim(), expectedStderr, "Registering a with an activationKey containing a pool for which not enough entitlements remain should fail.");
    Assert.assertEquals(registerResult.getExitCode(), expectedExitCode, "The exitCode from registering with an activationKey containing a pool for which non enough entitlements remain should fail.");
    // make sure there is no consumer cert - register with activation key should be 100% successful - if any one part fails, the whole operation fails
    Assert.assertNull(clienttasks.getCurrentConsumerCert(), "There should be no consumer cert on the system when register with activation key fails.");
}
Also used : JSONObject(org.json.JSONObject) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) SkipException(org.testng.SkipException) ConsumerType(rhsm.base.ConsumerType) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 68 with TestDefinition

use of com.github.redhatqe.polarize.metadata.TestDefinition in project rhsm-qe by RedHatQE.

the class ActivationKeyTests method testRegisterWithActivationKeyContainingMultiplePools.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-21795", "RHEL7-51612" }, 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 = "create an activation key and add many pools to it and then register asserting all the pools get consumed", groups = { "Tier3Tests", "blockedByBug-1040101" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testRegisterWithActivationKeyContainingMultiplePools() throws JSONException, Exception {
    // get all of the pools belonging to ownerKey
    JSONArray jsonPools = new JSONArray(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/owners/" + sm_clientOrg + "/pools?listall=true"));
    if (!(jsonPools.length() > 1))
        throw new SkipException("This test requires more than one pool for org '" + sm_clientOrg + "'.");
    jsonPools = clienttasks.workaroundForBug1040101(jsonPools);
    // create an activation key
    String activationKeyName = String.format("ActivationKey%sWithMultiplePoolsForOrg_%s", System.currentTimeMillis(), sm_clientOrg);
    Map<String, String> mapActivationKeyRequest = new HashMap<String, String>();
    mapActivationKeyRequest.put("name", activationKeyName);
    JSONObject jsonActivationKeyRequest = new JSONObject(mapActivationKeyRequest);
    JSONObject jsonActivationKey = new JSONObject(CandlepinTasks.postResourceUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, "/owners/" + sm_clientOrg + "/activation_keys", jsonActivationKeyRequest.toString()));
    // process each of the pools adding them to the activation key
    Integer addQuantity = null;
    JSONArray jsonPoolsAddedToActivationKey = new JSONArray();
    boolean isSystemVirtual = Boolean.valueOf(clienttasks.getFactValue("virt.is_guest"));
    for (int i = 0; i < jsonPools.length(); i++) {
        JSONObject jsonPool = (JSONObject) jsonPools.get(i);
        // for the purpose of this test, skip pools with no available entitlements (consumed>=quantity) (quantity=-1 is unlimited)
        if (jsonPool.getInt("quantity") > 0 && jsonPool.getInt("consumed") >= jsonPool.getInt("quantity"))
            continue;
        // for the purpose of this test, skip non-system pools otherwise the register will fail with "Consumers of this type are not allowed to subscribe to the pool with id '8a90f8c631ab7ccc0131ab7e46ca0619'."
        if (!CandlepinTasks.isPoolProductConsumableByConsumerType(sm_clientUsername, sm_clientPassword, sm_serverUrl, jsonPool.getString("id"), ConsumerType.system))
            continue;
        // for the purpose of this test, skip physical_only pools when system is virtual otherwise the register will fail with "Pool is restricted to physical systems: '8a9086d344549b0c0144549bf9ae0dd4'."
        if (isSystemVirtual && CandlepinTasks.isPoolRestrictedToPhysicalSystems(sm_clientUsername, sm_clientPassword, sm_serverUrl, jsonPool.getString("id")))
            continue;
        // for the purpose of this test, skip virt_only pools when system is physical otherwise the register will fail with "Pool is restricted to virtual guests: '8a9086d344549b0c0144549bf9ae0dd4'."
        if (!isSystemVirtual && CandlepinTasks.isPoolRestrictedToVirtualSystems(sm_clientUsername, sm_clientPassword, sm_serverUrl, jsonPool.getString("id")))
            continue;
        /* skipping pools that are not NORMAL is more reliable than this...
			// for the purpose of this test, skip virt_only derived_pool when server is standalone otherwise the register will fail with "Unable to entitle consumer to the pool with id '8a90f85733d86b130133d88c09410e5e'.: virt.guest.host.does.not.match.pool.owner"
			//if (servertasks.statusStandalone) {	// 5/29/2014 removed this check, I can't remember why I originally set it 
			// for the purpose of this test, skip virt_only derived_pool when otherwise the register will fail with "Guest's host does not match owner of pool: '8a908775463fef2301464072ee68496e'."
			if (true) {
				String pool_derived = CandlepinTasks.getPoolAttributeValue(jsonPool, "pool_derived");
				String virt_only = CandlepinTasks.getPoolAttributeValue(jsonPool, "virt_only");
				if (pool_derived!=null && virt_only!=null && Boolean.valueOf(pool_derived) && Boolean.valueOf(virt_only)) {
					continue;
				}
			}
			*/
        // for the purpose of this test, skip pools that are not NORMAL (eg. BONUS, ENTITLEMENT_DERIVED, STACK_DERIVED)
        String poolType = (String) CandlepinTasks.getPoolValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, jsonPool.getString("id"), "type");
        if (!poolType.equals("NORMAL"))
            continue;
        // add the pool to the activation key
        JSONObject jsonResult = new JSONObject(CandlepinTasks.postResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/activation_keys/" + jsonActivationKey.getString("id") + "/pools/" + jsonPool.getString("id") + (addQuantity == null ? "" : "?quantity=" + addQuantity), null));
        // if (clienttasks.isVersion(servertasks.statusVersion, ">", "0.9.30-1")) the POST now returns the jsonActivationKey and formerly returned the jsonPoolAddedToActivationKey	// candlepin commit 82b9af5dc2c63b58447366e680fcf6f156c6049f
        if (jsonResult.has("displayMessage")) {
            Assert.fail("Failed to add pool '" + jsonPool.getString("productId") + "' '" + jsonPool.getString("id") + "' to activation key '" + jsonActivationKey.getString("id") + "'.  DisplayMessage: " + jsonResult.getString("displayMessage"));
        }
        jsonPoolsAddedToActivationKey.put(jsonPool);
    }
    if (addQuantity == null)
        addQuantity = 1;
    jsonActivationKey = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, "/activation_keys/" + jsonActivationKey.getString("id")));
    Assert.assertTrue(jsonActivationKey.getJSONArray("pools").length() > 0, "MultiplePools have been added to the activation key: " + jsonActivationKey);
    Assert.assertEquals(jsonActivationKey.getJSONArray("pools").length(), jsonPoolsAddedToActivationKey.length(), "The number of attempted pools added equals the number of pools retrieved from the activation key: " + jsonActivationKey);
    // register with the activation key
    SSHCommandResult registerResult = clienttasks.register(null, null, sm_clientOrg, null, null, null, null, null, null, null, jsonActivationKey.getString("name"), null, null, null, true, null, null, null, null, null);
    // assert that all the pools were consumed
    List<ProductSubscription> consumedProductSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
    for (int i = 0; i < jsonPoolsAddedToActivationKey.length(); i++) {
        JSONObject jsonPoolAdded = (JSONObject) jsonPoolsAddedToActivationKey.get(i);
        // assert that the pool's providedProducts (excluding type=MKT products) are consumed (unless it is a ManagementAddOn product - indicated by no providedProducts)
        assertProvidedProductsFromPoolAreWithinConsumedProductSubscriptionsUsingQuantity(jsonPoolAdded, consumedProductSubscriptions, addQuantity, false);
    }
    Assert.assertEquals(clienttasks.getCurrentEntitlementCertFiles().size(), jsonActivationKey.getJSONArray("pools").length(), "Expecting a new entitlement cert file in '" + clienttasks.entitlementCertDir + "' for each of the pools added to the activation key.");
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) JSONArray(org.json.JSONArray) ProductSubscription(rhsm.data.ProductSubscription) SkipException(org.testng.SkipException) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 69 with TestDefinition

use of com.github.redhatqe.polarize.metadata.TestDefinition in project rhsm-qe by RedHatQE.

the class ActivationKeyTests method testRegisterWithActivationKeyUsingWrongOrg.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-21801", "RHEL7-51618" }, 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 = "Tier3")
@Test(description = "create an activation key for each org and then attempt to register with the activation key using a different org", groups = { "Tier3Tests" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testRegisterWithActivationKeyUsingWrongOrg() throws JSONException, Exception {
    // loop through existing owners and remember the orgs
    JSONArray jsonOwners = new JSONArray(CandlepinTasks.getResourceUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, "/owners"));
    if (jsonOwners.length() < 2)
        throw new SkipException("This test requires at least two orgs on your candlepin server.");
    List<String> orgs = new ArrayList<String>();
    for (int j = 0; j < jsonOwners.length(); j++) {
        JSONObject jsonOwner = (JSONObject) jsonOwners.get(j);
        // {
        // "contentPrefix": null,
        // "created": "2011-07-01T06:39:58.740+0000",
        // "displayName": "Snow White",
        // "href": "/owners/snowwhite",
        // "id": "8a90f8c630e46c7e0130e46ce114000a",
        // "key": "snowwhite",
        // "parentOwner": null,
        // "updated": "2011-07-01T06:39:58.740+0000",
        // "upstreamUuid": null
        // }
        orgs.add(jsonOwner.getString("key"));
    }
    // now loop through the orgs and create an activation key and attempt to register using a different org
    for (String org : orgs) {
        // generate a unique activationkey name for this org
        String activationKeyName = String.format("ActivationKey%sForOrg_%s", System.currentTimeMillis(), org);
        // create a JSON object to represent the request body
        Map<String, String> mapActivationKeyRequest = new HashMap<String, String>();
        mapActivationKeyRequest.put("name", activationKeyName);
        JSONObject jsonActivationKeyRequest = new JSONObject(mapActivationKeyRequest);
        // call the candlepin api to create an activation key
        JSONObject jsonActivationKeyC = new JSONObject(CandlepinTasks.postResourceUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, "/owners/" + org + "/activation_keys", jsonActivationKeyRequest.toString()));
        // assert that the creation was successful (does not contain a displayMessage)
        if (jsonActivationKeyC.has("displayMessage")) {
            String displayMessage = jsonActivationKeyC.getString("displayMessage");
            Assert.fail("The creation of an activation key appears to have failed: " + displayMessage);
        }
        Assert.assertTrue(true, "The absense of a displayMessage indicates the activation key creation was probably successful.");
        // now assert that the new activation key is found under /candlepin/activation_keys/<id>
        JSONObject jsonActivationKeyJ = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, "/activation_keys/" + jsonActivationKeyC.getString("id")));
        // Assert.assertEquals(jsonActivationKeyC.toString(), jsonActivationKeyJ.toString(), "Successfully found newly created activation key among all activation keys under /activation_keys.");
        Assert.assertTrue(areActivationKeysEqual(jsonActivationKeyC, jsonActivationKeyJ), "Successfully found newly created activation key among all activation keys under Candlepin API /activation_keys/<id>." + "\n jsonActivationKeyC='" + jsonActivationKeyC.toString() + "'" + "\n jsonActivationKeyJ='" + jsonActivationKeyJ.toString() + "'");
        // now let's attempt to register with the activation key using a different org
        for (String differentOrg : orgs) {
            if (differentOrg.equals(org))
                continue;
            SSHCommandResult registerResult = clienttasks.register_(null, null, differentOrg, null, null, null, null, null, null, null, activationKeyName, null, null, null, true, null, null, null, null, null);
            // assert the sshCommandResult here
            Integer expectedExitCode = new Integer(255);
            // EX_SOFTWARE	// post commit df95529a5edd0be456b3528b74344be283c4d258 bug 1119688
            if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.13.8-1"))
                expectedExitCode = new Integer(70);
            Assert.assertEquals(registerResult.getExitCode(), expectedExitCode, "The expected exit code from the register attempt with activationKey using the wrong org.");
            // Assert.assertEquals(registerResult.getStdout().trim(), "", "The expected stdout result the register attempt with activationKey using the wrong org.");
            String expectedStderr = "Activation key '" + activationKeyName + "' not found for organization '" + differentOrg + "'.";
            // Follows: candlepin-0.9.30-1	// https://github.com/candlepin/candlepin/commit/bcb4b8fd8ee009e86fc9a1a20b25f19b3dbe6b2a
            if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">", "0.9.30-1"))
                expectedStderr = String.format("None of the activation keys specified exist for this org.");
            Assert.assertEquals(registerResult.getStderr().trim(), expectedStderr, "The expected stderr result from the register attempt with activationKey '" + activationKeyName + "' using the wrong org '" + differentOrg + "'.");
            // make sure there is no consumer cert - register with activation key should be 100% successful - if any one part fails, the whole operation fails
            Assert.assertNull(clienttasks.getCurrentConsumerCert(), "There should be no consumer cert on the system when register with activation key fails.");
        }
    }
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) SkipException(org.testng.SkipException) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 70 with TestDefinition

use of com.github.redhatqe.polarize.metadata.TestDefinition in project rhsm-qe by RedHatQE.

the class ActivationKeyTests method testAttemptActivationKeyCreationWithBadServiceLevel.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-21789", "RHEL7-51606" }, 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 = "Tier3")
@Test(description = "use the candlepin api to attempt creation of an activation key with a bad service level", // Candlepin commit 387463519444634bb242b456db7bc89cf0eae43e Add SLA functionality to Activation Keys.
groups = { "Tier3Tests" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testAttemptActivationKeyCreationWithBadServiceLevel() throws JSONException, Exception {
    // create a JSON object to represent the request body (with bad service level)
    Map<String, String> mapActivationKeyRequest = new HashMap<String, String>();
    mapActivationKeyRequest.put("name", String.format("ActivationKey%s_WithNonExistantServiceLevel", System.currentTimeMillis()));
    mapActivationKeyRequest.put("serviceLevel", "NonExistantServiceLevel");
    JSONObject jsonActivationKeyRequest = new JSONObject(mapActivationKeyRequest);
    // call the candlepin api to create an activation key
    JSONObject jsonActivationKey = new JSONObject(CandlepinTasks.postResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/owners/" + sm_clientOrg + "/activation_keys", jsonActivationKeyRequest.toString()));
    // assert that the creation was NOT successful (contains a displayMessage)
    if (jsonActivationKey.has("displayMessage")) {
        String displayMessage = jsonActivationKey.getString("displayMessage");
        String expectedMessage = String.format("Service level '%s' is not available to units of organization %s.", mapActivationKeyRequest.get("serviceLevel"), sm_clientOrg);
        if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.3.1-1")) {
            // commit 0d5fefcfa8c1c2485921d2dee6633879b1e06931 Correct incorrect punctuation in user messages
            expectedMessage = String.format("Service level \"%s\" is not available to units of organization %s.", mapActivationKeyRequest.get("serviceLevel"), sm_clientOrg);
        }
        Assert.assertEquals(displayMessage, expectedMessage, "Expected the creation of this activation key to fail because this service level is non-existant for any of the subscriptions in this org.");
    } else {
        log.warning("The absense of a displayMessage indicates the activation key creation was probably successful when we expected it to fail due to an invalid service level '" + mapActivationKeyRequest.get("serviceLevel") + "'.");
        Assert.fail("The following activation key should not have been created with bad serviceLevel '" + mapActivationKeyRequest.get("serviceLevel") + "': " + jsonActivationKey);
    }
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Aggregations

TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)687 Test (org.testng.annotations.Test)687 SSHCommandResult (com.redhat.qe.tools.SSHCommandResult)401 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)366 SkipException (org.testng.SkipException)328 ArrayList (java.util.ArrayList)144 SubscriptionPool (rhsm.data.SubscriptionPool)137 JSONObject (org.json.JSONObject)95 BigInteger (java.math.BigInteger)90 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)88 HashMap (java.util.HashMap)78 File (java.io.File)74 ProductSubscription (rhsm.data.ProductSubscription)72 InstalledProduct (rhsm.data.InstalledProduct)66 EntitlementCert (rhsm.data.EntitlementCert)58 ProductCert (rhsm.data.ProductCert)54 YumRepo (rhsm.data.YumRepo)34 Repo (rhsm.data.Repo)26 Calendar (java.util.Calendar)25 List (java.util.List)24