Search in sources :

Example 61 with BugzillaAPIException

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

the class ReleaseTests method testReleaseListMatchesCDN.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-20009", "RHEL7-55174" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier1")
@Test(description = "register to a RHEL subscription and verify that release --list matches the expected CDN listing for this x-stream release of RHEL", groups = { "Tier1Tests", "blockedByBug-818298", "blockedByBug-820639", "blockedByBug-844368", "blockedByBug-893746", "blockedByBug-904193", "blockedByBug-1506271" }, dataProvider = "getCredentialsToVerifyReleaseListMatchesCDN_Test", enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testReleaseListMatchesCDN(Object bugzilla, String username, String password, String org) throws JSONException, Exception {
    // make sure we are newly registered
    clienttasks.register(username, password, org, null, null, null, null, null, null, null, (List<String>) null, null, null, null, true, null, null, null, null, null);
    // get the current base RHEL product cert
    ProductCert rhelProductCert = clienttasks.getCurrentRhelProductCert();
    // find an available RHEL subscription pool that provides for this base RHEL product cert
    // List<SubscriptionPool> rhelSubscriptionPools = clienttasks.getCurrentlyAvailableSubscriptionPools(rhelProductCert.productId, sm_serverUrl);	// no longer works; encounters "Insufficient permissions"
    List<SubscriptionPool> rhelSubscriptionPools = clienttasks.getCurrentlyAvailableSubscriptionPools(rhelProductCert.productId, /*sm_serverAdminUsername*/
    username, /*sm_serverAdminPassword*/
    password, sm_serverUrl);
    if (rhelSubscriptionPools.isEmpty())
        throw new SkipException("Cannot find an available SubscriptionPool that provides for this installed RHEL Product: " + rhelProductCert);
    // choose one
    SubscriptionPool rhelSubscriptionPool = rhelSubscriptionPools.get(0);
    // subscribe to the RHEL subscription
    clienttasks.subscribeToSubscriptionPool(rhelSubscriptionPool);
    // get the currently expected release listing based on the currently enabled repos
    List<String> expectedReleases = clienttasks.getCurrentlyExpectedReleases();
    // get the actual release listing
    List<String> actualReleases = clienttasks.getCurrentlyAvailableReleases(null, null, null, null);
    // TEMPORARY WORKAROUND FOR BUG
    boolean invokeWorkaroundWhileBugIsOpen = true;
    String bugId = "1108257";
    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) {
        if (rhelProductCert.productNamespace.providedTags.contains("rhel-5-client-workstation")) {
            throw new SkipException("Skipping this test while bug '" + bugId + "' is open. (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId + ")");
        }
    }
    // TEMPORARY WORKAROUND FOR BUG
    if (actualReleases.isEmpty() && !expectedReleases.isEmpty()) {
        invokeWorkaroundWhileBugIsOpen = true;
        // Bug 1518886 - RHEL-ALT-7.5 product certs should also provide tag "rhel-7"
        bugId = "1518886";
        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) {
            if (Arrays.asList(new String[] { // this is a RHEL-ALT system
            "419", /* Red Hat Enterprise Linux for ARM 64 */
            "420", /* Red Hat Enterprise Linux for Power 9 */
            "434", /* Red Hat Enterprise Linux for IBM System z (Structure A) */
            "363", /* Red Hat Enterprise Linux for ARM 64 Beta */
            "362", /* Red Hat Enterprise Linux for Power 9 Beta */
            "433" /* Red Hat Enterprise Linux for IBM System z (Structure A) Beta */
            }).contains(rhelProductCert.productId)) {
                throw new SkipException("subscription-manager release listings on RHEL-ALT will be empty until bug '" + bugId + "' is fixed.");
            }
        }
    }
    // END OF WORKAROUND
    // assert that they are equivalent
    Assert.assertTrue(expectedReleases.containsAll(actualReleases) && actualReleases.containsAll(expectedReleases), "The actual subscription-manager releases list " + actualReleases + " matches the expected consolidated CDN listing " + expectedReleases + " after being granted an entitlement from subscription product: " + rhelSubscriptionPool.productId);
    Assert.assertTrue(expectedReleases.size() == actualReleases.size(), "The actual subscription-manager releases list " + actualReleases + " does not contain any duplicates.  It should be a unique list.");
}
Also used : ProductCert(rhsm.data.ProductCert) SkipException(org.testng.SkipException) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 62 with BugzillaAPIException

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

