Search in sources :

Example 56 with BugzillaAPIException

use of com.redhat.qe.auto.bugzilla.BugzillaAPIException 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 57 with BugzillaAPIException

use of com.redhat.qe.auto.bugzilla.BugzillaAPIException 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 58 with BugzillaAPIException

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

the class ListTests method createSubscriptionsWithVariationsOnProductAttributeSockets.

/*debugTest*/
@BeforeClass(groups = "setup")
public void createSubscriptionsWithVariationsOnProductAttributeSockets() throws JSONException, Exception {
    String name, productId, resourcePath;
    List<String> providedProductIds = new ArrayList<String>();
    Map<String, String> attributes = new HashMap<String, String>();
    JSONObject jsonEngProduct, jsonMktProduct, jsonSubscription;
    if (server == null) {
        log.warning("Skipping createSubscriptionsWithVariationsOnProductAttributeSockets() when server is null.");
        return;
    }
    // Awesome OS for 0 sockets
    name = "Awesome OS for systems with sockets value=0";
    productId = "0-sockets";
    providedProductIds.clear();
    providedProductIds.add("90001");
    attributes.clear();
    attributes.put("sockets", "0");
    attributes.put("version", "1.0");
    attributes.put("variant", "server");
    attributes.put("arch", "ALL");
    attributes.put("warning_period", "30");
    // delete already existing subscription and products
    CandlepinTasks.deleteSubscriptionsAndRefreshPoolsUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, sm_clientOrg, productId);
    resourcePath = "/products/" + productId;
    if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.0.0"))
        resourcePath = "/owners/" + sm_clientOrg + resourcePath;
    CandlepinTasks.deleteResourceUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, resourcePath);
    resourcePath = "/products/" + providedProductIds.get(0);
    if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.0.0"))
        resourcePath = "/owners/" + sm_clientOrg + resourcePath;
    CandlepinTasks.deleteResourceUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, resourcePath);
    // create a new engineering product, marketing product that provides the engineering product, and a subscription for the marketing product
    attributes.put("type", "SVC");
    CandlepinTasks.createProductUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, sm_clientOrg, name + " BITS", providedProductIds.get(0), 1, attributes, null);
    attributes.put("type", "MKT");
    CandlepinTasks.createProductUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, sm_clientOrg, name, productId, 1, attributes, null);
    CandlepinTasks.createSubscriptionAndRefreshPoolsUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, sm_clientOrg, 20, -1 * 24 * 60, /*1 day ago*/
    15 * 24 * 60, /*15 days from now*/
    getRandInt(), getRandInt(), productId, providedProductIds, null);
    // Awesome OS for no sockets
    name = "Awesome OS for systems with no sockets";
    productId = "no-sockets";
    providedProductIds.clear();
    providedProductIds.add("90002");
    attributes.clear();
    attributes.remove("sockets");
    attributes.put("version", "0.0");
    attributes.put("variant", "workstation");
    attributes.put("arch", "ALL");
    attributes.put("warning_period", "30");
    // delete already existing subscription and products
    CandlepinTasks.deleteSubscriptionsAndRefreshPoolsUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, sm_clientOrg, productId);
    resourcePath = "/products/" + productId;
    if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.0.0"))
        resourcePath = "/owners/" + sm_clientOrg + resourcePath;
    CandlepinTasks.deleteResourceUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, resourcePath);
    resourcePath = "/products/" + providedProductIds.get(0);
    if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.0.0"))
        resourcePath = "/owners/" + sm_clientOrg + resourcePath;
    CandlepinTasks.deleteResourceUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, resourcePath);
    // create a new engineering product, marketing product that provides the engineering product, and a subscription for the marketing product
    attributes.put("type", "SVC");
    CandlepinTasks.createProductUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, sm_clientOrg, name + " BITS", providedProductIds.get(0), 1, attributes, null);
    attributes.put("type", "MKT");
    CandlepinTasks.createProductUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, sm_clientOrg, name, productId, 1, attributes, null);
    CandlepinTasks.createSubscriptionAndRefreshPoolsUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, sm_clientOrg, 20, -1 * 24 * 60, /*1 day ago*/
    15 * 24 * 60, /*15 days from now*/
    getRandInt(), getRandInt(), productId, providedProductIds, null);
    // Awesome OS for "zero" sockets
    name = "Awesome OS for systems with sockets value=\"zero\"";
    productId = "zero-sockets";
    providedProductIds.clear();
    providedProductIds.add("90003");
    attributes.clear();
    attributes.put("sockets", "zero");
    attributes.put("version", "0.0");
    attributes.put("variant", "workstation");
    attributes.put("arch", "ALL");
    attributes.put("warning_period", "30");
    // TEMPORARY WORKAROUND FOR BUG
    // Bug 795552 - invalid literal for int() with base 10: 'null'
    String bugId = "795552";
    boolean invokeWorkaroundWhileBugIsOpen = true;
    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("Skipping the creation of product: " + name);
    } else {
        // END OF WORKAROUND
        // TEMPORARY WORKAROUND FOR BUG
        // Bug 858286 - Runtime Error For input string: "zero" at java.lang.NumberFormatException.forInputString:65
        bugId = "858286";
        invokeWorkaroundWhileBugIsOpen = true;
        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 */
        }
        BUG_858286: if (invokeWorkaroundWhileBugIsOpen) {
            log.warning("Skipping the creation of product: " + name);
        } else {
            // END OF WORKAROUND
            // delete already existing subscription and products
            CandlepinTasks.deleteSubscriptionsAndRefreshPoolsUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, sm_clientOrg, productId);
            resourcePath = "/products/" + productId;
            if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.0.0"))
                resourcePath = "/owners/" + sm_clientOrg + resourcePath;
            CandlepinTasks.deleteResourceUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, resourcePath);
            resourcePath = "/products/" + providedProductIds.get(0);
            if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.0.0"))
                resourcePath = "/owners/" + sm_clientOrg + resourcePath;
            CandlepinTasks.deleteResourceUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, resourcePath);
            // create a new engineering product, marketing product that provides the engineering product, and a subscription for the marketing product
            attributes.put("type", "SVC");
            // after the fix for bug 858286, the sockets attribute value MUST be a non-negative attribute	// 1/25/2013 TODO move this block of code to create 'Awesome OS for "zero" sockets' to its own testcase
            try {
                CandlepinTasks.createProductUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, sm_clientOrg, name + " BITS", providedProductIds.get(0), 1, attributes, null);
            } catch (java.lang.AssertionError ae) {
                String expectedProductCreationErrorMsg = "The attribute 'sockets' must be an integer value.";
                if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.0.24-1")) {
                    // candlepin commit 92957a3f9eabb699832541031a5ebd15334886ca	// 1416825: Abstracted out property validation to new validator framework
                    expectedProductCreationErrorMsg = "The attribute \"sockets\" must be a positive, integer value";
                }
                Assert.assertTrue(ae.getMessage().contains(expectedProductCreationErrorMsg), ae.getMessage() + " contains expected product creation failure message '" + expectedProductCreationErrorMsg + "'.");
                break BUG_858286;
            }
            attributes.put("type", "MKT");
            CandlepinTasks.createProductUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, sm_clientOrg, name, productId, 1, attributes, null);
            CandlepinTasks.createSubscriptionAndRefreshPoolsUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, sm_clientOrg, 20, -1 * 24 * 60, /*1 day ago*/
            15 * 24 * 60, /*15 days from now*/
            getRandInt(), getRandInt(), productId, providedProductIds, null);
        }
    }
    // Awesome OS for null sockets
    name = "Awesome OS for systems with sockets value=null";
    productId = "null-sockets";
    providedProductIds.clear();
    providedProductIds.add("90004");
    attributes.clear();
    attributes.put("sockets", null);
    attributes.put("version", "0.0");
    attributes.put("variant", "server");
    attributes.put("arch", "ALL");
    attributes.put("warning_period", "30");
    // TEMPORARY WORKAROUND FOR BUG
    // Bug 807452 - refresh pools FAILS WITH: org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: org.mozilla.javascript.WrappedException: Wrapped java.lang.NullPointerException (rules#737)]
    bugId = "807452";
    invokeWorkaroundWhileBugIsOpen = true;
    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("Skipping the creation of product: " + name);
    } else {
        // END OF WORKAROUND
        // TEMPORARY WORKAROUND FOR BUG
        // Bug 813529 - refresh pools FAILS WITH: org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: org.mozilla.javascript.WrappedException: Wrapped java.lang.NullPointerException (rules#846)]
        bugId = "813529";
        invokeWorkaroundWhileBugIsOpen = true;
        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("Skipping the creation of product: " + name);
        } else {
            // delete already existing subscription and products
            CandlepinTasks.deleteSubscriptionsAndRefreshPoolsUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, sm_clientOrg, productId);
            resourcePath = "/products/" + productId;
            if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.0.0"))
                resourcePath = "/owners/" + sm_clientOrg + resourcePath;
            CandlepinTasks.deleteResourceUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, resourcePath);
            resourcePath = "/products/" + providedProductIds.get(0);
            if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.0.0"))
                resourcePath = "/owners/" + sm_clientOrg + resourcePath;
            CandlepinTasks.deleteResourceUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, resourcePath);
            // create a new engineering product, marketing product that provides the engineering product, and a subscription for the marketing product
            attributes.put("type", "SVC");
            CandlepinTasks.createProductUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, sm_clientOrg, name + " BITS", providedProductIds.get(0), 1, attributes, null);
            attributes.put("type", "MKT");
            CandlepinTasks.createProductUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, sm_clientOrg, name, productId, 1, attributes, null);
            CandlepinTasks.createSubscriptionAndRefreshPoolsUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, sm_clientOrg, 20, -1 * 24 * 60, /*1 day ago*/
            15 * 24 * 60, /*15 days from now*/
            getRandInt(), getRandInt(), productId, providedProductIds, null);
        }
    }
