Search in sources :

Example 46 with SubscriptionPool

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

the class ExpirationTests method testPoolIsRemovedAfterSubscriptionExpires.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-37710", "RHEL7-51450" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier2")
@Test(description = "assert that a soon to expire pool is removed from availablity after it expires", groups = { "Tier2Tests", "blockedByBug-1555582" }, dependsOnGroups = {}, enabled = true)
public void testPoolIsRemovedAfterSubscriptionExpires() throws Exception {
    // create a subscription pool that will expire 2 minutes from now
    int endingMinutesFromNow = 2;
    String expiringPoolId = createTestPool(-60 * 24, endingMinutesFromNow);
    // assert the expiring pool is currently available
    SubscriptionPool expiringPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", expiringPoolId, clienttasks.getCurrentlyAllAvailableSubscriptionPools());
    Assert.assertNotNull(expiringPool, "The expiring SubscriptionPool is currently available for subscribing: " + expiringPool);
    // wait for pool to expire
    // plus a 30 sec buffer;
    sleep(endingMinutesFromNow * 60 * 1000 + 30 * 1000);
    // assert pool is no longer available
    SubscriptionPool expiredPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", expiringPoolId, clienttasks.getCurrentlyAllAvailableSubscriptionPools());
    Assert.assertNull(expiredPool, "The expired SubscriptionPool is no longer available for subscribing");
}
Also used : SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 47 with SubscriptionPool

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

the class FactsTests method testFactCheckRhelDistribution.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36610", "RHEL7-59318" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier2")
@Test(description = "subscription-manager: facts and rules: fact check RHEL distribution", groups = { "Tier2Tests", "blockedByBug-666540" }, dependsOnGroups = {}, enabled = true)
@ImplementsNitrateTest(caseId = 56329)
public void testFactCheckRhelDistribution() {
    // skip if client1 and client2 are not a Server and Workstation distributions
    SSHCommandRunner workClient = null, servClient = null;
    SubscriptionManagerTasks workClientTasks = null, servClientTasks = null;
    if (client1 != null && client1tasks.getRedhatRelease().startsWith("Red Hat Enterprise Linux Workstation")) {
        workClient = client1;
        workClientTasks = client1tasks;
    }
    if (client2 != null && client2tasks.getRedhatRelease().startsWith("Red Hat Enterprise Linux Workstation")) {
        workClient = client2;
        workClientTasks = client2tasks;
    }
    if (client1 != null && client1tasks.getRedhatRelease().startsWith("Red Hat Enterprise Linux Server")) {
        servClient = client1;
        servClientTasks = client1tasks;
    }
    if (client2 != null && client2tasks.getRedhatRelease().startsWith("Red Hat Enterprise Linux Server")) {
        servClient = client2;
        servClientTasks = client2tasks;
    }
    if (workClient == null || servClient == null) {
        throw new SkipException("This test requires a RHEL Workstation client and a RHEL Server client.");
    }
    // start with fresh registrations using the same clientusername user
    workClientTasks.unregister(null, null, null, null);
    servClientTasks.unregister(null, null, null, null);
    workClientTasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, null, false, null, null, null, null);
    servClientTasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, null, false, null, null, null, null);
    // get all the pools available to each client
    List<SubscriptionPool> workClientPools = workClientTasks.getCurrentlyAvailableSubscriptionPools();
    List<SubscriptionPool> servClientPools = servClientTasks.getCurrentlyAvailableSubscriptionPools();
    log.info("Verifying that the pools available to the Workstation consumer are not identitcal to those available to the Server consumer...");
    if (!(!workClientPools.containsAll(servClientPools) || !servClientPools.containsAll(workClientPools))) {
        // TODO This testcase needs more work.  Running on different variants of RHEL alone is not enough to assert that the available pools are different.  In fact, then should be the same if the subscriptions are all set with a variant attribute of ALL
        throw new SkipException("The info message above is not accurate... The assertion that the pools available to a Workstation consumer versus a Server consumer is applicable ONLY when the org's subscriptions includes a variant aware subscription.  In fact, if the org's subscriptions are all set with a variant attribute of ALL, then the available pools should be identical.  This automated test needs some work.");
    }
    Assert.assertTrue(!workClientPools.containsAll(servClientPools) || !servClientPools.containsAll(workClientPools), "Because the facts of a system client running RHEL Workstation versus RHEL Server should be different, the available subscription pools to these two systems should not be the same.");
