use of rhsm.data.InstalledProduct in project rhsm-qe by RedHatQE.
the class StorageBandTests method testAutoHealStorageBandSubscription.
/**
* @author skallesh
* @throws Exception
* @throws JSONException
*/
@// update=true, // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-21461", "RHEL7-51710" }, 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 = "Tier3")
@Test(description = "verify if you auto-heal a system using 300TB of storage, installed storage product is fully subscribed from multiple pools that provide 256TB of coverage.", groups = { "Tier3Tests", "AutoHealStorageBandSubscription" }, dataProvider = "getStorageBandSubscriptions", enabled = true)
public void testAutoHealStorageBandSubscription(Object Bugzilla, SubscriptionPool storagebandpool) throws JSONException, Exception {
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);
log.info("To auto-heal this system for '" + bandStorageUsage + "'TB of storage, there must be more than one stackable pool for product SKU '" + storagebandpool.productId + "'.");
// to troubleshoot the existance of multiple pools
SSHCommandResult listResult = clienttasks.list(null, true, null, null, null, null, null, null, storagebandpool.productId, null, null, null, null, null);
List<SubscriptionPool> availableStorageBandPools = SubscriptionPool.parse(listResult.getStdout());
String expectedStatus = availableStorageBandPools.size() > 1 ? "Subscribed" : "Not Subscribed";
clienttasks.autoheal(null, true, null, null, null, null, null);
clienttasks.run_rhsmcertd_worker(true);
List<String> providedProductIds = CandlepinTasks.getPoolProvidedProductIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, storagebandpool.poolId);
List<InstalledProduct> installedProducts = clienttasks.getCurrentlyInstalledProducts();
for (String providedProductId : providedProductIds) {
InstalledProduct installedProduct = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productId", providedProductId, installedProducts);
if (installedProduct != null) {
Assert.assertEquals(installedProduct.status.trim(), expectedStatus, "Status of installed product '" + installedProduct.productName + "' provided for by Storage Band entitlement pools that covers only 256TB on a system using '" + bandStorageUsage + "'TBs (that has been autohealed with '" + availableStorageBandPools.size() + "' available '" + storagebandpool.productId + "' pools)");
}
}
}
use of rhsm.data.InstalledProduct in project rhsm-qe by RedHatQE.
the class StorageBandTests method testPartiallySubscribedStorageBandSubscription.
/**
* @author skallesh
* @throws Exception
* @throws JSONException
*/
@// update=true, // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-21462", "RHEL7-51711" }, 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 = "Tier3")
@Test(description = "verify that attaching a quantity of 1 entitlement from a pool capable of covering 256TB on a system with 300TB of usage, installed product will be partially subscribed", groups = { "Tier3Tests", "PartiallySubscribeStorageBandSubscription" }, dataProvider = "getStorageBandSubscriptions", enabled = true)
public void testPartiallySubscribedStorageBandSubscription(Object Bugzilla, SubscriptionPool storagebandpool) throws JSONException, Exception {
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.subscribe(null, null, storagebandpool.poolId, null, null, "1", null, null, null, null, null, null, null);
List<String> providedProductIds = CandlepinTasks.getPoolProvidedProductIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, storagebandpool.poolId);
List<InstalledProduct> installedProducts = clienttasks.getCurrentlyInstalledProducts();
for (String providedProductId : providedProductIds) {
InstalledProduct installedProduct = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productId", providedProductId, installedProducts);
if (installedProduct != null) {
Assert.assertEquals(installedProduct.status.trim(), "Partially Subscribed", "Status of installed product '" + installedProduct.productName + "' provided for by Storage Band entitlement pools that covers only 256TB on a system using '" + bandStorageUsage + "'TBs (that has been subscribed to pool SKU '" + storagebandpool.productId + "' '" + storagebandpool.subscriptionName + "' with quantity 1)");
String expectedReason = String.format("Only supports %dTB of %dTB of storage.", 1, bandStorageUsage);
Assert.assertTrue(installedProduct.statusDetails.contains(expectedReason), "Status Details includes expected reason '" + expectedReason + "'.");
}
}
}
use of rhsm.data.InstalledProduct in project rhsm-qe by RedHatQE.
the class SubscribeTests method testSubscribeWithAutoMoreThanOnce.
@// update=true, // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36580", "RHEL7-51382" }, 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 consumer more than once and verify we are not duplicately subscribed", groups = { "Tier2Tests", "blockedByBug-723044", "blockedByBug-743082", "blockedByBug-977321" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testSubscribeWithAutoMoreThanOnce() throws Exception {
// before testing, make sure all the expected subscriptionPoolProductId are available
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);
// TEMPORARY WORKAROUND
if (Boolean.valueOf(clienttasks.getFactValue("virt.is_guest"))) {
boolean invokeWorkaroundWhileBugIsOpen = true;
// Bug 1198494 - Auto-heal continuously attaches subscriptions to make the system compliant on a guest machine
String bugId = "1198494";
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) {
clienttasks.mapSystemAsAGuestOfItself();
}
}
// END OF WORKAROUND
// autosubscribe once
SSHCommandResult result1 = clienttasks.subscribe(Boolean.TRUE, null, (String) null, null, null, null, null, null, null, null, null, null, null);
List<File> entitlementCertFiles1 = clienttasks.getCurrentEntitlementCertFiles();
List<InstalledProduct> autosubscribedProductStatusList1 = InstalledProduct.parse(result1.getStdout());
// autosubscribe twice
SSHCommandResult result2 = clienttasks.subscribe(Boolean.TRUE, null, (String) null, null, null, null, null, null, null, null, null, null, null);
List<File> entitlementCertFiles2 = clienttasks.getCurrentEntitlementCertFiles();
List<InstalledProduct> autosubscribedProductStatusList2 = InstalledProduct.parse(result2.getStdout());
// assert results
Assert.assertEquals(entitlementCertFiles2.size(), entitlementCertFiles1.size(), "The number of granted entitlement certs is the same after a second autosubscribe.");
Assert.assertEquals(autosubscribedProductStatusList2.size(), autosubscribedProductStatusList1.size(), "The stdout from autosubscribe reports the same number of installed product status entries after a second autosubscribe.");
Assert.assertTrue(autosubscribedProductStatusList1.containsAll(autosubscribedProductStatusList2), "The list of installed product status entries from a second autosubscribe is the same as the first.");
}
use of rhsm.data.InstalledProduct in project rhsm-qe by RedHatQE.
the class ActivationKeyTests method assertProvidedProductsFromPoolAreWithinConsumedProductSubscriptionsUsingQuantity.
protected void assertProvidedProductsFromPoolAreWithinConsumedProductSubscriptionsUsingQuantity(JSONObject jsonPool, List<ProductSubscription> consumedProductSubscriptions, Integer addQuantity, boolean assertConsumptionIsLimitedToThisPoolOnly) throws Exception {
// assert that only the pool's providedProducts (excluding type=MKT products) are consumed (unless it is a ManagementAddOn product - indicated by no providedProducts)
JSONArray jsonProvidedProducts = jsonPool.getJSONArray("providedProducts");
// pluck out (remove) the providedProducts that have an attribute type=MKT products
for (int j = 0; j < jsonProvidedProducts.length(); j++) {
JSONObject jsonProvidedProduct = (JSONObject) jsonProvidedProducts.get(j);
String resourcePath = "/products/" + jsonProvidedProduct.getString("productId");
// starting with candlepin-2.0.11 /products/<ID> are requested by /owners/<KEY>/products/<ID> OR /products/<UUID>
if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.0.11"))
resourcePath = jsonPool.getJSONObject("owner").getString("href") + resourcePath;
JSONObject jsonProduct = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, resourcePath));
JSONArray jsonAttributes = jsonProduct.getJSONArray("attributes");
for (int k = 0; k < jsonAttributes.length(); k++) {
JSONObject jsonAttribute = (JSONObject) jsonAttributes.get(k);
if (jsonAttribute.getString("name").equals("type")) {
if (jsonAttribute.getString("value").equals("MKT")) {
log.warning("Found a providedProduct '" + jsonProvidedProduct.getString("productName") + "' from the pool added to the activation key that is actually a Marketing product (attribute type=\"MKT\"). Therefore this provided product will be excluded from the expected consumed ProductSubscriptions assertions that will follow...");
jsonProvidedProduct = /*Plucked*/
(JSONObject) jsonProvidedProducts.remove(j--);
break;
}
}
}
}
// translate the names of the jsonProvidedProducts into a list of string
List<String> providedProductNamesFromActivationKeyPool = new ArrayList<String>();
List<String> providedProductIdsFromActivationKeyPool = new ArrayList<String>();
for (int j = 0; j < jsonProvidedProducts.length(); j++) {
JSONObject jsonProvidedProduct = (JSONObject) jsonProvidedProducts.get(j);
providedProductNamesFromActivationKeyPool.add(jsonProvidedProduct.getString("productName"));
providedProductIdsFromActivationKeyPool.add(jsonProvidedProduct.getString("productId"));
}
if (assertConsumptionIsLimitedToThisPoolOnly) {
Assert.assertEquals(consumedProductSubscriptions.size(), 1, "Expecting only one consumed product subscription.");
ProductSubscription consumedProductSubscription = consumedProductSubscriptions.get(0);
if (jsonPool.has("accountNumber")) {
Assert.assertEquals(consumedProductSubscription.accountNumber.longValue(), jsonPool.getLong("accountNumber"), "The consumed product subscription comes from the same accountNumber as the pool added in the activation key.");
} else {
Assert.assertNull(consumedProductSubscription.accountNumber, "The consumed product subscription has no accountNumber since the pool added in the activation key had no accountNumber.");
}
if (jsonPool.has("contractNumber")) {
Assert.assertEquals(consumedProductSubscription.contractNumber.intValue(), jsonPool.getInt("contractNumber"), "The consumed product subscription comes from the same contractNumber as the pool added in the activation key.");
} else {
Assert.assertNull(consumedProductSubscription.contractNumber, "The consumed product subscription has no contractNumber since the pool added in the activation key had no contractNumber.");
}
if (addQuantity != null) {
Assert.assertEquals(consumedProductSubscription.quantityUsed, addQuantity, "The consumed product subscription is using the same quantity as requested by the pool added in the activation key.");
} else {
// valid after Bug 1023568 - [RFE] bind requests using activation keys that do not specify a quantity should automatically use the quantity needed to achieve compliance
Assert.assertTrue(consumedProductSubscription.quantityUsed >= 1, "The actual consumed product subscription quantity of '" + consumedProductSubscription.quantityUsed + "' is >= 1 to achieve compliance since the quantity requested by the pool added in the activation key was null (result of RFE bugzilla 1023568).");
// if this subscription was stackable, then assert that all of the installed products provided by this subscription are fully subscribed
if (consumedProductSubscription.subscriptionType.equals("Stackable")) {
for (InstalledProduct installedProduct : clienttasks.getCurrentlyInstalledProducts()) {
if (providedProductIdsFromActivationKeyPool.contains(installedProduct.productId)) {
// arch can be defined as a comma seperated string
Set<String> installedProductArches = new HashSet<String>(Arrays.asList(installedProduct.arch.split("\\s*,\\s*")));
if (installedProductArches.contains("x86")) {
installedProductArches.add("i386");
installedProductArches.add("i486");
installedProductArches.add("i586");
installedProductArches.add("i686");
}
if (installedProductArches.contains(clienttasks.arch) || installedProductArches.contains("ALL")) {
Assert.assertEquals(installedProduct.status, "Subscribed", "Installed Product '" + installedProduct.productName + "' provided by pool '" + consumedProductSubscription.productName + "' attached from a Smart ActivationKey (quantity='" + addQuantity + /*null*/
"') should be fully compliant.");
Assert.assertTrue(installedProduct.statusDetails.isEmpty(), "When Installed Product '" + installedProduct.productName + "' provided by pool '" + consumedProductSubscription.productName + "' attached from a Smart ActivationKey (quantity='" + addQuantity + /*null*/
"') is Subscribed, then it's Status Details should be empty.");
} else {
Assert.assertEquals(installedProduct.status, "Partially Subscribed", "When Installed Product '" + installedProduct.productName + "' provided by pool '" + consumedProductSubscription.productName + "' attached from a Smart ActivationKey (quantity='" + addQuantity + /*null*/
"') mismatches the system architecture, then it should be partially compliant.");
Assert.assertEquals(installedProduct.statusDetails.get(0), /*assumes only one detail*/
String.format("Supports architecture %s but the system is %s.", installedProduct.arch, clienttasks.arch), "When Installed Product '" + installedProduct.productName + "' provided by pool '" + consumedProductSubscription.productName + "' attached from a Smart ActivationKey (quantity='" + addQuantity + /*null*/
"') mismatches the system architecture, then the Status Details should state this.");
}
}
}
}
}
Assert.assertTrue(consumedProductSubscription.provides.containsAll(providedProductNamesFromActivationKeyPool) && providedProductNamesFromActivationKeyPool.containsAll(consumedProductSubscription.provides), "The consumed product subscription provides all the expected products " + providedProductNamesFromActivationKeyPool + " from the provided products of the pool added in the activation key.");
} else {
// after implementation of bug 908671, these three lines are replaced more efficiently by two lines
// List<ProductSubscription> subsetOfConsumedProductSubscriptions = ProductSubscription.findAllInstancesWithMatchingFieldFromList("accountNumber", new BigInteger(jsonPool.getString("accountNumber")), consumedProductSubscriptions);
// ProductSubscription consumedProductSubscription = ProductSubscription.findFirstInstanceWithMatchingFieldFromList("contractNumber", new Integer(jsonPool.getString("contractNumber")), subsetOfConsumedProductSubscriptions);
// Assert.assertNotNull(consumedProductSubscription,"Found a consumed product subscription whose account number '"+jsonPool.getLong("accountNumber")+"' AND contract number '"+jsonPool.getInt("contractNumber")+"' match the pool added to the activation key.");
ProductSubscription consumedProductSubscription = ProductSubscription.findFirstInstanceWithMatchingFieldFromList("poolId", jsonPool.getString("id"), consumedProductSubscriptions);
Assert.assertNotNull(consumedProductSubscription, "Found a consumed product subscription that came from pool id '" + jsonPool.getString("id") + "' that was added to the activation key.");
Assert.assertTrue(consumedProductSubscription.provides.containsAll(providedProductNamesFromActivationKeyPool) && providedProductNamesFromActivationKeyPool.containsAll(consumedProductSubscription.provides), "The consumed product subscription provides all the expected products " + providedProductNamesFromActivationKeyPool + " from the provided products of the pool added in the activation key.");
}
}
use of rhsm.data.InstalledProduct in project rhsm-qe by RedHatQE.
the class BugzillaTests method testStartEndDateOfSubscription.
/**
* @author skallesh
* @throws Exception
* @throws JSONException
*/
@// update=true, // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-21970", "RHEL7-51832" }, 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 = "Tier3")
@Test(description = "verify End date and start date of the subscription is appropriate one when you attach a future subscription and then heal after 1 min", groups = { "Tier3Tests", "VerifyStartEndDateOfSubscription", "blockedByBug-994853", "blockedByBug-1440934" }, enabled = true)
public void testStartEndDateOfSubscription() throws Exception {
clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, true, null, null, (String) null, null, null, null, true, null, null, null, null, null);
Map<String, String> factsMap = new HashMap<String, String>();
factsMap.put("cpu.cpu_socket(s)", String.valueOf(4));
clienttasks.createFactsFileWithOverridingValues(factsMap);
// [jsefler] I believe
clienttasks.facts(null, true, null, null, null, null);
// facts --update
// should be called
// after overriding
// facts
clienttasks.autoheal(null, null, true, null, null, null, null);
for (SubscriptionPool AvailablePools : clienttasks.getCurrentlyAvailableSubscriptionPools()) {
if (AvailablePools.productId.equals("awesomeos-x86_64")) {
clienttasks.subscribe(null, null, AvailablePools.poolId, null, null, "1", null, null, null, null, null, null, null);
}
}
InstalledProduct installedProduct = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productId", "100000000000002", clienttasks.getCurrentlyInstalledProducts());
for (ProductSubscription consumedProductSubscription : clienttasks.getCurrentlyConsumedProductSubscriptions()) {
if (consumedProductSubscription.provides.contains(installedProduct.productName)) {
Assert.assertTrue(!installedProduct.startDate.after(consumedProductSubscription.startDate), "Comparing Start Date '" + InstalledProduct.formatDateString(installedProduct.startDate) + "' of Installed Product '" + installedProduct.productName + "' to Start Date '" + InstalledProduct.formatDateString(consumedProductSubscription.startDate) + "' of Consumed Subscription '" + consumedProductSubscription.productName + "'. (Installed Product startDate should be <= Consumed Subscription startDate)");
}
}
clienttasks.autoheal(null, true, null, null, null, null, null);
clienttasks.restart_rhsmcertd(null, null, true);
InstalledProduct installedProductAfterRHSM = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productId", "100000000000002", clienttasks.getCurrentlyInstalledProducts());
for (ProductSubscription consumedProductSubscription : clienttasks.getCurrentlyConsumedProductSubscriptions()) {
if (consumedProductSubscription.provides.contains(installedProductAfterRHSM.productName)) {
Assert.assertTrue(!installedProductAfterRHSM.startDate.after(consumedProductSubscription.startDate), "Comparing Start Date '" + InstalledProduct.formatDateString(installedProductAfterRHSM.startDate) + "' of Installed Product '" + installedProductAfterRHSM.productName + "' to Start Date '" + InstalledProduct.formatDateString(consumedProductSubscription.startDate) + "' of Consumed Subscription '" + consumedProductSubscription.productName + "'. (Installed Product startDate should be <= Consumed Subscription startDate)");
if (!consumedProductSubscription.isActive) {
Assert.assertEquals(installedProductAfterRHSM.endDate, consumedProductSubscription.endDate);
}
}
}
}
Aggregations