// TODO: To get the product certs, use the CandlepinTasks REST API:
// "url": "/products/{product_uuid}/certificate",
// "GET"
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) BeforeClass(org.testng.annotations.BeforeClass)

Example 59 with BugzillaAPIException

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

the class ListTests method testCatCertContainingUTF8Character.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-37705", "RHEL7-51353" }, 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 = "rct: cat-cert an entitlement containing UTF-8 character(s)", groups = { "Tier2Tests", "SubscriptionContainingUTF8CharacterTests", "blockedByBug-890296", "blockedByBug-1048325" }, dependsOnMethods = { "testAttachSubscriptionContainingUTF8Character" }, priority = 130, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testCatCertContainingUTF8Character() throws JSONException, Exception {
    // TEMPORARY WORKAROUND FOR BUG
    // Bug 890296 - 'ascii' codec can't encode character u'\u2013'.
    String bugId = "890296";
    Boolean invokeWorkaroundWhileBugIsOpen = true;
    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) {
        // must cleanup utf8-subscription-sku to avoid contaminating other tests; then skip this test
        afterGroupForSubscriptionContainingUTF8CharacterTests();
        throw new SkipException("Skipping test while bug '" + bugId + "' is open.");
    }
    // END OF WORKAROUND
    List<File> entitlementCertFiles = clienttasks.getCurrentEntitlementCertFiles();
    Assert.assertEquals(entitlementCertFiles.size(), 1, "Expecting only one entitlement cert being consumed.");
    // [root@jsefler-6 ~]# rct cat-cert /etc/pki/entitlement/6487424643396210003.pem
    // Traceback (most recent call last):
    // File "/usr/bin/rct", line 44, in <module>
    // sys.exit(abs(main() or 0))
    // File "/usr/bin/rct", line 39, in main
    // return RctCLI().main()
    // File "/usr/share/rhsm/subscription_manager/cli.py", line 156, in main
    // return cmd.main()
    // File "/usr/share/rhsm/rct/commands.py", line 44, in main
    // return_code = self._do_command()
    // File "/usr/share/rhsm/rct/commands.py", line 92, in _do_command
    // skip_products=self.options.no_products)
    // File "/usr/share/rhsm/rct/printing.py", line 196, in printc
    // printer.printc(cert)
    // File "/usr/share/rhsm/rct/printing.py", line 105, in printc
    // print self.cert_to_str(cert)
    // File "/usr/share/rhsm/rct/printing.py", line 166, in cert_to_str
    // order_printer.as_str(cert.order), "\n".join(s))
    // File "/usr/share/rhsm/rct/printing.py", line 47, in as_str
    // s.append("\t%s: %s" % (_("Name"), xstr(order.name)))
    // File "/usr/share/rhsm/rct/printing.py", line 26, in xstr
    // return str(value)
    // UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in position 32: ordinal not in range(128)
    // [root@jsefler-6 ~]# echo $?
    // 1
    // SSHCommandResult sshCommandResult = clienttasks.runCommandWithLang(null/* null will cause command to be prefixed with PYTHONIOENCODING=ascii */, "rct cat-cert "+entitlementCertFiles.get(0));	// need for PYTHONIOENCODING=ascii workaround was eliminated by bug 1048325
    SSHCommandResult sshCommandResult = client.runCommandAndWait("rct cat-cert " + entitlementCertFiles.get(0));
    Assert.assertEquals(sshCommandResult.getExitCode(), Integer.valueOf(0), "ExitCode from an attempt to run rct cat-cert on an entitlement containing UTF-8 character(s)");
    Assert.assertEquals(sshCommandResult.getStderr().trim(), "", "Stderr from an attempt to run rct cat-cert on an entitlement containing UTF-8 character(s)");
}
Also used : SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) SkipException(org.testng.SkipException) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) File(java.io.File) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 60 with BugzillaAPIException

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

