Search in sources :

Example 76 with SubscriptionPool

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

the class DataCenterTests method getAvailableDataCenterSubscriptionPoolsDataAsListOfLists.

protected List<List<Object>> getAvailableDataCenterSubscriptionPoolsDataAsListOfLists() throws JSONException, Exception {
    List<List<Object>> ll = new ArrayList<List<Object>>();
    if (!isSetupBeforeSuiteComplete)
        return ll;
    // instrument the system to be a Physical host
    factsMap.clear();
    factsMap.put("virt.is_guest", String.valueOf(false));
    // set system facts that will always make the subscription available
    // ram
    factsMap.put("memory.memtotal", "1");
    // sockets
    factsMap.put("cpu.cpu_socket(s)", "1");
    // cores
    factsMap.put("cpu.core(s)_per_socket", "1");
    clienttasks.createFactsFileWithOverridingValues(factsMap);
    for (List<Object> list : getAvailableSubscriptionPoolsDataAsListOfLists(false)) {
        SubscriptionPool pool = (SubscriptionPool) (list.get(0));
        if (CandlepinTasks.isPoolADataCenter(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId)) {
            // will mask bug 1214001				if (CandlepinTasks.isPoolProductHostLimited(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId))
            ll.add(Arrays.asList(new Object[] { null, pool }));
        }
    }
    return ll;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) JSONObject(org.json.JSONObject) SubscriptionPool(rhsm.data.SubscriptionPool)

Example 77 with SubscriptionPool

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

the class EventTests method testExportCreated.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-21850", "RHEL7-51671" }, 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 = "subscription-manager: events: Export Created is sent over an RSS atom feed.", groups = { "Tier3Tests", "ExportCreated_Test" }, dependsOnGroups = { "ProductDeleted_Test" }, enabled = true, alwaysRun = true)
public // @ImplementsTCMS(id="")
void testExportCreated() throws Exception {
    if (sm_serverAdminUsername.equals("") || sm_serverAdminPassword.equals(""))
        throw new SkipException("This test requires the candlepin server admin username and password credentials.");
    // start fresh by unregistering
    clienttasks.unregister(null, null, null, null);
    // NOTE: Without the subscribe, this bugzilla is thrown:
    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.registerCandlepinConsumer(sm_clientUsername, sm_clientPassword, sm_clientOrg, sm_serverUrl, "candlepin");
    } else {
        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);
    }
    List<SubscriptionPool> pools = clienttasks.getCurrentlyAvailableSubscriptionPools();
    // avoid "Too many content sets..." from Issue/Bug 1455361 - strange pool availability and bind behavior for consumer of type candlepin
    pools.remove(SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", "mktProductId-93x2", pools));
    // avoid "Too many content sets..." from Issue/Bug 1455361 - strange pool availability and bind behavior for consumer of type candlepin
    pools.remove(SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", "mktProductId-186", pools));
    // randomly pick a pool
    testPool = pools.get(randomGenerator.nextInt(pools.size()));
    clienttasks.subscribe(null, null, testPool.poolId, null, null, null, null, null, null, null, null, null, null);
    // String consumerKey = result.getStdout().split(" ")[0];
    // get the owner and consumer feeds before we test the firing of a new event
    ConsumerCert consumerCert = clienttasks.getCurrentConsumerCert();
    String ownerKey = CandlepinTasks.getOwnerKeyOfConsumerId(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, consumerCert.consumerid);
    SyndFeed oldFeed = CandlepinTasks.getSyndFeed(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl);
    SyndFeed oldOwnerFeed = CandlepinTasks.getSyndFeedForOwner(ownerKey, sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl);
    SyndFeed oldConsumerFeed = CandlepinTasks.getSyndFeedForConsumer(/*ownerKey,*/
    consumerCert.consumerid, sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl);
    // do something that will fire a exported created event
    CandlepinTasks.exportConsumerUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, consumerCert.consumerid, "/tmp/export.zip");
    String[] newEventTitles = new String[] { "EXPORT CREATED" };
    // TEMPORARY WORKAROUND FOR BUG: https://bugzilla.redhat.com/show_bug.cgi?id=721136 - jsefler 07/14/2011
    boolean invokeWorkaroundWhileBugIsOpen = true;
    String bugId = "721136";
    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) {
        newEventTitles = new String[] { ownerKey + " created an export for consumer " + consumerCert.name };
    }
    // END OF WORKAROUND
    // assert the consumer feed...
    assertTheNewConsumerFeed(ownerKey, consumerCert.consumerid, oldConsumerFeed, newEventTitles);
    // assert the owner feed...
    assertTheNewOwnerFeed(ownerKey, oldOwnerFeed, newEventTitles);
    // assert the feed...
    assertTheNewFeed(oldFeed, newEventTitles);
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SkipException(org.testng.SkipException) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) SubscriptionPool(rhsm.data.SubscriptionPool) ConsumerCert(rhsm.data.ConsumerCert) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 78 with SubscriptionPool

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

