Search in sources :

Example 31 with BugzillaAPIException

use of com.redhat.qe.auto.bugzilla.BugzillaAPIException in project rhsm-qe by RedHatQE.

the class SubscriptionManagerCLITestScript method getRegisterCredentialsDataAsListOfLists.

/**
 * @return List of [String username, String password, String org]
 */
protected List<List<Object>> getRegisterCredentialsDataAsListOfLists() throws Exception {
    List<List<Object>> ll = new ArrayList<List<Object>>();
    if (!isSetupBeforeSuiteComplete)
        return ll;
    // when the candlepin server is not standalone, then we usually don't have access to the candlepin api paths to query the users, so let's use the input parameters
    if (!sm_serverType.equals(CandlepinType.standalone)) {
        for (String username : sm_clientUsernames) {
            String password = sm_clientPasswordDefault;
            // get the orgs for this username/password
            // List<Org> orgs = clienttasks.getOrgs(username,password);	// fails when: You must first accept Red Hat's Terms and conditions. Please visit https://www.redhat.com/wapps/ugc
            List<Org> orgs = Org.parse(clienttasks.orgs_(username, password, null, null, null, null, null, null).getStdout());
            // reveals when: You must first accept Red Hat's Terms and conditions. Please visit https://www.redhat.com/wapps/ugc
            if (orgs.isEmpty())
                orgs.add(new Org("null", "Null"));
            // append a username and password for each org the user belongs to
            for (Org org : orgs) {
                ll.add(Arrays.asList(new Object[] { username, password, org.orgKey }));
            }
        }
        return ll;
    }
    // Notes...
    // curl -k -u admin:admin https://jsefler-onprem-62candlepin.usersys.redhat.com:8443/candlepin/users | python -mjson.tool
    // curl -k -u admin:admin https://jsefler-onprem-62candlepin.usersys.redhat.com:8443/candlepin/users/testuser1 | python -mjson.tool
    // curl -k -u admin:admin https://jsefler-onprem-62candlepin.usersys.redhat.com:8443/candlepin/users/testuser1/owners | python -mjson.tool
    // get all of the candlepin users
    // curl -k -u admin:admin https://jsefler-onprem-62candlepin.usersys.redhat.com:8443/candlepin/users | python -mjson.tool
    JSONArray jsonUsers = new JSONArray(CandlepinTasks.getResourceUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, "/users"));
    for (int i = 0; i < jsonUsers.length(); i++) {
        JSONObject jsonUser = (JSONObject) jsonUsers.get(i);
        // Candlepin Users
        // {
        // "created": "2011-09-23T14:42:25.924+0000",
        // "hashedPassword": "e3e80f61a902ceca245e22005dffb4219ac1c5f7",
        // "id": "8a90f8c63296bc55013296bcc4040005",
        // "superAdmin": true,
        // "updated": "2011-09-23T14:42:25.924+0000",
        // "username": "admin"
        // },
        // Katello Users...
        // {
        // "created_at": "2011-09-24T01:29:02Z",
        // "disabled": false,
        // "helptips_enabled": true,
        // "id": 1,
        // "own_role_id": 4,
        // "page_size": 25,
        // "password": "07a1dacc4f283e817c0ba353bd1452de49ce5723b2b7f56f6ee2f1f400a974b360f98acb90b630c7fa411f692bdb4c5cdd0f4b916efcf3c77e7cd0453446b185TS0YtS0uRjY0UznEsx7JqGIpEM1vEfIrBSNGdnXkFdkxsDhjmyFINBJVvkCTxeC7",
        // "updated_at": "2011-09-24T01:29:02Z",
        // "username": "admin"
        // },
        // Boolean isSuperAdmin = jsonUser.getBoolean("superAdmin");
        String username = jsonUser.getString("username");
        String password = sm_clientPasswordDefault;
        if (username.equals(sm_serverAdminUsername))
            password = sm_serverAdminPassword;
        // TEMPORARY WORKAROUND FOR BUG: https://bugzilla.redhat.com/show_bug.cgi?id=741961 - jsefler 9/29/2011
        if (username.equals("anonymous")) {
            boolean invokeWorkaroundWhileBugIsOpen = true;
            String bugId = "741961";
            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("Ignoring the presence of user '" + username + "'.  No automated testing with this user will be executed.");
                continue;
            }
        }
        // END OF WORKAROUND
        // get the user's owners
        // curl -k -u testuser1:password https://jsefler-onprem-62candlepin.usersys.redhat.com:8443/candlepin/users/testuser1/owners | python -mjson.tool
        JSONArray jsonUserOwners = new JSONArray(CandlepinTasks.getResourceUsingRESTfulAPI(username, password, sm_serverUrl, "/users/" + username + "/owners"));
        for (int j = 0; j < jsonUserOwners.length(); j++) {
            JSONObject jsonOwner = (JSONObject) jsonUserOwners.get(j);
            // {
            // "contentPrefix": null,
            // "created": "2011-07-01T06:39:58.740+0000",
            // "displayName": "Snow White",
            // "href": "/owners/snowwhite",
            // "id": "8a90f8c630e46c7e0130e46ce114000a",
            // "key": "snowwhite",
            // "parentOwner": null,
            // "updated": "2011-07-01T06:39:58.740+0000",
            // "upstreamUuid": null
            // }
            String owner = jsonOwner.getString("key");
            // String username, String password, String owner
            ll.add(Arrays.asList(new Object[] { username, password, owner }));
        }
        // don't forget that some users (for which no owners are returned) probably have READ_ONLY permission to their orgs
        if (jsonUserOwners.length() == 0) {
            ll.add(Arrays.asList(new Object[] { username, password, null }));
        }
        // minimize the number of dataProvided rows (useful during automated testcase development)
        if (Boolean.valueOf(getProperty("sm.debug.dataProviders.minimize", "false")))
            break;
    }
    return ll;
}
Also used : Org(rhsm.data.Org) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) JSONObject(org.json.JSONObject) List(java.util.List) ArrayList(java.util.ArrayList) JSONObject(org.json.JSONObject)

