Search in sources :

Example 36 with ProductSubscription

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

the class ListTests method assertActualResultOfListConsumedWithMatches.

protected void assertActualResultOfListConsumedWithMatches(String matchesString, List<ProductSubscription> actualProductSubscriptionMatches, List<ProductSubscription> consumedProductSubscriptions) throws JSONException, Exception {
    // translate matchesString into a regexString
    // escape parentheses
    String regexString = matchesString.toLowerCase().replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)");
    // splat wildcards match any zero or more chars
    regexString = regexString.replaceAll("\\*", ".*");
    // question mark wildcards match any one char
    regexString = regexString.replaceAll("\\?", ".");
    // search through the available availableSubscriptionPools for expected matches on the matchesString
    // NOTE: exact matches means no wildcards and is case insensitive
    List<ProductSubscription> expectedProductSubscriptionMatches = new ArrayList<ProductSubscription>();
    for (ProductSubscription consumedProductSubscription : consumedProductSubscriptions) {
        // Test for match on Subscription Name:
        if (consumedProductSubscription.productName.toLowerCase().matches(regexString)) {
            log.info("Found a hit on matches '" + matchesString + "' against the consumed subscription '" + consumedProductSubscription.productName + "' Subscription Name: " + consumedProductSubscription.productName);
            if (!expectedProductSubscriptionMatches.contains(consumedProductSubscription))
                expectedProductSubscriptionMatches.add(consumedProductSubscription);
        }
        // Test for match on Provides:
        for (String providesName : consumedProductSubscription.provides) {
            if (providesName.toLowerCase().matches(regexString)) {
                log.info("Found a hit on matches '" + matchesString + "' against the consumed subscription '" + consumedProductSubscription.productName + "' Provides: " + consumedProductSubscription.provides);
                if (!expectedProductSubscriptionMatches.contains(consumedProductSubscription))
                    expectedProductSubscriptionMatches.add(consumedProductSubscription);
            }
        }
        // Test for match on SKU:
        if (consumedProductSubscription.productId.toLowerCase().matches(regexString)) {
            log.info("Found a hit on matches '" + matchesString + "' against the consumed subscription '" + consumedProductSubscription.productName + "' SKU: " + consumedProductSubscription.productId);
            if (!expectedProductSubscriptionMatches.contains(consumedProductSubscription))
                expectedProductSubscriptionMatches.add(consumedProductSubscription);
        }
        // Test for match on Contract:
        if (String.valueOf(consumedProductSubscription.contractNumber).toLowerCase().matches(regexString)) {
            log.info("Found a hit on matches '" + matchesString + "' against the consumed subscription '" + consumedProductSubscription.productName + "' Contract: " + consumedProductSubscription.contractNumber);
            if (!expectedProductSubscriptionMatches.contains(consumedProductSubscription))
                expectedProductSubscriptionMatches.add(consumedProductSubscription);
        }
        // Test for match on Service Level:
        if (consumedProductSubscription.serviceLevel.toLowerCase().matches(regexString)) {
            log.info("Found a hit on matches '" + matchesString + "' against the consumed subscription '" + consumedProductSubscription.productName + "' Service Level: " + consumedProductSubscription.serviceLevel);
            if (!expectedProductSubscriptionMatches.contains(consumedProductSubscription))
                expectedProductSubscriptionMatches.add(consumedProductSubscription);
        }
        // Test for match on Provided ProductId:
        for (String providedProductId : CandlepinTasks.getPoolProvidedProductIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, consumedProductSubscription.poolId)) {
            if (providedProductId.toLowerCase().matches(regexString)) {
                log.info("Found a hit on matches '" + matchesString + "' against the consumed subscription '" + consumedProductSubscription.productName + "' Provided Product ID: " + providedProductId);
                if (!expectedProductSubscriptionMatches.contains(consumedProductSubscription))
                    expectedProductSubscriptionMatches.add(consumedProductSubscription);
            }
        }
    // debugTesting
    // THIS TEST IS WRONG. DO NOT CHECK FOR MATCHES ON *DERIVED* PRODUCT IDS
    // // Test for match on Derived Provided ProductId:
    // for (String derivedProvidedProductId : CandlepinTasks.getPoolDerivedProvidedProductIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, consumedProductSubscription.poolId)) {
    // if (derivedProvidedProductId.toLowerCase().matches(regexString)) {
    // log.info("Found a hit on matches '"+matchesString+"' against the consumed subscription '"+consumedProductSubscription.productName+"' Derived Provided Product ID: "+derivedProvidedProductId);
    // if (!expectedProductSubscriptionMatches.contains(consumedProductSubscription)) expectedProductSubscriptionMatches.add(consumedProductSubscription);
    // }
    // }
    // Test for match on Derived Provided ProductId:
    // NOTE: list --available --matches is implemented server-side and appears to be searching the derivedProvidedProducts for product id matches.  Although unexpected, this feature has some benefit.
    // This behavior is in contrast to list --consumed --matches which is implemented client-side and does NOT search the derivedProvidedProducts for match on product id.
    // 10/31/2014 Verbal scrum discussion with devel decided to keep this behavior.
    /* Not testing for a derivedProvidedProduct ID match against --consumed as a result of discussion above 
			for (String derivedProvidedProductId : CandlepinTasks.getPoolDerivedProvidedProductIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, consumedProductSubscription.poolId)) {
				if (derivedProvidedProductId.toLowerCase().matches(regexString)) {
					log.info("Found a hit on matches '"+matchesString+"' against the consumed subscription '"+consumedProductSubscription.productName+"' Derived Provided Product ID: "+derivedProvidedProductId);
					if (!expectedProductSubscriptionMatches.contains(consumedProductSubscription)) expectedProductSubscriptionMatches.add(consumedProductSubscription);		
				}
			}
			*/
    // TODO May want to open an RFE to also search on these other consumed product fields
    // See https://bugzilla.redhat.com/show_bug.cgi?id=1146125#c7
    // Account:           12331131231
    // Serial:            2808682313592781316
    // Pool ID:           2c90af8b494355790149435902da0ee8
    // Active:            True
    // Quantity Used:     1
    // Service Type:
    // Status Details:
    // Subscription Type: Stackable
    // System Type:       Physical
    }
    // assert that all of the expectedProductSubscriptionMatches is identical to the actualProductSubscriptionMatches
    for (ProductSubscription expectedProductSubscription : expectedProductSubscriptionMatches) {
        if (!actualProductSubscriptionMatches.contains(expectedProductSubscription))
            log.warning("The actual list of product subscription matches does NOT contain expected product subscription: " + expectedProductSubscription);
    }
    for (ProductSubscription actualProductSubscription : actualProductSubscriptionMatches) {
        if (!expectedProductSubscriptionMatches.contains(actualProductSubscription))
            // issues with bug 1204311 are showing up here
            log.warning("The expected list of product subscription matches does NOT contain actual product subscription: " + actualProductSubscription);
    }
    Assert.assertTrue(expectedProductSubscriptionMatches.containsAll(actualProductSubscriptionMatches) && actualProductSubscriptionMatches.containsAll(expectedProductSubscriptionMatches), "All of the expected consumed subscriptions with an exact match (ignoring case) on '" + matchesString + "' were returned with the list --consumed --matches option.");
}
Also used : ProductSubscription(rhsm.data.ProductSubscription) ArrayList(java.util.ArrayList)