the class ReleaseTests method testReleaseListExcludes56OnRHEL5System.

@TestDefinition(projectID = {/*Project.RHEL5*/
}, testCaseID = {})
@Test(description = "register to a RHEL subscription and verify that release --list excludes 5.6, 5.5, 5.4, 5.3, 5.2, 5.1, 5.0", groups = { "Tier1Tests", "blockedByBug-785989", /*,"blockedByBug-840509" MOVED TO TEMPORARY WORKAROUND*/
"blockedByBug-919700" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testReleaseListExcludes56OnRHEL5System() throws JSONException, Exception {
    if (!clienttasks.redhatReleaseX.equals("5"))
        throw new SkipException("This test is only applicable on RHEL5.");
    // TEMPORARY WORKAROUND
    boolean invokeWorkaroundWhileBugIsOpen = true;
    String bugId = "840509";
    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("blockedByBug-840509");
    }
    // END OF WORKAROUND
    // make sure we are newly registered with autosubscribe
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, true, null, null, (List<String>) null, null, null, null, true, null, null, null, null, null);
    // get the current base RHEL product cert
    String providingTag = "rhel-" + clienttasks.redhatReleaseX;
    List<ProductCert> rhelProductCerts = clienttasks.getCurrentProductCerts(providingTag);
    // TODO: Don't know how to predict which one since I believe Workstation is really born after consuming a child channel of Client rather than a base channel; for now let's just assume the other
    if (clienttasks.releasever.equals("5Client") && rhelProductCerts.isEmpty()) {
        providingTag += "-workstation";
        rhelProductCerts = clienttasks.getCurrentProductCerts(providingTag);
    }
    Assert.assertEquals(rhelProductCerts.size(), 1, "Only one product cert is installed that provides RHEL tag '" + providingTag + "'");
    ProductCert rhelProductCert = rhelProductCerts.get(0);
    // assert that it was autosubscribed
    InstalledProduct rhelInstalledProduct = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productId", rhelProductCert.productId, clienttasks.getCurrentlyInstalledProducts());
    Assert.assertNotNull(rhelInstalledProduct, "Our base installed RHEL product was autosubscribed during registration.");
    // get the actual release listing
    List<String> actualReleases = clienttasks.getCurrentlyAvailableReleases(null, null, null, null);
    // assert that the list excludes 5.6, 5.5, 5.4, 5.3, 5.2, 5.1, 5.0, but includes the current X.Y release
    for (String release : new String[] { "5.6", "5.5", "5.4", "5.3", "5.2", "5.1", "5.0" }) {
        Assert.assertTrue(!actualReleases.contains(release), "The subscription-manager releases list should exclude '" + release + "' since '" + clienttasks.command + "' did not exist in RHEL Release '" + release + "'.");
    }
// NOT PRACTICAL SINCE CONTENT FROM THIS Y-STREAM MAY NOT BE AVAILABLE UNTIL GA Assert.assertTrue(actualReleases.contains(clienttasks.redhatReleaseXY), "The subscription-manager releases list should include '"+clienttasks.redhatReleaseXY+"' since it is the current RHEL Release under test.");
}
Also used : InstalledProduct(rhsm.data.InstalledProduct) ProductCert(rhsm.data.ProductCert) SkipException(org.testng.SkipException) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 63 with BugzillaAPIException

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