Example 32 with BugzillaAPIException

use of com.redhat.qe.auto.bugzilla.BugzillaAPIException in project rhsm-qe by RedHatQE.

the class SubscriptionManagerCLITestScript method verifyNoSELinuxDenialsWereLoggedAfterClass.

@AfterClass(groups = { "setup" }, description = "Search the SELinux audit log for denials after running the current class of tests")
public void verifyNoSELinuxDenialsWereLoggedAfterClass() {
    for (SubscriptionManagerTasks clienttasks : Arrays.asList(client1tasks, client2tasks)) {
        if (clienttasks != null) {
            String avcRegex;
            String tailFromMarkedFile = RemoteFileTasks.getTailFromMarkedFile(clienttasks.sshCommandRunner, clienttasks.auditLogFile, selinuxClassMarker, "denied").trim();
            // TEMPORARY WORKAROUND
            // [root@jsefler-rhel7 ~]# tail -f /var/log/audit/audit.log | grep AVC
            // type=USER_AVC msg=audit(1470087122.008:24063): pid=693 uid=81 auid=4294967295 ses=4294967295 subj=system_u:system_r:system_dbusd_t:s0-s0:c0.c1023 msg='avc:  denied  { 0x2 } for msgtype=signal interface=org.freedesktop.login1.Manager member=SessionNew dest=org.freedesktop.DBus spid=691 tpid=720 scontext=system_u:system_r:systemd_logind_t:s0 tcontext=system_u:system_r:modemmanager_t:s0 tclass=(null)  exe="/usr/bin/dbus-daemon" sauid=81 hostname=? addr=? terminal=?'
            // type=USER_AVC msg=audit(1470087122.226:24068): pid=693 uid=81 auid=4294967295 ses=4294967295 subj=system_u:system_r:system_dbusd_t:s0-s0:c0.c1023 msg='avc:  denied  { 0x2 } for msgtype=signal interface=org.freedesktop.login1.Manager member=SessionRemoved dest=org.freedesktop.DBus spid=691 tpid=720 scontext=system_u:system_r:systemd_logind_t:s0 tcontext=system_u:system_r:modemmanager_t:s0 tclass=(null)  exe="/usr/bin/dbus-daemon" sauid=81 hostname=? addr=? terminal=?'
            avcRegex = "type=USER_AVC .* msgtype=signal interface=org.freedesktop.login1.Manager member=Session(New|Removed) dest=org.freedesktop.DBus .* exe=\"/usr/bin/dbus-daemon\" .*";
            if (!tailFromMarkedFile.isEmpty() && doesStringContainMatches(tailFromMarkedFile, avcRegex)) {
                boolean invokeWorkaroundWhileBugIsOpen = true;
                // Bug 1362273 - avc denied /var/log/audit/audit.log when "systemd: Started Session # of user root." is written to /var/log/messages every two minutes
                String bugId = "1362273";
                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("Ignoring the presence of AVC denials matching '" + avcRegex + "' while bug '" + bugId + "' is open.");
                    tailFromMarkedFile = tailFromMarkedFile.replaceAll(avcRegex, "");
                }
            }
            // END OF WORKAROUND
            Assert.assertTrue(tailFromMarkedFile.trim().isEmpty(), "No SELinux denials found in the audit log '" + clienttasks.auditLogFile + "' on client " + clienttasks.sshCommandRunner.getConnection().getRemoteHostname() + " while executing this test class.");
        }
    }
}
Also used : SubscriptionManagerTasks(rhsm.cli.tasks.SubscriptionManagerTasks) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) AfterClass(org.testng.annotations.AfterClass)

