Search in sources :

Example 1 with ConsumerType

use of rhsm.base.ConsumerType 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 2 with ConsumerType

use of rhsm.base.ConsumerType 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 3 with ConsumerType

use of rhsm.base.ConsumerType in project rhsm-qe by RedHatQE.

the class RegisterTests method getRegisterWithNameAndTypeDataAsListOfLists.

protected List<List<Object>> getRegisterWithNameAndTypeDataAsListOfLists() throws JSONException, Exception {
    List<List<Object>> ll = new ArrayList<List<Object>>();
    if (!isSetupBeforeSuiteComplete)
        return ll;
    String username = sm_clientUsername;
    String password = sm_clientPassword;
    String owner = sm_clientOrg;
    List<String> registerableConsumerTypes = new ArrayList<String>();
    JSONArray jsonConsumerTypes = new JSONArray(CandlepinTasks.getResourceUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, "/consumertypes"));
    for (int i = 0; i < jsonConsumerTypes.length(); i++) {
        JSONObject jsonConsumerType = (JSONObject) jsonConsumerTypes.get(i);
        String consumerType = jsonConsumerType.getString("label");
        registerableConsumerTypes.add(consumerType);
    }
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.20.2-1")) {
        // Allowing a RHUI type to register is now acceptable, but not advertised
        if (!registerableConsumerTypes.contains(ConsumerType.RHUI.toString()))
            registerableConsumerTypes.add(ConsumerType.RHUI.toString());
    }
    // iterate across all ConsumerType values and append rows to the dataProvider
    for (ConsumerType type : ConsumerType.values()) {
        String name = type.toString() + "_NAME";
        // decide what username and password to test with
        if (type.equals(ConsumerType.person) && !getProperty("sm.rhpersonal.username", "").equals("")) {
            username = sm_rhpersonalUsername;
            password = sm_rhpersonalPassword;
            owner = sm_rhpersonalOrg;
        } else {
            username = sm_clientUsername;
            password = sm_clientPassword;
            owner = sm_clientOrg;
        }
        // String username, String password, String owner, String name, ConsumerType type, Integer expectedExitCode, String expectedStdoutRegex, String expectedStderrRegex
        if (registerableConsumerTypes.contains(type.toString())) {
            /* applicable to RHEL61 and RHEL57
				if (type.equals(ConsumerType.person)) {
					ll.add(Arrays.asList(new Object[] {new BlockedByBzBug("661130"),	username,	password,	name,	type,	Integer.valueOf(0),	"[a-f,0-9,\\-]{36} "+username,	null}));
				} else {
					ll.add(Arrays.asList(new Object[]{null,  							username,	password,	name,	type,	Integer.valueOf(0),	"[a-f,0-9,\\-]{36} "+name,	null}));			
				}
				*/
            Integer expectedExitCode = new Integer(0);
            String expectedStdoutRegex = "The system has been registered with ID: [a-f,0-9,\\-]{36}";
            String expectedStderrRegex = null;
            if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", /*TODO CHANGE TO ">" after candlepin 2.1.2-1 is tagged*/
            "2.1.1-1")) {
                // candlepin commit 739b51a0d196d9d3153320961af693a24c0b826f Bug 1455361: Disallow candlepin consumers to be registered via Subscription Manager
                if (ConsumerType.candlepin.equals(type) | ConsumerType.headpin.equals(type) | ConsumerType.katello.equals(type)) {
                    // FINE: ssh root@jsefler-rhel7.usersys.redhat.com subscription-manager register --username=testuser1 --password=password --org=admin --type=candlepin --name="candlepin_NAME"
                    // FINE: Stdout: Registering to: jsefler-candlepin.usersys.redhat.com:8443/candlepin
                    // FINE: Stderr: You may not create a manifest consumer via Subscription Manager.
                    // FINE: ExitCode: 70
                    expectedStdoutRegex = null;
                    expectedStderrRegex = "You may not create a manifest consumer via Subscription Manager.";
                    expectedExitCode = Integer.valueOf(70);
                }
            }
            if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.1.1-1")) {
                // candlepin commit 6976b7c45d48945d6d0bf1118bd1d8edebceb1f0
                if (ConsumerType.share.equals(type)) {
                    // FINE: ssh root@jsefler-rhel7.usersys.redhat.com subscription-manager register --username=testuser1 --password=password --org=admin --type=share --name="share_NAME"
                    // FINE: Stdout: Registering to: jsefler-candlepin.usersys.redhat.com:8443/candlepin
                    // FINE: Stderr: A unit type of "share" cannot have installed products
                    // FINE: ExitCode: 70
                    expectedStdoutRegex = null;
                    // Note: assuming there is at least one installed product since our client is a RHEL product afterall
                    expectedStderrRegex = "A unit type of \"share\" cannot have installed products";
                    expectedExitCode = Integer.valueOf(70);
                }
            }
            ll.add(Arrays.asList(new Object[] { null, username, password, owner, name, type, expectedExitCode, expectedStdoutRegex, expectedStderrRegex }));
        } else {
            String expectedStderrRegex = "No such consumer type: " + type;
            if (!clienttasks.workaroundForBug876764(sm_serverType))
                expectedStderrRegex = "No such unit type: " + type;
            // changed to this by bug 876758 comment 5; https://bugzilla.redhat.com/show_bug.cgi?id=876758#c5
            expectedStderrRegex = String.format("Unit type '%s' could not be found.", type);
            Integer expectedExitCode = new Integer(255);
            // EX_SOFTWARE	// post commit df95529a5edd0be456b3528b74344be283c4d258
            if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.13.8-1"))
                expectedExitCode = new Integer(70);
            ll.add(Arrays.asList(new Object[] { null, username, password, owner, name, type, expectedExitCode, null, expectedStderrRegex }));
        }
    }
    // process all of the rows and change the expected results due to 1461003: Deprecate --type option on register command
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.20.2-1")) {
        // post commit e0c34a729e9e347ab1e0f4f5fa656c8b20205fdf RFE Bug 1461003: Deprecate --type option on register command
        for (List<Object> l : ll) {
            // get the existing BlockedByBzBug
            BlockedByBzBug blockedByBzBug = (BlockedByBzBug) l.get(0);
            ConsumerType type = (ConsumerType) l.get(5);
            if (!type.equals(ConsumerType.system) && !type.equals(ConsumerType.RHUI)) {
                List<String> bugIds = blockedByBzBug == null ? new ArrayList<String>() : new ArrayList<String>(Arrays.asList(blockedByBzBug.getBugIds()));
                // Bug 1461003 - [RFE] Remove --type option from subscription-manager register
                bugIds.add("1461003");
                blockedByBzBug = new BlockedByBzBug(bugIds.toArray(new String[] {}));
                l.set(0, blockedByBzBug);
                // EX_USAGE
                l.set(6, new Integer(64));
                // stdout
                l.set(7, "");
                // stderr
                l.set(8, "Error: The --type option has been deprecated and may not be used.");
            }
            if (type.equals(ConsumerType.RHUI)) {
                List<String> bugIds = blockedByBzBug == null ? new ArrayList<String>() : new ArrayList<String>(Arrays.asList(blockedByBzBug.getBugIds()));
                // Bug 1485008 - subscription-manager register --type="RHUI" or --type="rhui" should both work as documented in various KBase articles
                bugIds.add("1485008");
                blockedByBzBug = new BlockedByBzBug(bugIds.toArray(new String[] {}));
                l.set(0, blockedByBzBug);
            }
        }
    }
    return ll;
}
Also used : ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) List(java.util.List) JSONObject(org.json.JSONObject) ConsumerType(rhsm.base.ConsumerType) BlockedByBzBug(com.redhat.qe.auto.bugzilla.BlockedByBzBug)

