use of rhsm.data.ProductSubscription in project rhsm-qe by RedHatQE.
the class SubscribeTests method testAutoSubscribeOnVirtualSystemsFavorVirtualPools.
@// update=true, // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36577", "RHEL7-51378" }, 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: autosubscribe on a virtual system should favor virtual pools", groups = { "Tier2Tests", "blockedByBug-927101", "AutoSubscribeOnVirtualSystemsFavorVirtualPools_Test" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testAutoSubscribeOnVirtualSystemsFavorVirtualPools() throws JSONException, Exception {
// force the system to be virtual
Map<String, String> factsMap = new HashMap<String, String>();
factsMap.put("virt.is_guest", String.valueOf(Boolean.TRUE));
clienttasks.createFactsFileWithOverridingValues(factsMap);
// get the current product certs
List<ProductCert> productCerts = clienttasks.getCurrentProductCerts();
if (rhsmProductCertDir == null) {
rhsmProductCertDir = clienttasks.getConfFileParameter(clienttasks.rhsmConfFile, "rhsm", "productCertDir");
}
// 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);
// get the available pools
List<SubscriptionPool> availablePools = clienttasks.getCurrentlyAvailableSubscriptionPools();
// find available subscriptions for which both a Virtual and a Physical pool is available
boolean testAttempted = false;
for (SubscriptionPool virtualPool : SubscriptionPool.findAllInstancesWithMatchingFieldFromList("machineType", "Virtual", availablePools)) {
for (SubscriptionPool physicalPool : SubscriptionPool.findAllInstancesWithMatchingFieldFromList("machineType", "Physical", availablePools)) {
if (virtualPool.productId.equals(physicalPool.productId)) {
// found a pair of subscriptions that we can test
// get the product certs that are provided by these pools
List<String> virtualProductIds = CandlepinTasks.getPoolProvidedProductIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, virtualPool.poolId);
List<String> physicalProductIds = CandlepinTasks.getPoolProvidedProductIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, physicalPool.poolId);
// TEMPORARY WORKAROUND
if (virtualPool.subscriptionType.contains("(Temporary)") && virtualProductIds.isEmpty() && !physicalProductIds.isEmpty()) {
boolean invokeWorkaroundWhileBugIsOpen = true;
// Bug 1394401 - The list of provided products for Temporary Subscriptions is empty
String bugId = "1394401";
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("Virtual pool '" + virtualPool.poolId + "' and and Physical pool '" + physicalPool.poolId + "' are not good candidates for this test while bug '" + bugId + "' is open. Looking for another pair.");
continue;
}
}
// END OF WORKAROUND
Assert.assertTrue(virtualProductIds.containsAll(physicalProductIds) && physicalProductIds.containsAll(virtualProductIds), "Provided product ids from virtual pool '" + virtualPool.poolId + "' and physical pool '" + physicalPool.poolId + "' sharing a common productId '" + virtualPool.productId + "' should be the same.");
// configure a temporary product cert directory containing only these provided product certs
RemoteFileTasks.runCommandAndAssert(client, "mkdir -p " + tmpProductCertDir, Integer.valueOf(0));
RemoteFileTasks.runCommandAndAssert(client, "rm -f " + tmpProductCertDir + "/*.pem", Integer.valueOf(0));
List<String> productCertIdsFound = new ArrayList<String>();
List<String> productCertNamesFound = new ArrayList<String>();
for (ProductCert productCert : productCerts) {
if (virtualProductIds.contains(productCert.productId)) {
RemoteFileTasks.runCommandAndAssert(client, "cp " + productCert.file + " " + tmpProductCertDir, Integer.valueOf(0));
productCertIdsFound.add(productCert.productId);
productCertNamesFound.add(productCert.productName);
}
}
clienttasks.updateConfFileParameter(clienttasks.rhsmConfFile, "productCertDir", tmpProductCertDir);
if (!productCertIdsFound.isEmpty()) {
// start testing... autosubscribe and assert the consumed subscriptions are Virtual
clienttasks.unsubscribe(true, (BigInteger) null, null, null, null, null, null);
clienttasks.subscribe(true, null, null, (String) null, null, null, null, null, null, null, null, null, null);
for (ProductSubscription productSubscription : clienttasks.getCurrentlyConsumedProductSubscriptions()) {
Assert.assertEquals(productSubscription.machineType, "Virtual", "Autosubscribing a virtual system should favor granting an entitlement from a Virtual pool that provides " + productCertIdsFound + " over a Physical pool that provides " + productCertIdsFound + "'.");
// TODO We may need to comment this out or fix it if it starts failing due to changes in the subscription data.
Assert.assertTrue(productSubscription.provides.containsAll(productCertNamesFound), "The autosubscribed virtual subscription '" + productSubscription + "' provides for all of the installed products " + productCertNamesFound + ". (Note: This could potentially fail when the provided product names are do not exactly match the installed product cert names which is okay since the productIds are what really matter).");
testAttempted = true;
}
// testAttempted = true; // relocated to inside of loop above
} else {
log.info("Did not find any installed product certs provided by Virtual and Physical subscriptions '" + virtualPool.productId + "'.");
}
}
}
}
if (!testAttempted)
throw new SkipException("Did not find all the resources needed to attempt this test.");
}
use of rhsm.data.ProductSubscription in project rhsm-qe by RedHatQE.
the class SubscribeTests method testSubscribeWithFileOfPoolIds.
@// update=true, // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36583", "RHEL7-51385" }, 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: subscribe with --file whose contents are a list of poolids", groups = { "Tier2Tests", "blockedByBug-1159974" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testSubscribeWithFileOfPoolIds() throws JSONException, Exception {
// commit 3167333fc3a261de939f4aa0799b4283f2b9f4d2 bug 1159974
if (clienttasks.isPackageVersion("subscription-manager", "<", "1.13.8-1"))
throw new SkipException("The attach --file function was not implemented in this version of subscription-manager.");
// getRandomBoolean();
Boolean all = false;
Boolean matchInstalled = getRandomBoolean();
Boolean noOverlap = getRandomBoolean();
if (clienttasks.getCurrentlyRegisteredOwnerKey() == null) {
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);
clienttasks.autoheal(null, null, true, null, null, null, null);
} else
clienttasks.unsubscribe_(true, (BigInteger) null, null, null, null, null, null);
// call list with --pool-only to get a random list of available poolids
String poolOnlyListCommand = clienttasks.listCommand(all, true, null, null, null, null, matchInstalled, noOverlap, null, true, null, null, null, null);
String tmpFile = "/tmp/poolIds.txt";
// RemoteFileTasks.runCommandAndAssert(client, poolOnlyListCommand+" > "+tmpFile, 0);
RemoteFileTasks.runCommandAndAssert(client, poolOnlyListCommand + " > " + tmpFile + " && echo abc123 >> " + tmpFile, 0);
SSHCommandResult poolOnlyListResult = client.runCommandAndWait("cat " + tmpFile);
// convert the result to a list
List<String> poolIdsFromFile = new ArrayList<String>();
if (!poolOnlyListResult.getStdout().trim().isEmpty())
poolIdsFromFile.addAll(Arrays.asList(poolOnlyListResult.getStdout().trim().split("\n")));
poolIdsFromFile.remove("abc123");
// subscribe with the --file option
SSHCommandResult subscribeWithFileResult = clienttasks.subscribe(null, null, (List<String>) null, (List<String>) null, null, null, null, null, tmpFile, null, null, null, null);
String expectedRejection = String.format("Pool with id %s could not be found.", "abc123");
Assert.assertTrue(subscribeWithFileResult.getStdout().trim().endsWith(expectedRejection), "The stdout result from subscribe with a file of poolIds ends with '" + expectedRejection + "'.");
// assert that all of the currently attached pools equal the poolIdsFromFile
List<ProductSubscription> consumedProductSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
List<String> poolIdsAttached = new ArrayList<String>();
for (ProductSubscription consumedProductSubscription : consumedProductSubscriptions) poolIdsAttached.add(consumedProductSubscription.poolId);
// assert the result
Assert.assertTrue(poolIdsAttached.containsAll(poolIdsFromFile) && poolIdsFromFile.containsAll(poolIdsAttached), "The list of pool ids in file '" + tmpFile + "' is equivalent to the list of currently attached pool ids.");
Assert.assertEquals(poolIdsAttached.size(), poolIdsFromFile.size(), "The number of poolIds currently attached matches the number of pool ids read from the file '" + tmpFile + "'.");
}
use of rhsm.data.ProductSubscription in project rhsm-qe by RedHatQE.
the class TemporaryPoolTests method testStatusDetailsAfterAttachingUnmappedGuestsOnlySubpool.
@// update=true, // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-20095", "RHEL7-51737" }, 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 = "given an available unmapped_guests_only pool, attach it and verify the granted entitlement (validityNotAfter date is 24 hours after consumer's registration), installed product (Subscribed), and system status (Insufficient - Guest has not been reported on any host and is using a temporary unmapped guest subscription.)", groups = { "Tier1Tests", "blockedByBug-1362701" }, dataProvider = "getAvailableUnmappedGuestsOnlySubscriptionPoolsData", enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testStatusDetailsAfterAttachingUnmappedGuestsOnlySubpool(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, false, null, null, null, null);
ConsumerCert cert = clienttasks.getCurrentConsumerCert();
// attach the unmapped guests only pool
// File serialPemFile = clienttasks.subscribeToSubscriptionPool(unmappedGuestsOnlyPool, null, sm_clientUsername, sm_clientPassword, sm_serverUrl);
// EntitlementCert entitlementCert = clienttasks.getEntitlementCertFromEntitlementCertFile(serialPemFile);
clienttasks.subscribe_(null, null, unmappedGuestsOnlyPool.poolId, null, null, null, null, null, null, null, null, null, null);
// ProductSubscription consumedUnmappedGuestsOnlyProductSubscription = clienttasks.getCurrentlyConsumedProductSubscriptions().get(0); // assumes only one consumed entitlement
ProductSubscription consumedUnmappedGuestsOnlyProductSubscription = ProductSubscription.findFirstInstanceWithMatchingFieldFromList("poolId", unmappedGuestsOnlyPool.poolId, clienttasks.getCurrentlyConsumedProductSubscriptions());
EntitlementCert entitlementCert = clienttasks.getEntitlementCertCorrespondingToProductSubscription(consumedUnmappedGuestsOnlyProductSubscription);
// assert the expiration is 24 hours post the consumer's registration
int hours = 24;
if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.1.0-1")) {
// commit 0704a73dc0d3bf753351e87ca0b65d85a71acfbe 1450079: virt-who temporary subscription should be 7 days
hours = 7 * /*days*/
24;
log.info("Due to Candlepin RFE Bug 1450079, the vailidity period for temporary subscription pools has increased from one day to one week.");
}
if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.0.30-1")) {
// commit 9302c8f57f37dd5ec3c4020770ac1675a87d99ba 1419576: Pre-date certs to ease clock skew issues
hours += 1;
log.info("Due to Candlepin RFE Bug 1419576, we need to increment the expected entitlement validity for the temporary pool by one hour to '" + hours + "' hours after the consumer identity's validityNotBefore date.");
}
Calendar expectedEntitlementCertEndDate = (Calendar) cert.validityNotBefore.clone();
expectedEntitlementCertEndDate.add(Calendar.HOUR, hours);
// Assert.assertEquals(ConsumerCert.formatDateString(entitlementCert.validityNotAfter), ConsumerCert.formatDateString(expectedEntitlementCertEndDate), "The End Date of the entitlement from a temporary pool should be exactly 24 hours after the registration date of the current consumer '"+ConsumerCert.formatDateString(cert.validityNotBefore)+"'.");
// allow for a few seconds of tolerance
Calendar expectedEntitlementCertEndDateUpperTolerance = (Calendar) expectedEntitlementCertEndDate.clone();
expectedEntitlementCertEndDateUpperTolerance.add(Calendar.SECOND, +25);
Calendar expectedEntitlementCertEndDateLowerTolerance = (Calendar) expectedEntitlementCertEndDate.clone();
expectedEntitlementCertEndDateLowerTolerance.add(Calendar.SECOND, -25);
Assert.assertTrue(entitlementCert.validityNotAfter.before(expectedEntitlementCertEndDateUpperTolerance) && entitlementCert.validityNotAfter.after(expectedEntitlementCertEndDateLowerTolerance), "The End Date of the entitlement from a temporary pool '" + ConsumerCert.formatDateString(entitlementCert.validityNotAfter) + "' should be '" + hours + "' hours (within several seconds) after the registration date of the current consumer '" + ConsumerCert.formatDateString(cert.validityNotBefore) + "'.");
// assert the Status Details of the attached subscription
String expectedStatusDetailsForAnUnmappedGuestsOnlyProductSubscription = "Guest has not been reported on any host and is using a temporary unmapped guest subscription.";
Assert.assertEquals(consumedUnmappedGuestsOnlyProductSubscription.statusDetails, Arrays.asList(new String[] { expectedStatusDetailsForAnUnmappedGuestsOnlyProductSubscription }), "Status Details of a consumed subscription from a temporary pool for unmapped guests only.");
// assert that the temporary subscription appears in the status report
SSHCommandResult statusResult = clienttasks.status(null, null, null, null, null);
// 2015-08-13 18:49:28.596 FINE: ssh root@jsefler-7.usersys.redhat.com subscription-manager status
// 2015-08-13 18:49:30.956 FINE: Stdout:
// +-------------------------------------------+
// System Status Details
// +-------------------------------------------+
// Overall Status: Insufficient
//
// Red Hat Enterprise Linux for Virtual Datacenters, Premium (DERIVED SKU):
// - Guest has not been reported on any host and is using a temporary unmapped guest subscription.
//
// 2015-08-19 10:33:50.675 FINE: ssh root@ibm-p8-kvm-04-guest-06.rhts.eng.bos.redhat.com subscription-manager status
// 2015-08-19 10:33:52.757 FINE: Stdout:
// +-------------------------------------------+
// System Status Details
// +-------------------------------------------+
// Overall Status: Invalid
//
// Red Hat Enterprise Linux for Virtual Datacenters, Premium (DERIVED SKU):
// - Guest has not been reported on any host and is using a temporary unmapped guest subscription.
//
// Red Hat Enterprise Linux for Power, little endian:
// - Not supported by a valid subscription.
Map<String, String> statusMap = StatusTests.getProductStatusMapFromStatusResult(statusResult);
Assert.assertTrue(statusMap.containsKey(consumedUnmappedGuestsOnlyProductSubscription.productName), "The status module reports an incompliance from temporary subscription '" + consumedUnmappedGuestsOnlyProductSubscription.productName + "'.");
Assert.assertEquals(statusMap.get(consumedUnmappedGuestsOnlyProductSubscription.productName), expectedStatusDetailsForAnUnmappedGuestsOnlyProductSubscription, "The status module reports an incompliance from temporary subscription '" + consumedUnmappedGuestsOnlyProductSubscription.productName + "' for this reason.");
// assert that the temporary subscription causes an overall status to be Invalid or Insufficient (either is possible and depends on what is installed and if the Temporary pool provides for what is installed)
Assert.assertTrue(statusResult.getStdout().contains("Overall Status: Invalid") || statusResult.getStdout().contains("Overall Status: Insufficient"), "Expecting Overall Status to be 'Invalid' or 'Insufficient' when a temporary subscription for '" + consumedUnmappedGuestsOnlyProductSubscription.productName + "' is attached (actual value depends on what is installed and if the temporary pool provides for what is installed)");
// assert the status of installed products provided by the temporary subscription
List<String> providedProductIds = CandlepinTasks.getPoolProvidedProductIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, unmappedGuestsOnlyPool.poolId);
List<InstalledProduct> installedProducts = clienttasks.getCurrentlyInstalledProducts();
for (String providedProductId : providedProductIds) {
InstalledProduct installedProduct = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productId", providedProductId, installedProducts);
if (installedProduct != null) {
// providedProduct is installed
// assert the status details
// see CLOSED NOTABUG Bug 1200882 - Wrong installed product status is displayed when a unmapped_guests_only pool is attached
Assert.assertEquals(installedProduct.status, "Subscribed", "Status of an installed product provided for by a temporary entitlement from a pool reserved for unmapped guests only.");
Assert.assertEquals(installedProduct.statusDetails, new ArrayList<String>(), "Status Details of an installed product provided for by a temporary entitlement from a pool reserved for unmapped guests only.");
// TODO: The above two asserts might be changed by RFE Bug 1201520 - [RFE] Usability suggestions to better identify a temporary (aka 24 hour) entitlement
// assert the start-end dates
// TEMPORARY WORKAROUND FOR BUG
// Bug 1199443 - Wrong "End date" in installed list after attaching 24-hour subscription on a unmapped-guest
String bugId = "1199443";
boolean invokeWorkaroundWhileBugIsOpen = true;
try {
if (invokeWorkaroundWhileBugIsOpen && BzChecker.getInstance().isBugOpen(bugId)) {
log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId).toString() + " Bugzilla " + bugId + ". (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId + ")");
SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId);
} else {
invokeWorkaroundWhileBugIsOpen = false;
}
} catch (BugzillaAPIException be) {
/* ignore exception */
} catch (RuntimeException re) {
/* ignore exception */
}
if (invokeWorkaroundWhileBugIsOpen) {
log.warning("Skipping assertion of the End Date for installed product '" + installedProduct.productName + "' provided by a temporary pool while bug '" + bugId + "' is open.");
} else
// assert the End Date
// END OF WORKAROUND
Assert.assertEquals(InstalledProduct.formatDateString(installedProduct.endDate), InstalledProduct.formatDateString(entitlementCert.validityNotAfter), "The End Date of coverage for the installed product '" + installedProduct.productName + "' should exactly match the end date from the temporary pool subscription.");
}
}
}
use of rhsm.data.ProductSubscription in project rhsm-qe by RedHatQE.
the class UnsubscribeTests method testUnsubscribeFromPool.
@// update=true, // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-47924", "RHEL7-51406" }, linkedWorkItems = { @LinkedItem(// RHSM-REQ : subscription-manager cli attaching and removing subscriptions
workitemId = "RHEL6-28489", project = Project.RHEL6, role = DefTypes.Role.VERIFIES), @LinkedItem(// RHSM-REQ : subscription-manager cli attaching and removing subscriptions
workitemId = "RHEL7-84911", project = Project.RedHatEnterpriseLinux7, role = DefTypes.Role.VERIFIES) }, 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 = "Attempt to unsubscribe from a valid pool id", groups = { "Tier1Tests", "blockedByBug-1198178" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testUnsubscribeFromPool() {
if (clienttasks.isPackageVersion("subscription-manager", "<", "1.16.5-1"))
throw new SkipException("The unsubscribe --pool function was not implemented in this version of subscription-manager. See RFE Bug 1198178");
// register and get available pools
clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (List<String>) null, null, null, null, true, false, null, null, null, null);
List<SubscriptionPool> pools = clienttasks.getCurrentlyAllAvailableSubscriptionPools();
// find available multi-entitlement (Stackable) pools
pools = SubscriptionPool.findAllInstancesWithMatchingFieldFromList("subscriptionType", "Stackable", pools);
pools = getRandomSubsetOfList(pools, 2);
List<String> poolIds = new ArrayList<String>();
// attach multiple serials per pool
for (SubscriptionPool pool : pools) {
clienttasks.subscribe(null, null, pool.poolId, null, null, null, null, null, null, null, null, null, null);
clienttasks.subscribe(null, null, pool.poolId, null, null, null, null, null, null, null, null, null, null);
poolIds.add(pool.poolId);
}
// choose a poolId and get serials from that pool
SubscriptionPool pool = pools.get(0);
List<String> serials = new ArrayList<String>();
for (ProductSubscription productSubscription : clienttasks.getCurrentlyConsumedProductSubscriptions()) {
if (productSubscription.poolId.equals(pool.poolId)) {
serials.add(productSubscription.serialNumber.toString());
}
}
// unsubscribe from poolId
SSHCommandResult result = clienttasks.unsubscribe_(null, null, pool.poolId, null, null, null, null);
if (!servertasks.statusCapabilities.contains("remove_by_pool_id")) {
Integer expectedExitCode = new Integer(69);
Assert.assertEquals(result.getExitCode(), expectedExitCode, "Asserting exit code when attempting to unsubscribe from an invalid pool id (from an incapable server).");
if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.16.7-1")) {
// d9a82d3135a1770f794c2c8181f44e7e4628e0b6 Output of errors now goes to stderr
Assert.assertEquals(result.getStderr().trim(), "Error: The registered entitlement server does not support remove --pool.\nInstead, use the remove --serial option.", "Stderr");
Assert.assertEquals(result.getStdout().trim(), "", "Stdout");
} else {
Assert.assertEquals(result.getStdout().trim(), "Error: The registered entitlement server does not support remove --pool.\nInstead, use the remove --serial option.", "Stdout");
Assert.assertEquals(result.getStderr().trim(), "", "Stderr");
}
throw new SkipException("The registered entitlement server does not support remove --pool");
}
Integer expectedExitCode = new Integer(0);
Assert.assertEquals(result.getExitCode(), expectedExitCode, "Exit code when attempting to unsubscribe from a valid pool id.");
// String expectedStdout = String.format("Pools successfully removed at the server:\n %s\nSerial numbers successfully removed at the server:\n %s\n %s\n%d local certificates have been deleted.", pool.poolId, serials.get(0), serials.get(1), serials.size());
// Assert.assertEquals(result.getStdout().trim(),expectedStdout,"Stdout when attempting to unsubscribe from a valid pool id.");
String expectedStdoutRegex = String.format("Pools successfully removed at the server:\n %s\nSerial numbers successfully removed at the server:\n %s\n %s\n%d local certificates have been deleted.", pool.poolId, "(" + serials.get(0) + "|" + serials.get(1) + ")", "(" + serials.get(0) + "|" + serials.get(1) + ")", serials.size());
// commit f64d5a6b012f49bb4d6d6653441d4de9bf373660 1319678: Alter the return message for removing entitlements at server
if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.17.8-1"))
expectedStdoutRegex = String.format("The entitlement server successfully removed these pools:\n %s\nThe entitlement server successfully removed these serial numbers:\n %s\n %s\n%d local certificates have been deleted.", pool.poolId, "(" + serials.get(0) + "|" + serials.get(1) + ")", "(" + serials.get(0) + "|" + serials.get(1) + ")", serials.size());
// commit d88d09c7060a17fba34a138313e7efd21cc79d02 D-Bus service for removing entitlements (all/ID/serial num.)
if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.20.2-1"))
expectedStdoutRegex = String.format("%d local certificates have been deleted.\nThe entitlement server successfully removed these pools:\n %s\nThe entitlement server successfully removed these serial numbers:\n %s\n %s", serials.size(), pool.poolId, "(" + serials.get(0) + "|" + serials.get(1) + ")", "(" + serials.get(0) + "|" + serials.get(1) + ")");
Assert.assertMatch(result.getStdout().trim(), expectedStdoutRegex);
Assert.assertEquals(result.getStderr(), "", "Stderr when attempting to unsubscribe from a valid pool id.");
}
use of rhsm.data.ProductSubscription in project rhsm-qe by RedHatQE.
the class UnsubscribeTests method testUnsubscribeAfterSubscribingToFutureSubscriptionPool.
@// update=true, // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-27125", "RHEL7-51946" }, linkedWorkItems = { @LinkedItem(// RHSM-REQ : subscription-manager cli attaching and removing subscriptions
workitemId = "RHEL6-28489", project = Project.RHEL6, role = DefTypes.Role.VERIFIES), @LinkedItem(// RHSM-REQ : subscription-manager cli attaching and removing subscriptions
workitemId = "RHEL7-84911", project = Project.RedHatEnterpriseLinux7, role = DefTypes.Role.VERIFIES) }, 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: subscribe and then unsubscribe from a future subscription pool", groups = { "Tier2Tests", "blockedByBug-727970", "blockedByBug-958775" }, // dataProvider="getAllFutureSystemSubscriptionPoolsData", // 06/04/2014 takes too long; rarely reveals a bug
dataProvider = "getRandomSubsetOfFutureSystemSubscriptionPoolsData", enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testUnsubscribeAfterSubscribingToFutureSubscriptionPool(SubscriptionPool pool) throws Exception {
// if (!pool.productId.equals("awesomeos-virt-unlmtd-phys")) throw new SkipException("debugTesting pool productId="+pool.productId);
Calendar now = new GregorianCalendar();
now.setTimeInMillis(System.currentTimeMillis());
// subscribe to the future SubscriptionPool
SSHCommandResult subscribeResult = clienttasks.subscribe(null, null, pool.poolId, null, null, null, null, null, null, null, null, null, null);
// Pool is restricted to physical systems: '8a9086d3443c043501443c052aec1298'.
if (subscribeResult.getStdout().startsWith("Pool is restricted")) {
throw new SkipException("Subscribing to this future subscription is not applicable to this test: " + pool);
}
// assert that the granted EntitlementCert and its corresponding key exist
EntitlementCert entitlementCert = clienttasks.getEntitlementCertCorrespondingToSubscribedPool(pool);
File entitlementCertFile = clienttasks.getEntitlementCertFileFromEntitlementCert(entitlementCert);
File entitlementCertKeyFile = clienttasks.getEntitlementCertKeyFileFromEntitlementCert(entitlementCert);
Assert.assertEquals(RemoteFileTasks.testFileExists(client, entitlementCertFile.getPath()), 1, "EntitlementCert file exists after subscribing to future SubscriptionPool.");
Assert.assertEquals(RemoteFileTasks.testFileExists(client, entitlementCertKeyFile.getPath()), 1, "EntitlementCert key file exists after subscribing to future SubscriptionPool.");
// find the consumed ProductSubscription from the future SubscriptionPool
ProductSubscription productSubscription = ProductSubscription.findFirstInstanceWithMatchingFieldFromList("serialNumber", entitlementCert.serialNumber, clienttasks.getCurrentlyConsumedProductSubscriptions());
Assert.assertNotNull(productSubscription, "Found the newly consumed ProductSubscription after subscribing to future subscription pool '" + pool.poolId + "'.");
// unsubscribe
clienttasks.unsubscribeFromProductSubscription(productSubscription);
// assert that the EntitlementCert file and its key are removed.
/* NOTE: this assertion is already built into the unsubscribeFromProductSubscription task above
Assert.assertEquals(RemoteFileTasks.testFileExists(client, entitlementCertFile.getPath()), 0,"EntitlementCert file has been removed after unsubscribing to future SubscriptionPool.");
Assert.assertEquals(RemoteFileTasks.testFileExists(client, entitlementCertKeyFile.getPath()), 0,"EntitlementCert key file has been removed after unsubscribing to future SubscriptionPool.");
*/
}
Aggregations