Search in sources :

Example 41 with TestDefinition

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

the class VirtualizationTests method testGuestIdIsRemovedFromHostConsumerAWhenHostConsumerBPutsSameGuestId.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-47926", "RHEL7-97325" }, linkedWorkItems = { @LinkedItem(// RHSM-REQ : Host-limited Guest Subscriptions
workitemId = "RHEL6-28576", project = Project.RHEL6, role = DefTypes.Role.RELATES_TO), @LinkedItem(// RHSM-REQ : Host-limited Guest Subscriptions
workitemId = "RHEL7-84958", project = Project.RedHatEnterpriseLinux7, role = DefTypes.Role.RELATES_TO) }, 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 = "When Host B PUTs the same guestId as HostA, the guestId should be removed from HostA (simulation of a guest moved from Host A to Host B)", groups = { "Tier2Tests", "blockedByBug-737935", "VerifyGuestIdIsRemovedFromHostConsumerAWhenHostConsumerBPutsSameGuestId_Test" }, dependsOnGroups = {}, enabled = true)
public void testGuestIdIsRemovedFromHostConsumerAWhenHostConsumerBPutsSameGuestId() throws JSONException, Exception {
    int k = 1;
    JSONObject jsonConsumer;
    List<String> actualGuestIds = new ArrayList<String>() {
    };
    // trick this system into believing it is a host
    forceVirtWhatToReturnHost();
    // create host consumer A
    String consumerIdOfHostA = clienttasks.getCurrentConsumerId(clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, true, null, null, null, null, null));
    for (int c = 0; c < 2; c++) {
        // run this test twice
        // call Candlepin API to PUT some guestIds onto the host consumer A
        JSONObject jsonData = new JSONObject();
        ArrayList<String> expectedGuestIdsOnHostA = new ArrayList<String>() {
        };
        for (String guestId : Arrays.asList(new String[] { "test-guestId" + k++, "test-guestId" + k++ })) expectedGuestIdsOnHostA.add(guestId);
        jsonData.put("guestIds", expectedGuestIdsOnHostA);
        CandlepinTasks.putResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/consumers/" + consumerIdOfHostA, jsonData);
        // get the host consumer and assert that it has all the guestIds just PUT
        if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.0.29-1")) {
            // candlepin commit 9eb578122851bdd3d5bb67f205d29996fc91e0ec Remove guestIds from the consumer json output
            // actual guestIds
            actualGuestIds = CandlepinTasks.getConsumerGuestIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, consumerIdOfHostA);
        } else {
            jsonConsumer = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/consumers/" + consumerIdOfHostA));
            // actual guestIds
            // DEBUGGING jsonConsumer.put("guestIds", new JSONArray(expectedGuestIdsOnHostA));
            actualGuestIds.clear();
            for (int g = 0; g < jsonConsumer.getJSONArray("guestIds").length(); g++) {
                actualGuestIds.add(jsonConsumer.getJSONArray("guestIds").getJSONObject(g).getString("guestId"));
            }
        }
        // assert expected guestIds
        for (String guestId : expectedGuestIdsOnHostA) Assert.assertContains(actualGuestIds, guestId);
        Assert.assertEquals(actualGuestIds.size(), expectedGuestIdsOnHostA.size(), "All of the expected guestIds PUT on host consumer '" + consumerIdOfHostA + "' using the Candlepin API were verified.");
        // Now let's create a second host consumer B and add its own guestIds to it and assert the same test
        // this will keep consumer A registered
        clienttasks.clean();
        String consumerIdOfHostB = clienttasks.getCurrentConsumerId(clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, null, null, null, null, null, null));
        // call Candlepin API to PUT some guestIds onto the host consumer B
        // NOTE: decrementing k will effectively move the last guestId from HostA to HostB
        k--;
        log.info("Simulating the moving of guestId '" + expectedGuestIdsOnHostA.get(expectedGuestIdsOnHostA.size() - 1) + "' from host consumer A to host consumer B by PUTting it on the list of guestIds for host consumer B...");
        List<String> expectedGuestIdsOnHostB = Arrays.asList(new String[] { "test-guestId" + k++, "test-guestId" + k++, "test-guestId" + k++, "test-guestId" + k++ });
        jsonData.put("guestIds", expectedGuestIdsOnHostB);
        CandlepinTasks.putResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/consumers/" + consumerIdOfHostB, jsonData);
        // get the host consumer and assert that it has all the guestIds just PUT
        if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.0.29-1")) {
            // candlepin commit 9eb578122851bdd3d5bb67f205d29996fc91e0ec Remove guestIds from the consumer json output
            // actual guestIds
            actualGuestIds = CandlepinTasks.getConsumerGuestIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, consumerIdOfHostB);
        } else {
            jsonConsumer = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/consumers/" + consumerIdOfHostB));
            // actual guestIds
            // DEBUGGING jsonConsumer.put("guestIds", new JSONArray(expectedGuestIdsOnHostB));
            actualGuestIds.clear();
            for (int g = 0; g < jsonConsumer.getJSONArray("guestIds").length(); g++) {
                actualGuestIds.add(jsonConsumer.getJSONArray("guestIds").getJSONObject(g).getString("guestId"));
            }
        }
        // assert expected guestIds
        for (String guestId : expectedGuestIdsOnHostB) Assert.assertContains(actualGuestIds, guestId);
        Assert.assertEquals(actualGuestIds.size(), expectedGuestIdsOnHostB.size(), "All of the expected guestIds PUT on consumer '" + consumerIdOfHostB + "' using the Candlepin API were verified.");
        // Now let's re-verify that the guestIds of host consumer A have not changed
        // NOTE: The last guestId SHOULD BE REMOVED since it was most recently reported as a guest on HostB
        log.info("Because guestId '" + expectedGuestIdsOnHostA.get(expectedGuestIdsOnHostA.size() - 1) + "' was most recently reported as a guest on host consumer B, it should no longer be on the list of guestIds for host consumer A...");
        expectedGuestIdsOnHostA.remove(expectedGuestIdsOnHostA.size() - 1);
        // get the host consumer and assert that it has all the guestIds just PUT
        if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.0.29-1")) {
            // candlepin commit 9eb578122851bdd3d5bb67f205d29996fc91e0ec Remove guestIds from the consumer json output
            // actual guestIds
            actualGuestIds = CandlepinTasks.getConsumerGuestIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, consumerIdOfHostA);
        } else {
            jsonConsumer = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/consumers/" + consumerIdOfHostA));
            // actual guestIds
            // DEBUGGING jsonConsumer.put("guestIds", new JSONArray(expectedGuestIdsOnHostA));
            actualGuestIds.clear();
            for (int g = 0; g < jsonConsumer.getJSONArray("guestIds").length(); g++) {
                actualGuestIds.add(jsonConsumer.getJSONArray("guestIds").getJSONObject(g).getString("guestId"));
            }
        }
        // assert expected guestIds
        for (String guestId : expectedGuestIdsOnHostA) Assert.assertContains(actualGuestIds, guestId);
        if (actualGuestIds.size() == expectedGuestIdsOnHostA.size() + c + 1)
            throw new SkipException("Currently Candlepin does NOT purge duplicate guest ids PUT by virt-who onto different host consumers.  The most recently PUT guest id is the winner. Entitlements should be revoked for the older guest id.  Development has decided to keep the stale guest id for potential reporting purposes, hence this test is being skipped until needed in the future.");
        else
            Assert.assertEquals(actualGuestIds.size(), expectedGuestIdsOnHostA.size(), "All of the expected guestIds PUT on consumer '" + consumerIdOfHostA + "' using the Candlepin API were verified.");
    }
}
Also used : JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) SkipException(org.testng.SkipException) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 42 with TestDefinition

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