the class RepoOverrideTests method testAddAndRemoveRepoOverridesOneRepoAtATime.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-19976", "RHEL7-51015" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier1")
@Test(description = "add yum repo overrides, verify they persist, and remove them one repo at a time", groups = { "Tier1Tests", "blockedByBug-1069230", "blockedByBug-1034396" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testAddAndRemoveRepoOverridesOneRepoAtATime() {
    // register
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, true, false, null, null, null, null);
    // subscribe to a random pool (so as to consume an entitlement) and remember the original list of YumRepos read from the redhat.repo file
    List<YumRepo> originalYumRepos = attachRandomSubscriptionThatProvidesYumRepos();
    // choose a random small subset of repos to test repo-override
    List<YumRepo> originalYumReposSubset = getRandomSubsetOfList(originalYumRepos, 5);
    // add several repo overrides (one repo at a time)
    Map<String, Map<String, String>> repoOverridesMapOfMaps = new HashMap<String, Map<String, String>>();
    for (YumRepo yumRepo : originalYumReposSubset) {
        String repoId = yumRepo.id;
        Map<String, String> repoOverrideNameValueMap = new HashMap<String, String>();
        repoOverrideNameValueMap.put("enabled", "true");
        repoOverrideNameValueMap.put("gpgcheck", "false");
        repoOverrideNameValueMap.put("exclude", "foo-bar");
        repoOverrideNameValueMap.put("retries", "5");
        repoOverrideNameValueMap.put("ui_repoid_vars", "releasever basearch foo");
        repoOverrideNameValueMap.put("sslverify", "false");
        repoOverrideNameValueMap.put("sslcacert", "/overridden/candlepin.pem");
        repoOverrideNameValueMap.put("sslclientkey", "/overridden/serial-key.pem");
        repoOverrideNameValueMap.put("sslclientcert", "/overridden/serial.pem");
        repoOverridesMapOfMaps.put(repoId, repoOverrideNameValueMap);
        clienttasks.repo_override(null, null, repoId, null, repoOverrideNameValueMap, null, null, null, null);
    }
    // verify the current YumRepos read from the redhat.repo file actually contain the overrides
    verifyCurrentYumReposReflectRepoOverrides(originalYumRepos, repoOverridesMapOfMaps, true);
    // unsubscribe/resubscribe
    SSHCommandResult listResultBeforeUnsubscribe = clienttasks.repo_override_(true, null, (String) null, (String) null, null, null, null, null, null);
    List<String> poolIds = new ArrayList<String>();
    for (ProductSubscription productSubscription : clienttasks.getCurrentlyConsumedProductSubscriptions()) {
        clienttasks.unsubscribe(true, productSubscription.serialNumber, null, null, null, null, null);
        poolIds.add(productSubscription.poolId);
    }
    SSHCommandResult listResultAfterUnsubscribe = clienttasks.repo_override_(true, null, (String) null, (String) null, null, null, null, null, null);
    // valid prior to bug 1034396	Assert.assertEquals(listResultAfterUnsubscribe.getStdout().trim(), "This system does not have any subscriptions.", "Stdout from repo-override --list without any subscriptions attached (but should still have overrides cached in the consumer).");
    Assert.assertEquals(listResultAfterUnsubscribe.getStdout(), listResultBeforeUnsubscribe.getStdout(), "Stdout from repo-override --list without any subscriptions attached should be identical to the list when subscriptions were attached.");
    Assert.assertTrue(clienttasks.getCurrentlySubscribedYumRepos().isEmpty(), "The YumRepos in '" + clienttasks.redhatRepoFile + "' should be empty after unsubscribing from each serial.");
    clienttasks.subscribe(null, null, poolIds, null, null, null, null, null, null, null, null, null, null);
    // ...and verify the YumRepos read from the redhat.repo file persists the overrides
    verifyCurrentYumReposReflectRepoOverrides(originalYumRepos, repoOverridesMapOfMaps, false);
    // remove names from one repo override and verify the list
    // choose one repoId
    String repoId = (String) repoOverridesMapOfMaps.keySet().toArray()[0];
    clienttasks.repo_override(null, null, Arrays.asList(new String[] { repoId }), Arrays.asList(new String[] { "name" }), null, null, null, null, null);
    repoOverridesMapOfMaps.get(repoId).remove("name");
    clienttasks.repo_override(null, null, Arrays.asList(new String[] { repoId }), Arrays.asList(new String[] { "name", "enabled", "ui_repoid_vars" }), null, null, null, null, null);
    repoOverridesMapOfMaps.get(repoId).remove("name");
    repoOverridesMapOfMaps.get(repoId).remove("enabled");
    repoOverridesMapOfMaps.get(repoId).remove("ui_repoid_vars");
    // clienttasks.repo_override(null,null,Arrays.asList(new String[]{repoId}),Arrays.asList(new String[]{"gpgcheck","exclude","retries"}),null,null,null,null);	// for test variability, let's not delete these
    // repoOverridesMapOfMaps.get(repoId).remove("gpgcheck");
    // repoOverridesMapOfMaps.get(repoId).remove("exclude");
    // repoOverridesMapOfMaps.get(repoId).remove("retries");
    clienttasks.repo_override(null, null, Arrays.asList(new String[] { repoId }), Arrays.asList(new String[] { "sslverify", "sslcacert", "sslclientkey", "sslclientcert" }), null, null, null, null, null);
    repoOverridesMapOfMaps.get(repoId).remove("sslverify");
    repoOverridesMapOfMaps.get(repoId).remove("sslcacert");
    repoOverridesMapOfMaps.get(repoId).remove("sslclientkey");
    repoOverridesMapOfMaps.get(repoId).remove("sslclientcert");
    // repoOverridesMapOfMaps.remove(repoid);	// remove one repoid from the overrides Map
    // verify the current YumRepos read from the redhat.repo file no longer contains the removed override (the original should be restored)
    verifyCurrentYumReposReflectRepoOverrides(originalYumRepos, repoOverridesMapOfMaps, false);
    // remove all of the repo overrides
    clienttasks.repo_override(null, true, (String) null, (String) null, null, null, null, null, null);
    repoOverridesMapOfMaps.clear();
    // TEMPORARY WORKAROUND
    if (CandlepinType.standalone.equals(sm_serverType)) {
        boolean invokeWorkaroundWhileBugIsOpen = true;
        // Bug 1195501 - The redhat.repo file should be refreshed after a successful repo-override removal
        String bugId = "1195501";
        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) {
            // trigger a yum transaction so that subscription-manager yum plugin will refresh redhat.repo
            // sshCommandRunner.runCommandAndWait("killall -9 yum"); // is this needed?
            // sshCommandRunner.runCommandAndWait("yum repolist all --disableplugin=rhnplugin"); // --disableplugin=rhnplugin helps avoid: up2date_client.up2dateErrors.AbuseError
            // sshCommandRunner.runCommandAndWait("yum -q repolist --disableplugin=rhnplugin"); // --disableplugin=rhnplugin helps avoid: up2date_client.up2dateErrors.AbuseError
            // NOT REALLY SURE WHAT TO DO HERE SINCE THE WORKAROUNDS ARE UNRELIABLE
            log.warning("Skipping test's final assertion on repo-override removal while bug '" + bugId + "' is open.");
            return;
        }
    }
    // END OF WORKAROUND
    // verify the current YumRepos read from the redhat.repo file no longer contains any overrides (the original should be restored)
    verifyCurrentYumReposReflectRepoOverrides(originalYumRepos, repoOverridesMapOfMaps, false);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProductSubscription(rhsm.data.ProductSubscription) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) YumRepo(rhsm.data.YumRepo) HashMap(java.util.HashMap) Map(java.util.Map) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 64 with BugzillaAPIException

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