Example 37 with ProductSubscription

use of rhsm.data.ProductSubscription 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)

Example 38 with ProductSubscription

use of rhsm.data.ProductSubscription 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 39 with ProductSubscription

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

the class RHELPersonalTests method testEntitlementCertForSubPoolIsNotRevokedOnceAnotherSystemUnsubscribesFromSubPool.

// DUE TO BEHAVIOR CHNAGE, THIS TEST WAS REPLACED BY EnsurePersonCannotUnsubscribeWhileSubpoolsAreConsumed_Test
// @Test(	description="subscription-manager-cli: Ensure that the entitlement certs for subscribed subpool is revoked once the person unsubscribes from RHEL Personal",
// groups={"Tier2Tests","EnsureEntitlementCertForSubPoolIsRevokedOncePersonUnsubscribesFromRHELPersonal_Test","RHELPersonal","blockedByBug-639434"},
// dependsOnGroups={"SubscribeMultipleSystemsToSubPool_Test","EnsurePersonCannotUnsubscribeWhileSubpoolsAreConsumed_Test","EnsurePersonCannotUnregisterWhileSubpoolsAreConsumed_Test"},
// //			dataProvider="getRHELPersonalData",
// enabled=true)
// @ImplementsNitrateTest(caseId=58898)
// // 1) unsubscribe person from personal pool while systems are subscribed to subpool (scenario from calfanso@redhat.com)
// public void EnsureEntitlementCertForSubPoolIsRevokedOncePersonUnsubscribesFromRHELPersonal_Test(/*String consumerUsername,	String consumerPassword,	String personSubscriptionName,		String systemSubscriptionName,	String systemConsumedProductName*/) {
// log.info("Assuming that multiple systems have subscribed to subpool '"+systemSubscriptionName+"' in prior testcase...");
// 
// log.info("Now, unsubscribe the person on client 1 from the '"+personSubscriptionName+"' and assert that the '"+systemConsumedProductName+"' and '"+systemSubscriptionName+"' gets revoked from the system consumers.");
// client1tasks.unsubscribeFromAllOfTheCurrentlyConsumedProductSubscriptions();
// 
// log.info("Now the the certs for '"+systemConsumedProductName+"' and '"+systemSubscriptionName+"' should be revoked from the system consumers...");
// for (String consumerId : consumerIds) {
// //client2tasks.reregister(consumerUsername,consumerPassword,consumerId);
// client2tasks.reregisterToExistingConsumer(consumerUsername,consumerPassword,consumerId);
// // 10/11/2010 NOT NEEDED SINCE register --consumerid NOW REFRESHES CERTS			client2tasks.restart_rhsmcertd(1, true);	// give rhsmcertd a chance to download the consumer's certs
// ProductSubscription productSubscription = client2tasks.findProductSubscriptionWithMatchingFieldFromList("productName",systemConsumedProductName,client2tasks.getCurrentlyConsumedProductSubscriptions());
// Assert.assertTrue(productSubscription==null,systemConsumedProductName+" is no longer consumed by '"+consumerId+"' (registered as a system under username '"+consumerUsername+"')");
// SubscriptionPool systemSubscriptionPool = client2tasks.findSubscriptionPoolWithMatchingFieldFromList("subscriptionName",systemSubscriptionName,client2tasks.getCurrentlyAvailableSubscriptionPools());
// Assert.assertTrue(systemSubscriptionPool==null,systemSubscriptionName+" is no longer available to consumer '"+consumerId+"' (registered as a system under username '"+consumerUsername+"')");
// }
// }
@Test(description = "subscription-manager-cli: Ensure that unsubscribing system from subpool while other systems are subscribed to subpool does not cause subpool to go away", groups = { "Tier2Tests", "EnsureEntitlementCertForSubPoolIsNotRevokedOnceAnotherSystemUnsubscribesFromSubPool_Test", "RHELPersonal", "blockedByBug-643405" }, // dependsOnGroups={"SubscribeMultipleSystemsToSubPool_Test","EnsurePersonCannotUnsubscribeWhileSubpoolsAreConsumed_Test","EnsurePersonCannotUnregisterWhileSubpoolsAreConsumed_Test"},
priority = 160, dependsOnMethods = { "testSubscribeMultipleSystemsToSubPool" }, // 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 = 58899)
public // 2) unsubscribe system from subpool while other systems are subscribed to subpool, make sure the subpool doesn't go away (scenario from calfanso@redhat.com)
void testEntitlementCertForSubPoolIsNotRevokedOnceAnotherSystemUnsubscribesFromSubPool() throws JSONException {
    log.info("Now start unsubscribing each system from the consumed product(s) and assert the personal sub pool is still available...");
    for (String consumerId : systemConsumerIds) {
        // client2tasks.reregister(consumerUsername,consumerPassword,consumerId);
        client2tasks.reregisterToExistingConsumer(username, password, consumerId);
        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");
            JSONArray bundledProductData = subpoolProductDataAsJSONObject.getJSONArray("bundledProductData");
            String systemConsumedProductName = null;
            for (int k = 0; k < bundledProductData.length(); k++) {
                JSONObject bundledProductAsJSONObject = (JSONObject) bundledProductData.get(k);
                systemConsumedProductName = bundledProductAsJSONObject.getString("productName");
            }
            ProductSubscription productSubscription = ProductSubscription.findFirstInstanceWithMatchingFieldFromList("productName", systemConsumedProductName, client2tasks.getCurrentlyConsumedProductSubscriptions());
            Assert.assertNotNull(productSubscription, "Found the consumed Product Subscription with productName='" + systemConsumedProductName + "'.");
            client2tasks.unsubscribeFromProductSubscription(productSubscription);
            SubscriptionPool systemSubscriptionPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", systemProductId, client2tasks.getCurrentlyAvailableSubscriptionPools());
            Assert.assertNotNull(systemSubscriptionPool, "Subscription to ProductId '" + systemProductId + "' is once again available to consumer '" + consumerId + "' (registered as a system under username '" + username + "')");
        }
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ProductSubscription(rhsm.data.ProductSubscription) SubscriptionPool(rhsm.data.SubscriptionPool) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 40 with ProductSubscription

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

the class RHELPersonalTests method testSubscribeMultipleSystemsToSubPool.

@Test(description = "subscription-manager-cli: Ensure that multiple (unlimited) systems can subscribe to subpool", groups = { "Tier2Tests", "SubscribeMultipleSystemsToSubPool_Test", "RHELPersonal" /*, "blockedByBug-661130"*/
}, // dependsOnGroups={"EnsureAvailabilityOfSubPoolIsRevokedOncePersonUnsubscribesFromRHELPersonal_Test"},
priority = 130, dependsOnMethods = { "testSubPoolIsAvailableAfterRegisteredPersonSubscribesToRHELPersonal" }, // 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)
public // @ImplementsTCMS(id="")
void testSubscribeMultipleSystemsToSubPool() throws JSONException {
    log.info("Making sure the clients are not subscribed to anything...");
    // client2tasks.unsubscribeFromAllOfTheCurrentlyConsumedProductSubscriptions();
    // client2tasks.unregister();
    // client1tasks.unsubscribeFromAllOfTheCurrentlyConsumedProductSubscriptions();
    unsubscribeAndUnregisterMultipleSystemsAfterGroups();
    client1tasks.register(username, password, owner, null, ConsumerType.person, /*"blockedByBug-661130" "ME"*/
    null, null, null, null, null, (String) null, null, null, null, null, false, null, null, null, null);
    personConsumerId = client1tasks.getCurrentConsumerId();
    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");
        JSONArray bundledProductData = subpoolProductDataAsJSONObject.getJSONArray("bundledProductData");
        log.info("Subscribe client1 (already registered as a person under username '" + username + "') to subscription pool with ProductId'" + personProductId + "'...");
        personSubscriptionPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", personProductId, client1tasks.getCurrentlyAllAvailableSubscriptionPools());
        Assert.assertNotNull(personSubscriptionPool, "Personal subscription with ProductId '" + personProductId + "' is available to user '" + username + "' registered as a person.");
        // client1tasks.subscribe(personSubscriptionPool.poolId, null, null, null, null);
        // personalEntitlementCert = client1tasks.getEntitlementCertFromEntitlementCertFile(client1tasks.subscribeToSubscriptionPool(personSubscriptionPool));
        personEntitlementCert = client1tasks.getEntitlementCertFromEntitlementCertFile(client1tasks.subscribeToSubscriptionPool(personSubscriptionPool, /*sm_serverAdminUsername*/
        username, /*sm_serverAdminPassword*/
        password, sm_serverUrl));
        log.info("Register " + multipleSystems + " new systems under username '" + username + "' and subscribe to sub productId '" + systemProductId + "'...");
        systemConsumerIds = new ArrayList<String>();
        for (int systemNum = 1; systemNum <= multipleSystems; systemNum++) {
            // simulate a clean system
            client2tasks.removeAllCerts(true, true, false);
            String consumerId = client2tasks.getCurrentConsumerId(client2tasks.register(username, password, owner, null, ConsumerType.system, null, null, null, null, null, (String) null, null, null, null, Boolean.TRUE, false, null, null, null, null));
            systemConsumerIds.add(consumerId);
            SubscriptionPool subPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", systemProductId, client2tasks.getCurrentlyAvailableSubscriptionPools());
            log.info("Subscribing system '" + systemNum + "' ('" + consumerId + "' under username '" + username + "') to sub pool for productId '" + systemProductId + "'...");
            client2tasks.subscribeToSubscriptionPool(subPool);
            /* OLD ASSERTION BEFORE IMPLEMENTATION OF Bug 801187 - collapse list of provided products for subscription-manager list --consumed
				for (int k=0; k<bundledProductData.length(); k++) {
					JSONObject bundledProductAsJSONObject = (JSONObject) bundledProductData.get(k);
					String systemConsumedProductName = bundledProductAsJSONObject.getString("productName");

					ProductSubscription productSubscription = ProductSubscription.findFirstInstanceWithMatchingFieldFromList("productName",systemConsumedProductName,client2tasks.getCurrentlyConsumedProductSubscriptions());
					Assert.assertNotNull(productSubscription,systemConsumedProductName+" is now consumed by consumer '"+consumerId+"' (registered as a system under username '"+username+"')");
				}
				*/
            List<String> systemConsumedProductNames = new ArrayList<String>();
            for (int k = 0; k < bundledProductData.length(); k++) {
                JSONObject bundledProductAsJSONObject = (JSONObject) bundledProductData.get(k);
                String systemConsumedProductName = bundledProductAsJSONObject.getString("productName");
                systemConsumedProductNames.add(systemConsumedProductName);
            }
            log.info("Now client2 should be consuming the subscription '" + personSubscriptionName + "' that provides '" + systemConsumedProductNames + "'...");
            ProductSubscription systemProductSubscription = ProductSubscription.findFirstInstanceWithMatchingFieldFromList("productName", personSubscriptionName, client2tasks.getCurrentlyConsumedProductSubscriptions());
            Assert.assertNotNull(systemProductSubscription, personSubscriptionName + " is now consumed by consumer '" + consumerId + "' (registered as a system under username '" + username + "')");
            Assert.assertTrue(systemProductSubscription.provides.containsAll(systemConsumedProductNames) && systemConsumedProductNames.containsAll(systemProductSubscription.provides), "All of the expected bundled products " + systemConsumedProductNames + " are now being provided for on client2 system '" + client2.getConnection().getRemoteHostname() + "' consumed by consumer '" + consumerId + "'.");
        }
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) ProductSubscription(rhsm.data.ProductSubscription) SubscriptionPool(rhsm.data.SubscriptionPool) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Aggregations

ProductSubscription (rhsm.data.ProductSubscription)90 Test (org.testng.annotations.Test)82 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)72 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)56 SkipException (org.testng.SkipException)46 ArrayList (java.util.ArrayList)41 SubscriptionPool (rhsm.data.SubscriptionPool)38 SSHCommandResult (com.redhat.qe.tools.SSHCommandResult)31 JSONObject (org.json.JSONObject)31 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)23 HashMap (java.util.HashMap)22 BigInteger (java.math.BigInteger)20 EntitlementCert (rhsm.data.EntitlementCert)17 InstalledProduct (rhsm.data.InstalledProduct)16 Calendar (java.util.Calendar)15 JSONArray (org.json.JSONArray)13 File (java.io.File)10 GregorianCalendar (java.util.GregorianCalendar)10 HashSet (java.util.HashSet)6 ConsumerCert (rhsm.data.ConsumerCert)6