use of rhsm.data.ProductSubscription in project rhsm-qe by RedHatQE.
the class SubscribeTests method testSubscribeWithQuantity.
@// update=true, // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-19981", "RHEL7-33098" }, 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 using various good and bad values for the --quantity option", groups = { "Tier1Tests", "blockedByBug-962520" }, dataProvider = "getSubscribeWithQuantityData", enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testSubscribeWithQuantity(Object meta, SubscriptionPool pool, String quantity, Integer expectedExitCode, String expectedStdoutRegex, String expectedStderrRegex) {
log.info("Testing subscription-manager subscribe using various good and bad values for the --quantity option.");
// special case in the dataProvider to identify when a test pool was not available; expectedStderrRegex contains a message for what kind of test pool was being searched for.
if (pool == null)
throw new SkipException(expectedStderrRegex);
// start fresh by returning all entitlements
clienttasks.unsubscribeFromAllOfTheCurrentlyConsumedProductSubscriptions();
// for debugging purposes, list what is currently available so we can see the available quantity before we attempt to attach
clienttasks.list_(null, true, null, null, null, null, null, null, null, null, null, null, null, null);
// subscribe with quantity
SSHCommandResult sshCommandResult = clienttasks.subscribe_(null, null, pool.poolId, null, null, quantity, null, null, null, null, null, null, null);
// assert the sshCommandResult here
if (expectedExitCode != null)
Assert.assertEquals(sshCommandResult.getExitCode(), expectedExitCode, "ExitCode after subscribe with quantity=\"" + quantity + "\" option:");
if (expectedStdoutRegex != null)
Assert.assertContainsMatch(sshCommandResult.getStdout().trim(), expectedStdoutRegex, "Stdout after subscribe with --quantity=\"" + quantity + "\" option:");
if (expectedStderrRegex != null)
Assert.assertContainsMatch(sshCommandResult.getStderr().trim(), expectedStderrRegex, "Stderr after subscribe with --quantity=\"" + quantity + "\" option:");
// when successful, assert that the quantity is correctly reported in the list of consumed subscriptions
List<ProductSubscription> subscriptionsConsumed = client1tasks.getCurrentlyConsumedProductSubscriptions();
List<EntitlementCert> entitlementCerts = client1tasks.getCurrentEntitlementCerts();
if (expectedExitCode == 0 && expectedStdoutRegex != null && expectedStdoutRegex.contains("Successful")) {
Assert.assertEquals(entitlementCerts.size(), 1, "One EntitlementCert should have been downloaded to " + client1tasks.hostname + " when the attempt to subscribe is successful.");
Assert.assertEquals(entitlementCerts.get(0).orderNamespace.quantityUsed, quantity.replaceFirst("^\\+", ""), "The quantityUsed in the OrderNamespace of the downloaded EntitlementCert should match the quantity requested when we subscribed to pool '" + pool.poolId + "'. OrderNamespace: " + entitlementCerts.get(0).orderNamespace);
for (ProductSubscription productSubscription : subscriptionsConsumed) {
Assert.assertEquals(productSubscription.quantityUsed, Integer.valueOf(quantity.replaceFirst("^\\+", "")), "The quantityUsed reported in each consumed ProductSubscription should match the quantity requested when we subscribed to pool '" + pool.poolId + "'. ProductSubscription: " + productSubscription);
}
} else {
Assert.assertEquals(subscriptionsConsumed.size(), 0, "No subscriptions should be consumed when the attempt to subscribe is not successful.");
}
}
use of rhsm.data.ProductSubscription in project rhsm-qe by RedHatQE.
the class TemporaryPoolTests method testAutomaticRemovalOfAnAttachedUnmappedGuestsOnlySubpoolOnceGuestIsMapped.
@// update=true, // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-22237", "RHEL7-59322" }, 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 = "Once a guest is mapped, while consuming a temporary pool entitlement, the entitlement should be removed at the next checkin. Verify this while autoheal is disabled.", groups = { "Tier1Tests", "blockedByBug-1198494" }, dataProvider = "getAvailableUnmappedGuestsOnlySubscriptionPoolsData", enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testAutomaticRemovalOfAnAttachedUnmappedGuestsOnlySubpoolOnceGuestIsMapped(Object bugzilla, SubscriptionPool unmappedGuestsOnlyPool) throws JSONException, Exception {
// system facts were overridden in dataProvider with factsMap to fake this system as a guest
// make sure we are freshly registered (to discard a consumer from a former data provided iteration that has mapped guests)
clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, true, null, null, null, null, null);
// ensure that auto-healing is off
clienttasks.autoheal(null, null, true, null, null, null, null);
// attach the unmapped guests only pool
clienttasks.subscribe_(null, null, unmappedGuestsOnlyPool.poolId, null, null, null, null, null, null, null, null, null, null);
ProductSubscription consumedUnmappedGuestsOnlyProductSubscription = ProductSubscription.findFirstInstanceWithMatchingFieldFromList("poolId", unmappedGuestsOnlyPool.poolId, clienttasks.getCurrentlyConsumedProductSubscriptions());
Assert.assertNotNull(consumedUnmappedGuestsOnlyProductSubscription, "Successfully found the consumed product subscription after attaching temporary pool '" + unmappedGuestsOnlyPool.subscriptionName + "' (poolId='" + unmappedGuestsOnlyPool.poolId + "').");
// map the guest
clienttasks.mapSystemAsAGuestOfItself();
// trigger a rhsmcertd checkin (either of these calls are valid - randomly choose)
// TEMPORARY WORKAROUND FOR BUG
// Bug 1366301 - Server error attempting a PUT to /subscription/consumers/<UUID>/certificates?lazy_regen=true returned status 404
String bugId = "1366301";
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 && CandlepinType.hosted.equals(sm_serverType)) {
log.warning("Skipping a random call to refresh local certificates while bug '" + bugId + "' is open.");
// no need to pass autoheal option because it is already set true on the consumer
clienttasks.run_rhsmcertd_worker(null);
} else // END OF WORKAROUND
if (getRandomListItem(Arrays.asList(true, false)))
clienttasks.refresh(null, null, null, null);
else
// no need to pass autoheal option because it is already set true on the consumer
clienttasks.run_rhsmcertd_worker(null);
// verify that the attached temporary subscription has automatically been removed
List<ProductSubscription> currentlyConsumedProductSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
Assert.assertTrue(ProductSubscription.findAllInstancesWithMatchingFieldFromList("poolId", unmappedGuestsOnlyPool.poolId, currentlyConsumedProductSubscriptions).isEmpty(), "Now that the guest is mapped, the consumed entitlements from the temporary pool '" + unmappedGuestsOnlyPool.subscriptionName + "' (poolId='" + unmappedGuestsOnlyPool.poolId + "') have automatically been removed.");
Assert.assertTrue(currentlyConsumedProductSubscriptions.isEmpty(), "Now that the guest is mapped (and autoheal was off at the instant the guest was mapped), not only is the temporary entitlement removed, but no new entitlements are granted.");
}
use of rhsm.data.ProductSubscription in project rhsm-qe by RedHatQE.
the class TemporaryPoolTests method testAutoHealingOfAnAttachedUnmappedGuestsOnlySubpoolOnceGuestIsMapped.
@// update=true, // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-22236", "RHEL7-59321" }, 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 = "Once a guest is mapped, while consuming a temporary pool entitlement, the entitlement should be removed and the system auto-healed at the next checkin. Verify it.", groups = { "Tier1Tests", "blockedByBug-1198494" }, dataProvider = "getAvailableUnmappedGuestsOnlySubscriptionPoolsData", enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testAutoHealingOfAnAttachedUnmappedGuestsOnlySubpoolOnceGuestIsMapped(Object bugzilla, SubscriptionPool unmappedGuestsOnlyPool) throws JSONException, Exception {
// system facts were overridden in dataProvider with factsMap to fake this system as a guest
// make sure we are freshly registered (to discard a consumer from a former data provided iteration that has mapped guests)
clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, true, null, null, null, null, null);
// ensure that auto-healing is on
clienttasks.autoheal(null, true, null, null, null, null, null);
// attach the unmapped guests only pool
clienttasks.subscribe_(null, null, unmappedGuestsOnlyPool.poolId, null, null, null, null, null, null, null, null, null, null);
ProductSubscription consumedUnmappedGuestsOnlyProductSubscription = ProductSubscription.findFirstInstanceWithMatchingFieldFromList("poolId", unmappedGuestsOnlyPool.poolId, clienttasks.getCurrentlyConsumedProductSubscriptions());
Assert.assertNotNull(consumedUnmappedGuestsOnlyProductSubscription, "Successfully found the consumed product subscription after attaching temporary pool '" + unmappedGuestsOnlyPool.subscriptionName + "' (poolId='" + unmappedGuestsOnlyPool.poolId + "').");
// map the guest
clienttasks.mapSystemAsAGuestOfItself();
// trigger a rhsmcertd checkin (either of these calls are valid - randomly choose)
// TEMPORARY WORKAROUND FOR BUG
// Bug 1366301 - Server error attempting a PUT to /subscription/consumers/<UUID>/certificates?lazy_regen=true returned status 404
String bugId = "1366301";
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 && CandlepinType.hosted.equals(sm_serverType)) {
log.warning("Skipping a random call to refresh local certificates while bug '" + bugId + "' is open.");
// no need to pass autoheal option because it is already set true on the consumer
clienttasks.run_rhsmcertd_worker(null);
} else // END OF WORKAROUND
if (getRandomListItem(Arrays.asList(true, false)))
clienttasks.refresh(null, null, null, null);
else
// no need to pass autoheal option because it is already set true on the consumer
clienttasks.run_rhsmcertd_worker(null);
// verify that the attached temporary subscription has automatically been removed
Assert.assertTrue(ProductSubscription.findAllInstancesWithMatchingFieldFromList("poolId", unmappedGuestsOnlyPool.poolId, clienttasks.getCurrentlyConsumedProductSubscriptions()).isEmpty(), "Now that the guest is mapped, the consumed entitlements from the temporary pool '" + unmappedGuestsOnlyPool.subscriptionName + "' (poolId='" + unmappedGuestsOnlyPool.poolId + "') have automatically been removed.");
// assert that we have been autohealed as well as possible
List<File> entitlementCertFileAfterMapping = clienttasks.getCurrentEntitlementCertFiles();
clienttasks.subscribe(true, null, (String) null, null, null, null, null, null, null, null, null, null, null);
List<File> entitlementCertFileAfterAutosubscribing = clienttasks.getCurrentEntitlementCertFiles();
Assert.assertTrue(entitlementCertFileAfterMapping.containsAll(entitlementCertFileAfterAutosubscribing) && entitlementCertFileAfterAutosubscribing.containsAll(entitlementCertFileAfterMapping), "When the entitlement certs on the system are identical after a guest has been mapped and auto-healed and an explicit auto-subscribe is attempted, then we are confident that the guest was auto-healed at the instant the guest was mapped.)");
}
use of rhsm.data.ProductSubscription in project rhsm-qe by RedHatQE.
the class TemporaryPoolTests method testExpirationOfUnmappedGuestsOnlySubpool.
@Test(description = "Consume a temporary pool entitlement and wait a day for it to expire, then assert its removal and assert the pool is not longer available to this consumer.", groups = { "Tier1Tests", "blockedByBug-1199078", "VerifyExpirationOfUnmappedGuestsOnlySubpool_Test" }, dataProvider = "getAvailableUnmappedGuestsOnlySubscriptionPoolsData", // TODO Temporarily disabling this test because changing the system clock during an automated test seems to knock the system off the network during runs on Jenkins thereby loosing ssh connection; service network restarts are needed
enabled = false)
public // @ImplementsNitrateTest(caseId=)
void testExpirationOfUnmappedGuestsOnlySubpool(Object bugzilla, SubscriptionPool unmappedGuestsOnlyPool) throws JSONException, Exception {
if (!CandlepinType.standalone.equals(sm_serverType))
throw new SkipException("This automated test should only be attempted on a standalone server.");
// system facts are overridden with factsMap to fake this system as a guest
// reset the date on the client and server
resetDatesAfterTestExpirationOfUnmappedGuestsOnlySubpool();
// make sure we are freshly registered (to discard a consumer from a former data provided iteration that has mapped guests)
clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, true, null, /* autoheal defaults to true*/
null, null, null, null);
// attach the unmapped guests only pool
clienttasks.subscribe_(null, null, unmappedGuestsOnlyPool.poolId, null, null, null, null, null, null, null, null, null, null);
ProductSubscription consumedUnmappedGuestsOnlyProductSubscription = ProductSubscription.findFirstInstanceWithMatchingFieldFromList("poolId", unmappedGuestsOnlyPool.poolId, clienttasks.getCurrentlyConsumedProductSubscriptions());
Assert.assertNotNull(consumedUnmappedGuestsOnlyProductSubscription, "Successfully found the consumed product subscription after attaching temporary pool '" + unmappedGuestsOnlyPool.subscriptionName + "' (poolId='" + unmappedGuestsOnlyPool.poolId + "').");
// advance the date on the client and server
RemoteFileTasks.runCommandAndAssert(client, String.format("date -s +%dhours", 24), 0);
clientHoursFastForwarded += 24;
RemoteFileTasks.runCommandAndAssert(server, String.format("date -s +%dhours", 24), 0);
serverHoursFastForwarded += 24;
// assert that the list of consumedUnmappedGuestsOnlyProductSubscription now appears expired (Active: False, Status Details: Subscription is expired)
ProductSubscription expiredUnmappedGuestsOnlyProductSubscription = ProductSubscription.findFirstInstanceWithMatchingFieldFromList("poolId", unmappedGuestsOnlyPool.poolId, clienttasks.getCurrentlyConsumedProductSubscriptions());
Assert.assertFalse(expiredUnmappedGuestsOnlyProductSubscription.isActive, "The value of Active shown on the consumed temporary product subscription 24 hours after pool '" + unmappedGuestsOnlyPool.poolId + "' was attached.");
Assert.assertEquals(expiredUnmappedGuestsOnlyProductSubscription.statusDetails, Arrays.asList("Subscription is expired"), "The Status Details shown on the consumed temporary product subscription 24 hours after pool '" + unmappedGuestsOnlyPool.poolId + "' was attached.");
// catch Bug 1201727 - After the 24 hour pool is expired,consumed --list displays a value,even after attaching a subscription
// TODO
// assert the installed product appears expired (Active: False, Status Details: Subscription is expired)
// TODO
// trigger an autohealing rhsmcertd checkin (assumes that autoheal defaults to true on a newly registered consumer)
// must pass autoheal=true
clienttasks.run_rhsmcertd_worker(true);
// assert the expired entitlement is immediately removed when autohealing is run // Bug 1199078 - expired guest 24 hour subscription not removed on auto-attach
if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "0.9.46-1")) {
// commit d24a59b3640aef1acb2b6067100d653fc76636f5 1199078: Remove expired unmapped guest pools on autoheal
Assert.assertNull(ProductSubscription.findFirstInstanceWithMatchingFieldFromList("poolId", unmappedGuestsOnlyPool.poolId, clienttasks.getCurrentlyConsumedProductSubscriptions()), "After an autohealing rhsmcertd checkin, the expired temporary product subscription should be immediately removed from the system.");
}
// verify that the temporary unmapped_guests_only pool is no longer available for consumption
Assert.assertNull(SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", unmappedGuestsOnlyPool.poolId, clienttasks.getCurrentlyAvailableSubscriptionPools()), "Temporary pool '" + unmappedGuestsOnlyPool.subscriptionName + "' poolId='" + unmappedGuestsOnlyPool.poolId + "' is NO LONGER available for consumption 24 hours after the unmapped guest consumer registered.");
// assert that we are blocked from an attempt to attach the temporary pool 24 hours after the consumer registered
// 201503191706:00.370 - FINE: ssh root@jsefler-os6.usersys.redhat.com subscription-manager subscribe --pool=8a9087e34c335894014c3359e22517fa
// 201503191706:03.965 - FINE: Stdout: Pool is restricted to virtual guests in their first day of existence: '8a9087e34c335894014c3359e22517fa'
// 201503191706:03.968 - FINE: Stderr:
// 201503191706:03.970 - FINE: ExitCode: 1
SSHCommandResult result = clienttasks.subscribe_(null, null, unmappedGuestsOnlyPool.poolId, null, null, null, null, null, null, null, null, null, null);
String expectedStdout = String.format("Pool is restricted to virtual guests in their first day of existence: '%s'", unmappedGuestsOnlyPool.poolId);
if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.3.1-1")) {
// commit 0d5fefcfa8c1c2485921d2dee6633879b1e06931 Correct incorrect punctuation in user messages
expectedStdout = String.format("Pool is restricted to virtual guests in their first day of existence: \"%s\".", unmappedGuestsOnlyPool.poolId);
}
String expectedStderr = "";
Assert.assertEquals(result.getStdout().trim(), expectedStdout, "Stdout from an attempt to attach a temporary pool to a virtual guest 24 hours after the guest registered.");
Assert.assertEquals(result.getStderr().trim(), expectedStderr, "Stderr from an attempt to attach a temporary pool to a virtual guest 24 hours after the guest registered.");
Assert.assertEquals(result.getExitCode(), Integer.valueOf(1), "Exit code from an attempt to attach a temporary pool to a virtual guest 24 hours after the guest registered.");
}
use of rhsm.data.ProductSubscription in project rhsm-qe by RedHatQE.
the class SubscriptionManagerTasks method subscribeToSubscriptionPool.
/**
* subscribe to the given SubscriptionPool (assumes pool came from the list of available pools)
* @return the newly installed EntitlementCert file to the newly consumed ProductSubscriptions
*/
public File subscribeToSubscriptionPool(SubscriptionPool pool, String quantity, String authenticator, String password, String serverUrl) {
List<ProductSubscription> beforeProductSubscriptions = getCurrentlyConsumedProductSubscriptions();
List<File> beforeEntitlementCertFiles = getCurrentEntitlementCertFiles();
log.info("Subscribing to subscription pool: " + pool);
SSHCommandResult sshCommandResult = subscribe(null, null, pool.poolId, null, null, quantity, null, null, null, null, null, null, null);
// is this pool multi-entitleable?
/* This information is now in the SubscriptionPool itself
boolean isPoolMultiEntitlement = false;
try {
isPoolMultiEntitlement = CandlepinTasks.isPoolProductMultiEntitlement(this.currentlyRegisteredUsername,this.currentlyRegisteredPassword,SubscriptionManagerBaseTestScript.sm_serverUrl,pool.poolId);
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
*/
// get the pool's product "arch" attribute that this subscription pool supports
String poolProductAttributeArch = "";
List<String> poolProductAttributeArches = new ArrayList<String>();
if (authenticator != null && password != null && serverUrl != null) {
try {
poolProductAttributeArch = CandlepinTasks.getPoolProductAttributeValue(authenticator, password, serverUrl, pool.poolId, "arch");
if (poolProductAttributeArch != null && !poolProductAttributeArch.trim().isEmpty()) {
// Note: the arch attribute can be a comma separated list of values
poolProductAttributeArches.addAll(Arrays.asList(poolProductAttributeArch.trim().split(" *, *")));
// Note: x86 is a general arch to cover all 32-bit intel microprocessors
if (poolProductAttributeArches.contains("x86"))
poolProductAttributeArches.addAll(Arrays.asList("i386", "i486", "i586", "i686"));
// if (productSupportedArches.contains("ALL")) productSupportedArches.add(arch);
}
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
// assert that the remaining SubscriptionPools does NOT contain the pool just subscribed to (unless it is multi-entitleable)
List<SubscriptionPool> afterSubscriptionPools = getCurrentlyAvailableSubscriptionPools();
if (pool.subscriptionType != null && pool.subscriptionType.equals("Other")) {
Assert.fail("Encountered a subscription pool of type '" + pool.subscriptionType + "'. Do not know how to assert the remaining availability of this pool after subscribing to it: " + pool);
} else if (pool.multiEntitlement == null && pool.subscriptionType != null && pool.subscriptionType.isEmpty()) {
log.warning("Encountered a pool with an empty value for subscriptionType (indicative of an older candlepin server): " + pool);
log.warning("Skipping assertion of the pool's expected availability after having subscribed to it.");
} else if (!pool.quantity.equalsIgnoreCase("unlimited") && Integer.valueOf(pool.quantity) <= 1) {
Assert.assertTrue(!afterSubscriptionPools.contains(pool), "When the final quantity from the pool was consumed, the remaining available subscription pools no longer contains the just subscribed to pool: " + pool);
} else if (pool.multiEntitlement != null && !pool.multiEntitlement) {
Assert.assertTrue(!afterSubscriptionPools.contains(pool), "When the pool is not multi-entitleable, the remaining available subscription pools no longer contains the just subscribed to pool: " + pool);
} else if (pool.subscriptionType != null && (!pool.subscriptionType.equals("Stackable") && !pool.subscriptionType.equals("Multi-Entitleable") && !pool.subscriptionType.equals("Instance Based") && !pool.subscriptionType.equals("Stackable (Temporary)") && !pool.subscriptionType.equals("Multi-Entitleable (Temporary)") && !pool.subscriptionType.equals("Instance Based (Temporary)"))) {
// see https://bugzilla.redhat.com/show_bug.cgi?id=1029968#c2
Assert.assertTrue(!afterSubscriptionPools.contains(pool), "When the pool is not multi-entitleable (not Stackable && not Multi-Entitleable && not Instance Based), the remaining available subscription pools no longer contains the just subscribed to pool: " + pool);
} else if (!poolProductAttributeArches.isEmpty() && !poolProductAttributeArches.contains("ALL") && !poolProductAttributeArches.contains(arch)) {
Assert.assertTrue(!afterSubscriptionPools.contains(pool), "When the pools product attribute arch '" + poolProductAttributeArch + "' does not support this system arch '" + arch + "', the remaining available subscription pools should never contain the just subscribed to pool: " + pool);
} else {
Assert.assertTrue(afterSubscriptionPools.contains(pool), // TODO fix the assertions for "if this fails"
"When the pool is multi-entitleable, the remaining available subscription pools still contains the just subscribed to pool: " + pool + " (TODO: if this fails, then we likely attached the final entitlements from the pool)");
}
// assert that the remaining SubscriptionPools do NOT contain the same productId just subscribed to
// log.warning("We will no longer assert that the remaining available pools do not contain the same productId ("+pool.productId+") as the pool that was just subscribed. Reference: https://bugzilla.redhat.com/show_bug.cgi?id=663455");
/*
for (SubscriptionPool afterSubscriptionPool : afterSubscriptionPools) {
Assert.assertTrue(!afterSubscriptionPool.productId.equals(pool.productId),
"This remaining available pool "+afterSubscriptionPool+" does NOT contain the same productId ("+pool.productId+") after subscribing to pool: "+pool);
}
*/
// is this a personal subpool?
String poolProductId = pool.productId;
boolean isSubpool = false;
try {
JSONArray personSubscriptionPoolProductData;
// personSubscriptionPoolProductData = new JSONArray(System.getProperty("sm.person.subscriptionPoolProductData", "<>").replaceAll("<", "[").replaceAll(">", "]")); // hudson parameters use <> instead of []
// hudson JSONArray parameters get surrounded with double quotes that need to be stripped
personSubscriptionPoolProductData = new JSONArray(SubscriptionManagerBaseTestScript.getProperty("sm.person.subscriptionPoolProductData", "[]").replaceFirst("^\"", "").replaceFirst("\"$", "").replaceAll("<", "[").replaceAll(">", "]"));
for (int j = 0; j < personSubscriptionPoolProductData.length(); j++) {
JSONObject poolProductDataAsJSONObject = (JSONObject) personSubscriptionPoolProductData.get(j);
String personProductId = poolProductDataAsJSONObject.getString("personProductId");
JSONObject subpoolProductDataAsJSONObject = poolProductDataAsJSONObject.getJSONObject("subPoolProductData");
String systemProductId = subpoolProductDataAsJSONObject.getString("systemProductId");
if (poolProductId.equals(systemProductId)) {
// special case when pool's productId is really a personal subpool
poolProductId = personProductId;
isSubpool = true;
break;
}
}
} catch (JSONException e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
// figure out which entitlement cert file has been newly installed into /etc/pki/entitlement after attempting to subscribe to pool
/* OLD - THIS ALGORITHM BREAKS DOWN WHEN MODIFIER ENTITLEMENTS ARE IN PLAY
File newCertFile = null;
List<File> afterEntitlementCertFiles = getCurrentEntitlementCertFiles();
for (File file : afterEntitlementCertFiles) {
if (!beforeEntitlementCertFiles.contains(file)) {
newCertFile = file; break;
}
}
*/
/* VALID BUT INEFFICIENT
List<File> afterEntitlementCertFiles = getCurrentEntitlementCertFiles();
File newCertFile = null;
Map<BigInteger, SubscriptionPool> map = new HashMap<BigInteger, SubscriptionPool>();
try {
map = getCurrentSerialMapToSubscriptionPools(this.currentAuthenticator,this.currentAuthenticatorPassword);
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
for (BigInteger serial: map.keySet()) {
if (map.get(serial).poolId.equals(pool.poolId)) {
newCertFile = new File(this.entitlementCertDir+"/"+serial+".pem");
break;
}
}
*/
// NOTE: this block of code is somewhat duplicated in getEntitlementCertCorrespondingToSubscribedPool(...)
File newCertFile = null;
List<File> afterEntitlementCertFiles = getCurrentEntitlementCertFiles("-t");
if (authenticator != null && password != null && serverUrl != null) {
for (File entitlementCertFile : afterEntitlementCertFiles) {
if (!beforeEntitlementCertFiles.contains(entitlementCertFile)) {
EntitlementCert entitlementCert = getEntitlementCertFromEntitlementCertFile(entitlementCertFile);
try {
// JSONObject jsonEntitlement = CandlepinTasks.getEntitlementUsingRESTfulAPI(authenticator,password,serverUrl,entitlementCert.id); // is throwing a 500 in stage, but only for qa@redhat.com credentials - I don't know why
JSONObject jsonEntitlement = CandlepinTasks.getEntitlementUsingRESTfulAPI(currentlyRegisteredUsername, currentlyRegisteredPassword, serverUrl, entitlementCert.id);
JSONObject jsonPool = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(authenticator, password, serverUrl, jsonEntitlement.getJSONObject("pool").getString("href")));
if (jsonPool.getString("id").equals(pool.poolId)) {
newCertFile = entitlementCertFile;
break;
}
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
}
}
// when the pool is already subscribed to...
if (sshCommandResult.getStdout().startsWith("This consumer is already subscribed")) {
// assert that NO new entitlement cert file has been installed in /etc/pki/entitlement
/*Assert.assertNull(newCertFile,
"A new entitlement certificate has NOT been installed after attempting to subscribe to an already subscribed to pool: "+pool);
*/
Assert.assertEquals(beforeEntitlementCertFiles.size(), afterEntitlementCertFiles.size(), "The existing entitlement certificate count remains unchanged after attempting to subscribe to an already subscribed to pool: " + pool);
// find the existing entitlement cert file corresponding to the already subscribed pool
/* ALREADY FOUND USING ALGORITHM ABOVE
EntitlementCert entitlementCert = null;
for (File thisEntitlementCertFile : getCurrentEntitlementCertFiles()) {
EntitlementCert thisEntitlementCert = getEntitlementCertFromEntitlementCertFile(thisEntitlementCertFile);
if (thisEntitlementCert.orderNamespace.productId.equals(poolProductId)) {
entitlementCert = thisEntitlementCert;
break;
}
}
Assert.assertNotNull(entitlementCert, isSubpool?
"Found an already existing Entitlement Cert whose personal productId matches the system productId from the subscription pool: "+pool:
"Found an already existing Entitlement Cert whose productId matches the productId from the subscription pool: "+pool);
newCertFile = getEntitlementCertFileFromEntitlementCert(entitlementCert); // not really new, just already existing
*/
// assert that consumed ProductSubscriptions has NOT changed
List<ProductSubscription> afterProductSubscriptions = getCurrentlyConsumedProductSubscriptions();
Assert.assertTrue(afterProductSubscriptions.size() == beforeProductSubscriptions.size() && afterProductSubscriptions.size() > 0, "The list of currently consumed product subscriptions has not changed (from " + beforeProductSubscriptions.size() + " to " + afterProductSubscriptions.size() + ") since the productId of the pool we are trying to subscribe to is already consumed.");
// when no free entitlements exist... // No entitlements are available from the pool with id '8a90f8143611c33f013611c4797b0456'. // No subscriptions are available from the pool with id '8a90f8303c98703a013c98715ca80494'. Bug 876758
} else if (sshCommandResult.getStdout().startsWith("No entitlements are available") || sshCommandResult.getStdout().startsWith("No subscriptions are available")) {
// assert that the depleted pool Quantity is zero
SubscriptionPool depletedPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", pool.poolId, getCurrentlyAllAvailableSubscriptionPools());
/* behavior changed on list --all --available (3/4/2011)
Assert.assertNotNull(depletedPool,
"Found the depleted pool amongst --all --available after having consumed all of its available entitlements: ");
*/
Assert.assertNull(depletedPool, "Should no longer find the depleted pool amongst --all --available after having consumed all of its available entitlements: ");
// "Asserting the pool's quantity after having consumed all of its available entitlements is zero.");
if (authenticator != null && password != null && serverUrl != null) {
JSONObject jsonPool = null;
int consumed = 0;
int quantityAvailable = Integer.valueOf(pool.quantity);
try {
jsonPool = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(authenticator, password, serverUrl, "/pools/" + pool.poolId));
consumed = jsonPool.getInt("consumed");
quantityAvailable = jsonPool.getInt("quantity");
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
Assert.assertEquals(consumed, quantityAvailable, "Asserting the pool's consumed attribute equals it's total quantity after having consumed all of its available entitlements.");
}
// assert that NO new entitlement cert file has been installed in /etc/pki/entitlement
Assert.assertNull(newCertFile, "A new entitlement certificate has NOT been installed after attempting to subscribe to depleted pool: " + depletedPool);
Assert.assertEquals(beforeEntitlementCertFiles.size(), afterEntitlementCertFiles.size(), "The existing entitlement certificate count remains unchanged after attempting to subscribe to depleted pool: " + depletedPool);
// otherwise, the pool is NOT already subscribe to...
} else {
// assert that only ONE new entitlement cert file has been installed in /etc/pki/entitlement
// https://bugzilla.redhat.com/show_bug.cgi?id=640338
Assert.assertTrue(afterEntitlementCertFiles.size() == beforeEntitlementCertFiles.size() + 1, "Only ONE new entitlement certificate has been installed (count was '" + beforeEntitlementCertFiles.size() + "'; is now '" + afterEntitlementCertFiles.size() + "') after subscribing to pool: " + pool);
if (authenticator != null && password != null && serverUrl != null) {
// assert the new entitlement cert file has been installed in /etc/pki/entitlement
Assert.assertNotNull(newCertFile, "A new entitlement certificate has been installed after subscribing to pool: " + pool);
log.info("The new entitlement certificate file is: " + newCertFile);
// assert that the productId from the pool matches the entitlement productId
// TEMPORARY WORKAROUND FOR BUG: https://bugzilla.redhat.com/show_bug.cgi?id=650278 - jsefler 11/05/2010
// TEMPORARY WORKAROUND FOR BUG: https://bugzilla.redhat.com/show_bug.cgi?id=806986 - jsefler 06/28/2012
boolean invokeWorkaroundWhileBugIsOpen = true;
String bugId1 = "650278";
String bugId2 = "806986";
try {
if (invokeWorkaroundWhileBugIsOpen && (BzChecker.getInstance().isBugOpen(bugId1) || BzChecker.getInstance().isBugOpen(bugId2))) {
log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId1).toString() + " Bugzilla " + bugId1 + ". (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId1 + ")");
SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId1);
log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId2).toString() + " Bugzilla " + bugId2 + ". (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId2 + ")");
SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId2);
} else {
invokeWorkaroundWhileBugIsOpen = false;
}
} catch (BugzillaAPIException be) {
/* ignore exception */
} catch (RuntimeException re) {
/* ignore exception */
}
if (invokeWorkaroundWhileBugIsOpen) {
log.warning("Skipping assert that the productId from the pool matches the entitlement productId");
} else {
// END OF WORKAROUND
EntitlementCert entitlementCert = getEntitlementCertFromEntitlementCertFile(newCertFile);
File newCertKeyFile = getEntitlementCertKeyFileFromEntitlementCert(entitlementCert);
Assert.assertEquals(entitlementCert.orderNamespace.productId, poolProductId, isSubpool ? "New EntitlementCert productId '" + entitlementCert.orderNamespace.productId + "' matches originating Personal SubscriptionPool productId '" + poolProductId + "' after subscribing to the subpool." : "New EntitlementCert productId '" + entitlementCert.orderNamespace.productId + "' matches originating SubscriptionPool productId '" + poolProductId + "' after subscribing to the pool.");
Assert.assertTrue(RemoteFileTasks.testExists(sshCommandRunner, newCertFile.getPath()), "New EntitlementCert file exists after subscribing to SubscriptionPool '" + pool.poolId + "'.");
Assert.assertTrue(RemoteFileTasks.testExists(sshCommandRunner, newCertKeyFile.getPath()), "New EntitlementCert key file exists after subscribing to SubscriptionPool '" + pool.poolId + "'.");
}
}
// assert that consumed ProductSubscriptions has NOT decreased
List<ProductSubscription> afterProductSubscriptions = getCurrentlyConsumedProductSubscriptions();
// this assertion was valid prior to bug Bug 801187 - collapse list of provided products for subscription-manager list --consumed
// Assert.assertTrue(afterProductSubscriptions.size() >= beforeProductSubscriptions.size() && afterProductSubscriptions.size() > 0,
// "The list of currently consumed product subscriptions has increased (from "+beforeProductSubscriptions.size()+" to "+afterProductSubscriptions.size()+"), or has remained the same after subscribing (using poolID="+pool.poolId+") to pool: "+pool+" Note: The list of consumed product subscriptions can remain the same when all the products from this subscription pool are a subset of those from a previously subscribed pool.");
Assert.assertTrue(afterProductSubscriptions.size() == beforeProductSubscriptions.size() + 1, "The list of currently consumed product subscriptions has increased by 1 (from " + beforeProductSubscriptions.size() + " to " + afterProductSubscriptions.size() + "), after subscribing to pool: " + pool);
}
return newCertFile;
}
Aggregations