the class EventTests method testEntitlementCreated.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-21842", "RHEL7-51663" }, 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 = "subscription-manager: events: Enitlement Created is sent over an RSS atom feed.", groups = { "Tier3Tests", "EntitlementCreated_Test" }, dependsOnGroups = { "ConsumerCreated_Test" }, enabled = true)
@ImplementsNitrateTest(caseId = 50403)
public void testEntitlementCreated() throws Exception {
    // test prerequisites
    List<SubscriptionPool> pools = clienttasks.getCurrentlyAvailableSubscriptionPools();
    ConsumerCert consumerCert = clienttasks.getCurrentConsumerCert();
    // 7/30/2012 updating consumer's autoheal to prevent an auto 'ENTITLEMENT CREATED' event
    CandlepinTasks.setAutohealForConsumer(sm_clientUsername, sm_clientPassword, sm_serverUrl, consumerCert.consumerid, false);
    // get the owner and consumer feeds before we test the firing of a new event
    String ownerKey = CandlepinTasks.getOwnerKeyOfConsumerId(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, consumerCert.consumerid);
    SyndFeed oldFeed = CandlepinTasks.getSyndFeed(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl);
    SyndFeed oldOwnerFeed = CandlepinTasks.getSyndFeedForOwner(ownerKey, sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl);
    SyndFeed oldConsumerFeed = CandlepinTasks.getSyndFeedForConsumer(/*ownerKey,*/
    consumerCert.consumerid, sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl);
    // fire a subscribe event
    // SubscriptionPool pool = pools.get(0); // pick the first pool
    // randomly pick a pool
    testPool = pools.get(randomGenerator.nextInt(pools.size()));
    // debugTesting randomly picked standalone non-zero virt_limit pools
    // testPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", "awesomeos-virt-4", pools);
    // testPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", "awesomeos-virt-unlimited", pools);
    // testPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", "awesomeos-server-basic-dc", pools);
    // testPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", "8a90860f5eed6282015eed64099a0193", pools);
    // testPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("contract", "", pools);
    // testPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("subscriptionType", "Standard (Temporary)", pools);
    // clienttasks.subscribeToSubscriptionPoolUsingPoolId(testPool);	// RHEL59: THIS IS GENERATING EXTRA CONSUMER MODIFIED EVENTS THAT WE DON'T REALLY WANT TO TEST
    clienttasks.subscribe(null, null, testPool.poolId, null, null, null, null, null, null, null, null, null, null);
    List<String> newEventTitles = new ArrayList<String>();
    // newEventTitles.add("COMPLIANCE CREATED");	// COMPLIANCE CREATED events were added to support gutterball
    newEventTitles.add("ENTITLEMENT CREATED");
    // newEventTitles.add("COMPLIANCE CREATED");
    // newEventTitles.add("COMPLIANCE CREATED");
    // TEMPORARY WORKAROUND FOR BUG
    // Status: 	CLOSED CURRENTRELEASE
    boolean invokeWorkaroundWhileBugIsOpen = false;
    // jsefler 07/14/2011 Bug 721136 - the content of the atom feeds has the same value for title and description
    String bugId = "721136";
    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) {
        newEventTitles.clear();
        newEventTitles.add(clienttasks.hostname + " consumed a subscription for product " + testPool.subscriptionName);
    }
    // END OF WORKAROUND
    // assert the consumer feed...
    // assertTheNewConsumerFeed(ownerKey, consumerCert.consumerid, oldConsumerFeed, newEventTitles.toArray(new String[]{}));	// worked prior to RHEL59
    // TODO Using the IgnoringEventTitles is a workaround bug 838123#c2
    assertTheNewConsumerFeedIgnoringEventTitles(ownerKey, consumerCert.consumerid, oldConsumerFeed, newEventTitles.toArray(new String[] {}), new HashSet<String>() {

        {
            add("CONSUMER MODIFIED");
            add("COMPLIANCE CREATED");
        }
    });
    // adjust the expected events when the candlepin server is standalone and the pool has a non-zero virt_limit
    String virt_limit = CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, testPool.poolId, "virt_limit");
    if (servertasks.statusStandalone && virt_limit != null && !virt_limit.equals("0")) {
        newEventTitles.add(1, "POOL CREATED");
    }
    // assert the owner feed...
    // assertTheNewOwnerFeed(ownerKey, oldOwnerFeed, newEventTitles.toArray(new String[]{}));	// worked prior to RHEL59
    // TODO Using the IgnoringEventTitles is a workaround bug 838123#c2
    assertTheNewOwnerFeedIgnoringEventTitles(ownerKey, oldOwnerFeed, newEventTitles.toArray(new String[] {}), new HashSet<String>() {

        {
            add("CONSUMER MODIFIED");
            add("COMPLIANCE CREATED");
        }
    });
    // assert the feed...
    // assertTheNewFeed(oldFeed, newEventTitles.toArray(new String[]{}));	// worked prior to RHEL59
    assertTheNewFeedIgnoringEventTitles(oldFeed, newEventTitles.toArray(new String[] {}), new HashSet<String>() {

        {
            add("CONSUMER MODIFIED");
            add("COMPLIANCE CREATED");
        }
    });
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) ArrayList(java.util.ArrayList) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) SubscriptionPool(rhsm.data.SubscriptionPool) ConsumerCert(rhsm.data.ConsumerCert) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 79 with SubscriptionPool

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