// FIXME TODO Verify with development that these are valid asserts
// log.info("Verifying that the pools available to the Workstation consumer do not contain Server in the ProductName...");
// log.info("Verifying that the pools available to the Server consumer do not contain Workstation in the ProductName...");
}
Also used : SSHCommandRunner(com.redhat.qe.tools.SSHCommandRunner) SubscriptionManagerTasks(rhsm.cli.tasks.SubscriptionManagerTasks) SkipException(org.testng.SkipException) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 48 with SubscriptionPool

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

the class FactsTests method testBypassRulesDueToTypeAndCapabilities.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36607", "RHEL7-51419" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier2")
@Test(description = "subscription-manager: facts and rules: bypass rules due to candlepin type and capabilities", groups = { "Tier2Tests", "blockedByBug-641027", "BypassRulesDueToTypeAndCapabilities_Test" }, dependsOnGroups = {}, enabled = true)
@ImplementsNitrateTest(caseId = 56331)
public void testBypassRulesDueToTypeAndCapabilities() throws Exception {
    // this list will grow in time as candlepins are programmed to handle more subscription types (I got this list from the dev team)
    // List<String> allCapabilities = Arrays.asList(new String[]{"cores", "ram", "instance_multiplier", "derived_product", "cert_v3"});
    // we can actually get this list from the candlepin API call to /status
    List<String> allCapabilities = servertasks.statusCapabilities;
    // randomly reorder this list
    allCapabilities = getRandomSubsetOfList(allCapabilities, allCapabilities.size());
    // set minimal facts
    // these facts will prevent cores, sockets, and ram from interfering with compliance based on the system arch
    Map<String, String> factsMap = new HashMap<String, String>();
    factsMap.put("cpu.cpu_socket(s)", "1");
    factsMap.put("cpu.core(s)_per_socket", "1");
    factsMap.put("memory.memtotal", "1");
    clienttasks.createFactsFileWithOverridingValues(factsMap);
    // register (as type candlepin)
    String consumerId;
    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
        clienttasks.unregister(null, null, null, null);
        clienttasks.registerCandlepinConsumer(sm_clientUsername, sm_clientPassword, sm_clientOrg, sm_serverUrl, "candlepin");
        consumerId = clienttasks.getCurrentConsumerId();
    } else {
        consumerId = clienttasks.getCurrentConsumerId(clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, ConsumerType.candlepin, null, null, null, null, null, (String) null, null, null, null, true, false, null, null, null, null));
    }
    // by default, this consumer starts out with no capabilities
    JSONObject jsonConsumer = (JSONObject) new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/consumers/" + consumerId));
    JSONArray jsonCapabilities = jsonConsumer.getJSONArray("capabilities");
    Assert.assertTrue(jsonCapabilities.length() == 0, "By default, a freshly registered consumer of type=candlepin has no capabilities.");
    // get the initial list of available pools and all available pools
    List<SubscriptionPool> initialAvailablePools = clienttasks.getCurrentlyAvailableSubscriptionPools();
    List<SubscriptionPool> initialAllAvailablePools = clienttasks.getCurrentlyAllAvailableSubscriptionPools();
    Assert.assertTrue(initialAllAvailablePools.containsAll(initialAvailablePools), "The pools --available to a consumer of type=candlepin is a subset of --all --available pools.");
    Assert.assertFalse(initialAvailablePools.containsAll(initialAllAvailablePools), "Without any capabilities, --all --available pools contains addtional pools that are not --available for consumption by a consumer of type=candlepin (Assumes some subscriptions with attributes " + allCapabilities + " are available to org " + sm_clientOrg);
    // incrementally give the candlepin consumer more capabilities (starting with none)
    List<String> currentCapabilities = new ArrayList<String>();
    for (int i = 0; i <= allCapabilities.size(); i++) {
        // get the current list of available pools and all available pools
        List<SubscriptionPool> currentAvailablePools = clienttasks.getCurrentlyAvailableSubscriptionPools();
        List<SubscriptionPool> currentAllAvailablePools = clienttasks.getCurrentlyAllAvailableSubscriptionPools();
        // loop through the unavailable pools and assert that the subscription's product attribute contains a capability that is absent from this consumer
        for (SubscriptionPool pool : currentAllAvailablePools) {
            if (!currentAvailablePools.contains(pool)) {
                SubscriptionPool unavailablePool = pool;
                // the reason this pool from allAvailablePools should not be available is because it must have a product attribute that is not among the consumer's current capabilities.  Let's test it...
                boolean unavailablePoolHasAnUnavailableCapability = false;
                for (String capability : allCapabilities) {
                    // assume the capability is a an attribute of the pool product
                    if (!currentCapabilities.contains(capability)) {
                        if (CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, capability) != null) {
                            Assert.assertTrue(true, "Subscription Pool '" + pool.subscriptionName + "' is not available to a consumer of type=candlepin with capabilities " + currentCapabilities + " because this pool's product attributes includes capability '" + capability + "' and therefore requires that the candlepin consumer also possess the capability '" + capability + "'.");
                            unavailablePoolHasAnUnavailableCapability = true;
                        }
                    }
                    // handle "derived_product" capability a little differently
                    if (!currentCapabilities.contains(capability) && capability.equals("derived_product")) {
                        if (CandlepinTasks.isPoolADataCenter(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId)) {
                            Assert.assertTrue(true, "Subscription Pool '" + pool.subscriptionName + "' is not available to a consumer of type=candlepin with capabilities " + currentCapabilities + " because this pool will derive subpools for a different product and requires that this consumer of type=candlepin to possess the capability '" + capability + "'.");
                            unavailablePoolHasAnUnavailableCapability = true;
                        }
                    }
                // TODO we probably need to handle "cert_v3" capability a little differently
                }
                Assert.assertTrue(unavailablePoolHasAnUnavailableCapability, "At least one of the capability attributes present in Subscription Pool '" + pool.subscriptionName + "' is not among the current capabilities " + currentCapabilities + " of this consumer of type=candlepin. (This is why this pool appears in list --all --available and is not just list --available.)");
            }
        }
        // break out of the loop when we have tested all capabilities
        if (currentCapabilities.containsAll(allCapabilities))
            break;
        // update the consumer with another capability
        currentCapabilities.add(allCapabilities.get(i));
        CandlepinTasks.setCapabilitiesForConsumer(sm_clientUsername, sm_clientPassword, sm_serverUrl, consumerId, currentCapabilities);
    }
    // now that the consumer has all capabilities, list --available and list --all --available should be identical for a candlepin consumer
    log.info("Now that this candlepin consumer supports all the available capabilities " + allCapabilities + ", the list of --available pools should be identical to --all --available pools regardless of fact rules.");
    List<SubscriptionPool> finalAvailablePools = clienttasks.getCurrentlyAvailableSubscriptionPools();
    List<SubscriptionPool> finalAllAvailablePools = clienttasks.getCurrentlyAllAvailableSubscriptionPools();
    Assert.assertTrue(finalAvailablePools.containsAll(finalAllAvailablePools) && finalAllAvailablePools.containsAll(finalAvailablePools), "The pools --available to a consumer of type=candlepin with all capabilities " + allCapabilities + " is identical to --all --available pools.");
    Assert.assertTrue(finalAvailablePools.containsAll(initialAllAvailablePools) && initialAllAvailablePools.containsAll(finalAvailablePools), "The pools --available to a consumer of type=candlepin with all capabilities " + allCapabilities + " is identical to --all --available pools when the same consumer possessed no capabilities.");
    // now let's compare the type=candlepin's finalAllAvailablePools to a type=system's listAllAvailablePools
    // the difference in the list should be generated subpools and DOMAIN subscriptions
    log.info("Now let's register a consumer of type=system and compare its list --all --available to the type=candlepin consumer's list --all --available.");
    // register (as type system)
    consumerId = clienttasks.getCurrentConsumerId(clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, ConsumerType.system, null, null, null, null, null, (String) null, null, null, null, true, false, null, null, null, null));
    List<SubscriptionPool> allAvailablePoolsToSystem = clienttasks.getCurrentlyAllAvailableSubscriptionPools();
    List<SubscriptionPool> allAvailablePoolsToCandlepin = finalAllAvailablePools;
    for (SubscriptionPool pool : allAvailablePoolsToSystem) {
        if (!allAvailablePoolsToCandlepin.contains(pool)) {
            log.warning("Pool '" + pool.subscriptionName + "' is in consumer type=system list --all --available, but NOT in consumer type=candlepin list --all --available.");
            Assert.assertTrue(CandlepinTasks.isPoolDerived(sm_clientUsername, sm_clientPassword, pool.poolId, sm_serverUrl), "Pool '" + pool.subscriptionName + "' is in consumer type=system list --all --available, but NOT in consumer type=candlepin list --all --available because this is a derived pool.");
        }
    }
    for (SubscriptionPool pool : allAvailablePoolsToCandlepin) {
        if (!allAvailablePoolsToSystem.contains(pool)) {
            log.warning("Pool '" + pool.subscriptionName + "' is in candlepin list --all --available, but NOT in system list --all --available.");
            String requiresConsumerType = CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "requires_consumer_type");
            Assert.assertTrue(requiresConsumerType != null && !requiresConsumerType.equals(ConsumerType.system), "Pool '" + pool.subscriptionName + "' is in candlepin list --all --available, but NOT in system list --all --available because this pool's product requires_consumer_type '" + requiresConsumerType + "'.");
        }
    }
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 49 with SubscriptionPool

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