the class ReposTests method testReposListReportsGrantedContentNamespacesAfterSubscribingToPool.

// 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-19972", "RHEL7-51011" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier1")
@Test(description = "subscription-manager: subscribe to a pool and verify that the newly entitled content namespaces are represented in the repos list", groups = { "Tier1Tests", "blockedByBug-807407", "blockedByBug-962520", "blockedByBug-1034649" }, // dataProvider="getAvailableSubscriptionPoolsData",	// very thorough, but takes too long to execute and rarely finds more bugs
dataProvider = "getRandomSubsetOfAvailableSubscriptionPoolsData", enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testReposListReportsGrantedContentNamespacesAfterSubscribingToPool(SubscriptionPool pool) throws JSONException, Exception {
    log.info("Following is a list of previously subscribed repos...");
    List<Repo> priorRepos = clienttasks.getCurrentlySubscribedRepos();
    // choose a quantity before subscribing to avoid Stdout: Quantity '1' is not a multiple of instance multiplier '2'
    String quantity = null;
    /*if (clienttasks.isPackageVersion("subscription-manager",">=","1.10.3-1"))*/
    if (pool.suggested != null) {
        // when the Suggested quantity is 0, let's specify a quantity to avoid Stdout: Quantity '1' is not a multiple of instance multiplier '2'
        if (pool.suggested < 1)
            quantity = CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "instance_multiplier");
        if (pool.suggested > 1 && quantity == null)
            quantity = pool.suggested.toString();
    }
    // subscribe and get the granted entitlement
    // File entitlementCertFile = clienttasks.subscribeToSubscriptionPool(pool);	// for this test, we can skip the exhaustive asserts done by this call to clienttasks.subscribeToSubscriptionPool(pool)
    File entitlementCertFile = clienttasks.subscribeToSubscriptionPool_(pool, quantity);
    Assert.assertTrue(RemoteFileTasks.testExists(client, entitlementCertFile.getPath()), "Found the EntitlementCert file (" + entitlementCertFile + ") that was granted after subscribing to pool id '" + pool.poolId + "'.");
    EntitlementCert entitlementCert = clienttasks.getEntitlementCertFromEntitlementCertFile(entitlementCertFile);
    // check the modifierSubscriptionData for SubscriptionPools that may already have been subscribed too and will modify this pool thereby enabling more repos than expected
    for (List<Object> row : modifierSubscriptionData) {
        // ll.add(Arrays.asList(new Object[]{modifierPool, label, modifiedProductIds, requiredTags, providingPools}));
        SubscriptionPool modifierPool = (SubscriptionPool) row.get(0);
        String label = (String) row.get(1);
        List<String> modifiedProductIds = (List<String>) row.get(2);
        String requiredTags = (String) row.get(3);
        List<SubscriptionPool> poolsModified = (List<SubscriptionPool>) row.get(4);
        if (poolsModified.contains(pool)) {
            if (priorSubscribedPoolIds.contains(modifierPool.poolId)) {
                // the modifier's content should now be available in the repos too
                EntitlementCert modifierEntitlementCert = clienttasks.getEntitlementCertCorrespondingToSubscribedPool(modifierPool);
                // simply add the contentNamespaces (if not already there) from the modifier to the entitlement cert's contentNamespaces so they will be accounted for in the repos list test below
                for (ContentNamespace contentNamespace : modifierEntitlementCert.contentNamespaces) {
                    if (!contentNamespace.type.equalsIgnoreCase("yum"))
                        continue;
                    if (!entitlementCert.contentNamespaces.contains(contentNamespace)) {
                        log.warning("Due to a previously subscribed modifier subscription pool (" + modifierPool.subscriptionName + "), the new repos listed should also include ContentNamespace: " + contentNamespace);
                        entitlementCert.contentNamespaces.add(contentNamespace);
                    }
                }
            }
        }
    }
    priorSubscribedPoolIds.add(pool.poolId);
    log.info("Following is the new list of subscribed repos after subscribing to pool: " + pool);
    List<Repo> actualRepos = clienttasks.getCurrentlySubscribedRepos();
    // assert that the new contentNamespaces from the entitlementCert are listed in repos
    int numNewRepos = 0;
    for (ContentNamespace contentNamespace : entitlementCert.contentNamespaces) {
        if (!contentNamespace.type.equalsIgnoreCase("yum"))
            continue;
        // instantiate the expected Repo that represents this contentNamespace
        // the expected RepoUrl is set by joining the rhsm.conf baseurl with the downloadUrl in the contentNamespace which is usually a relative path.  When it is already a full path, leave it!
        String expectedRepoUrl;
        if (contentNamespace.downloadUrl.contains("://")) {
            expectedRepoUrl = contentNamespace.downloadUrl;
        } else {
            // join baseurl to downloadUrl with "/"
            expectedRepoUrl = clienttasks.baseurl.replaceFirst("//+$", "//") + contentNamespace.downloadUrl.replaceFirst("^//+", "");
        }
        Repo expectedRepo = new Repo(contentNamespace.name, contentNamespace.label, expectedRepoUrl, contentNamespace.enabled);
        // assert the subscription-manager repos --list reports the expectedRepo (unless it requires tags that are not found in the installed product certs)
        if (clienttasks.areAllRequiredTagsInContentNamespaceProvidedByProductCerts(contentNamespace, currentProductCerts)) {
            // TEMPORARY WORKAROUND FOR Bug 1246636 - an expected entitled content set is not reflected in subscription-manager repos --list
            if (expectedRepo.repoName.equals("content") && !actualRepos.contains(expectedRepo)) {
                boolean invokeWorkaroundWhileBugIsOpen = true;
                String bugId = "1246636";
                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("The newly entitled contentNamespace '" + contentNamespace + "' is NOT represented in the subscription-manager repos --list by: " + expectedRepo);
                    continue;
                }
            }
            // END OF WORKAROUND
            Assert.assertTrue(actualRepos.contains(expectedRepo), "The newly entitled contentNamespace '" + contentNamespace + "' is represented in the subscription-manager repos --list by: " + expectedRepo);
            // also count the number of NEW contentNamespaces
            if (!priorRepos.contains(expectedRepo))
                numNewRepos++;
        } else {
            Assert.assertFalse(actualRepos.contains(expectedRepo), "The newly entitled contentNamespace '" + contentNamespace + "' is NOT represented in the subscription-manager repos --list because it requires tags (" + contentNamespace.requiredTags + ") that are not provided by the currently installed product certs.");
        }
    }
    // assert that the number of repos reported has increased by the number of contentNamespaces in the new entitlementCert (unless the
    Assert.assertEquals(actualRepos.size(), priorRepos.size() + numNewRepos, "The number of entitled repos has increased by the number of NEW contentNamespaces (" + numNewRepos + ") from the newly granted entitlementCert (including applicable contentNamespaces from a previously subscribed modifier pool).");
