use of rhsm.data.InstalledProduct in project rhsm-qe by RedHatQE.
the class ComplianceTests method testSystemCompliantFactWhenNoProductsAreSubscribable.
@// update=true, // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-21720", "RHEL7-51085" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier1")
@Test(description = "subscription-manager: verify the system.compliant fact is False when no installed products are subscribable", groups = { "Tier1Tests", "configureProductCertDirForNoProductsSubscribable", "cli.tests", "blockedbyBug-1183175" }, priority = 500, enabled = true)
public // @ImplementsTCMS(id="")
void testSystemCompliantFactWhenNoProductsAreSubscribable() throws JSONException, Exception {
clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, Boolean.TRUE, false, null, null, null, null);
// to avoid unmapped_guests_only pools
if (Boolean.valueOf(clienttasks.getFactValue("virt.is_guest")))
clienttasks.mapSystemAsAGuestOfItself();
Assert.assertFalse(clienttasks.getCurrentlyInstalledProducts().isEmpty(), "Products are currently installed for which the compliance of NONE are covered by currently available subscription pools.");
Assert.assertEquals(clienttasks.getFactValue(factNameForSystemCompliance), factValueForSystemNonCompliance, "Before attempting to subscribe and become compliant for all the currently installed products, the system should be non-compliant (see value for fact '" + factNameForSystemCompliance + "').");
clienttasks.subscribeToTheCurrentlyAvailableSubscriptionPoolsCollectively();
for (InstalledProduct installedProduct : clienttasks.getCurrentlyInstalledProducts()) {
Assert.assertEquals(installedProduct.status, "Not Subscribed", "When config rhsm.productcertdir is populated with product certs for which NONE are covered by the currently available subscriptions, then each installed product status should be Not Subscribed.");
}
Assert.assertEquals(clienttasks.getFactValue(factNameForSystemCompliance), factValueForSystemNonCompliance, "When a system has products installed for which NONE are covered by available subscription pools, the system should NOT become compliant (see value for fact '" + factNameForSystemCompliance + "') after having subscribed to every available subscription pool.");
if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.13.10-1")) {
// commit 13fe8ffd8f876d27079b961fb6675424e65b9a10 Bug 1171602 - subscription-manager status always exits 1
Assert.assertEquals(clienttasks.status_(null, null, null, null, null).getExitCode(), new Integer(1), "Expected exitCode from a call to status when the system is '" + factValueForSystemNonCompliance + "'.");
}
}
use of rhsm.data.InstalledProduct in project rhsm-qe by RedHatQE.
the class ComplianceTests method setupProductCertDirsBeforeClass.
@BeforeClass(groups = { "setup" }, dependsOnMethods = { "moveOriginalProductCertDefaultDirFilesBeforeClass" })
public void setupProductCertDirsBeforeClass() throws JSONException, Exception {
// clean out the productCertDirs
for (String productCertDir : new String[] { productCertDirForSomeProductsSubscribable, productCertDirForAllProductsSubscribable, productCertDirForNoProductsSubscribable, productCertDirForNoProductsinstalled, productCertDirForAllProductsSubscribableInTheFuture, productCertDirForAllProductsSubscribableByOneCommonServiceLevel, productCertDirForAllProductsSubscribableByMoreThanOneCommonServiceLevel }) {
RemoteFileTasks.runCommandAndAssert(client, "rm -rf " + productCertDir, 0);
RemoteFileTasks.runCommandAndAssert(client, "mkdir " + productCertDir, 0);
}
// register and subscribe to all available subscriptions
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);
// to avoid unmapped_guests_only pools
if (Boolean.valueOf(clienttasks.getFactValue("virt.is_guest")))
clienttasks.mapSystemAsAGuestOfItself();
clienttasks.subscribeToTheCurrentlyAvailableSubscriptionPoolsCollectively();
// get the current certs
List<EntitlementCert> currentEntitlementCerts = clienttasks.getCurrentEntitlementCerts();
List<ProductCert> currentProductCerts = clienttasks.getCurrentProductCerts();
List<InstalledProduct> installedProducts = clienttasks.getCurrentlyInstalledProducts();
// distribute a copy of the product certs amongst the productCertDirs based on their status
for (ProductCert productCert : currentProductCerts) {
InstalledProduct installedProduct = clienttasks.getInstalledProductCorrespondingToProductCert(productCert, installedProducts);
if (installedProduct.status.equals("Not Subscribed")) {
// "Not Subscribed" case...
RemoteFileTasks.runCommandAndAssert(client, "cp " + productCert.file + " " + productCertDirForNoProductsSubscribable, 0);
RemoteFileTasks.runCommandAndAssert(client, "cp " + productCert.file + " " + productCertDirForSomeProductsSubscribable, 0);
} else if (installedProduct.status.equals("Subscribed")) {
// "Subscribed" case...
RemoteFileTasks.runCommandAndAssert(client, "cp " + productCert.file + " " + productCertDirForAllProductsSubscribable, 0);
RemoteFileTasks.runCommandAndAssert(client, "cp " + productCert.file + " " + productCertDirForSomeProductsSubscribable, 0);
} else {
// TODO "Partially Subscribed" case
// InstalledProduct installedProduct = clienttasks.getInstalledProductCorrespondingToEntitlementCert(correspondingEntitlementCert);
}
}
// setup for productCertDirForAllProductsSubscribableInTheFuture
// clienttasks.unsubscribeFromAllOfTheCurrentlyConsumedProductSubscriptions();
List<File> productCertFilesCopied = new ArrayList<File>();
futureSystemSubscriptionPools = new ArrayList<SubscriptionPool>();
for (List<Object> futureSystemSubscriptionPoolsDataRow : getAllFutureSystemSubscriptionPoolsDataAsListOfLists()) {
SubscriptionPool futureSystemSubscriptionPool = (SubscriptionPool) futureSystemSubscriptionPoolsDataRow.get(0);
// for (ProductCert productCert : clienttasks.getCurrentProductCertsProvidedBySubscriptionPool(futureSystemSubscriptionPool)) { // TODO not efficient; testing fix on next line
for (ProductCert productCert : clienttasks.getProductCertsProvidedBySubscriptionPool(currentProductCerts, futureSystemSubscriptionPool)) {
if (!productCertFilesCopied.contains(productCert.file)) {
// RemoteFileTasks.runCommandAndAssert(client, "cp -n "+productCert.file+" "+productCertDirForAllProductsSubscribableInTheFuture, 0); // RHEL5 does not understand cp -n
// no clobber copy for both RHEL5 ad RHEL6
RemoteFileTasks.runCommandAndAssert(client, "if [ ! -e " + productCertDirForAllProductsSubscribableInTheFuture + File.separator + productCert.file.getName() + " ]; then cp " + productCert.file + " " + productCertDirForAllProductsSubscribableInTheFuture + "; fi;", 0);
productCertFilesCopied.add(productCert.file);
if (!futureSystemSubscriptionPools.contains(futureSystemSubscriptionPool)) {
futureSystemSubscriptionPools.add(futureSystemSubscriptionPool);
}
}
}
}
// determine the serviceLevel and all the products that are subscribable by one common service level
// Map<String,Set<String>> serviceLevelToProductIdsMap = getServiceLevelToProductIdsMapFromEntitlementCerts(clienttasks.getCurrentEntitlementCerts()); // TODO not efficient; testing fix on next line
Map<String, Set<String>> serviceLevelToProductIdsMap = getServiceLevelToProductIdsMapFromEntitlementCerts(currentEntitlementCerts);
// /*debugTesting*/ serviceLevelToProductIdsMap.get("Premium").add("17000");
Map<String, Set<String>> productIdsToServiceLevelsMap = getInvertedMap(serviceLevelToProductIdsMap);
Set<String> allProductsSubscribableByOneCommonServiceLevelCandidates = productIdsToServiceLevelsMap.keySet();
boolean allProductsSubscribableByOneCommonServiceLevelDeterminable = true;
OUT: do {
String serviceLevelCandidate = getKeyToLongestMap(serviceLevelToProductIdsMap);
Assert.assertNotNull(serviceLevelCandidate, "If the key to the longest map of serviceLevel to ProductIds is null, then there are probably no subscriptions available.");
// does this candidate have all candidate products?
if (serviceLevelToProductIdsMap.get(serviceLevelCandidate).containsAll(allProductsSubscribableByOneCommonServiceLevelCandidates)) {
// is there another serviceLevel that has all candidate products?
for (String serviceLevel : serviceLevelToProductIdsMap.keySet()) {
if (serviceLevel.equals(serviceLevelCandidate))
continue;
if (serviceLevelToProductIdsMap.get(serviceLevel).size() == serviceLevelToProductIdsMap.get(serviceLevelCandidate).size()) {
allProductsSubscribableByOneCommonServiceLevelDeterminable = false;
break OUT;
}
}
allProductsSubscribableByOneCommonServiceLevelValue = serviceLevelCandidate;
} else {
// pluck the first candidate product that is not in the serviceLevelCandidate map of products
for (String productId : (String[]) allProductsSubscribableByOneCommonServiceLevelCandidates.toArray(new String[] {})) {
if (!serviceLevelToProductIdsMap.get(serviceLevelCandidate).contains(productId)) {
allProductsSubscribableByOneCommonServiceLevelCandidates.remove(productId);
for (String serviceLevel : serviceLevelToProductIdsMap.keySet()) {
serviceLevelToProductIdsMap.get(serviceLevel).remove(productId);
}
break;
}
}
}
} while (allProductsSubscribableByOneCommonServiceLevelValue == null && allProductsSubscribableByOneCommonServiceLevelDeterminable);
// copy the products to productCertDirForAllProductsSubscribableByOneCommonServiceLevel
if (allProductsSubscribableByOneCommonServiceLevelDeterminable) {
// for (ProductCert productCert : clienttasks.getCurrentProductCerts()) { // TODO not efficient; testing fix on next line
for (ProductCert productCert : currentProductCerts) {
if (allProductsSubscribableByOneCommonServiceLevelCandidates.contains(productCert.productId)) {
RemoteFileTasks.runCommandAndAssert(client, "cp " + productCert.file + " " + productCertDirForAllProductsSubscribableByOneCommonServiceLevel, 0);
}
}
} else {
log.warning("Cannot determine a set of products where allProductsSubscribableByOneCommonServiceLevel.");
}
// determine the serviceLevels and all the products that are subscribable by more than one common service level
// serviceLevelToProductIdsMap = getServiceLevelToProductIdsMapFromEntitlementCerts(clienttasks.getCurrentEntitlementCerts()); // TODO not efficient; testing fix on next line
serviceLevelToProductIdsMap = getServiceLevelToProductIdsMapFromEntitlementCerts(currentEntitlementCerts);
productIdsToServiceLevelsMap = getInvertedMap(serviceLevelToProductIdsMap);
List<String> allProductsSubscribableByMoreThanOneCommonServiceLevelCandidates = new ArrayList<String>();
for (String productId : productIdsToServiceLevelsMap.keySet()) {
if (productIdsToServiceLevelsMap.get(productId).size() > 1)
allProductsSubscribableByMoreThanOneCommonServiceLevelCandidates.add(productId);
}
if (!allProductsSubscribableByMoreThanOneCommonServiceLevelCandidates.isEmpty()) {
// randomly choose the service levels from the candidates
// allProductsSubscribableByMoreThanOneCommonServiceLevelValues = Arrays.asList(productIdsToServiceLevelsMap.get(allProductsSubscribableByMoreThanOneCommonServiceLevelCandidates.get(randomGenerator.nextInt(allProductsSubscribableByMoreThanOneCommonServiceLevelCandidates.size()))).toArray(new String[]{}));
allProductsSubscribableByMoreThanOneCommonServiceLevelValues.addAll(productIdsToServiceLevelsMap.get(allProductsSubscribableByMoreThanOneCommonServiceLevelCandidates.get(randomGenerator.nextInt(allProductsSubscribableByMoreThanOneCommonServiceLevelCandidates.size()))));
// pluck out the productIds that do not map to all of the values in allProductsSubscribableByMoreThanOneCommonServiceLevelValues
for (String productId : productIdsToServiceLevelsMap.keySet()) {
if (!productIdsToServiceLevelsMap.get(productId).containsAll(allProductsSubscribableByMoreThanOneCommonServiceLevelValues)) {
allProductsSubscribableByMoreThanOneCommonServiceLevelCandidates.remove(productId);
}
}
// for (ProductCert productCert : clienttasks.getCurrentProductCerts()) { // TODO not efficient; testing fix on next line
for (ProductCert productCert : currentProductCerts) {
if (allProductsSubscribableByMoreThanOneCommonServiceLevelCandidates.contains(productCert.productId)) {
RemoteFileTasks.runCommandAndAssert(client, "cp " + productCert.file + " " + productCertDirForAllProductsSubscribableByMoreThanOneCommonServiceLevel, 0);
}
}
} else {
log.warning("Cannot determine a set of products where allProductsSubscribableByMoreThanOneCommonServiceLevel.");
}
// remember the originally configured productCertDir
this.originalProductCertDir = clienttasks.productCertDir;
}
use of rhsm.data.InstalledProduct in project rhsm-qe by RedHatQE.
the class PluginTests method testPluginsListWithEnabledProductIdRemoveTestPlugin.
// TODO ProductIdRemoveTestPlugin Tests ***************************************************
// CURRENTLY BLOCKED BY BUGZILLA 922882
@// update=true // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL7-55178" }, 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 = "enable ProductIdRemoveTestPlugin and assert the plugins list reports enablement", groups = { "Tier1Tests", "blockedByBug-922882" }, priority = 710, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testPluginsListWithEnabledProductIdRemoveTestPlugin() {
// Red Hat Enterprise Linux High Availability (for RHEL Server)
String haProductId = "83";
// Red Hat Enterprise Linux High Availability (for IBM z Systems)
if (clienttasks.arch.startsWith("s390"))
haProductId = "300";
// TEMPORARY WORKAROUND FOR BUG
String bugId = "922882";
boolean invokeWorkaroundWhileBugIsOpen = true;
// RFE Bug 922882 was CLOSED NOTABUG and will be re-opened when actually needed. However, we still need to invoke this workaround to remove the ccs package from the prior test
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) {
// remove the HA package that was installed by prior test verifyEnabledProductIdInstallTestPluginHooksAreCalled_Test
List<String> haPackages = HighAvailabilityTests.getHighAvailabilityPackages(clienttasks.redhatReleaseXY, clienttasks.arch);
if (!haPackages.isEmpty() && clienttasks.isPackageInstalled(haPackages.get(0))) {
// yum -y remove ccs
clienttasks.yumRemovePackage(haPackages.get(0));
}
// remove the HA product cert too
InstalledProduct haInstalledProduct = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productId", haProductId, clienttasks.getCurrentlyInstalledProducts());
if (haInstalledProduct != null) {
ProductCert haInstalledProductCert = ProductCert.findFirstInstanceWithMatchingFieldFromList("productId", haProductId, clienttasks.getCurrentProductCerts());
log.warning("Manually removing installed High Availability product cert and restoring '" + clienttasks.productIdJsonFile + "' (you are probably running a RHEL5 client)...");
client.runCommandAndWait("rm -f " + haInstalledProductCert.file.getPath());
restoreProductIdJsonFileAfterClass();
haInstalledProduct = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productId", haProductId, clienttasks.getCurrentlyInstalledProducts());
}
Assert.assertNull(haInstalledProduct, "The High Availability product id '" + haProductId + "' should NOT be installed after successful removal of all High Availability packages.");
throw new SkipException("Skipping test while bug '" + bugId + "' is not implemented.");
}
// END OF WORKAROUND
Assert.fail("This test will be implemented after RFE bug 922882 is implemented.");
}
use of rhsm.data.InstalledProduct in project rhsm-qe by RedHatQE.
the class ListTests method assertActualResultOfListInstalledWithMatches.
protected void assertActualResultOfListInstalledWithMatches(String matchesString, List<InstalledProduct> actualInstalledProductMatches, List<InstalledProduct> installedProducts) throws JSONException, Exception {
// translate matchesString into a regexString
// escape parentheses
String regexString = matchesString.toLowerCase().replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)");
// splat wildcards match any zero or more chars
regexString = regexString.replaceAll("\\*", ".*");
// question mark wildcards match any one char
regexString = regexString.replaceAll("\\?", ".");
// search through the available availableSubscriptionPools for expected matches on the matchesString
// NOTE: exact matches means no wildcards and is case insensitive
List<InstalledProduct> expectedInstalledProductMatches = new ArrayList<InstalledProduct>();
for (InstalledProduct installedProduct : installedProducts) {
// Test for match on Product Name:
if (installedProduct.productName.toLowerCase().matches(regexString)) {
log.info("Found a hit on matches '" + matchesString + "' against the installed product '" + installedProduct.productName + "' Product Name: " + installedProduct.productName);
if (!expectedInstalledProductMatches.contains(installedProduct))
expectedInstalledProductMatches.add(installedProduct);
}
// Test for match on Product ID:
if (installedProduct.productId.toLowerCase().matches(regexString)) {
log.info("Found a hit on matches '" + matchesString + "' against the installed product '" + installedProduct.productName + "' Product ID: " + installedProduct.productId);
if (!expectedInstalledProductMatches.contains(installedProduct))
expectedInstalledProductMatches.add(installedProduct);
}
// TODO May want to open an RFE to also search on these other installed product fields
// See https://bugzilla.redhat.com/show_bug.cgi?id=1146125#c7
// Version: 7.0
// Arch: x86_64
// Status: Not Subscribed
// Status Details: Not supported by a valid subscription.
// Starts:
// Ends:
}
// assert that all of the expectedProductSubscriptionMatches is identical to the actualProductSubscriptionMatches
Assert.assertTrue(expectedInstalledProductMatches.containsAll(actualInstalledProductMatches) && actualInstalledProductMatches.containsAll(expectedInstalledProductMatches), "All of the expected installed products with an exact match (ignoring case) on '" + matchesString + "' were returned with the list --installed --matches option.");
}
use of rhsm.data.InstalledProduct in project rhsm-qe by RedHatQE.
the class ListTests method testInstalledProductsListed.
@// update=true // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-37700", "RHEL7-51326" }, 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-cli: list installed products", groups = { "Tier2Tests" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testInstalledProductsListed() {
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);
List<ProductCert> productCerts = clienttasks.getCurrentProductCerts();
Set<String> productCertIds = clienttasks.getCurrentProductIds();
String installedProductsAsString = clienttasks.listInstalledProducts().getStdout();
// List <InstalledProduct> installedProducts = clienttasks.getCurrentlyInstalledProducts();
List<InstalledProduct> installedProducts = InstalledProduct.parse(installedProductsAsString);
// assert some stdout
if (installedProducts.size() > 0) {
String bannerTitle = "Installed Product Status";
Assert.assertTrue(installedProductsAsString.contains(bannerTitle), "The list of installed products is entitled '" + bannerTitle + "'.");
}
// assert the number of installed product matches the unique product certs Ids installed
Assert.assertEquals(installedProducts.size(), productCertIds.size(), "A single product is reported as installed for each unique product cert ID found in " + clienttasks.productCertDir + " and " + clienttasks.productCertDefaultDir);
// assert that each of the installed ProductCerts are listed as InstalledProducts with status "Not Subscribed"
for (ProductCert productCert : productCerts) {
InstalledProduct installedProduct = clienttasks.getInstalledProductCorrespondingToProductCert(productCert, installedProducts);
Assert.assertNotNull(installedProduct, "The following installed product cert is included by subscription-manager in the list --installed: " + (installedProduct == null ? "null" : installedProduct));
Assert.assertEquals(installedProduct.status, "Not Subscribed", "The status of installed product when newly registered: " + installedProduct);
}
}
Aggregations