the class ListTests method EnsureOnlyRHELPersonalIsAvailableToRegisteredPerson_Test.

@Test(description = "subscription-manager-cli: RHEL Personal should be the only available subscription to a consumer registered as type person", groups = { "Tier2Tests", "EnsureOnlyRHELPersonalIsAvailableToRegisteredPerson_Test" }, // registered consumers type of "person" was originally intended for entitling people to training.  Red Hat Learning Management systems never made use if it, and candlepin has no active requirements for it.  Disabling the personal tests...  Reference https://bugzilla.redhat.com/show_bug.cgi?id=967160#c1
enabled = false)
public // @ImplementsNitrateTest(caseId=)
void EnsureOnlyRHELPersonalIsAvailableToRegisteredPerson_Test() throws JSONException {
    // String rhelPersonalProductId = getProperty("sm.rhpersonal.productId", "");
    // if (rhelPersonalProductId.equals("")) throw new SkipException("This testcase requires specification of a RHPERSONAL_PRODUCTID.");
    // decide what username and password to test with
    String username = sm_clientUsername;
    String password = sm_clientPassword;
    String owner = sm_clientOrg;
    if (!sm_rhpersonalUsername.equals("")) {
        username = sm_rhpersonalUsername;
        password = sm_rhpersonalPassword;
        owner = sm_rhpersonalOrg;
    }
    // register a person
    clienttasks.unregister(null, null, null, null);
    clienttasks.register(username, password, owner, null, ConsumerType.person, null, null, null, null, null, (String) null, null, null, null, null, false, null, null, null, null);
    // assert that subscriptions with personal productIds are available to this person consumer
    List<SubscriptionPool> subscriptionPools = clienttasks.getCurrentlyAvailableSubscriptionPools();
    for (String personProductId : getPersonProductIds()) {
        SubscriptionPool rhelPersonalPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", personProductId, subscriptionPools);
        Assert.assertNotNull(rhelPersonalPool, "Personal ProductId '" + personProductId + "' is available to this consumer registered as type person");
    }
    // assert that personal subscriptions are the only available pools to this person consumer
    for (SubscriptionPool subscriptionPool : subscriptionPools) {
        Assert.assertTrue(getPersonProductIds().contains(subscriptionPool.productId), "This available ProductId '" + subscriptionPool.productId + "' available to the registered person is among the expected list of personal products that we expect to be consumable by this person.");
    }
}
Also used : SubscriptionPool(rhsm.data.SubscriptionPool) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 80 with SubscriptionPool

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