Example 4 with ConsumerType

use of rhsm.base.ConsumerType in project rhsm-qe by RedHatQE.

the class ActivationKeyTests method testRegisterWithActivationKeyContainingPoolWithQuantity.

/**
 * @param blockedByBug
 * @param keyName
 * @param jsonPool
 * @param addQuantity
 * @return If an attempt to register with the proposed activation key (made with the given keyName, jsonPool, and addQuantity) is made, then the result from the register is returned.  If no attempt is made, then null is returned.
 * @throws JSONException
 * @throws Exception
 */
@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-47896", "RHEL7-96498" }, linkedWorkItems = { @LinkedItem(// RHSM-REQ : subscription-manager cli registration and deregistration
workitemId = "RHEL6-28485", project = Project.RHEL6, role = DefTypes.Role.VERIFIES), @LinkedItem(// RHSM-REQ : subscription-manager cli registration and deregistration
workitemId = "RHEL7-84906", project = Project.RedHatEnterpriseLinux7, role = DefTypes.Role.VERIFIES) }, 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, add a pool to it with a quantity, and then register with the activation key (include variations on valid/invalid quantities)", groups = { "Tier3Tests", "blockedByBug-973838" }, dataProvider = "getRegisterWithActivationKeyContainingPoolWithQuantityData", enabled = true)
public // @ImplementsNitrateTest(caseId=)
SSHCommandResult testRegisterWithActivationKeyContainingPoolWithQuantity(Object blockedByBug, String keyName, JSONObject jsonPool, Integer addQuantity) throws JSONException, Exception {
    // if (!jsonPool.getString("productId").equals("awesomeos-virt-4")) throw new SkipException("debugging...");
    // if (jsonPool.getInt("quantity")!=-1) throw new SkipException("debugging...");
    // if (!jsonPool.getString("productId").equals("awesomeos-virt-unlimited")) throw new SkipException("debugging...");
    String poolId = jsonPool.getString("id");
    // TEMPORARY WORKAROUND FOR BUG: https://bugzilla.redhat.com/show_bug.cgi?id=728721 - jsefler 8/6/2011
    if (CandlepinTasks.isPoolProductConsumableByConsumerType(sm_clientUsername, sm_clientPassword, sm_serverUrl, poolId, ConsumerType.person)) {
        boolean invokeWorkaroundWhileBugIsOpen = true;
        String bugId = "728721";
        try {
            if (invokeWorkaroundWhileBugIsOpen && BzChecker.getInstance().isBugOpen(bugId)) {
                log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId).toString() + " Bugzilla " + bugId + ".  (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId + ")");
                SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId);
            } else {
                invokeWorkaroundWhileBugIsOpen = false;
            }
        } catch (BugzillaAPIException be) {
        /* ignore exception */
        } catch (RuntimeException re) {
        /* ignore exception */
        }
        if (invokeWorkaroundWhileBugIsOpen) {
            throw new SkipException("Skipping this test while bug '" + bugId + "' is open. (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId + ")");
        }
    }
    // END OF WORKAROUND
    // generate a unique activation key name for this test
    // String keyName = String.format("ActivationKey%s_ForPool%s", System.currentTimeMillis(), poolId);
    // create a JSON object to represent the request body
    Map<String, String> mapActivationKeyRequest = new HashMap<String, String>();
    mapActivationKeyRequest.put("name", keyName);
    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.assertEquals(jsonActivationKey.getString("name"), keyName, "Activation key creation attempt appears successful.  Activation key: " + jsonActivationKey);
    // add the pool with a random available quantity (?quantity=#) to the activation key
    int quantityAvail = jsonPool.getInt("quantity") - jsonPool.getInt("consumed");
    JSONObject jsonResult = new JSONObject(CandlepinTasks.postResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/activation_keys/" + jsonActivationKey.getString("id") + "/pools/" + poolId + (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 (addQuantity == null) {
    // addQuantity=1;	// this was true before Bug 1023568 - [RFE] bind requests using activation keys that do not specify a quantity should automatically use the quantity needed to achieve compliance
    }
    // handle the case when the pool productAttributes contain name:"requires_consumer_type" value:"person"
    if (ConsumerType.person.toString().equals(CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, poolId, "requires_consumer_type"))) {
        // assert that the adding of the pool to the key was NOT successful (contains a displayMessage from some thrown exception)
        if (jsonResult.has("displayMessage")) {
            String displayMessage = jsonResult.getString("displayMessage");
            // Assert.assertEquals(displayMessage,"Pools requiring a 'person' consumer should not be added to an activation key since a consumer type of 'person' cannot be used with activation keys","Expected the addition of a requires consumer type person pool '"+poolId+"' to activation key named '"+keyName+"' with quantity '"+addQuantity+"' to be blocked.");
            Assert.assertEquals(displayMessage, "Cannot add pools restricted to consumer type 'person' to activation keys.", "Expected the addition of a requires consumer type person pool '" + poolId + "' to activation key named '" + keyName + "' with quantity '" + addQuantity + "' to be blocked.");
        } else {
            log.warning("The absense of a displayMessage indicates the activation key creation was probably successful when we expected it to fail since we should be blocked from adding pools that require consumer type person to an activation key.");
            Assert.assertFalse(keyName.equals(jsonActivationKey.getString("name")), "Pool '" + poolId + "' which requires a consumer type 'person' should NOT have been added to the following activation key with any quantity: " + jsonActivationKey);
        }
        return null;
    }
    // handle the case when the pool is NOT multi_entitlement and we tried to add the pool to the key with a quantity > 1
    if (!CandlepinTasks.isPoolProductMultiEntitlement(sm_clientUsername, sm_clientPassword, sm_serverUrl, poolId) && addQuantity != null && addQuantity > 1) {
        // assert that the adding of the pool to the key was NOT successful (contains a displayMessage from some thrown exception)
        if (jsonResult.has("displayMessage")) {
            String displayMessage = jsonResult.getString("displayMessage");
            Assert.assertEquals(displayMessage, "Error: Only pools with multi-entitlement product subscriptions can be added to the activation key with a quantity greater than one.", "Expected the addition of a non-multi-entitlement pool '" + poolId + "' to activation key named '" + keyName + "' with quantity '" + addQuantity + "' to be blocked.");
        } else {
            log.warning("The absense of a displayMessage indicates the activation key creation was probably successful when we expected it to fail due to greater than one quantity '" + addQuantity + "'.");
            Assert.assertFalse(keyName.equals(jsonActivationKey.getString("name")), "Non multi-entitlement pool '" + poolId + "' should NOT have been added to the following activation key with a quantity '" + addQuantity + "' greater than one: " + jsonActivationKey);
        }
        return null;
    }
    // handle the case when the quantity is excessive
    if (addQuantity != null && addQuantity > jsonPool.getInt("quantity") && addQuantity > 1) {
        String expectedDisplayMessage = "The quantity must not be greater than the total allowed for the pool";
        if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "0.9.37-1")) {
            // commit 3cdb39430c86de141405e815a2a428ad64b1c220	// Removed rules for activation key creation. Relaxation of activation key rules at register time means the keys can have many more differing pools at create time
            // new relaxed behavior
            log.warning("Prior to candlepin commit 3cdb39430c86de141405e815a2a428ad64b1c220, this test asserted that candlepin attempts to create an activation key that attached a pool quantity exceeding its total pool size would be blocked.  This is now relaxed.  QE believes that this will cause usability issues.");
            Assert.assertFalse(jsonResult.has("displayMessage"), "After candlepin-common-1.0.17-1, attempts to create an activation key that attached a pool quantity exceeding its total pool size are permitted.  QE believes that this will cause usability issues.");
        } else {
            // assert that adding the pool to the key was NOT successful (contains a displayMessage)
            if (jsonResult.has("displayMessage")) {
                String displayMessage = jsonResult.getString("displayMessage");
                Assert.assertEquals(displayMessage, expectedDisplayMessage, "Expected the addition of multi-entitlement pool '" + poolId + "' to activation key named '" + keyName + "' with an excessive quantity '" + addQuantity + "' to be blocked.");
            } 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 excessive quantity '" + addQuantity + "'.");
                Assert.assertFalse(keyName.equals(jsonActivationKey.getString("name")), "Pool '" + poolId + "' should NOT have been added to the following activation key with an excessive quantity '" + addQuantity + "': " + jsonActivationKey);
            }
            return null;
        }
    }
    // handle the case when the quantity is insufficient (less than one)
    if (addQuantity != null && addQuantity < 1) {
        // assert that adding the pool to the key was NOT successful (contains a displayMessage)
        if (jsonResult.has("displayMessage")) {
            String displayMessage = jsonResult.getString("displayMessage");
            Assert.assertEquals(displayMessage, "The quantity must be greater than 0", "Expected the addition of pool '" + poolId + "' to activation key named '" + keyName + "' with quantity '" + addQuantity + "' less than one be blocked.");
        } else {
            log.warning("The absense of a displayMessage indicates the activation key creation was probably successful when we expected it to fail due to insufficient quantity '" + addQuantity + "'.");
            Assert.assertFalse(keyName.equals(jsonActivationKey.getString("name")), "Pool '" + poolId + "' should NOT have been added to the following activation key with insufficient quantity '" + addQuantity + "': " + jsonActivationKey);
        }
        return null;
    }
    // assert the pool is added
    jsonActivationKey = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, "/activation_keys/" + jsonActivationKey.getString("id")));
    String addedPoolId = null;
    if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.0.12-1")) {
        // candlepin commit a868d9706b722cb548d697854c42e7de97a3ec9b Added a DTO for activation keys
        // [root@jsefler-rhel7 ~]# curl --stderr /dev/null --insecure --user admin:admin --request GET https://jsefler-candlepin.usersys.redhat.com:8443/candlepin/activation_keys/8a90860f54ce9e030154ceef3f2010b6 | python -m json/tool
        // {
        // "autoAttach": null,
        // "contentOverrides": [],
        // "created": "2016-05-20T16:11:06+0000",
        // "description": null,
        // "id": "8a90860f54ce9e030154ceef3f2010b6",
        // "name": "ActivationKey1463760627557_ForPool8a90860f54ce9e030154ce9faf820933_Quantity2",
        // "owner": {
        // "displayName": "Admin Owner",
        // "href": "/owners/admin",
        // "id": "8a90860f54ce9e030154ce9f136c0002",
        // "key": "admin"
        // },
        // "pools": [
        // {
        // "poolId": "8a90860f54ce9e030154ce9faf820933",
        // "quantity": 2
        // }
        // ],
        // "products": [],
        // "releaseVer": {
        // "releaseVer": null
        // },
        // "serviceLevel": null,
        // "updated": "2016-05-20T16:11:06+0000"
        // }
        // get(0) since there should only be one pool added
        addedPoolId = ((JSONObject) jsonActivationKey.getJSONArray("pools").get(0)).getString("poolId");
    } else {
        // # curl -k -u admin:admin https://jsefler-onprem-62candlepin.usersys.redhat.com:8443/candlepin/activation_keys/8a90f8c63196bb2001319f66afa83cb4 | python -mjson.tool
        // {
        // "created": "2011-08-06T14:02:12.264+0000",
        // "id": "8a90f8c63196bb2001319f66afa83cb4",
        // "name": "ActivationKey1312639332183_ForPool8a90f8c63196bb20013196bc7f6302dc",
        // "owner": {
        // "displayName": "Admin Owner",
        // "href": "/owners/admin",
        // "id": "8a90f8c63196bb20013196bb9e210006",
        // "key": "admin"
        // },
        // "pools": [
        // {
        // "created": "2011-08-06T14:02:12.419+0000",
        // "id": "8a90f8c63196bb2001319f66b0433cb6",
        // "pool": {
        // "href": "/pools/8a90f8c63196bb20013196bc7f6302dc",
        // "id": "8a90f8c63196bb20013196bc7f6302dc"
        // },
        // "quantity": 1,
        // "updated": "2011-08-06T14:02:12.419+0000"
        // }
        // ],
        // "updated": "2011-08-06T14:02:12.264+0000"
        // }
        // get(0) since there should only be one pool added
        addedPoolId = ((JSONObject) jsonActivationKey.getJSONArray("pools").get(0)).getJSONObject("pool").getString("id");
    }
    Assert.assertEquals(addedPoolId, poolId, "Pool id '" + poolId + "' appears to be successfully added to activation key: " + jsonActivationKey);
    if (addQuantity != null) {
        // get(0) since there should only be one pool added
        Integer addedQuantity = ((JSONObject) jsonActivationKey.getJSONArray("pools").get(0)).getInt("quantity");
        Assert.assertEquals(addedQuantity, addQuantity, "Pool id '" + poolId + "' appears to be successfully added with quantity '" + addQuantity + "' to activation key: " + jsonActivationKey);
    } else {
        // only possible after Bug 1023568 - [RFE] bind requests using activation keys that do not specify a quantity should automatically use the quantity needed to achieve compliance
        Assert.assertTrue(((JSONObject) jsonActivationKey.getJSONArray("pools").get(0)).isNull("quantity"), "Pool id '" + poolId + "' appears to be successfully added with a null quantity to 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);
    // handle the case when "Consumers of this type are not allowed to subscribe to the pool with id '"+poolId+"'."
    ConsumerType activationkeyPoolRequiresConsumerType = null;
    if (!CandlepinTasks.isPoolProductConsumableByConsumerType(sm_clientUsername, sm_clientPassword, sm_serverUrl, poolId, ConsumerType.system)) {
        String expectedStderr = String.format("Consumers of this type are not allowed to subscribe to the pool with id '%s'.", poolId);
        if (!clienttasks.workaroundForBug876764(sm_serverType))
            expectedStderr = String.format("Units of this type are not allowed to attach the pool with ID '%s'.", poolId);
        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 system consumer using an activationKey containing a pool that requires a non-system consumer type should fail.");
        Assert.assertEquals(registerResult.getExitCode(), expectedExitCode, "The exitCode from registering a system consumer using an activationKey containing a pool that requires a non-system consumer type 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.");
        // now register with the same activation key using the needed ConsumerType
        activationkeyPoolRequiresConsumerType = ConsumerType.valueOf(CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, poolId, "requires_consumer_type"));
        registerResult = clienttasks.register_(null, null, sm_clientOrg, null, activationkeyPoolRequiresConsumerType, null, null, null, null, null, jsonActivationKey.getString("name"), null, null, null, false, /*was already unregistered by force above*/
        null, null, null, null, null);
        if (activationkeyPoolRequiresConsumerType != null) {
            if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.20.2-1")) {
                // post commit e0c34a729e9e347ab1e0f4f5fa656c8b20205fdf RFE Bug 1461003: Deprecate --type option on register command
                expectedStderr = "Error: The --type option has been deprecated and may not be used.";
                expectedExitCode = new Integer(64);
                Assert.assertEquals(registerResult.getStderr().trim(), expectedStderr, "Registering a system consumer using an activationKey containing a pool that requires a non-system consumer type should fail.");
                Assert.assertEquals(registerResult.getExitCode(), expectedExitCode, "The exitCode from registering a system consumer using an activationKey containing a pool that requires a non-system consumer type should fail.");
                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\":\"" + activationkeyPoolRequiresConsumerType + "\"");
            }
        }
    }
    // resolution to: Bug 728721 - NullPointerException thrown when registering with an activation key bound to a pool that requires_consumer_type person
    if (ConsumerType.person.equals(activationkeyPoolRequiresConsumerType)) {
        Assert.assertEquals(registerResult.getStderr().trim(), "A consumer type of 'person' cannot be used with activation keys", "Registering with an activationKey containing a pool that requires_consumer_type=person should fail.");
        Assert.assertEquals(registerResult.getExitCode(), Integer.valueOf(255), "The exitCode from registering with an activationKey containing a pool that requires a person consumer 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.");
        Assert.assertEquals(clienttasks.getCurrentlyConsumedProductSubscriptions().size(), 0, "No subscriptions should be consumed after attempting to register with an activationKey containing a pool that requires a person consumer type.");
        return registerResult;
    }
    // handle the case when our quantity request exceeds the quantityAvail (when pool quantity is NOT unlimited)
    if ((addQuantity != null) && (addQuantity > quantityAvail) && (jsonPool.getInt("quantity") != -1)) {
        // Assert.assertEquals(registerResult.getStderr().trim(), String.format("No entitlements are available from the pool with id '%s'.",poolId), "Registering with an activationKey containing a pool for which not enough entitlements remain should fail.");	// expected string changed by bug 876758
        String expectedStderr = String.format("No subscriptions are available from the pool with id '%s'.", poolId);
        if (!clienttasks.workaroundForBug876764(sm_serverType))
            expectedStderr = String.format("No subscriptions are available from the pool with ID '%s'.", poolId);
        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\".", poolId);
        }
        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 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 not 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.");
        return registerResult;
    }
    // handle the case when our candlepin is standalone and we have attempted a subscribe to 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)) {
            // TEMPORARY WORKAROUND FOR BUG: https://bugzilla.redhat.com/show_bug.cgi?id=756628
            boolean invokeWorkaroundWhileBugIsOpen = true;
            String bugId = "756628";
            try {
                if (invokeWorkaroundWhileBugIsOpen && BzChecker.getInstance().isBugOpen(bugId)) {
                    log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId).toString() + " Bugzilla " + bugId + ".  (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId + ")");
                    SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId);
                } else {
                    invokeWorkaroundWhileBugIsOpen = false;
                }
            } catch (BugzillaAPIException be) {
            /* ignore exception */
            } catch (RuntimeException re) {
            /* ignore exception */
            }
            if (invokeWorkaroundWhileBugIsOpen) {
                // 201111232226:08.420 - FINE: ssh root@jsefler-onprem-5server.usersys.redhat.com subscription-manager register --org=admin --activationkey=ActivationKey1322105167469_ForPool8a90f85733d31add0133d337f9410c52 --force
                // 201111232226:10.299 - FINE: Stdout: The system with UUID bd0271b6-2a0c-41b5-bbb8-df0ad4c7a088 has been unregistered
                // 201111232226:10.299 - FINE: Stderr: Unable to entitle consumer to the pool with id '8a90f85733d31add0133d337f9410c52'.: virt.guest.host.does.not.match.pool.owner
                // 201111232226:10.300 - FINE: ExitCode: 255
                Assert.assertTrue(registerResult.getStderr().trim().startsWith("Unable to entitle consumer to the pool with id '" + poolId + "'."), "Expected stderr to start with: \"Unable to entitle consumer to the pool with id '" + poolId + "'.\" because the host has not registered.");
                Assert.assertEquals(registerResult.getExitCode(), Integer.valueOf(255), "The exitCode from registering with an activationKey containing a virt_only derived_pool on a standalone candlepin server for which our system's host is not registered.");
                // 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.");
                return registerResult;
            }
            // 201112021710:31.299 - FINE: ExitCode: 255
            if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, "<", "0.9.45-1")) {
                // valid prior to the pools of "type": "UNMAPPED_GUEST"
                Assert.assertEquals(registerResult.getStderr().trim(), "Guest's host does not match owner of pool: '" + poolId + "'.");
                Assert.assertEquals(registerResult.getExitCode(), Integer.valueOf(255), "The exitCode from registering with an activationKey containing a virt_only derived_pool on a standalone candlepin server for which our system's host is not registered.");
                // 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.");
                return registerResult;
            } else {
            // TODO beyond the scope of this test, we could assert that the consumed subscription details match...
            // Status Details:      Guest has not been reported on any host and is using a temporary unmapped guest subscription.
            // [root@jsefler-os6 ~]# subscription-manager list --consumed
            // +-------------------------------------------+
            // Consumed Subscriptions
            // +-------------------------------------------+
            // Subscription Name:   Awesome OS Instance Based (Standard Support)
            // Provides:            Awesome OS Instance Server Bits
            // SKU:                 awesomeos-instancebased
            // Contract:            0
            // Account:             12331131231
            // Serial:              4452426557824085674
            // Pool ID:             ff8080814d6d978a014d6d98c5f41aaa
            // Provides Management: No
            // Active:              True
            // Quantity Used:       1
            // Service Level:       Standard
            // Service Type:        L1-L3
            // Status Details:      Guest has not been reported on any host and is using a temporary unmapped guest subscription.
            // Subscription Type:   Instance Based (Temporary)
            // Starts:              05/18/2015
            // Ends:                05/20/2015
            // System Type:         Virtual
            }
        }
    }
    // handle the case when the pool is restricted to a system that is not the same type as the pool
    boolean isSystemVirtual = Boolean.valueOf(clienttasks.getFactValue("virt.is_guest"));
    if (isSystemVirtual && CandlepinTasks.isPoolRestrictedToPhysicalSystems(sm_clientUsername, sm_clientPassword, sm_serverUrl, poolId)) {
        String expectedStderr = "Pool is restricted to physical systems: '" + poolId + "'.";
        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, "Expected feedback when pool is restricted to physical systems.");
        Assert.assertEquals(registerResult.getExitCode(), expectedExitCode, "The exitCode from registering with an activationKey containing a physical_only pool while the registering system is virtual.");
        return registerResult;
    }
    if (!isSystemVirtual && CandlepinTasks.isPoolRestrictedToVirtualSystems(sm_clientUsername, sm_clientPassword, sm_serverUrl, poolId)) {
        String expectedStderr = "Pool is restricted to virtual guests: '" + poolId + "'.";
        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, "Expected feedback when pool is restricted to virtual guests.");
        Assert.assertEquals(registerResult.getExitCode(), expectedExitCode, "The exitCode from registering with an activationKey containing a virt_only pool while the registering system is physical.");
        return registerResult;
    }
    // TEMPORARY WORKAROUND FOR BUG: 1183122 - rhsmd/subman dbus traceback on 'attach --pool'
    if (registerResult.getStderr().contains("KeyError: 'product_id'")) {
        boolean invokeWorkaroundWhileBugIsOpen = true;
        String bugId = "1183122";
        try {
            if (invokeWorkaroundWhileBugIsOpen && BzChecker.getInstance().isBugOpen(bugId)) {
                log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId).toString() + " Bugzilla " + bugId + ".  (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId + ")");
                SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId);
            } else {
                invokeWorkaroundWhileBugIsOpen = false;
            }
        } catch (BugzillaAPIException be) {
        /* ignore exception */
        } catch (RuntimeException re) {
        /* ignore exception */
        }
        if (invokeWorkaroundWhileBugIsOpen) {
            log.warning("Encountered bug '" + bugId + "'. Skipping stderr assertion from the prior register with activationkey command while bug '" + bugId + "' is open.");
        }
    } else
        // Assert.assertEquals(registerResult.getStderr().trim(), "");
        // END OF WORKAROUND
        // assert success
        Assert.assertEquals(registerResult.getStderr().trim(), "");
    // Assert.assertNotSame(registerResult.getExitCode(), Integer.valueOf(255), "The exit code from the register command does not indicate a failure.");
    Assert.assertTrue(registerResult.getExitCode() <= 1, "The exit code from the register command does not indicate a failure.");
    // assert that only the pool's providedProducts (excluding type=MKT products) are consumed (unless it is a ManagementAddOn product - indicated by no providedProducts)
    assertProvidedProductsFromPoolAreWithinConsumedProductSubscriptionsUsingQuantity(jsonPool, clienttasks.getCurrentlyConsumedProductSubscriptions(), addQuantity, true);
    // assert that the YumRepos immediately reflect the entitled contentNamespace labels // added for the benefit of Bug 973838 - subscription-manager needs to refresh redhat.repo when registering against katello
    verifyCurrentEntitlementCertsAreReflectedInCurrentlySubscribedYumRepos(clienttasks.getCurrentProductCerts());
    return registerResult;
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) SkipException(org.testng.SkipException) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) ConsumerType(rhsm.base.ConsumerType) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 5 with ConsumerType