// randomly decide to unsubscribe from the pool only for the purpose of saving on accumulated logging and avoid a java heap memory error
// if (randomGenerator.nextInt(2)==1) clienttasks.unsubscribe(null, entitlementCert.serialNumber, null, null, null); AND ALSO REMOVE pool FROM priorSubscribedPools
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) ContentNamespace(rhsm.data.ContentNamespace) Repo(rhsm.data.Repo) YumRepo(rhsm.data.YumRepo) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 65 with BugzillaAPIException

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

the class RHELPersonalTests method testSubPoolIsAvailableAfterRegisteredPersonSubscribesToRHELPersonal.

// Test Methods ***********************************************************************
@Test(description = "subscription-manager-cli: Ensure RHEL Personal Bits are available and unlimited after a person has subscribed to RHEL Personal", groups = { "Tier2Tests", "EnsureSubPoolIsAvailableAfterRegisteredPersonSubscribesToRHELPersonal_Test", "RHELPersonal", "blockedByBug-624816", "blockedByBug-641155", "blockedByBug-643405", "blockedByBug-967160" }, priority = 100, // 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 CLOSED WONTFIX BUG https://bugzilla.redhat.com/show_bug.cgi?id=967160#c1
enabled = false)
@ImplementsNitrateTest(caseId = 55702)
public // @ImplementsNitrateTest(caseId={55702,55718})
void testSubPoolIsAvailableAfterRegisteredPersonSubscribesToRHELPersonal() throws JSONException {
    if (client2tasks == null)
        throw new SkipException("These tests are designed to use a second client.");
    if (username.equals(sm_serverAdminUsername))
        throw new SkipException("This test requires that the client user (" + username + ") is NOT " + sm_serverAdminUsername);
    // TEMPORARY WORKAROUND FOR BUG: https://bugzilla.redhat.com/show_bug.cgi?id=624423 - jsefler 8/16/2010
    Boolean invokeWorkaroundWhileBugIsOpen = false;
    try {
        String bugId = "624423";
        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) {
        servertasks.restartTomcat();
    }
    // END OF WORKAROUND
    client2tasks.unregister(null, null, null, null);
    // just in case client1 is still registered as the person consumer
    client1tasks.unregister(null, null, null, null);
    for (int j = 0; j < sm_personSubscriptionPoolProductData.length(); j++) {
        JSONObject poolProductDataAsJSONObject = (JSONObject) sm_personSubscriptionPoolProductData.get(j);
        String personProductId = poolProductDataAsJSONObject.getString("personProductId");
        JSONObject subpoolProductDataAsJSONObject = poolProductDataAsJSONObject.getJSONObject("subPoolProductData");
        String systemProductId = subpoolProductDataAsJSONObject.getString("systemProductId");
        SubscriptionPool pool = null;
        log.info("Register client2 under username '" + username + "' as a system and assert that ProductId '" + systemProductId + "' is NOT yet available...");
        client2tasks.register(username, password, owner, null, ConsumerType.system, null, null, null, null, null, (String) null, null, null, null, null, false, null, null, null, null);
        List<SubscriptionPool> client2BeforeSubscriptionPools = client2tasks.getCurrentlyAvailableSubscriptionPools();
        pool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", systemProductId, client2BeforeSubscriptionPools);
        Assert.assertNull(pool, "ProductId '" + systemProductId + "' is NOT yet available to client2 system '" + client2.getConnection().getRemoteHostname() + "' registered under user '" + username + "'.");
        // log.info("Now register client1 under username '"+consumerUsername+"' as a person and subscribe to the '"+personSubscriptionName+"' subscription pool...");
        log.info("Now register client1 under username '" + username + "' as a person and subscribe to the personal subscription pool with ProductId '" + personProductId + "'...");
        // client1tasks.unregister(null, null, null);
        client1tasks.register(username, password, owner, null, ConsumerType.person, null, null, null, null, null, (String) null, null, null, null, null, false, null, null, null, null);
        personConsumerId = client1tasks.getCurrentConsumerId();
        // pool = client1tasks.findSubscriptionPoolWithMatchingFieldFromList("subscriptionName",personSubscriptionName,client1tasks.getCurrentlyAllAvailableSubscriptionPools());
        pool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", personProductId, client1tasks.getCurrentlyAvailableSubscriptionPools());
        personSubscriptionName = pool.subscriptionName;
        Assert.assertNotNull(pool, "Personal Subscription with ProductId '" + personProductId + "' is available to user '" + username + "' registered as a person.");
        client1tasks.subscribeToSubscriptionPool(pool);
        log.info("Now client2 (already registered as a system under username '" + username + "') should now have ProductId '" + systemProductId + "' available with a quantity if '" + systemSubscriptionQuantity + "'...");
        List<SubscriptionPool> client2AfterSubscriptionPools = client2tasks.getCurrentlyAvailableSubscriptionPools();
        SubscriptionPool systemSubscriptionPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", systemProductId, client2AfterSubscriptionPools);
        Assert.assertNotNull(systemSubscriptionPool, "ProductId '" + systemProductId + "' is now available to client2 '" + client2.getConnection().getRemoteHostname() + "' (registered as a system under username '" + username + "')");
        Assert.assertEquals(systemSubscriptionPool.quantity.toLowerCase(), systemSubscriptionQuantity, "A quantity of '" + systemSubscriptionQuantity + "' entitlements is available to the subscription for " + systemProductId + ".");
        log.info("Verifying that the available subscription pools available to client2 has increased by only the '" + systemProductId + "' pool...");
        Assert.assertTrue(client2AfterSubscriptionPools.containsAll(client2BeforeSubscriptionPools) && client2AfterSubscriptionPools.contains(systemSubscriptionPool) && client2AfterSubscriptionPools.size() == client2BeforeSubscriptionPools.size() + 1, "The list of available subscription pools seen by client2 increases only by '" + systemProductId + "' pool: " + systemSubscriptionPool);
    }
}
Also used : JSONObject(org.json.JSONObject) SkipException(org.testng.SkipException) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) SubscriptionPool(rhsm.data.SubscriptionPool) 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