the class VirtualizationTests method testHostAndGuestPoolQuantities.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-22223", "RHEL7-59439" }, 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 = "Tier1 Tier2")
@Test(description = "Verify host and guest pools quantities generated from a virtualization-aware subscription", // "blockedByBug-679617" indirectly when this script is run as part of the full TestNG suite since this is influenced by other scripts calling refresh pools
groups = { "Tier1Tests", "Tier2Tests", "VerifyHostAndGuestPoolQuantities_Test" }, dependsOnGroups = {}, dataProvider = "getVirtSubscriptionData", enabled = true)
public void testHostAndGuestPoolQuantities(String subscriptionId, String productName, String productId, int quantity, String virtLimit, String hostPoolId, String guestPoolId, Boolean physicalOnly) throws JSONException, Exception {
    if (hostPoolId == null && guestPoolId == null)
        throw new SkipException("Failed to find expected host and guest pools derived from virtualization-aware subscription id '" + subscriptionId + "' (" + productName + ").");
    // if (!productId.equals("awesomeos-virt-unlimited")) throw new SkipException("debugTesting VerifyHostAndGuestPoolQuantities_Test");
    JSONObject jsonHostPool = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/pools/" + hostPoolId));
    int jsonHostPoolQuantity = jsonHostPool.getInt("quantity");
    int jsonHostPoolQuantityConsumed = jsonHostPool.getInt("consumed");
    int jsonHostPoolQuantityExported = jsonHostPool.getInt("exported");
    JSONObject jsonGuestPool = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/pools/" + guestPoolId));
    int jsonGuestPoolQuantity = jsonGuestPool.getInt("quantity");
    int jsonGuestPoolQuantityConsumed = jsonGuestPool.getInt("consumed");
    int jsonGuestPoolQuantityExported = jsonGuestPool.getInt("exported");
    // trick this system into believing it is a virt guest
    forceVirtWhatToReturnGuest("kvm");
    // get the available pools
    List<SubscriptionPool> allAvailablePools = clienttasks.getCurrentlyAllAvailableSubscriptionPools();
    // get the hostPool
    SubscriptionPool hostPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", hostPoolId, allAvailablePools);
    // determine the availability of the hostPool
    if (jsonHostPoolQuantityConsumed > jsonHostPoolQuantity) {
        Assert.fail("Host pool id '" + hostPoolId + "' has a consumed attribute value '" + jsonHostPoolQuantityConsumed + "' that exceeds its total quantity '" + jsonHostPoolQuantity + "'.  This does NOT make sense.");
    } else if (jsonHostPoolQuantityConsumed == jsonHostPoolQuantity) {
        Assert.assertNull(hostPool, "Host pool id '" + hostPoolId + "', derived from the virtualization-aware subscription id '" + subscriptionId + "', is NOT listed in all available subscriptions since all of its quantity are already being consumed by other systems.");
    } else {
        Assert.assertNotNull(hostPool, "Host pool id '" + hostPoolId + "', derived from the virtualization-aware subscription id '" + subscriptionId + "', is listed in all available subscriptions: " + hostPool);
        // Assert.assertEquals(Integer.valueOf(hostPool.quantity), Integer.valueOf(quantity-jsonHostPoolQuantityConsumed), "Assuming '"+jsonHostPoolQuantityConsumed+"' entitlements are currently being consumed from this host pool '"+hostPool.poolId+"', the quantity of available entitlements should be '"+quantity+"' minus '"+jsonHostPoolQuantityConsumed+"' (COULD BE DIFFERENT IF ANOTHER PHYSICAL HOST SYSTEM IS SIMULTANEOUSLY SUBSCRIBING TO THE SAME POOL OR JUST RETURNED AN ENTITLEMENT TO THE SAME POOL).");
        if (!Integer.valueOf(hostPool.quantity).equals(Integer.valueOf(quantity - jsonHostPoolQuantityConsumed))) {
            log.warning("Assuming '" + jsonHostPoolQuantityConsumed + "' entitlements are currently being consumed from this host pool '" + hostPool.poolId + "', the quantity of available entitlements should be '" + quantity + "' minus '" + jsonHostPoolQuantityConsumed + "' (COULD BE DIFFERENT IF ANOTHER PHYSICAL HOST SYSTEM IS SIMULTANEOUSLY SUBSCRIBING TO THE SAME POOL OR JUST RETURNED AN ENTITLEMENT TO THE SAME POOL).");
        }
        if (!CandlepinType.hosted.equals(sm_serverType)) {
            // too many false negatives occur on hosted due to simultaneous client consumption from the same pool
            Assert.assertEquals(Integer.valueOf(hostPool.quantity), Integer.valueOf(quantity - jsonHostPoolQuantityConsumed), "Assuming '" + jsonHostPoolQuantityConsumed + "' entitlements are currently being consumed from this host pool '" + hostPool.poolId + "', the quantity of available entitlements should be '" + quantity + "' minus '" + jsonHostPoolQuantityConsumed + "' (COULD BE DIFFERENT IF ANOTHER PHYSICAL HOST SYSTEM IS SIMULTANEOUSLY SUBSCRIBING TO THE SAME POOL OR JUST RETURNED AN ENTITLEMENT TO THE SAME POOL).");
        }
    }
    // get the guestPool
    SubscriptionPool guestPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", guestPoolId, allAvailablePools);
    // determine the availability of the guestPool
    if (jsonGuestPoolQuantity == -1) {
        Assert.assertNotNull(guestPool, "Guest pool id '" + guestPoolId + "', derived from the virtualization-aware subscription id '" + subscriptionId + "', is listed in all available subscriptions: " + guestPool);
        // assert guestPoolId quantity is unlimited
        // altered after Bug 862885 - String Update: Capitalize unlimited in the All Available Subscriptions tab
        Assert.assertEquals(guestPool.quantity, "Unlimited", "When the subscription product has a quantity attribute of '-1', then the guest pool's quantity viewed by within the list --all --available should be 'Unlimited'.");
        Assert.assertEquals(virtLimit, "unlimited", "When the subscription product has a quantity attribute of '-1', then the guest pool's virt_limit attribute should be 'unlimited'.");
    } else if (jsonGuestPoolQuantityConsumed > jsonGuestPoolQuantity) {
        Assert.fail("Guest pool id '" + guestPoolId + "' has a consumed attribute value '" + jsonGuestPoolQuantityConsumed + "' that exceeds its total quantity '" + jsonGuestPoolQuantity + "'.  This does NOT make sense.");
    } else if (jsonGuestPoolQuantityConsumed == jsonGuestPoolQuantity) {
        Assert.assertNull(guestPool, "Guest pool id '" + guestPoolId + "', derived from the virtualization-aware subscription id '" + subscriptionId + "', is NOT listed in all available subscriptions since all of its quantity are already being consumed by other systems.");
    } else {
        Assert.assertNotNull(guestPool, "Guest pool id '" + guestPoolId + "', derived from the virtualization-aware subscription id '" + subscriptionId + "', is listed in all available subscriptions: " + guestPool);
        // Assert.assertEquals(Integer.valueOf(guestPool.quantity), Integer.valueOf((quantity-jsonHostPoolQuantityExported)*Integer.valueOf(virtLimit)-jsonGuestPoolQuantityConsumed), "Assuming '"+jsonGuestPoolQuantityConsumed+"' entitlements are currently being consumed from guest pool '"+guestPool.poolId+"', the quantity of available entitlements for this guest pool should be the host pool's virt_limit of '"+virtLimit+"' times (the host's total quantity '"+quantity+"' minus those exported '"+jsonHostPoolQuantityExported+"') minus the number of already consumed from the pool '"+jsonGuestPoolQuantityConsumed+"'  (COULD BE DIFFERENT IF ANOTHER VIRTUAL GUEST SYSTEM IS SIMULTANEOUSLY SUBSCRIBING TO THE SAME POOL).");
        if (!Integer.valueOf(guestPool.quantity).equals(Integer.valueOf((quantity - jsonHostPoolQuantityExported) * Integer.valueOf(virtLimit) - jsonGuestPoolQuantityConsumed))) {
            log.warning("Assuming '" + jsonGuestPoolQuantityConsumed + "' entitlements are currently being consumed from guest pool '" + guestPool.poolId + "', the quantity of available entitlements for this guest pool should be the host pool's virt_limit of '" + virtLimit + "' times (the host's total quantity '" + quantity + "' minus those exported '" + jsonHostPoolQuantityExported + "') minus the number of already consumed from the pool '" + jsonGuestPoolQuantityConsumed + "'  (COULD BE DIFFERENT IF ANOTHER VIRTUAL GUEST SYSTEM IS SIMULTANEOUSLY SUBSCRIBING TO THE SAME POOL).");
        }
        if (!CandlepinType.hosted.equals(sm_serverType)) {
            // too many false negatives occur on hosted due to simultaneous client consumption from the same pool
            Assert.assertEquals(Integer.valueOf(guestPool.quantity), Integer.valueOf((quantity - jsonHostPoolQuantityExported) * Integer.valueOf(virtLimit) - jsonGuestPoolQuantityConsumed), "Assuming '" + jsonGuestPoolQuantityConsumed + "' entitlements are currently being consumed from guest pool '" + guestPool.poolId + "', the quantity of available entitlements for this guest pool should be the host pool's virt_limit of '" + virtLimit + "' times (the host's total quantity '" + quantity + "' minus those exported '" + jsonHostPoolQuantityExported + "') minus the number of already consumed from the pool '" + jsonGuestPoolQuantityConsumed + "'  (COULD BE DIFFERENT IF ANOTHER VIRTUAL GUEST SYSTEM IS SIMULTANEOUSLY SUBSCRIBING TO THE SAME POOL).");
        }
    }
}
Also used : JSONObject(org.json.JSONObject) 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)