the class ListTests method testListAvailableWithPoolOnly.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36562", "RHEL7-51344" }, 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: subcription manager list --available with --pool-only", groups = { "Tier2Tests", "blockedByBug-1159974" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testListAvailableWithPoolOnly() throws JSONException, Exception {
    // commit 25cb581cb6ebe13063d0f78a5020715a2854d337 bug 1159974
    if (clienttasks.isPackageVersion("subscription-manager", "<", "1.13.8-1"))
        throw new SkipException("The list --pool-only function was not implemented in this version of subscription-manager.");
    Boolean all = getRandomBoolean();
    Boolean matchInstalled = getRandomBoolean();
    Boolean noOverlap = getRandomBoolean();
    if (clienttasks.getCurrentlyRegisteredOwnerKey() == null) {
        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);
        clienttasks.autoheal(null, null, true, null, null, null, null);
    } else
        clienttasks.unsubscribe_(true, (BigInteger) null, null, null, null, null, null);
    // get available subscription pools
    List<SubscriptionPool> availableSubscriptionPools = SubscriptionPool.parse(clienttasks.list(all, true, null, null, null, null, matchInstalled, noOverlap, null, null, null, null, null, null).getStdout());
    // make the same call with --pool-only
    SSHCommandResult poolOnlyResult = clienttasks.list(all, true, null, null, null, null, matchInstalled, noOverlap, null, true, null, null, null, null);
    // [root@jsefler-os7 ~]# subscription-manager list --available --pool-only
    // 2c90af8b4976c7ee014976cb29bf0b02
    // 2c90af8b4976c7ee014976cb388c1256
    // 2c90af8b4976c7ee01497bbfec1837da
    // 2c90af8b4976c7ee014976cb1f0d06f8
    // convert the result to a list
    List<String> actualSubscriptionPoolIds = new ArrayList<String>();
    if (!poolOnlyResult.getStdout().trim().isEmpty())
        actualSubscriptionPoolIds = Arrays.asList(poolOnlyResult.getStdout().trim().split("\n"));
    // assert the result
    Assert.assertEquals(poolOnlyResult.getExitCode(), new Integer(0), "Exitcode expected from calling list --available --pool-only");
    for (SubscriptionPool availableSubscriptionPool : availableSubscriptionPools) Assert.assertTrue(actualSubscriptionPoolIds.contains(availableSubscriptionPool.poolId), "The result of list --available with --pool-only contains expected poolId '" + availableSubscriptionPool.poolId + "'.");
    Assert.assertEquals(actualSubscriptionPoolIds.size(), availableSubscriptionPools.size(), "The number of poolIds returned from calling list --pool-only should match the number of available SubscriptionPools listed without --pool-only.");
}
Also used : BigInteger(java.math.BigInteger) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) 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