the class FactsTests method testBypassRulesDueToType.

@Test(description = "subscription-manager: facts and rules: bypass rules due to type", groups = { "Tier2Tests", "blockedByBug-641027" }, dependsOnGroups = {}, // 9/17/2013 this test has been disabled in favor of new BypassRulesDueToTypeAndCapabilities_Test
enabled = false)
// cores, ram, instance_multiplier, derived_product
@ImplementsNitrateTest(caseId = 56331)
public void testBypassRulesDueToType() throws Exception {
    // determine which client is a RHEL Workstation
    SSHCommandRunner client = null;
    SubscriptionManagerTasks clienttasks = null;
    if (client1 != null && client1tasks.getRedhatRelease().startsWith("Red Hat Enterprise Linux Workstation")) {
        client = client1;
        clienttasks = client1tasks;
    } else if (client2 != null && client2tasks.getRedhatRelease().startsWith("Red Hat Enterprise Linux Workstation")) {
        client = client2;
        clienttasks = client2tasks;
    } else {
        throw new SkipException("This test requires a Red Hat Enterprise Linux Workstation.");
    }
    // on a RHEL workstation register to candlepin (as type system)
    clienttasks.unregister(null, null, null, null);
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, ConsumerType.system, null, null, null, null, null, (String) null, null, null, null, null, false, null, null, null, null);
    // get a list of available pools and all available pools (for this system consumer)
    List<SubscriptionPool> compatiblePoolsAsSystemConsumer = clienttasks.getCurrentlyAvailableSubscriptionPools();
    List<SubscriptionPool> allPoolsAsSystemConsumer = clienttasks.getCurrentlyAllAvailableSubscriptionPools();
    Assert.assertFalse(compatiblePoolsAsSystemConsumer.containsAll(allPoolsAsSystemConsumer), "Without bypassing the rules, not *all* pools are available for subscribing by a type=system consumer.");
    Assert.assertTrue(allPoolsAsSystemConsumer.containsAll(compatiblePoolsAsSystemConsumer), "The pools available to a type=system consumer is a subset of --all --available pools.");
    // now register to candlepin (as type candlepin)
    clienttasks.unregister(null, null, null, null);
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, ConsumerType.candlepin, null, null, null, null, null, (String) null, null, null, null, null, false, null, null, null, null);
    // get a list of available pools and all available pools (for this candlepin consumer)
    List<SubscriptionPool> compatiblePoolsAsCandlepinConsumer = clienttasks.getCurrentlyAvailableSubscriptionPools();
    List<SubscriptionPool> allPoolsAsCandlepinConsumer = clienttasks.getCurrentlyAllAvailableSubscriptionPools();
    Assert.assertTrue(compatiblePoolsAsCandlepinConsumer.containsAll(allPoolsAsCandlepinConsumer) && allPoolsAsCandlepinConsumer.containsAll(compatiblePoolsAsCandlepinConsumer), "The pools available to a type=candlepin consumer bypass the rules (list --all --available is identical to list --available).");
    // now assert that all the pools can be subscribed to by the consumer (registered as type candlepin)
    clienttasks.subscribeToTheCurrentlyAvailableSubscriptionPoolsCollectively();
}
Also used : SSHCommandRunner(com.redhat.qe.tools.SSHCommandRunner) SubscriptionManagerTasks(rhsm.cli.tasks.SubscriptionManagerTasks) SkipException(org.testng.SkipException) SubscriptionPool(rhsm.data.SubscriptionPool) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 50 with SubscriptionPool

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