use of rhsm.base.ConsumerType in project rhsm-qe by RedHatQE.

the class ContentIntegrationTests method getContentNamespaceDataAsListOfLists.

protected List<List<Object>> getContentNamespaceDataAsListOfLists() throws JSONException {
    List<List<Object>> ll = new ArrayList<List<Object>>();
    for (List<Object> row : contentNamespaceData) {
        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);
        ContentNamespace contentNamespace = (ContentNamespace) row.get(5);
        EntitlementCert entitlementCert = (EntitlementCert) row.get(6);
        // 
        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)

Aggregations

JSONObject (org.json.JSONObject)6 ConsumerType (rhsm.base.ConsumerType)6 ArrayList (java.util.ArrayList)4 List (java.util.List)4 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)2 SSHCommandResult (com.redhat.qe.tools.SSHCommandResult)2 JSONArray (org.json.JSONArray)2 SkipException (org.testng.SkipException)2 Test (org.testng.annotations.Test)2 ContentNamespace (rhsm.data.ContentNamespace)2 EntitlementCert (rhsm.data.EntitlementCert)2 BlockedByBzBug (com.redhat.qe.auto.bugzilla.BlockedByBzBug)1 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)1 HashMap (java.util.HashMap)1 SubscriptionPool (rhsm.data.SubscriptionPool)1