use of rhsm.data.EntitlementCert in project rhsm-qe by RedHatQE.
the class SubscribeTests method testSubscribeToSubscriptionPoolProductId.
// Test methods ***********************************************************************
@// update=true, // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-19980", "RHEL7-33092" }, 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")
@// ; and assert the subscription pool is not available when it does not match the system hardware.",
Test(// ; and assert the subscription pool is not available when it does not match the system hardware.",
description = "subscription-manager-cli: subscribe consumer to subscription pool product id", dataProvider = "getAllSystemSubscriptionPoolProductData", groups = { "Tier1Tests", "blockedByBug-660713", "blockedByBug-806986", "blockedByBug-878986", "blockedByBug-962520", "blockedByBug-1008647", "blockedByBug-1009600", "blockedByBug-996993" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testSubscribeToSubscriptionPoolProductId(String productId, JSONArray bundledProductDataAsJSONArray) throws Exception {
// /*debugTesting*/ if (!productId.equals("awesomeos-ul-quantity-virt")) throw new SkipException("debugTesting - Automator should comment out this line.");
// /*debugTesting*/ if (!productId.equals("awesomeos-onesocketib")) throw new SkipException("debugTesting - Automator should comment out this line.");
// /*debugTesting*/ if (!productId.equals("awesomeos-virt-4")) throw new SkipException("debugTesting - Automator should comment out this line.");
// /*debugTesting*/ if (!productId.equals("awesomeos-virt-4")&&!productId.equals("awesomeos-ul-quantity-virt")&&!productId.equals("awesomeos-onesocketib")&&!productId.equals("awesomeos-instancebased")) throw new SkipException("debugTesting - Automator should comment out this line.");
// /*debugTesting*/ if (!productId.equals("2cores-2ram-multiattr")) throw new SkipException("debugTesting - Automator should comment out this line.");
// /*debugTesting*/ if (!productId.equals("RH0380468")) throw new SkipException("debugTesting - Automator should comment out this line.");
// /*debugTesting*/ if (!productId.equals("RH00284")) throw new SkipException("debugTesting - Automator should comment out this line.");
// /*debugTesting*/ if (!productId.equals("awesomeos-super-hypervisor")) throw new SkipException("debugTesting - Automator should comment out this line.");
// /*debugTesting*/ if (!productId.equals("MCT3115")) throw new SkipException("debugTesting - Automator should comment out this line.");
// is this system a virtual guest system or a physical system
boolean systemIsGuest = Boolean.valueOf(clienttasks.getFactValue("virt.is_guest"));
// begin test with a fresh register
clienttasks.unregister(null, null, null, null);
clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, null, false, null, null, null, null);
// assert the subscription pool with the matching productId is available
// clienttasks.getCurrentlyAvailableSubscriptionPools() is tested at the conclusion of this test
SubscriptionPool pool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", productId, clienttasks.getCurrentlyAllAvailableSubscriptionPools());
// special case...
if (pool == null) {
// when pool is null, another likely cause is that all of the available subscriptions from the pools are being consumed, let's check...
for (String poolId : CandlepinTasks.getPoolIdsForProductId(sm_clientUsername, sm_clientPassword, sm_serverUrl, clienttasks.getCurrentlyRegisteredOwnerKey(), productId)) {
int quantity = (Integer) CandlepinTasks.getPoolValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, poolId, "quantity");
int consumed = (Integer) CandlepinTasks.getPoolValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, poolId, "consumed");
if (consumed >= quantity) {
throw new SkipException("The total quantity '" + quantity + "' of subscriptions from poolId '" + poolId + "' for product '" + productId + "' are being consumed; hence this product subscription is appropriately not available to subscribe.");
}
}
}
Assert.assertNotNull(pool, "Expected SubscriptionPool with ProductId '" + productId + "' is available for subscribing.");
// assemble a list of expected bundled product names
List<String> bundledProductNames = new ArrayList<String>();
for (int j = 0; j < bundledProductDataAsJSONArray.length(); j++) {
JSONObject bundledProductAsJSONObject = (JSONObject) bundledProductDataAsJSONArray.get(j);
String bundledProductId = bundledProductAsJSONObject.getString("productId");
String bundledProductName = bundledProductAsJSONObject.getString("productName");
bundledProductNames.add(bundledProductName);
}
// TEMPORARY WORKAROUND
boolean invokeWorkaroundWhileBugIsOpen = true;
// Bug 1016300 - the "Provides:" field in subscription-manager list --available should exclude "MKT" products.
String bugId = "1016300";
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("While bug '" + bugId + "' is open, skip assertion that the actual list of SubscriptionPool provided product names " + pool.provides + " matches the expected list of bundledProductDataNames " + bundledProductNames + ".");
} else /*if (clienttasks.isPackageVersion("subscription-manager",">=","1.10.3-1"))*/
if (pool.provides != null) {
// TEMPORARY WORKAROUND
invokeWorkaroundWhileBugIsOpen = true;
// Bug 1394401 - The list of provided products for Temporary Subscriptions is empty
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 && !bundledProductNames.isEmpty() && pool.provides.isEmpty() && pool.subscriptionType.contains("Temporary")) {
log.warning("While bug '" + bugId + "' is open, skip assertion that the actual list of SubscriptionPool provided product names " + pool.provides + " matches the expected list of bundledProductDataNames " + bundledProductNames + ".");
} else
// END OF WORKAROUND
// assert that the pool's list of Provides matches the list of bundled product names after implementation of Bug 996993 - [RFE] Search for or list matching providedProducts; subscription-manager commit b8738a74c1109975e387fc51105c8ff58eaa8f01
Assert.assertTrue(bundledProductNames.containsAll(pool.provides) && pool.provides.containsAll(bundledProductNames), "The actual list of SubscriptionPool provided product names " + pool.provides + " matches the expected list of bundledProductDataNames " + bundledProductNames + ". (If this fails due to provided Product Names changes by Release Engineering, refresh pools for account '" + sm_clientUsername + "' is needed.)");
}
List<ProductCert> currentlyInstalledProductCerts = clienttasks.getCurrentProductCerts();
List<InstalledProduct> currentlyInstalledProducts = clienttasks.getCurrentlyInstalledProducts();
// assert the installed status of the bundled products
for (int j = 0; j < bundledProductDataAsJSONArray.length(); j++) {
JSONObject bundledProductAsJSONObject = (JSONObject) bundledProductDataAsJSONArray.get(j);
String bundledProductId = bundledProductAsJSONObject.getString("productId");
// assert the status of the installed products listed
for (ProductCert productCert : ProductCert.findAllInstancesWithMatchingFieldFromList("productId", bundledProductId, currentlyInstalledProductCerts)) {
InstalledProduct installedProduct = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productName", productCert.productName, currentlyInstalledProducts);
Assert.assertNotNull(installedProduct, "The status of installed product cert with ProductName '" + productCert.productName + "' is reported in the list of installed products.");
Assert.assertEquals(installedProduct.status, "Not Subscribed", "Before subscribing to pool for ProductId '" + productId + "', the status of Installed Product '" + productCert.productName + "' is Not Subscribed.");
}
}
// when the Suggested quantity is 0, let's specify a quantity to avoid Stdout: Quantity '1' is not a multiple of instance multiplier '2'
// adjust quantity for instance_multiplier pools
String instance_multiplier = CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "instance_multiplier");
String quantity = null;
/*if (clienttasks.isPackageVersion("subscription-manager",">=","1.10.3-1"))*/
if (pool.suggested != null) {
if (pool.suggested < 1 && instance_multiplier != null) {
quantity = instance_multiplier;
}
}
boolean isPoolRestrictedToUnmappedVirtualSystems = CandlepinTasks.isPoolRestrictedToUnmappedVirtualSystems(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId);
// subscribe to the pool
File entitlementCertFile = clienttasks.subscribeToSubscriptionPool(pool, quantity, /*sm_serverAdminUsername*/
sm_clientUsername, /*sm_serverAdminPassword*/
sm_clientPassword, sm_serverUrl);
EntitlementCert entitlementCert = clienttasks.getEntitlementCertFromEntitlementCertFile(entitlementCertFile);
currentlyInstalledProducts = clienttasks.getCurrentlyInstalledProducts();
List<ProductSubscription> currentlyConsumedProductSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
// after subscribing to a pool, assert that its corresponding productSubscription is found among the currently consumed productSubscriptions
ProductSubscription consumedProductSubscription = ProductSubscription.findFirstInstanceWithMatchingFieldFromList("productId", pool.productId, currentlyConsumedProductSubscriptions);
Assert.assertNotNull(consumedProductSubscription, "The consumed ProductSubscription corresponding to the subscribed SubscriptionPool productId '" + pool.productId + "' was found among the list of consumed ProductSubscriptions.");
// assert that the quantityUsed matches the quantitySuggested after implementation of Bug 1008647 - [RFE] bind requests that do not specify a quantity should automatically use the quantity needed to achieve compliance
if (quantity != null) {
Assert.assertEquals(consumedProductSubscription.quantityUsed, Integer.valueOf(quantity), "When the attachment quantity '" + quantity + "' is specified, the quantity used from the consumed product subscription should match.");
} else {
/*if (clienttasks.isPackageVersion("subscription-manager",">=","1.10.3-1"))*/
if (pool.suggested != null) {
if (pool.suggested > 1) {
Assert.assertEquals(consumedProductSubscription.quantityUsed, pool.suggested, "When the suggested consumption quantity '" + pool.suggested + "' from the available pool is greater than one, the quantity used from the consumed product subscription should match.");
} else {
Assert.assertEquals(consumedProductSubscription.quantityUsed, Integer.valueOf(1), "When the suggested consumption quantity '" + pool.suggested + "' from the available pool is NOT greater than one, the quantity used from the consumed product subscription should be one.");
}
}
}
/*if (clienttasks.isPackageVersion("subscription-manager",">=","1.10.3-1"))*/
if (consumedProductSubscription.machineType != null) {
Assert.assertEquals(consumedProductSubscription.machineType, pool.machineType, "After subscribing from a pool with a machine type '" + pool.machineType + "', the consumed product subscription's machine type should match.");
}
// TEMPORARY WORKAROUND
/*boolean*/
invokeWorkaroundWhileBugIsOpen = true;
// Bug 1204311 - Refreshing pools causes unexpected temporary pools for unmapped guests to become available
bugId = "1204311";
/*String*/
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 && isPoolRestrictedToUnmappedVirtualSystems) {
log.warning("While bug '" + bugId + "' is open and we have subscrbed to a Temporary pool, skip assertion that the consumed productSubscription provides all of the expected bundled product names " + bundledProductNames + " after subscribing to pool: " + pool);
} else // END OF WORKAROUND
{
// TEMPORARY WORKAROUND
invokeWorkaroundWhileBugIsOpen = true;
// Bug 1394401 - The list of provided products for Temporary Subscriptions is empty
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 && isPoolRestrictedToUnmappedVirtualSystems) {
log.warning("While bug '" + bugId + "' is open and we have subscrbed to a Temporary pool, skip assertion that the consumed productSubscription provides all of the expected bundled product names " + bundledProductNames + " after subscribing to pool: " + pool);
} else
// END OF WORKAROUND
// assert that the consumed product subscription provides all the expected bundled products.
Assert.assertTrue(consumedProductSubscription.provides.containsAll(bundledProductNames) && bundledProductNames.containsAll(consumedProductSubscription.provides), "The consumed productSubscription provides all of the expected bundled product names " + bundledProductNames + " after subscribing to pool: " + pool);
}
// assert the dates of the consumed product subscription...
if (isPoolRestrictedToUnmappedVirtualSystems) {
// ... assert endDate is 24 hours after the date of registration
ConsumerCert cert = clienttasks.getCurrentConsumerCert();
Calendar consumerCertStartDate = cert.validityNotBefore;
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 expires_after by one hour to account for pre-dating the consumer identity's validityNotBefore date by one hour.");
}
consumerCertStartDate.add(Calendar.HOUR, hours);
Assert.assertEquals(ProductSubscription.formatDateString(consumedProductSubscription.endDate), ProductSubscription.formatDateString(consumerCertStartDate), "Consumed productSubscription (from a unmapped_guests_only pool '" + pool.poolId + "') expires '" + hours + "' hours after the time of consumer registration (" + ConsumerCert.formatDateString(clienttasks.getCurrentConsumerCert().validityNotBefore) + ").");
// TODO Assert the start date after bug 1199670 is resolved
} else {
// ... assert endDate matches the originating subscription pool
Assert.assertEquals(ProductSubscription.formatDateString(consumedProductSubscription.endDate), ProductSubscription.formatDateString(pool.endDate), "Consumed productSubscription expires on the same DAY as the originating subscription pool.");
// FIXME Assert.assertTrue(productSubscription.startDate.before(entitlementCert.validityNotBefore), "Consumed ProductSubscription Began before the validityNotBefore date of the new entitlement: "+entitlementCert);
}
// assert the expected products are consumed
for (int j = 0; j < bundledProductDataAsJSONArray.length(); j++) {
JSONObject bundledProductAsJSONObject = (JSONObject) bundledProductDataAsJSONArray.get(j);
String bundledProductId = bundledProductAsJSONObject.getString("productId");
String bundledProductName = bundledProductAsJSONObject.getString("productName");
bundledProductNames.add(bundledProductName);
// find the corresponding productNamespace from the entitlementCert
ProductNamespace productNamespace = null;
for (ProductNamespace pn : entitlementCert.productNamespaces) {
if (pn.id.equals(bundledProductId))
productNamespace = pn;
}
// TEMPORARY WORKAROUND
invokeWorkaroundWhileBugIsOpen = true;
// Bug 1394401 - The list of provided products for Temporary Subscriptions is empty
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 && !bundledProductNames.isEmpty() && pool.provides.isEmpty() && pool.subscriptionType.contains("Temporary")) {
log.warning("While bug '" + bugId + "' is open, skip assertion of the consumed entitlement provided products amongst the list of install products.");
} else // assert the installed status of the corresponding product
if (entitlementCert.productNamespaces.isEmpty()) {
log.warning("This product '" + productId + "' (" + bundledProductName + ") does not appear to grant entitlement to any client side content. This must be a server side management add-on product. Asserting as such...");
Assert.assertEquals(entitlementCert.contentNamespaces.size(), 0, "When there are no productNamespaces in the entitlementCert, there should not be any contentNamespaces.");
// when there is no corresponding product, then there better not be an installed product status by the same product name
Assert.assertNull(InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productName", bundledProductName, currentlyInstalledProducts), "Should not find any installed product status matching a server side management add-on productName: " + bundledProductName);
// when there is no corresponding product, then there better not be an installed product cert by the same product name
Assert.assertNull(ProductCert.findFirstInstanceWithMatchingFieldFromList("productName", bundledProductName, currentlyInstalledProductCerts), "Should not find any installed product certs matching a server side management add-on productName: " + bundledProductName);
} else {
Assert.assertNotNull(productNamespace, "The new entitlement cert's product namespace corresponding to this expected ProductSubscription with ProductName '" + bundledProductName + "' was found.");
// assert the status of the installed products listed
// should be a list of one or empty
List<ProductCert> productCerts = ProductCert.findAllInstancesWithMatchingFieldFromList("productId", productNamespace.id, currentlyInstalledProductCerts);
for (ProductCert productCert : productCerts) {
List<InstalledProduct> installedProducts = InstalledProduct.findAllInstancesWithMatchingFieldFromList("productName", productCert.productName, currentlyInstalledProducts);
Assert.assertEquals(installedProducts.size(), 1, "The status of installed product '" + productCert.productName + "' should only be reported once in the list of installed products.");
InstalledProduct installedProduct = installedProducts.get(0);
// TEMPORARY WORKAROUND FOR BUG
if (installedProduct.arch.contains(",")) {
/*boolean*/
invokeWorkaroundWhileBugIsOpen = true;
// Bug 951633 - installed product with comma separated arch attribute fails to go green
bugId = "951633";
/*String*/
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("Verification for status of Installed Product name='" + installedProduct.productName + "' with arch='" + installedProduct.arch + "' is blocked by open bugzilla '" + bugId + "'.");
}
}
// END OF WORKAROUND
// decide what the status should be... "Subscribed" or "Partially Subscribed" (SPECIAL CASE WHEN poolProductSocketsAttribute=0 or "null" SHOULD YIELD Subscribed)
String poolProductSocketsAttribute = CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "sockets");
// introduced by 885785 [RFE] Subscription Manager should alert a user if subscription vcpu limits are lower than system vcpu allocation
String poolProductVcpuAttribute = CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "vcpu");
String poolProductArchAttribute = CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "arch");
List<String> poolProductArches = new ArrayList<String>();
if (poolProductArchAttribute != null) {
// Note: the arch attribute can be a comma separated list of values
poolProductArches.addAll(Arrays.asList(poolProductArchAttribute.trim().split(" *, *")));
// Note: x86 is a general arch to cover all 32-bit intel microprocessors
if (poolProductArches.contains("x86")) {
poolProductArches.addAll(Arrays.asList("i386", "i486", "i586", "i686"));
}
if (poolProductArches.contains("ALL"))
poolProductArches.add(clienttasks.arch);
}
// if the sockets attribute is not numeric (e.g. "null"), then this subscription should be available to this client
try {
Integer.valueOf(poolProductSocketsAttribute);
} catch (NumberFormatException e) {
// do not mark productAttributesPassRulesCheck = false;
log.warning("Ecountered a non-numeric value for product sockets attribute sockets on productId='" + productId + "' poolId '" + pool.poolId + "'. SIMPLY IGNORING THIS ATTRIBUTE.");
poolProductSocketsAttribute = null;
}
// consider the socket/vcpu coverage and assert the installed product's status
if (isPoolRestrictedToUnmappedVirtualSystems && false) /*since 1200882 was CLOSED NOTABUG, never run the assertion in this if condition*/
{
// TEMPORARY WORKAROUND
/*boolean*/
invokeWorkaroundWhileBugIsOpen = true;
// Bug 1200882 - Wrong installed product status is displayed when a unmapped_guests_only pool is attached
bugId = "1200882";
/*String*/
try {
if (invokeWorkaroundWhileBugIsOpen && BzChecker.getInstance().isBugOpen(bugId)) {
log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId).toString() + " Bugzilla " + bugId + ". (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId + ")");
SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId);
} else {
invokeWorkaroundWhileBugIsOpen = false;
}
} catch (BugzillaAPIException be) {
/* ignore exception */
} catch (RuntimeException re) {
/* ignore exception */
}
if (invokeWorkaroundWhileBugIsOpen) {
log.warning("Skipping the assertion of the installed product status after subscribing to an unmapped_guests_only pool for ProductId '" + productId + "' while bug '" + bugId + "' is open.");
} else
// END OF WORKAROUND
// for more info, see bugzilla https://bugzilla.redhat.com/show_bug.cgi?id=1197897 // CLOSED NOTABUG
Assert.assertEquals(installedProduct.status, "Partially Subscribed", "After subscribing to an unmapped_guests_only pool for ProductId '" + productId + "', the status of Installed Product '" + bundledProductName + "' should be Partially Subscribed regardless of any hardware socket/vcpu coverage or other subscriptions attached.");
} else 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 installedProduct.status after subscribing to pool: " + 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("After subscribing to a pool for ProductId '" + productId + ", skipping assertion of the installed product status for products provided by this pool: " + pool);
} else if (pool.multiEntitlement != null && !pool.multiEntitlement && /*ADDED AFTER IMPLEMENTATION OF BUG 1008647*/
!systemIsGuest && /*ADDED AFTER IMPLEMENTATION OF BUG 885785*/
poolProductSocketsAttribute != null && Integer.valueOf(poolProductSocketsAttribute) < Integer.valueOf(clienttasks.sockets) && Integer.valueOf(poolProductSocketsAttribute) > 0) {
Assert.assertEquals(installedProduct.status, "Partially Subscribed", "After subscribing this physical system to a pool for ProductId '" + productId + "' (covers '" + poolProductSocketsAttribute + "' sockets), the status of Installed Product '" + bundledProductName + "' should be Partially Subscribed since a corresponding product cert was found in " + clienttasks.productCertDir + " and the machine's sockets value (" + clienttasks.sockets + ") is greater than what a single subscription from a non-multi-entitlement pool covers.");
} else if (pool.subscriptionType != null && (pool.subscriptionType.equals("Standard") || pool.subscriptionType.equals("Stackable only with other subscriptions")) && /*ADDED AFTER IMPLEMENTATION OF BUG 1008647 AND 1029968*/
!systemIsGuest && /*ADDED AFTER IMPLEMENTATION OF BUG 885785*/
poolProductSocketsAttribute != null && Integer.valueOf(poolProductSocketsAttribute) < Integer.valueOf(clienttasks.sockets) && Integer.valueOf(poolProductSocketsAttribute) > 0) {
Assert.assertEquals(installedProduct.status, "Partially Subscribed", "After subscribing this physical system to a pool for ProductId '" + productId + "' (covers '" + poolProductSocketsAttribute + "' sockets), the status of Installed Product '" + bundledProductName + "' should be Partially Subscribed since a corresponding product cert was found in " + clienttasks.productCertDir + " and the machine's sockets value (" + clienttasks.sockets + ") is greater than what a single subscription from a non-multi-entitlement pool covers.");
} else if (pool.multiEntitlement != null && !pool.multiEntitlement && /*ADDED AFTER IMPLEMENTATION OF BUG 1008647*/
systemIsGuest && /*ADDED AFTER IMPLEMENTATION OF BUG 885785*/
poolProductVcpuAttribute != null && Integer.valueOf(poolProductVcpuAttribute) < Integer.valueOf(clienttasks.vcpu) && Integer.valueOf(poolProductVcpuAttribute) > 0) {
Assert.assertEquals(installedProduct.status, "Partially Subscribed", "After subscribing this virtual system to a pool for ProductId '" + productId + "' (covers '" + poolProductVcpuAttribute + "' vcpu), the status of Installed Product '" + bundledProductName + "' should be Partially Subscribed since a corresponding product cert was found in " + clienttasks.productCertDir + " and the machine's vcpu value (" + clienttasks.vcpu + ") is greater than what a single subscription from a non-multi-entitlement pool covers.");
} else if (pool.subscriptionType != null && (pool.subscriptionType.equals("Standard") || pool.subscriptionType.equals("Stackable only with other subscriptions")) && /*ADDED AFTER IMPLEMENTATION OF BUG 1008647 AND 1029968*/
systemIsGuest && /*ADDED AFTER IMPLEMENTATION OF BUG 885785*/
poolProductVcpuAttribute != null && Integer.valueOf(poolProductVcpuAttribute) < Integer.valueOf(clienttasks.vcpu) && Integer.valueOf(poolProductVcpuAttribute) > 0) {
Assert.assertEquals(installedProduct.status, "Partially Subscribed", "After subscribing this virtual system to a pool for ProductId '" + productId + "' (covers '" + poolProductVcpuAttribute + "' vcpu), the status of Installed Product '" + bundledProductName + "' should be Partially Subscribed since a corresponding product cert was found in " + clienttasks.productCertDir + " and the machine's vcpu value (" + clienttasks.vcpu + ") is greater than what a single subscription from a non-multi-entitlement pool covers.");
} else if (!poolProductArches.contains(clienttasks.arch)) {
log.warning("This case is indicative that a pool refresh may be needed for this owner.");
Assert.assertEquals(installedProduct.status, "Partially Subscribed", "After subscribing this system with arch '" + clienttasks.arch + "' to a pool for ProductId '" + productId + "' (that supports '" + poolProductArchAttribute + "' arch), the status of Installed Product '" + bundledProductName + "' should be Partially Subscribed with a reason stating that the system's arch is not supported by this subscription.");
// Example Status Details: Supports architecture x86_64,ppc64,ia64,ppc,x86,s390,s390x but the system is ppc64le.
String reason = String.format("Supports architecture %s but the system is %s.", poolProductArchAttribute, clienttasks.arch);
Assert.assertTrue(installedProduct.statusDetails.contains(reason), "Installed Product '" + installedProduct.productName + "' Status Details includes '" + reason + "'.");
} else {
Assert.assertEquals(installedProduct.status, "Subscribed", "After subscribing to a pool for ProductId '" + productId + "', the status of Installed Product '" + bundledProductName + "' is Subscribed since a corresponding product cert was found in " + clienttasks.productCertDir + " and the system's sockets/vcpu needs were met.");
}
// TEMPORARY WORKAROUND
/*boolean*/
invokeWorkaroundWhileBugIsOpen = true;
// Bug 1199443 - Wrong "End date" in installed list after attaching 24-hour subscription on a unmapped-guest
bugId = "1199443";
/*String*/
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 && isPoolRestrictedToUnmappedVirtualSystems) {
log.warning("Skipping the assertion of installed product start-end date range after subscribing to an unmapped_guests_only pool for ProductId '" + productId + "' while bug '" + bugId + "' is open.");
} else // Assert.assertEquals(InstalledProduct.formatDateString(installedProduct.startDate), ProductSubscription.formatDateString(productSubscription.startDate), "Installed Product '"+bundledProductName+"' starts on the same DAY as the consumed ProductSubscription: "+productSubscription);
if (installedProduct.status.equals("Subscribed")) {
// assert the valid date range on the installed product match the validity period of the product subscription
Assert.assertEquals(InstalledProduct.formatDateString(installedProduct.endDate), ProductSubscription.formatDateString(consumedProductSubscription.endDate), "Installed Product '" + bundledProductName + "' expires on the same DAY as the consumed ProductSubscription: " + consumedProductSubscription);
Assert.assertEquals(InstalledProduct.formatDateString(installedProduct.startDate), ProductSubscription.formatDateString(consumedProductSubscription.startDate), "Installed Product '" + bundledProductName + "' starts on the same DAY as the consumed ProductSubscription: " + consumedProductSubscription);
} else {
/* valid assertion before Bug 990639 - Update information displayed on My Installed Products tab when product is partially subscribed
// assert the date range on the installed product is None
Assert.assertNull(installedProduct.startDate, "Installed Product '"+bundledProductName+"' start date range should be None/null when today's status '"+installedProduct.status+"' is NOT fully Subscribed.");
Assert.assertNull(installedProduct.endDate, "Installed Product '"+bundledProductName+"' end date range should be None/null when today's status '"+installedProduct.status+"' is NOT fully Subscribed.");
*/
// assert the date range on the installed product is NOT None
Assert.assertNotNull(installedProduct.startDate, "Installed Product '" + bundledProductName + "' start date range should NOT be None/null even when today's status '" + installedProduct.status + "' is NOT fully Subscribed.");
Assert.assertNotNull(installedProduct.endDate, "Installed Product '" + bundledProductName + "' end date range should NOT be None/null even when today's status '" + installedProduct.status + "' is NOT fully Subscribed.");
}
}
if (productCerts.isEmpty()) {
Assert.assertNull(InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productName", bundledProductName, currentlyInstalledProducts), "There should NOT be an installed status report for '" + bundledProductName + "' since a corresponding product cert was not found in " + clienttasks.productCertDir);
}
}
}
// TODO I BELIEVE THIS FINAL BLOCK OF TESTING IS INACCURATE - jsefler 5/27/2012
// I THINK IT SHOULD BE CHECKING HARDWARE SOCKETS AND NOT INSTALLED SOFTWARE
/*
// check if this subscription matches the installed software and then test for availability
boolean subscriptionProductIdMatchesInstalledSoftware = false;
for (ContentNamespace contentNamespace : entitlementCert.contentNamespaces) {
if (clienttasks.areAllRequiredTagsInContentNamespaceProvidedByProductCerts(contentNamespace, currentlyInstalledProductCerts)) {
subscriptionProductIdMatchesInstalledSoftware=true; break;
}
}
clienttasks.unsubscribeFromSerialNumber(entitlementCert.serialNumber);
pool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", productId, clienttasks.getCurrentlyAvailableSubscriptionPools());
if (currentlyInstalledProductCerts.isEmpty()) {
log.info("A final assertion to verify that SubscriptionPool with ProductId '"+productId+"' is available based on matching installed software is not applicable when the list of installed software is empty.");
} else {
if (subscriptionProductIdMatchesInstalledSoftware) {
Assert.assertNotNull(pool, "Expected SubscriptionPool with ProductId '"+productId+"' matches the installed software and is available for subscribing when listing --available.");
} else {
Assert.assertNull(pool, "Expected SubscriptionPool with ProductId '"+productId+"' does NOT match the installed software and is only available for subscribing when listing --all --available.");
}
}
*/
}
use of rhsm.data.EntitlementCert 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.EntitlementCert in project rhsm-qe by RedHatQE.
the class UnsubscribeTests method testUnsubscribeAndAttemptToReuseTheRevokedEntitlementCert.
@// update=true, // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-47922", "RHEL7-97323" }, 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.NEGATIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier1")
@Test(description = "Unsubscribe from a valid entitlement and then maliciously attempt to reuse the revoked entitlement cert.", groups = { "Tier1Tests", "blockedByBug-584137", "blockedByBug-602852", "blockedByBug-672122", "blockedByBug-804227", "blockedByBug-871146", "blockedByBug-905546", "blockedByBug-962520", "blockedByBug-822402", "blockedByBug-986572", "blockedByBug-1000301", "blockedByBug-1026435" }, // dataProvider="getAvailableSubscriptionPoolsData", // very thorough, but takes too long to execute and rarely finds more bugs
dataProvider = "getRandomSubsetOfAvailableSubscriptionPoolsData", enabled = true)
@ImplementsNitrateTest(caseId = 41903)
public void testUnsubscribeAndAttemptToReuseTheRevokedEntitlementCert(SubscriptionPool subscriptionPool) throws JSONException, Exception {
client.runCommandAndWaitWithoutLogging("killall -9 yum");
// choose a quantity before subscribing to avoid Stdout: Quantity '1' is not a multiple of instance multiplier '2'
String quantity = null;
/*if (clienttasks.isPackageVersion("subscription-manager",">=","1.10.3-1"))*/
if (subscriptionPool.suggested != null) {
// when the Suggested quantity is 0, let's specify a quantity to avoid Stdout: Quantity '1' is not a multiple of instance multiplier '2'
if (subscriptionPool.suggested < 1)
quantity = CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, subscriptionPool.poolId, "instance_multiplier");
if (subscriptionPool.suggested > 1 && quantity == null)
quantity = subscriptionPool.suggested.toString();
}
// subscribe to a pool
File entitlementCertFile = clienttasks.subscribeToSubscriptionPool(subscriptionPool, quantity, /*sm_serverAdminUsername*/
sm_clientUsername, /*sm_serverAdminPassword*/
sm_clientPassword, sm_serverUrl);
EntitlementCert entitlementCert = clienttasks.getEntitlementCertFromEntitlementCertFile(entitlementCertFile);
List<EntitlementCert> entitlementCerts = new ArrayList<EntitlementCert>();
entitlementCerts.add(entitlementCert);
// assert all of the entitlement certs are reported in the "yum repolist all"
clienttasks.assertEntitlementCertsInYumRepolist(entitlementCerts, true);
// copy entitlement certificate from location /etc/pki/entitlement/product/ to /tmp
log.info("Now let's copy the valid entitlement cert to the side so we can maliciously try to reuse it after its serial has been unsubscribed.");
String randDir = "/tmp/sm-certForSubscriptionPool-" + subscriptionPool.poolId;
client.runCommandAndWait("rm -rf " + randDir + "; mkdir -p " + randDir);
client.runCommandAndWait("cp " + entitlementCertFile + " " + randDir + "; cp " + clienttasks.getEntitlementCertKeyFileCorrespondingToEntitlementCertFile(entitlementCertFile) + " " + randDir);
// unsubscribe from the pool (Note: should be the only one subscribed too
clienttasks.unsubscribeFromSerialNumber(clienttasks.getSerialNumberFromEntitlementCertFile(entitlementCertFile));
// assert all of the entitlement certs are no longer reported in the "yum repolist all"
clienttasks.assertEntitlementCertsInYumRepolist(entitlementCerts, false);
/* restarting rhsmcertd takes too long and can screw up the certCheckInterval
// restart the rhsm cert deamon
// Note: by passing assertCertificatesUpdate=null, we are assuming that the subsequent assertions will execute within 2 min before the next cert update and waitForRegexInRhsmcertdLog
int certFrequency = 2; clienttasks.restart_rhsmcertd(certFrequency, null, null);
*/
log.info("Assuming that the currently configured value of certCheckInterval='" + clienttasks.getConfParameter("certCheckInterval") + "' will not interfere with this test.");
// move the copied entitlement certificate from /tmp to location /etc/pki/entitlement/product
// Note: this is malicious activity (user is trying to continue using entitlement certs that have been unsubscribed)
client.runCommandAndWait("cp -f " + randDir + "/* " + clienttasks.entitlementCertDir);
// assert all of the entitlement certs are reported in the "yum repolist all" again
clienttasks.assertEntitlementCertsInYumRepolist(entitlementCerts, true);
// assert that the rhsmcertd will clean up the malicious activity
/* restarting rhsmcertd takes too long; instead we will call run_rhsmcertd_worker(false)
log.info("Now let's wait for \"Certificates updated\" by the rhsmcertd and assert that the deamon deletes the copied entitlement certificate since it was put on candlepins certificate revocation list during the unsubscribe.");
String marker = "Testing UnsubscribeAndAttemptToReuseTheRevokedEntitlementCert_Test..."; // https://tcms.engineering.redhat.com/case/41692/
RemoteFileTasks.runCommandAndAssert(client,"echo \""+marker+"\" >> "+clienttasks.rhsmcertdLogFile,Integer.valueOf(0));
clienttasks.waitForRegexInRhsmcertdLog("Certificates updated.", certFrequency); // https://bugzilla.redhat.com/show_bug.cgi?id=672122
sleep(10000); // plus a little padding for the client to do it's thing
*/
clienttasks.run_rhsmcertd_worker(false);
Assert.assertTrue(!RemoteFileTasks.testExists(client, entitlementCertFile.getPath()), "Entitlement certificate '" + entitlementCertFile + "' was deleted by the rhsm certificate deamon.");
clienttasks.assertEntitlementCertsInYumRepolist(entitlementCerts, false);
// cleanup
client.runCommandAndWait("rm -rf " + randDir);
}
use of rhsm.data.EntitlementCert in project rhsm-qe by RedHatQE.
the class UnsubscribeTests method testUnsubscribeFromPoolIdWhenNotRegistered.
@// update=true, // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-47923", "RHEL7-51407" }, 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.NEGATIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier1")
@Test(description = "Attempt to unsubscribe from a pool id when not registered", groups = { "Tier1Tests", "blockedByBug-1198178" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testUnsubscribeFromPoolIdWhenNotRegistered() {
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");
// first make sure we are subscribed to a pool
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.getCurrentlyAvailableSubscriptionPools();
// random available pool
SubscriptionPool pool = pools.get(randomGenerator.nextInt(pools.size()));
EntitlementCert entitlementCert = clienttasks.getEntitlementCertFromEntitlementCertFile(clienttasks.subscribeToSubscriptionPool(pool, /*sm_serverAdminUsername*/
sm_clientUsername, /*sm_serverAdminPassword*/
sm_clientPassword, sm_serverUrl));
// now remove the consumer cert to simulate an unregister
clienttasks.removeAllCerts(true, false, false);
SSHCommandResult identityResult = clienttasks.identity_(null, null, null, null, null, null, null, null);
if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.13.8-1")) {
// post commit 5697e3af094be921ade01e19e1dfe7b548fb7d5b bug 1119688
Assert.assertEquals(identityResult.getStderr().trim(), clienttasks.msg_ConsumerNotRegistered, "stderr");
} else {
Assert.assertEquals(identityResult.getStdout().trim(), clienttasks.msg_ConsumerNotRegistered, "stdout");
}
// now unsubscribe from the pool number (while not registered)
Assert.assertTrue(clienttasks.getCurrentlyConsumedProductSubscriptions().size() > 0, "We should be consuming an entitlement (even while not registered)");
SSHCommandResult result = clienttasks.unsubscribe_(null, null, pool.poolId, null, null, null, null);
if (servertasks.statusCapabilities.contains("remove_by_pool_id")) {
Integer expectedExitCode = new Integer(0);
Assert.assertEquals(result.getExitCode(), expectedExitCode, "Asserting exit code when attempting to unsubscribe from a valid pool (while not registered).");
Assert.assertEquals(result.getStdout().trim(), "Subscription with serial number " + entitlementCert.serialNumber + " removed from this system", "We should always be able to remove a subscription (even while not registered).");
Assert.assertEquals(clienttasks.getCurrentlyConsumedProductSubscriptions().size(), 0, "We should not be consuming any entitlements after unsubscribing (while not registered).");
} else {
// coverage for Bug 1285004 - subscription-manager remove --pool throws: Runtime Error Could not find resource for relative of full path
Integer expectedExitCode = new Integer(69);
Assert.assertEquals(result.getExitCode(), expectedExitCode, "Asserting exit code when attempting to unsubscribe from a valid pool (while not registered) (from an incapable candlepin 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");
}
Assert.assertTrue(clienttasks.getCurrentlyConsumedProductSubscriptions().size() > 0, "After attempts to remove by pool ID against an incapable candlepin should still be consuming an entitlement (even while not registered)");
throw new SkipException("The registered entitlement server does not support remove --pool");
}
}
use of rhsm.data.EntitlementCert 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