Example 33 with BugzillaAPIException

use of com.redhat.qe.auto.bugzilla.BugzillaAPIException in project rhsm-qe by RedHatQE.

the class EventTests method testEnititlementDeleted.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-21844", "RHEL7-51665" }, 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: Entitlement Deleted is sent over an RSS atom feed.", groups = { "Tier3Tests", "EnititlementDeleted_Test" }, dependsOnGroups = { "PoolModifiedAndEntitlementModified_Test" }, enabled = true, alwaysRun = true)
public // @ImplementsTCMS(id="")
void testEnititlementDeleted() throws Exception {
    if (sm_serverAdminUsername.equals("") || sm_serverAdminPassword.equals(""))
        throw new SkipException("This test requires the candlepin server admin username and password credentials.");
    // 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);
    // fire an unsubscribe event
    clienttasks.unsubscribeFromAllOfTheCurrentlyConsumedProductSubscriptions();
    String[] newEventTitles = new String[] { "ENTITLEMENT DELETED" };
    // COMPLIANCE CREATED events were added to support gutterball
    newEventTitles = new String[] { "COMPLIANCE CREATED", "COMPLIANCE CREATED", "ENTITLEMENT DELETED" };
    if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "0.9.37-1")) {
        // commit bb1d2e6184a6cd9b80ff9c9d3045e9d780116226	// Only send Compliance event when compliance changes
        newEventTitles = new String[] { "COMPLIANCE CREATED", "ENTITLEMENT DELETED" };
    }
    // TODO FIXME 7/21/2016 assertTheNewConsumerFeedIgnoringEventTitles() call below started failing because the actual newEventTitles occur in reverse order from expected
    if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.0.16-1")) {
        // probably candlepin commit 6beae873733174df24178a552b116fcb8c8876ef Dont trigger async compliance during batch revoke
        // attempting to reversing the order
        // if this does not help, then we might try to alter the assertTheNew*() methods to IgnoreOrder of just call the assertTheNew**Contains() methods ..
        // switched the expected order; after discussions with vritant and crog who said the order of the expected new event titles may not be a guaranteed and apparently that's okay
        newEventTitles = new String[] { "ENTITLEMENT DELETED", "COMPLIANCE CREATED" };
    }
    if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.1.1-1")) {
        // commit 1ad3fd6f338d9bbcedc8eba8361d4bc6c807f84d	1474443 compliance.created events now use UUID for 'consumerId' field
        newEventTitles = new String[] { "ENTITLEMENT DELETED" };
    }
    // 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[] { clienttasks.hostname + " returned the subscription for " + testPool.subscriptionName };
    }
    // END OF WORKAROUND
    // assert the consumer feed...
    // assertTheNewConsumerFeed(ownerKey, consumerCert.consumerid, oldConsumerFeed, newEventTitles);
    assertTheNewConsumerFeedIgnoringEventTitles(ownerKey, consumerCert.consumerid, oldConsumerFeed, newEventTitles, new HashSet<String>() {

        {
            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 (// DO NOT INTERFERE WITH THE "switched the expected order" FROM ABOVE
    SubscriptionManagerTasks.isVersion(servertasks.statusVersion, "<", "2.0.16-1"))
        if (servertasks.statusStandalone && virt_limit != null && !virt_limit.equals("0")) {
            newEventTitles = new String[] { "COMPLIANCE CREATED", "ENTITLEMENT DELETED" };
        }
    // assert the owner feed...
    // assertTheNewOwnerFeed(ownerKey, oldOwnerFeed, newEventTitles);
    assertTheNewOwnerFeedIgnoringEventTitles(ownerKey, oldOwnerFeed, newEventTitles, new HashSet<String>() {

        {
            add("COMPLIANCE CREATED");
        }
    });
    // assert the feed...
    // assertTheNewFeed(oldFeed, newEventTitles);
    assertTheNewFeedIgnoringEventTitles(oldFeed, newEventTitles, new HashSet<String>() {

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

Example 34 with BugzillaAPIException

use of com.redhat.qe.auto.bugzilla.BugzillaAPIException in project rhsm-qe by RedHatQE.

the class EventTests method testConsumerCreated.

// Test methods ***********************************************************************
@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-21840", "RHEL7-51661" }, 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: Consumer Created is sent over an RSS atom feed.", groups = { "Tier3Tests", "ConsumerCreated_Test" }, dependsOnGroups = {}, enabled = true)
public // @ImplementsTCMS(id="")
void testConsumerCreated() 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);
    // get the owner and consumer feeds before we test the firing of a new event
    String ownerKey = sm_clientOrg;
    SyndFeed oldFeed = CandlepinTasks.getSyndFeed(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl);
    SyndFeed oldOwnerFeed = CandlepinTasks.getSyndFeedForOwner(ownerKey, sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl);
    // fire a register event
    clienttasks.register(sm_clientUsername, sm_clientPassword, ownerKey, null, null, null, null, null, null, null, (String) null, null, null, null, null, null, null, null, null, null);
    String[] newEventTitles = new String[] { "CONSUMER CREATED" };
    // COMPLIANCE CREATED events were added to support gutterball
    newEventTitles = new String[] { "COMPLIANCE CREATED", "COMPLIANCE CREATED", "CONSUMER CREATED" };
    if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "0.9.37-1")) {
        // commit bb1d2e6184a6cd9b80ff9c9d3045e9d780116226	// Only send Compliance event when compliance changes
        newEventTitles = new String[] { "COMPLIANCE CREATED", "CONSUMER CREATED" };
    }
    if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.1.1-1")) {
        // commit 1ad3fd6f338d9bbcedc8eba8361d4bc6c807f84d	1474443 compliance.created events now use UUID for 'consumerId' field
        newEventTitles = new String[] { "CONSUMER 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[] { sm_clientUsername + " created new consumer " + clienttasks.hostname };
    }
    // END OF WORKAROUND
    ConsumerCert consumerCert = clienttasks.getCurrentConsumerCert();
    // assert the consumer feed...
    // assertTheNewConsumerFeed(ownerKey, consumerCert.consumerid, null, newEventTitles);
    assertTheNewConsumerFeedIgnoringEventTitles(ownerKey, consumerCert.consumerid, null, newEventTitles, new HashSet<String>() {

        {
            add("COMPLIANCE CREATED");
        }
    });
    // assert the owner feed...
    // assertTheNewOwnerFeed(ownerKey, oldOwnerFeed, newEventTitles);
    assertTheNewOwnerFeedIgnoringEventTitles(ownerKey, oldOwnerFeed, newEventTitles, new HashSet<String>() {

        {
            add("COMPLIANCE CREATED");
        }
    });
    // assert the feed...
    // assertTheNewFeed(oldFeed, newEventTitles);
    assertTheNewFeedIgnoringEventTitles(oldFeed, newEventTitles, new HashSet<String>() {

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

Example 35 with BugzillaAPIException

use of com.redhat.qe.auto.bugzilla.BugzillaAPIException in project rhsm-qe by RedHatQE.

the class EventTests method testImportCreated.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-21851", "RHEL7-51672" }, 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: Import Created is sent over an RSS atom feed.", groups = { "Tier3Tests", "blockedByBug-891334", "ImportCreated_Test" }, dependsOnGroups = { "ExportCreated_Test", "OwnerCreated_Test" }, enabled = true)
public // @ImplementsTCMS(id="")
void testImportCreated() throws Exception {
    // get the owner and consumer feeds before we test the firing of a new event
    String ownerKey = testJSONOwner.getString("key");
    SyndFeed oldFeed = CandlepinTasks.getSyndFeed(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl);
    SyndFeed oldOwnerFeed = CandlepinTasks.getSyndFeedForOwner(ownerKey, sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl);
    // do something that will fire an import created event
    CandlepinTasks.importConsumerUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, ownerKey, "/tmp/export.zip");
    // Note: the POOL CREATED comes from the subscribed pool
    String[] newEventTitles = new String[] { "IMPORT CREATED", "POOL CREATED", "SUBSCRIPTION CREATED" };
    if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.0.0")) {
        newEventTitles = new String[] { "IMPORT CREATED", "POOL CREATED" /*, "SUBSCRIPTION CREATED" is no longer created in candlepin-2.0 */
        };
    }
    List<String> newEventTitlesList = new ArrayList<String>();
    newEventTitlesList.addAll(Arrays.asList(newEventTitles));
    // 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[] { sm_clientOrg + " imported a manifest for owner " + ownerKey, sm_clientOrg + " created a pool for product " + testPool.subscriptionName, sm_clientOrg + " created new subscription for product " + testPool.subscriptionName };
    }
    // END OF WORKAROUND
    // assert the owner feed...
    // assertTheNewOwnerFeed(ownerKey, oldOwnerFeed, new String[]{"IMPORT CREATED", "POOL CREATED"});
    // assertTheNewOwnerFeed(ownerKey, oldOwnerFeed, newEventTitles);
    // could have one or two "POOL CREATED" events, ignore them
    assertTheNewOwnerFeedIgnoringEventTitles(ownerKey, oldOwnerFeed, newEventTitles, new HashSet<String>() {

        {
            add("POOL CREATED");
        }
    });
    // assert the feed...
    // assertTheNewFeed(oldFeed, new String[]{"IMPORT CREATED", "POOL CREATED", "SUBSCRIPTION CREATED"});
    // assertTheNewFeed(oldFeed, newEventTitles);	// TODO 12/6/2012 several POOL MODIFIED may occur between new events POOL CREATED and SUBSCRIPTION CREATED.  Seems to happen when re-running the script after hours of other troubleshooting runs.  Redeploying candlepin and running EventTests does NOT encounter the extraneous POOL MODIFIED event.  We may want change this to...  assertTheNewFeedContains(oldFeed, Arrays.asList(newEventTitles));
    // TODO 10/24/2013 don't yet understand why "RULES MODIFIED" have randomly started showing up like the POOL MODIFIED events in the comment above
    assertTheNewFeedIgnoringEventTitles(oldFeed, newEventTitles, new HashSet<String>() {

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

Aggregations

BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)134 Test (org.testng.annotations.Test)91 SkipException (org.testng.SkipException)89 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)88 SSHCommandResult (com.redhat.qe.tools.SSHCommandResult)77 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)55 ArrayList (java.util.ArrayList)44 SubscriptionPool (rhsm.data.SubscriptionPool)28 File (java.io.File)23 ProductSubscription (rhsm.data.ProductSubscription)23 ProductCert (rhsm.data.ProductCert)22 JSONObject (org.json.JSONObject)20 EntitlementCert (rhsm.data.EntitlementCert)16 InstalledProduct (rhsm.data.InstalledProduct)14 BigInteger (java.math.BigInteger)13 List (java.util.List)12 ConsumerCert (rhsm.data.ConsumerCert)11 SyndFeed (com.sun.syndication.feed.synd.SyndFeed)10 Calendar (java.util.Calendar)10 HashMap (java.util.HashMap)10