the class ListTests method testListConsumedMatchesProductsListedInTheEntitlementCerts.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-27117", "RHEL7-51343" }, 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: list of consumed entitlements should display the provided product marketing names", groups = { "Tier2Tests", "blockedByBug-878986", "blockedByBug-976924" }, dataProvider = "getAllEntitlementCertsData", // this new test implementation was implemented due to change in list of consumed product subscriptions (from many to one) - see bug 806986
enabled = true)
@ImplementsNitrateTest(caseId = 48092, fromPlan = 2481)
public void testListConsumedMatchesProductsListedInTheEntitlementCerts(EntitlementCert entitlementCert) {
    // find the consumed product subscription corresponding to this entitlement cert and assert there is only one found
    List<ProductSubscription> allConsumedProductSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
    List<ProductSubscription> productSubscriptions = ProductSubscription.findAllInstancesWithMatchingFieldFromList("serialNumber", entitlementCert.serialNumber, allConsumedProductSubscriptions);
    Assert.assertEquals(productSubscriptions.size(), 1, "Found a single consumed product subscription with a matching serialNumber from this entitlementCert: " + entitlementCert);
    ProductSubscription productSubscription = productSubscriptions.get(0);
    List<String> providedProductNames = new ArrayList<String>();
    for (ProductNamespace productNamespace : entitlementCert.productNamespaces) providedProductNames.add(productNamespace.name);
    // TEMPORARY WORKAROUND FOR BUG
    if (entitlementCert.orderNamespace.supportLevel == null || entitlementCert.orderNamespace.supportType == null) {
        String bugId = "842170";
        boolean invokeWorkaroundWhileBugIsOpen = true;
        try {
            if (invokeWorkaroundWhileBugIsOpen && BzChecker.getInstance().isBugOpen(bugId)) {
                log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId).toString() + " Bugzilla " + bugId + ".  (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId + ")");
                SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId);
            } else {
                invokeWorkaroundWhileBugIsOpen = false;
            }
        } catch (BugzillaAPIException be) {
        /* ignore exception */
        } catch (RuntimeException re) {
        /* ignore exception */
        }
        if (invokeWorkaroundWhileBugIsOpen) {
            throw new SkipException("While bug " + bugId + " is open, skipping assertion of consumed product subscription in list for entitlement's with a null support level/type.");
        }
    }
    // when the entitlement OID value parsed was null, it should effectively be reported as ""  (Reference related bugs 842170 847354)
    if (entitlementCert.orderNamespace.supportLevel == null)
        entitlementCert.orderNamespace.supportLevel = "";
    if (entitlementCert.orderNamespace.supportType == null)
        entitlementCert.orderNamespace.supportType = "";
    // Subscription Name:    	Awesome OS Server Bundled (2 Sockets, Standard Support)
    // Provides:             	Clustering Bits
    // Awesome OS Server Bits
    // Shared Storage Bits
    // Management Bits
    // Large File Support Bits
    // Load Balancing Bits
    // SKU:                  	awesomeos-server-2-socket-std
    // Contract:             	36
    // Account:              	12331131231
    // Serial Number:        	6683485045354827351
    // Active:               	True
    // Quantity Used:        	1
    // Service Level:        	Standard
    // Service Type:         	L1-L3
    // Starts:               	07/20/2012
    // Ends:                 	07/20/2013
    Calendar now = Calendar.getInstance();
    // TEMPORARY WORKAROUND FOR BUG
    boolean invokeWorkaroundWhileBugIsOpen = true;
    try {
        String bugId = "883486";
        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("The workaround while this bug is open is to compensate the expected entitlement start/end dates for daylight savings.");
        // adjust the expected entitlement dates for daylight savings time (changed by https://github.com/candlepin/subscription-manager/pull/385)
        // now.get(Calendar.DST_OFFSET) will equal 0 in the winter StandardTime; will equal 1000*60*60 in the summer DaylightSavingsTime (when the local time zone observes DST)
        entitlementCert.orderNamespace.startDate.add(Calendar.MILLISECOND, now.get(Calendar.DST_OFFSET) - entitlementCert.orderNamespace.startDate.get(Calendar.DST_OFFSET));
        entitlementCert.orderNamespace.endDate.add(Calendar.MILLISECOND, now.get(Calendar.DST_OFFSET) - entitlementCert.orderNamespace.endDate.get(Calendar.DST_OFFSET));
    }
    // END OF WORKAROUND
    // assert all of the product subscription's fields match the entitlement cert
    Assert.assertEquals(productSubscription.productName, entitlementCert.orderNamespace.productName, "productName from ProductSubscription in list --consumed matches productName from OrderNamespace in this entitlementCert");
    Assert.assertTrue(productSubscription.provides.containsAll(providedProductNames) && providedProductNames.containsAll(productSubscription.provides), "The consumed product subscription provides all the expected products " + providedProductNames + " from the provided ProductNamespaces in the entitlementCert.");
    Assert.assertEquals(productSubscription.productId, entitlementCert.orderNamespace.productId, "productId from ProductSubscription in list --consumed matches productId from OrderNamespace in this entitlementCert");
    Assert.assertEquals(productSubscription.contractNumber, entitlementCert.orderNamespace.contractNumber, "contractNumber from ProductSubscription in list --consumed matches contractNumber from OrderNamespace in this entitlementCert");
    Assert.assertEquals(productSubscription.accountNumber, entitlementCert.orderNamespace.accountNumber, "accountNumber from ProductSubscription in list --consumed matches accountNumber from OrderNamespace in this entitlementCert");
    if (now.after(entitlementCert.orderNamespace.startDate) && now.before(entitlementCert.orderNamespace.endDate)) {
        Assert.assertTrue(productSubscription.isActive, "isActive is True when the current time (" + EntitlementCert.formatDateString(now) + ") is between the start/end dates in this entitlementCert");
    } else {
        Assert.assertFalse(productSubscription.isActive, "isActive is False when the current time (" + EntitlementCert.formatDateString(now) + ") is NOT between the start/end dates in this entitlementCert");
    }
    Assert.assertEquals(productSubscription.quantityUsed.toString(), entitlementCert.orderNamespace.quantityUsed, "quantityUsed from ProductSubscription in list --consumed matches quantityUsed from OrderNamespace in this entitlementCert");
    Assert.assertEquals(productSubscription.serviceLevel, entitlementCert.orderNamespace.supportLevel, "serviceLevel from ProductSubscription in list --consumed matches supportLevel from OrderNamespace in this entitlementCert");
    Assert.assertEquals(productSubscription.serviceType, entitlementCert.orderNamespace.supportType, "serviceType from ProductSubscription in list --consumed matches serviceType from OrderNamespace in this entitlementCert");
    Assert.assertEquals(ProductSubscription.formatDateString(productSubscription.startDate), ProductSubscription.formatDateString(entitlementCert.orderNamespace.startDate), "startDate from ProductSubscription in list --consumed matches startDate from OrderNamespace (" + OrderNamespace.formatDateString(entitlementCert.orderNamespace.startDate) + ") after conversion from GMT in EntitlementCert to local time.");
    Assert.assertEquals(ProductSubscription.formatDateString(productSubscription.endDate), ProductSubscription.formatDateString(entitlementCert.orderNamespace.endDate), "endDate from ProductSubscription in list --consumed matches endDate from OrderNamespace (" + OrderNamespace.formatDateString(entitlementCert.orderNamespace.endDate) + ") after conversion from GMT in EntitlementCert to local time.");
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) ProductSubscription(rhsm.data.ProductSubscription) ArrayList(java.util.ArrayList) SkipException(org.testng.SkipException) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) ProductNamespace(rhsm.data.ProductNamespace) 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)

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