the class FactsTests method testPoolsWithSocketsGreaterThanSystemsCpuSocketAreNotAvailable.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36606", "RHEL7-51418" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier2")
@Test(description = "subscription-manager: facts and rules: check sockets", groups = { "Tier2Tests" }, dependsOnGroups = {}, dataProvider = "getClientsData", enabled = true)
public // @ImplementsTCMS(id="")
void testPoolsWithSocketsGreaterThanSystemsCpuSocketAreNotAvailable(SubscriptionManagerTasks smt) throws Exception {
    smt.unregister(null, null, null, null);
    String consumerId = smt.getCurrentConsumerId(smt.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, null, false, null, null, null, null));
    String ownerKey = CandlepinTasks.getOwnerKeyOfConsumerId(sm_clientUsername, sm_clientPassword, sm_serverUrl, consumerId);
    boolean foundPoolWithSocketAttributes = false;
    boolean conclusiveTest = false;
    // get all the pools available to each client
    List<SubscriptionPool> clientPools = smt.getCurrentlyAvailableSubscriptionPools();
    // get the number of cpu_sockets for this system consumer
    String factName = "cpu.cpu_socket(s)";
    // TODO need a workaround for bug 696791 when getFactValue(factName)==null when getFactValue("uname.machine").equals("s390x"); should probably treat this as though socket is 1   see http://hudson.rhq.lab.eng.bos.redhat.com:8080/hudson/job/rhsm-beaker-on-premises-RHEL5/179/TestNG_Report/
    int systemValue = Integer.valueOf(smt.getFactValue(factName));
    log.info(factName + " for this system consumer: " + systemValue);
    // loop through the owner's subscriptions
    /* 7/10/2015 devel consciously decided to drop @Verify(value = Owner.class, subResource = SubResource.SUBSCRIPTIONS) on this GET method starting with candlepin-2.0.
		 * 7/10/2015 modifying this testware to simply raise the authentication credentials to admin
		JSONArray jsonSubscriptions = new JSONArray(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername,sm_clientPassword,sm_serverUrl,"/owners/"+ownerKey+"/subscriptions"));
		 */
    JSONArray jsonSubscriptions = new JSONArray(CandlepinTasks.getResourceUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, "/owners/" + ownerKey + "/subscriptions"));
    for (int i = 0; i < jsonSubscriptions.length(); i++) {
        JSONObject jsonSubscription = (JSONObject) jsonSubscriptions.get(i);
        String poolId = jsonSubscription.getString("id");
        JSONObject jsonProduct = (JSONObject) jsonSubscription.getJSONObject("product");
        String subscriptionName = jsonProduct.getString("name");
        String productId = jsonProduct.getString("id");
        JSONArray jsonAttributes = jsonProduct.getJSONArray("attributes");
        // loop through the attributes of this subscription looking for the "sockets" attribute
        for (int j = 0; j < jsonAttributes.length(); j++) {
            JSONObject jsonAttribute = (JSONObject) jsonAttributes.get(j);
            String attributeName = jsonAttribute.getString("name");
            if (attributeName.equals("sockets")) {
                // found the sockets attribute
                foundPoolWithSocketAttributes = true;
                SubscriptionPool pool = new SubscriptionPool(productId, poolId);
                // test if the sockets attribute value is not numeric (e.g. null)
                if (jsonAttribute.isNull("value")) {
                    // do not mark productAttributesPassRulesCheck = false;
                    log.info("Since this sockets value is null, Subscription Pool " + pool + " may or may not be available depending on other facts besides " + factName + " (e.g. arch).");
                    break;
                }
                // test if the sockets attribute value is not numeric (e.g. "zero")
                try {
                    Integer.valueOf(jsonAttribute.getString("value"));
                } catch (NumberFormatException e) {
                    // do not mark productAttributesPassRulesCheck = false;
                    log.info("Since this sockets value '" + jsonAttribute.getString("value") + "' is a non-integer, Subscription Pool " + pool + " may or may not be available depending on other facts besides " + factName + " (e.g. arch).");
                    break;
                }
                int poolValue = jsonAttribute.getInt("value");
                // assert that if the maximum cpu_sockets for this subscription pool is greater than the cpu_sockets facts for this consumer, then this product should NOT be available
                log.fine("Maximum sockets for this subscriptionPool name=" + subscriptionName + ": " + poolValue);
                if (poolValue < systemValue) {
                    Assert.assertFalse(clientPools.contains(pool), "Subscription Pool " + pool + " IS NOT available since this system's " + factName + " (" + systemValue + ") exceeds the maximum (" + poolValue + ") for this pool to be a candidate for availability.");
                    conclusiveTest = true;
                } else {
                    log.info("Subscription Pool " + pool + " may or may not be available depending on other facts besides " + factName + " (e.g. arch).");
                }
                break;
            }
        }
    }
    if (jsonSubscriptions.length() == 0) {
        log.warning("No owner subscriptions were found for a system registered by '" + sm_clientUsername + "' and therefore we could not attempt this test.");
        throw new SkipException("No owner subscriptions were found for a system registered by '" + sm_clientUsername + "' and therefore we could not attempt this test.");
    }
    if (!conclusiveTest) {
        // log.warning("The facts for this system did not allow us to perform a conclusive test.");
        throw new SkipException("The facts for this system did not allow us to perform a conclusive test.");
    }
    Assert.assertTrue(foundPoolWithSocketAttributes, "At least one Subscription Pool was found for which we could attempt this test.");
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) SkipException(org.testng.SkipException) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Aggregations

SubscriptionPool (rhsm.data.SubscriptionPool)195 Test (org.testng.annotations.Test)155 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)137 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)112 SkipException (org.testng.SkipException)90 ArrayList (java.util.ArrayList)87 JSONObject (org.json.JSONObject)66 SSHCommandResult (com.redhat.qe.tools.SSHCommandResult)53 ProductSubscription (rhsm.data.ProductSubscription)38 BigInteger (java.math.BigInteger)37 File (java.io.File)34 List (java.util.List)33 EntitlementCert (rhsm.data.EntitlementCert)33 HashMap (java.util.HashMap)32 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)28 InstalledProduct (rhsm.data.InstalledProduct)25 ProductCert (rhsm.data.ProductCert)24 JSONArray (org.json.JSONArray)22 Calendar (java.util.Calendar)12 GregorianCalendar (java.util.GregorianCalendar)11