Example 43 with TestDefinition

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

the class VirtualizationTests method testGuestPoolQuantityIsNotClobberedByRefreshPools.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-47928", "RHEL7-97327" }, linkedWorkItems = { @LinkedItem(// RHSM-REQ : Host-limited Guest Subscriptions
workitemId = "RHEL6-28576", project = Project.RHEL6, role = DefTypes.Role.RELATES_TO), @LinkedItem(// RHSM-REQ : Host-limited Guest Subscriptions
workitemId = "RHEL7-84958", project = Project.RedHatEnterpriseLinux7, role = DefTypes.Role.RELATES_TO) }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier2")
@Test(description = "Verify the virt_limit multiplier on guest pool quantity is not clobbered by refresh pools", groups = { "Tier2Tests", "blockedByBug-679617" }, dependsOnGroups = {}, dependsOnMethods = { "testHostAndGuestPoolQuantities" }, dataProvider = "getVirtSubscriptionData", enabled = true)
public void testGuestPoolQuantityIsNotClobberedByRefreshPools(String subscriptionId, String productName, String productId, int quantity, String virtLimit, String hostPoolId, String guestPoolId, Boolean physicalOnly) throws JSONException, Exception {
    if (hostPoolId == null && guestPoolId == null)
        throw new SkipException("Failed to find expected host and guest pools derived from virtualization-aware subscription id '" + subscriptionId + "' (" + productName + ").");
    if (servertasks.dbConnection == null)
        throw new SkipException("This testcase requires a connection to the candlepin database so that it can updateSubscriptionDatesOnDatabase.");
    // get the hostPool
    List<SubscriptionPool> allAvailablePools = clienttasks.getCurrentlyAllAvailableSubscriptionPools();
    SubscriptionPool hostPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", hostPoolId, allAvailablePools);
    Assert.assertNotNull(hostPool, "A host pool derived from the virtualization-aware subscription id '" + subscriptionId + "' is listed in all available subscriptions: " + hostPool);
    // remember the hostPool quantity before calling refresh pools
    String hostPoolQuantityBefore = hostPool.quantity;
    // get the guestPool
    SubscriptionPool guestPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", guestPoolId, allAvailablePools);
    Assert.assertNotNull(guestPool, "A guest pool derived from the virtualization-aware subscription id '" + subscriptionId + "' is listed in all available subscriptions: " + guestPool);
    // remember the hostPool quantity before calling refresh pools
    String guestPoolQuantityBefore = guestPool.quantity;
    log.info("Now let's modify the start date of the virtualization-aware subscription id '" + subscriptionId + "'...");
    /* 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"));
    JSONObject jsonSubscription = null;
    for (int i = 0; i < jsonSubscriptions.length(); i++) {
        jsonSubscription = (JSONObject) jsonSubscriptions.get(i);
        if (jsonSubscription.getString("id").equals(subscriptionId)) {
            break;
        } else {
            jsonSubscription = null;
        }
    }
    // "startDate":"2012-02-08T00:00:00.000+0000"
    Calendar startDate = parseISO8601DateString(jsonSubscription.getString("startDate"), "GMT");
    // subtract a month
    Calendar newStartDate = (Calendar) startDate.clone();
    // subtract a month
    newStartDate.add(Calendar.MONTH, -1);
    updateSubscriptionDatesOnDatabase(subscriptionId, newStartDate, null);
    log.info("Now let's refresh the subscription pools...");
    JSONObject jobDetail = CandlepinTasks.refreshPoolsUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, ownerKey);
    jobDetail = CandlepinTasks.waitForJobDetailStateUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, jobDetail, "FINISHED", 10 * 1000, 3);
    allAvailablePools = clienttasks.getCurrentlyAllAvailableSubscriptionPools();
    // retrieve the host pool again and assert the quantity has not changed
    hostPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", hostPoolId, allAvailablePools);
    Assert.assertEquals(hostPool.quantity, hostPoolQuantityBefore, "The quantity of entitlements available from the host pool has NOT changed after refreshing pools.");
    // retrieve the guest pool again and assert the quantity has not changed
    guestPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", guestPoolId, allAvailablePools);
    Assert.assertEquals(guestPool.quantity, guestPoolQuantityBefore, "The quantity of entitlements available from the guest pool has NOT changed after refreshing pools.");
}
Also used : JSONObject(org.json.JSONObject) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) 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)

Example 44 with TestDefinition

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

the class VirtualizationTests method testGuestIdsCanBePutOntoHostConsumer.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-37711", "RHEL7-51488" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier2")
@Test(description = "Verify the Candlepin API accepts PUTting of guestIds onto host consumer (to be used by virt-who)", groups = { "Tier2Tests", "blockedByBug-737935", "VerifyGuestIdsCanBePutOntoHostConsumer_Test" }, dependsOnGroups = {}, enabled = true)
public void testGuestIdsCanBePutOntoHostConsumer() throws JSONException, Exception {
    int k = 1;
    JSONObject jsonConsumer;
    List<String> actualGuestIds = new ArrayList<String>() {
    };
    // trick this system into believing it is a host
    forceVirtWhatToReturnHost();
    // create host consumer A
    String consumerIdOfHostA = clienttasks.getCurrentConsumerId(clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, true, null, null, null, null, null));
    for (int c = 0; c < 2; c++) {
        // run this test twice
        // call Candlepin API to PUT some guestIds onto the host consumer A
        JSONObject jsonData = new JSONObject();
        List<String> expectedGuestIdsOnHostA = Arrays.asList(new String[] { "test-guestId" + k++, "test-guestId" + k++ });
        jsonData.put("guestIds", expectedGuestIdsOnHostA);
        CandlepinTasks.putResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/consumers/" + consumerIdOfHostA, jsonData);
        // get the host consumer and assert that it has all the guestIds just PUT
        if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.0.29-1")) {
            // candlepin commit 9eb578122851bdd3d5bb67f205d29996fc91e0ec Remove guestIds from the consumer json output
            // actual guestIds
            actualGuestIds = CandlepinTasks.getConsumerGuestIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, consumerIdOfHostA);
        } else {
            jsonConsumer = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/consumers/" + consumerIdOfHostA));
            // actual guestIds
            // DEBUGGING jsonConsumer.put("guestIds", new JSONArray(expectedGuestIdsOnHostA));
            actualGuestIds.clear();
            for (int g = 0; g < jsonConsumer.getJSONArray("guestIds").length(); g++) {
                actualGuestIds.add(jsonConsumer.getJSONArray("guestIds").getJSONObject(g).getString("guestId"));
            }
        }
        // assert expected guestIds
        for (String guestId : expectedGuestIdsOnHostA) Assert.assertContains(actualGuestIds, guestId);
        Assert.assertEquals(actualGuestIds.size(), expectedGuestIdsOnHostA.size(), "All of the expected guestIds PUT on host consumer '" + consumerIdOfHostA + "' using the Candlepin API were verified.");
        // Now let's create a second host consumer B and add its own guestIds to it and assert the same test
        // this will keep consumer A registered
        clienttasks.clean();
        String consumerIdOfHostB = clienttasks.getCurrentConsumerId(clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, null, null, null, null, null, null));
        // call Candlepin API to PUT some guestIds onto the host consumer B
        List<String> expectedGuestIdsOnHostB = Arrays.asList(new String[] { "test-guestId" + k++, "test-guestId" + k++, "test-guestId" + k++, "test-guestId" + k++ });
        jsonData.put("guestIds", expectedGuestIdsOnHostB);
        CandlepinTasks.putResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/consumers/" + consumerIdOfHostB, jsonData);
        // get the host consumer and assert that it has all the guestIds just PUT
        if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.0.29-1")) {
            // candlepin commit 9eb578122851bdd3d5bb67f205d29996fc91e0ec Remove guestIds from the consumer json output
            // actual guestIds
            actualGuestIds = CandlepinTasks.getConsumerGuestIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, consumerIdOfHostB);
        } else {
            jsonConsumer = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/consumers/" + consumerIdOfHostB));
            // actual guestIds
            // DEBUGGING jsonConsumer.put("guestIds", new JSONArray(expectedGuestIdsOnHostB));
            actualGuestIds.clear();
            // }
            for (int g = 0; g < jsonConsumer.getJSONArray("guestIds").length(); g++) {
                actualGuestIds.add(jsonConsumer.getJSONArray("guestIds").getJSONObject(g).getString("guestId"));
            }
        }
        // assert expected guestIds
        for (String guestId : expectedGuestIdsOnHostB) Assert.assertContains(actualGuestIds, guestId);
        Assert.assertEquals(actualGuestIds.size(), expectedGuestIdsOnHostB.size(), "All of the expected guestIds PUT on consumer '" + consumerIdOfHostB + "' using the Candlepin API were verified.");
        // get the host consumer and assert that it has all the guestIds just PUT
        if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.0.29-1")) {
            // candlepin commit 9eb578122851bdd3d5bb67f205d29996fc91e0ec Remove guestIds from the consumer json output
            // actual guestIds
            actualGuestIds = CandlepinTasks.getConsumerGuestIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, consumerIdOfHostA);
        } else {
            jsonConsumer = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/consumers/" + consumerIdOfHostA));
            // actual guestIds
            // DEBUGGING jsonConsumer.put("guestIds", new JSONArray(expectedGuestIdsOnHostA));
            actualGuestIds.clear();
            for (int g = 0; g < jsonConsumer.getJSONArray("guestIds").length(); g++) {
                actualGuestIds.add(jsonConsumer.getJSONArray("guestIds").getJSONObject(g).getString("guestId"));
            }
        }
        // assert expected guestIds
        for (String guestId : expectedGuestIdsOnHostA) Assert.assertContains(actualGuestIds, guestId);
        Assert.assertEquals(actualGuestIds.size(), expectedGuestIdsOnHostA.size(), "All of the expected guestIds PUT on consumer '" + consumerIdOfHostA + "' using the Candlepin API were verified.");
    }
}
Also used : JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 45 with TestDefinition

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

the class StatusTests method testStatusWhileRegisteredWithoutEntitlements.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-19969", "RHEL7-51008" }, 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 = "Tier1")
@Test(description = "run subscription-manager status when registered without entitlements", groups = { "Tier1Tests" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testStatusWhileRegisteredWithoutEntitlements() {
    int numberOfInstalledProducts = clienttasks.getCurrentProductCertFiles().size();
    SSHCommandResult statusResult;
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, true, false, null, null, null, null);
    List<InstalledProduct> installedProducts = clienttasks.getCurrentlyInstalledProducts();
    statusResult = clienttasks.status(null, null, null, null, null);
    // [root@jsefler-5 ~]# subscription-manager status
    // +-------------------------------------------+
    // System Status Details
    // +-------------------------------------------+
    // Overall Status: Invalid
    // 
    // Awesome OS Modifier Bits:
    // - Not covered by a valid subscription.
    // assert the overall status
    String expectedStatus;
    if (numberOfInstalledProducts == 0) {
        // translation for "valid"
        expectedStatus = "Overall Status: Current";
    } else {
        // translation for "invalid"
        expectedStatus = "Overall Status: Invalid";
    }
    Assert.assertTrue(statusResult.getStdout().contains(expectedStatus), "Expecting '" + expectedStatus + "' when registered without entitlements and '" + numberOfInstalledProducts + "' installed products.");
    // assert the individual installed product status details
    for (InstalledProduct installedProduct : installedProducts) {
        for (String statusDetail : installedProduct.statusDetails) {
            Assert.assertTrue(!getSubstringMatches(statusResult.getStdout(), "^" + installedProduct.productName.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)") + ":(\\n- .*)*?\\n- " + statusDetail.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)")).isEmpty(), "Expecting the status detail '" + statusDetail + "' of installed product '" + installedProduct.productName + "' to appear in the list of overall status details.");
            Assert.assertTrue(!doesStringContainMatches(statusResult.getStdout(), statusDetail.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)") + "(\\n- .*)*?\\n- " + statusDetail.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)")), "Status detail '" + statusDetail + "' of installed product '" + installedProduct.productName + "' should not appear in duplicate.");
        }
    }
    if (installedProducts.isEmpty()) {
        Assert.assertTrue(statusResult.getStdout().trim().endsWith(expectedStatus), "There should be no report of installed product details when there are no installed products; only expected '" + expectedStatus + "'.");
    }
}
Also used : SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) InstalledProduct(rhsm.data.InstalledProduct) 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