use of rhsm.data.InstalledProduct in project rhsm-qe by RedHatQE.
the class PluginTests method testEnabledProductIdInstallTestPluginHooksAreCalled.
@// update=true // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-20060", "RHEL7-55177" }, 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 = "execute subscription-manager modules and verify the expected ProductIdInstallTestPlugin hooks are called", groups = { "Tier1Tests", "blockedByBug-859197", "blockedByBug-922871", /*, "blockedByBug-922882"*/
"blockedByBug-1512948" }, priority = 630, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testEnabledProductIdInstallTestPluginHooksAreCalled() {
if (clienttasks.getCurrentProductCertFiles().isEmpty())
throw new SkipException("This test will install a layered RHEL product which requires a base RHEL product cert to be installed. Skipping this test because no RHEL product is installed.");
truncateRhsmLog();
// get the current rhsm logging level; INFO or DEBUG
String rhsmLogLevel = null;
if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.17.10-1")) {
// RHEL7.3 commit d84b15f42c2e4521e130b939039960c0846b849c 1334916: Move logging configuration to rhsm.conf
rhsmLogLevel = clienttasks.getConfFileParameter(clienttasks.rhsmConfFile, "logging", "default_log_level");
} else if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.14.2-1")) {
// commit 66aafd77dc629b921379f0e121421c1c21c0b787 Move to fileConfig based logging.
rhsmLogLevel = clienttasks.getConfFileParameter(clienttasks.rhsmLoggingConfFile, "handler_rhsm_log", "level");
} else {
// default
rhsmLogLevel = "DEBUG";
}
// register
String consumerId = clienttasks.getCurrentConsumerId(clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (List<String>) null, null, null, null, true, null, null, null, null, null));
// mark the rhsm.log file
String logMarker = System.currentTimeMillis() + " Testing verifyEnabledProductIdInstallTestPluginHooksAreCalled_Test...";
RemoteFileTasks.markFile(client, clienttasks.rhsmLogFile, logMarker);
// do a yum transaction and assert that the product_id_install hooks are NOT yet called
clienttasks.getYumRepolist("all --enableplugin=product-id");
// sleep(5000); // give the plugin hooks a chance to be called; I think this is an async process
// get the tail of the marked rhsm.log file
String logTail = RemoteFileTasks.getTailFromMarkedFile(client, clienttasks.rhsmLogFile, logMarker, "Running p").trim();
// assert the pre/post_product_id_install_hooks are NOT called
List<String> notExpectedLogInfo = Arrays.asList("Running pre_product_id_install_hook", "Running post_product_id_install_hook", "");
Assert.assertTrue(!logTail.replaceAll("\n", "").matches(".*" + joinListToString(notExpectedLogInfo, ".*") + ".*"), "The '" + clienttasks.rhsmLogFile + "' DOES NOT report log messages (becasue no product id should have been installed): " + notExpectedLogInfo);
// now login with the HighAvailability credentials and install a package and assert the pre/post_product_id_install_hooks are called
if (sm_haUsername.equals(""))
throw new SkipException("Skipping this test when no value was given for the High Availability username.");
// 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";
// register to an account that offers High Availability subscriptions
consumerId = clienttasks.getCurrentConsumerId(clienttasks.register(sm_haUsername, sm_haPassword, sm_haOrg, null, null, null, null, null, null, null, (String) null, null, null, null, true, null, null, null, null, null));
// make sure that there are no ha packages and no productId installed
List<String> haPackages = HighAvailabilityTests.getHighAvailabilityPackages(clienttasks.redhatReleaseXY, clienttasks.arch);
for (String haPackage : haPackages) {
if (clienttasks.isPackageInstalled(haPackage))
clienttasks.yumRemovePackage(haPackage);
}
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.");
// Subscribe to the High Availability subscription SKU
List<SubscriptionPool> availableSubscriptionPools = clienttasks.getCurrentlyAvailableSubscriptionPools();
String haSku = HighAvailabilityTests.getHighAvailabilitySku(clienttasks.arch);
SubscriptionPool haPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("productId", haSku, availableSubscriptionPools);
if (clienttasks.variant.equals("Server") && getArchesOfferringHighAvailabilityContent().contains(clienttasks.arch)) {
Assert.assertNotNull(haPool, "A subscription pool for High Availability SKU '" + haSku + "' is available.");
clienttasks.subscribe(null, null, haPool.poolId, null, null, null, null, null, null, null, null, null, null);
} else {
throw new SkipException("Not expecting High Availability subscription SKU '" + haSku + "' to offer content on a RHEL '" + clienttasks.redhatReleaseX + "' '" + clienttasks.variant + "' system with arch '" + clienttasks.arch + "'.");
}
// NOT ANYMORE, WE NOW NEED TO ENABLE THE ADDON REPO (A GOOD CHANGE BY REL-ENG DURING THE RHEL7.4 TEST PHASE, AND APPLIED TO ALL RELEASES)
if (/*clienttasks.redhatReleaseX.equals("7") && */
clienttasks.arch.equals("x86_64")) {
clienttasks.repos(null, null, null, "rhel-ha-for-rhel-" + clienttasks.redhatReleaseX + "-server-rpms", null, null, null, null, null);
}
// INFO: rhel-ha-for-rhel-7-for-system-z-rpms/7Server/s390x is NOT enabled by default
if (clienttasks.redhatReleaseX.equals("7") && clienttasks.arch.equals("s390x")) {
clienttasks.repos(null, null, null, "rhel-ha-for-rhel-7-for-system-z-rpms", null, null, null, null, null);
}
// mark the rhsm.log file
logMarker = System.currentTimeMillis() + " Testing verifyEnabledProductIdInstallTestPluginHooksAreCalled_Test...";
RemoteFileTasks.markFile(client, clienttasks.rhsmLogFile, logMarker);
// do a yum install of an ha package
// WARNING! Package ccs also belongs to Resilient Storage which may cause productId 90 to also be installed from one of the beaker repos, therefore --disablerepo=beaker*
// yum -y install ccs --disablerepo=beaker-*
clienttasks.yumInstallPackage(haPackages.get(0), "--disablerepo=beaker-*");
// sleep(5000); // give the plugin hooks a chance to be called; I think this is an async process
// get the tail of the marked rhsm.log file
logTail = RemoteFileTasks.getTailFromMarkedFile(client, clienttasks.rhsmLogFile, logMarker, "Running p").trim();
// assert the pre/post_product_id_install_hooks are called
List<String> expectedLogInfo = new ArrayList<String>();
if (rhsmLogLevel.equals("DEBUG"))
expectedLogInfo.add("Running pre_product_id_install_hook in product_id_install_test.ProductIdInstallTestPlugin");
if (rhsmLogLevel.equals("DEBUG") || rhsmLogLevel.equals("INFO"))
expectedLogInfo.add("Running pre_product_id_install_hook: yum product-id plugin is about to install a product cert");
if (rhsmLogLevel.equals("DEBUG"))
expectedLogInfo.add("Running post_product_id_install_hook in product_id_install_test.ProductIdInstallTestPlugin");
if (rhsmLogLevel.equals("DEBUG") || rhsmLogLevel.equals("INFO"))
expectedLogInfo.add("Running post_product_id_install_hook: yum product-id plugin just installed a product cert");
// if (rhsmLogLevel.equals("DEBUG")||rhsmLogLevel.equals("INFO")) expectedLogInfo.add("Running post_product_id_install_hook: 1 product_ids were just installed"); // probably correct, but not necessary to verify post_product_id_install_hook was called
if (rhsmLogLevel.equals("DEBUG") || rhsmLogLevel.equals("INFO"))
expectedLogInfo.add("Running post_product_id_install_hook: product_id " + haProductId + " was just installed");
// Product Name: Red Hat Enterprise Linux High Availability (for RHEL Server)
// Product ID: 83
Assert.assertTrue(logTail.replaceAll("\n", "").matches(".*" + joinListToString(expectedLogInfo, ".*") + ".*"), "The '" + clienttasks.rhsmLogFile + "' reports log messages: " + expectedLogInfo);
}
use of rhsm.data.InstalledProduct in project rhsm-qe by RedHatQE.
the class ListTests method testListInstalledWithExactMatches.
@// update=true // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36563", "RHEL7-51345" }, 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: subcription manager list --installed with exact --matches on Product Name, Product ID. Note: exact match means no wildcards and is case insensitive.", groups = { "Tier2Tests", "blockedByBug-1146125" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testListInstalledWithExactMatches() throws JSONException, Exception {
if (clienttasks.isPackageVersion("subscription-manager", "<", "1.13.6-1"))
throw new SkipException("The list --matches function was not implemented in this version of subscription-manager.");
String matchesString;
List<InstalledProduct> actualInstalledProductMatches;
// register if necessary
if (clienttasks.getCurrentlyRegisteredOwnerKey() == null) {
clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, true, null, null, null, null, null);
clienttasks.autoheal(null, null, true, null, null, null, null);
} else
clienttasks.unsubscribe_(true, (BigInteger) null, null, null, null, null, null);
// attach one of all the currently available subscriptions (attaching only one so that some installed products might remain noncompliant)
// assemble a list of all the available SubscriptionPool ids
List<String> poolIds = new ArrayList<String>();
List<SubscriptionPool> subscriptionPools = clienttasks.getCurrentlyAvailableSubscriptionPools();
for (SubscriptionPool pool : subscriptionPools) poolIds.add(pool.poolId);
if (!poolIds.isEmpty())
clienttasks.subscribe(null, null, poolIds, null, null, "1", null, null, null, null, null, null, null);
// get all the installed products
List<InstalledProduct> installedProducts = InstalledProduct.parse(clienttasks.list(null, null, null, true, null, null, null, null, null, null, null, null, null, null).getStdout());
// randomly choose one of the installed products
InstalledProduct randomInstalledProduct = getRandomListItem(installedProducts);
// [root@jsefler-os7 ~]# subscription-manager list --installed
// Product Name: Red Hat Enterprise Linux Server
// Product ID: 69
// Version: 7.0
// Arch: x86_64
// Status: Not Subscribed
// Status Details: Not supported by a valid subscription.
// Starts:
// Ends:
// Test 1: test exact --matches on Product Name:
matchesString = randomInstalledProduct.productName;
actualInstalledProductMatches = InstalledProduct.parse(clienttasks.list(null, null, null, true, null, null, null, null, matchesString, null, null, null, null, null).getStdout());
assertActualResultOfListInstalledWithMatches(matchesString, actualInstalledProductMatches, installedProducts);
// also test case insensitivity
matchesString = randomizeCaseOfCharactersInString(matchesString);
actualInstalledProductMatches = InstalledProduct.parse(clienttasks.list(null, null, null, true, null, null, null, null, matchesString, null, null, null, null, null).getStdout());
assertActualResultOfListInstalledWithMatches(matchesString, actualInstalledProductMatches, installedProducts);
// Test 2: test exact --matches on Product ID:
matchesString = randomInstalledProduct.productId;
actualInstalledProductMatches = InstalledProduct.parse(clienttasks.list(null, null, null, true, null, null, null, null, matchesString, null, null, null, null, null).getStdout());
assertActualResultOfListInstalledWithMatches(matchesString, actualInstalledProductMatches, installedProducts);
// also test case insensitivity
matchesString = randomizeCaseOfCharactersInString(matchesString);
actualInstalledProductMatches = InstalledProduct.parse(clienttasks.list(null, null, null, true, null, null, null, null, matchesString, null, null, null, null, null).getStdout());
assertActualResultOfListInstalledWithMatches(matchesString, actualInstalledProductMatches, installedProducts);
}
use of rhsm.data.InstalledProduct in project rhsm-qe by RedHatQE.
the class ListTests method testListInstalledWithProductDefault.
@// update=true // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-19966", "RHEL7-33101" }, 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")
@// see description in https://github.com/candlepin/subscription-manager/pull/1009
Test(// see description in https://github.com/candlepin/subscription-manager/pull/1009
description = "subscription-manager: list installed should include product certs in /etc/pki/product-default", // subscription-manager 1123029 - [RFE] Use default product certificates when they are present COMPLEMENT TO REL-ENG RFE 1080012 - [RFE] Include default product certificate in redhat-release
groups = { "Tier1Tests", "ListInstalledWithProductDefault_Test", "blockedByBug-1123029" /*1080012*/
}, priority = 150, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testListInstalledWithProductDefault() {
if (clienttasks.isPackageVersion("subscription-manager", "<", "1.12.14-1"))
throw new SkipException("The /etc/pki/product-default feature is not implemented in this version of subscription-manager.");
// strategy...
// copy a random selection of product certs from subscription-manager-migration-data into /etc/pki/product-default
// make sure that some of the product certs copied include product ids already installed in /etc/pki/product
// assert that list --installed includes all the product certs but those in /etc/pki/product take precedence over /etc/pki/product-default
// assert the existance of /etc/pki/product-default
Assert.assertTrue(RemoteFileTasks.testExists(client, clienttasks.productCertDefaultDir), "Expecting directory '" + clienttasks.productCertDefaultDir + "' to exist.");
// get the original product certs that are currently installed in /etc/pki/product-default
originalDefaultProductCerts = clienttasks.getProductCerts(clienttasks.productCertDefaultDir);
// get the product certs that are currently installed in /etc/pki/product
List<ProductCert> productCerts = clienttasks.getProductCerts(clienttasks.productCertDir);
// copy migration-data product certs to /etc/pki/product-default (including productCerts whose product id matches /etc/pki/product cert and does not already exist in /etc/pki/product-default)
List<File> migrationProductCertsFiles = clienttasks.getProductCertFiles("/usr/share/rhsm/product/RHEL" + "-" + clienttasks.redhatReleaseX);
Set<String> defaultProductCertProductIds = new HashSet<String>();
for (ProductCert defaultProductCert : originalDefaultProductCerts) defaultProductCertProductIds.add(defaultProductCert.productId);
String migrationProductCertFilesToCopy = "";
for (File migrationProductCertFile : migrationProductCertsFiles) {
String migrationProductCertProductId = MigrationDataTests.getProductIdFromProductCertFilename(migrationProductCertFile.getPath());
// if this migrationProductCertProductId is already among the defaultProductCertProductIds, skip it - do not copy another since it does not make sense to have multiple product certs with the same productId in the same directory
if (defaultProductCertProductIds.contains(migrationProductCertProductId)) {
continue;
}
// if this migrationProductCertProductId is installed in /etc/pki/product, copy it to /etc/pki/product-default
if (ProductCert.findFirstInstanceWithMatchingFieldFromList("productId", migrationProductCertProductId, productCerts) != null) {
// TOO MUCH LOGGING client.runCommandAndWait("cp -n "+migrationProductCertFile+" "+clienttasks.productCertDefaultDir);
migrationProductCertFilesToCopy += migrationProductCertFile + " ";
defaultProductCertProductIds.add(migrationProductCertProductId);
continue;
}
// randomly skip 75% of these copies to reduce logging noise
if (getRandomListItem(Arrays.asList(new Integer[] { 1 /*,2,3,4*/
})).equals(1)) {
// TOO MUCH LOGGING client.runCommandAndWait("cp -n "+migrationProductCertFile+" "+clienttasks.productCertDefaultDir);
migrationProductCertFilesToCopy += migrationProductCertFile + " ";
defaultProductCertProductIds.add(migrationProductCertProductId);
}
}
if (!migrationProductCertFilesToCopy.isEmpty())
client.runCommandAndWait("cp -n " + migrationProductCertFilesToCopy + " " + clienttasks.productCertDefaultDir);
// get the product certs that are currently installed in /etc/pki/product-default
List<ProductCert> defaultProductCerts = clienttasks.getProductCerts(clienttasks.productCertDefaultDir);
// get the currently InstalledProducts
List<InstalledProduct> installedProducts = clienttasks.getCurrentlyInstalledProducts();
// etc/pki/product are included in the currently InstalledProducts
for (ProductCert productCert : productCerts) {
List<InstalledProduct> installedProductsMatchingProductCertId = InstalledProduct.findAllInstancesWithMatchingFieldFromList("productId", productCert.productId, installedProducts);
Assert.assertEquals(installedProductsMatchingProductCertId.size(), 1, "The list of Installed Products contains exactly 1 entry with a productId='" + productCert.productId + "' from '" + clienttasks.productCertDir + "'.");
InstalledProduct installedProductMatchingProductCertId = installedProductsMatchingProductCertId.get(0);
Assert.assertEquals(installedProductMatchingProductCertId.productName, productCert.productNamespace.name, "The list of Installed Products includes '" + productCert.productNamespace.name + "' from '" + clienttasks.productCertDir + "'.");
Assert.assertEquals(installedProductMatchingProductCertId.version, productCert.productNamespace.version, "The list of Installed Products includes '" + productCert.productNamespace.name + "' version '" + productCert.productNamespace.version + "' from '" + clienttasks.productCertDir + "'.");
}
// etc/pki/product-default are included in the currently InstalledProducts (unless it's productId is already installed in /etc/pki/product which takes precedence over /etc/pki/product-default).
for (ProductCert defaultProductCert : defaultProductCerts) {
List<InstalledProduct> installedProductsMatchingProductCertId = InstalledProduct.findAllInstancesWithMatchingFieldFromList("productId", defaultProductCert.productId, installedProducts);
Assert.assertEquals(installedProductsMatchingProductCertId.size(), 1, "The list of Installed Products contains exactly 1 entry with a productId='" + defaultProductCert.productId + "' from '" + clienttasks.productCertDefaultDir + "'.");
InstalledProduct installedProductMatchingProductCertId = installedProductsMatchingProductCertId.get(0);
ProductCert precedentProductCert = ProductCert.findFirstInstanceWithMatchingFieldFromList("productId", defaultProductCert.productId, productCerts);
if (precedentProductCert != null) {
// verify the precedentProductCert overrides the defaultProductCert
Assert.assertEquals(installedProductMatchingProductCertId.productName, precedentProductCert.productNamespace.name, "The list of Installed Products includes '" + precedentProductCert.productNamespace.name + "' from '" + clienttasks.productCertDir + "' since it takes precedence over '" + defaultProductCert + "' from '" + clienttasks.productCertDefaultDir + "'.");
Assert.assertEquals(installedProductMatchingProductCertId.version, precedentProductCert.productNamespace.version, "The list of Installed Products includes '" + precedentProductCert.productNamespace.name + "' version '" + precedentProductCert.productNamespace.version + "' from '" + clienttasks.productCertDir + "' since it takes precedence over '" + defaultProductCert + "' from '" + clienttasks.productCertDefaultDir + "'.");
Assert.assertEquals(installedProductMatchingProductCertId.arch, precedentProductCert.productNamespace.arch, "The list of Installed Products includes '" + precedentProductCert.productNamespace.name + "' arch '" + precedentProductCert.productNamespace.arch + "' from '" + clienttasks.productCertDir + "' since it takes precedence over '" + defaultProductCert + "' from '" + clienttasks.productCertDefaultDir + "'.");
} else {
// verify that the defaultProductCert is included in list of Installed Products
Assert.assertEquals(installedProductMatchingProductCertId.productName, defaultProductCert.productNamespace.name, "The list of Installed Products includes '" + defaultProductCert.productNamespace.name + "' from '" + clienttasks.productCertDefaultDir + "' since there is no product cert with ID '" + defaultProductCert.productId + "' in '" + clienttasks.productCertDir + "' that takes precedence.");
Assert.assertEquals(installedProductMatchingProductCertId.version, defaultProductCert.productNamespace.version, "The list of Installed Products includes '" + defaultProductCert.productNamespace.name + "' version '" + defaultProductCert.productNamespace.version + "' from '" + clienttasks.productCertDefaultDir + "' since there is no product cert with ID '" + defaultProductCert.productId + "' in '" + clienttasks.productCertDir + "' that takes precedence.");
Assert.assertEquals(installedProductMatchingProductCertId.arch, defaultProductCert.productNamespace.arch, "The list of Installed Products includes '" + defaultProductCert.productNamespace.name + "' arch '" + defaultProductCert.productNamespace.arch + "' from '" + clienttasks.productCertDefaultDir + "' since there is no product cert with ID '" + defaultProductCert.productId + "' in '" + clienttasks.productCertDir + "' that takes precedence.");
}
}
}
use of rhsm.data.InstalledProduct in project rhsm-qe by RedHatQE.
the class StackingTests method testStackEachPoolToAchieveAttributeCompliance.
// 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-20011", "RHEL7-51033" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier1")
@Test(description = "subscription-manager: subscribe to each pool with the same stacking_id to achieve compliance", enabled = true, groups = { "Tier1Tests", "blockedByBug-739671", "blockedByBug-740377", "blockedByBug-861993", "blockedByBug-955142" }, dataProvider = "getAvailableStackableAttributeSubscriptionPoolsData")
public // @ImplementsNitrateTest(caseId=)
void testStackEachPoolToAchieveAttributeCompliance(Object bugzilla, String attribute, boolean systemIsGuest, List<SubscriptionPool> stackableAttributeSubscriptionPools) throws JSONException, Exception {
// The strategy in this test is to simulate the facts on the systems so that the attribute being tested ("cores","ram",or "sockets", or "vcpu")
// will achieve full compliance for all of the provided products after attaching a quantity of one entitlement
// from each pool in the list of stackable subscription pools. As we incrementally attach from each pool, we will assert
// a partial compliance until the final subscription is attached which should achieve full compliance.
// loop through the pools to determine the minimum attribute count for which one
// of each stackable pool is needed to achieve compliance of the provided products
// also keep a list of all the provided productIds
Integer minimumAttributeValue = 0;
Integer minimumSocketsValue = 0;
Set<String> productIdsProvidedForByAllStackableSubscriptionPools = new HashSet<String>();
Map<String, Integer> poolProductAttributeValueMap = new HashMap<String, Integer>();
for (SubscriptionPool pool : stackableAttributeSubscriptionPools) {
String attributeValue = CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, attribute);
productIdsProvidedForByAllStackableSubscriptionPools.addAll(CandlepinTasks.getPoolProvidedProductIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId));
minimumAttributeValue += Integer.valueOf(attributeValue);
poolProductAttributeValueMap.put(pool.poolId, Integer.valueOf(attributeValue));
}
// override the system facts setting the attribute count to a value for which all the stackable subscriptions are needed to achieve compliance
Map<String, String> factsMap = new HashMap<String, String>();
// force the system to be physical or virtual
factsMap.put("virt.is_guest", Boolean.valueOf(systemIsGuest).toString());
factsMap.put("memory.memtotal", "1");
factsMap.put("cpu.cpu_socket(s)", "1");
factsMap.put("cpu.core(s)_per_socket", "1");
if (attribute.equals("ram")) {
// "memory.memtotal" is stored in Kilobytes; "ram" is specified in Gigabytes; for conversions, see http://www.whatsabyte.com/P1/byteconverter.htm
factsMap.put("memory.memtotal", String.valueOf(minimumAttributeValue * 1048576));
}
if (attribute.equals("sockets")) {
factsMap.put("cpu.cpu_socket(s)", String.valueOf(minimumAttributeValue));
}
if (attribute.equals("cores") || attribute.equals("vcpu")) {
// vcpu (on a virt system) maps to cores (on a physical system)
if (Integer.valueOf(minimumAttributeValue) % 2 == 0) {
// configure facts for an even number of cores
factsMap.put("cpu.core(s)_per_socket", "2");
minimumSocketsValue = Integer.valueOf(minimumAttributeValue) / 2;
factsMap.put("cpu.cpu_socket(s)", String.valueOf(minimumSocketsValue));
} else {
// configure facts for an odd number of cores
factsMap.put("cpu.core(s)_per_socket", "1");
minimumSocketsValue = Integer.valueOf(minimumAttributeValue);
factsMap.put("cpu.cpu_socket(s)", String.valueOf(minimumSocketsValue));
}
}
clienttasks.createFactsFileWithOverridingValues(factsMap);
// register the system which has now been instrumented with facts to test the stack
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);
// assert installed product status for all the products that the stacked subscriptions will provide for
List<InstalledProduct> currentlyInstalledProducts = clienttasks.getCurrentlyInstalledProducts();
for (String productId : productIdsProvidedForByAllStackableSubscriptionPools) {
List<InstalledProduct> installedProducts = InstalledProduct.findAllInstancesWithMatchingFieldFromList("productId", productId, currentlyInstalledProducts);
// this productIdProvidedFor is not installed
if (installedProducts.isEmpty())
continue;
// this should be impossible because the would all share the same /etc/pki/product/<productId>.pem file name
if (installedProducts.size() > 1)
Assert.fail("Something is seriously wrong. Found multiple InstalledProduct " + installedProducts + " with a common productId '" + productId + "'.");
InstalledProduct installedProduct = installedProducts.get(0);
// Message changed by candlepin commit 43a17952c724374c3fee735642bce52811a1e386 covers -> supports
List<String> expectedStatusDetails = Arrays.asList(new String[] { "Not supported by a valid subscription." });
Assert.assertEquals(installedProduct.status, "Not Subscribed", "Prior to subscribing to any of the stackable subscription pools, Installed product '" + installedProduct.productName + "' which is provided for by the subscription stack should have this status.");
if (installedProduct.statusDetails.isEmpty())
log.warning("Status Details appears empty. Is your candlepin server older than 0.8.6?");
Assert.assertEquals(installedProduct.statusDetails, expectedStatusDetails, "Prior to subscribing to any of the stackable subscription pools, Installed product '" + installedProduct.productName + "' which is provided for by the subscription stack should have these status details: " + expectedStatusDetails);
// Assert.assertTrue(isEqualNoOrder(installedProduct.statusDetails,expectedStatusDetails),"Prior to subscribing to any of the stackable subscription pools, Installed product '"+installedProduct.productName+"' which is provided for by the subscription stack should have these status details: "+expectedStatusDetails);
}
// incrementally attach one entitlement from each pool in the stack asserting the installed product's status and details along the way
// the final attachment should achieve full compliance for the provided products in the stack
int s = 0;
Integer attributeValueStackedThusFar = 0;
Integer socketsValueStackedThusFar = 0;
Integer vcpuValueStackedThusFar = 0;
Set<String> productIdsProvidedForThusFar = new HashSet<String>();
for (SubscriptionPool pool : stackableAttributeSubscriptionPools) {
clienttasks.subscribe(null, null, pool.poolId, null, null, "1", null, null, null, null, null, null, null);
// add some test coverage for bugs 861993 and 955142
EntitlementCert entitlementCert = clienttasks.getEntitlementCertCorrespondingToSubscribedPool(pool);
if (attribute.equals("ram")) {
Assert.assertEquals(entitlementCert.orderNamespace.ramLimit, poolProductAttributeValueMap.get(pool.poolId).toString(), "rct cat-cert tool reports the expected RAM Limit value in the Order for subscription '" + pool.subscriptionName + "'.");
}
if (attribute.equals("sockets")) {
Assert.assertEquals(entitlementCert.orderNamespace.socketLimit, poolProductAttributeValueMap.get(pool.poolId).toString(), "rct cat-cert tool reports the expected Socket Limit value in the Order for subscription '" + pool.subscriptionName + "'.");
}
if (attribute.equals("cores")) {
Assert.assertEquals(entitlementCert.orderNamespace.coreLimit, poolProductAttributeValueMap.get(pool.poolId).toString(), "rct cat-cert tool reports the expected Core Limit value in the Order for subscription '" + pool.subscriptionName + "'.");
}
/* TODO Open a bug to include vcpu in the order repo
* Bug 1055617 - [RFE] rct cat-cert should also report the "VCPU Limit" attribute for an Order
if (attribute.equals("vcpu")) {
Assert.assertEquals(entitlementCert.orderNamespace.vcpuLimit,poolProductAttributeValueMap.get(pool.poolId).toString(),"rct cat-cert tool reports the expected VCPU Limit value in the Order for subscription '"+pool.subscriptionName+"'.");
}
*/
// keep a running total of how much of the stackable attribute our entitlements have covered thus far
attributeValueStackedThusFar += poolProductAttributeValueMap.get(pool.poolId);
// keep a running total of how much socket coverage our stacked entitlements have covered thus far
String socketsValue = CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "sockets");
if (socketsValue != null) {
socketsValueStackedThusFar += Integer.valueOf(socketsValue);
}
// keep a running total of how much vcpu coverage our stacked entitlements have covered thus far
String vcpuValue = CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "vcpu");
if (vcpuValue != null) {
vcpuValueStackedThusFar += Integer.valueOf(vcpuValue);
}
// keep a running set of which productIdsProvidedFor have been covered by the subscriptions thus far
productIdsProvidedForThusFar.addAll(CandlepinTasks.getPoolProvidedProductIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId));
// assert the installed products that have been provided for by the stack of subscriptions thus far are Partially Subscribed
for (InstalledProduct installedProduct : clienttasks.getCurrentlyInstalledProducts()) {
if (productIdsProvidedForThusFar.contains(installedProduct.productId)) {
List<String> expectedStatusDetails = new ArrayList<String>();
if (attribute.equals("ram") && attributeValueStackedThusFar < minimumAttributeValue) {
// Message changed by candlepin commit 43a17952c724374c3fee735642bce52811a1e386 covers -> supports
expectedStatusDetails.add(String.format("Only supports %sGB of %sGB of RAM.", attributeValueStackedThusFar, minimumAttributeValue));
}
if (attribute.equals("sockets") && !systemIsGuest && attributeValueStackedThusFar < minimumAttributeValue) {
// Message changed by candlepin commit 43a17952c724374c3fee735642bce52811a1e386 covers -> supports
expectedStatusDetails.add(String.format("Only supports %s of %s sockets.", attributeValueStackedThusFar, minimumAttributeValue));
}
if (attribute.equals("cores") && !systemIsGuest && attributeValueStackedThusFar < minimumAttributeValue) {
// Message changed by candlepin commit 43a17952c724374c3fee735642bce52811a1e386 covers -> supports
expectedStatusDetails.add(String.format("Only supports %s of %s cores.", attributeValueStackedThusFar, minimumAttributeValue));
}
if (attribute.equals("vcpu") && systemIsGuest && attributeValueStackedThusFar < minimumAttributeValue) {
// Message changed by candlepin commit 43a17952c724374c3fee735642bce52811a1e386 covers -> supports
expectedStatusDetails.add(String.format("Only supports %s of %s vCPUs.", attributeValueStackedThusFar, minimumAttributeValue));
}
if (attribute.equals("cores") && !systemIsGuest && socketsValueStackedThusFar > 0 && socketsValueStackedThusFar < minimumSocketsValue) {
// when a cores stack also includes sockets (on a physical system), we will have more status details
// Message changed by candlepin commit 43a17952c724374c3fee735642bce52811a1e386 covers -> supports
expectedStatusDetails.add(String.format("Only supports %s of %s sockets.", socketsValueStackedThusFar, minimumSocketsValue));
}
if (attribute.equals("cores") && systemIsGuest && vcpuValueStackedThusFar > 0 && vcpuValueStackedThusFar < minimumAttributeValue) {
// when a cores stack also includes vcpu (on a virtual system), we will have more status details
// Message changed by candlepin commit 43a17952c724374c3fee735642bce52811a1e386 covers -> supports
expectedStatusDetails.add(String.format("Only supports %s of %s vCPUs.", vcpuValueStackedThusFar, minimumAttributeValue));
}
if (attribute.equals("sockets") && systemIsGuest && vcpuValueStackedThusFar > 0 && vcpuValueStackedThusFar < minimumAttributeValue) {
// when a sockets stack also includes vcpu (on a virtual system), we will have more status details
// Message changed by candlepin commit 43a17952c724374c3fee735642bce52811a1e386 covers -> supports
expectedStatusDetails.add(String.format("Only supports %s of %s vCPUs.", vcpuValueStackedThusFar, minimumAttributeValue));
}
if (attribute.equals("vcpu") && !systemIsGuest && socketsValueStackedThusFar > 0 && socketsValueStackedThusFar < minimumSocketsValue) {
// when a vcpu stack also includes sockets (on a physical system), we will have more status details
// Message changed by candlepin commit 43a17952c724374c3fee735642bce52811a1e386 covers -> supports
expectedStatusDetails.add(String.format("Only supports %s of %s sockets.", socketsValueStackedThusFar, minimumSocketsValue));
}
if (expectedStatusDetails.isEmpty()) {
Assert.assertEquals(installedProduct.status, "Subscribed", "After an incremental attachment of one stackable '" + attribute + "' subscription for '" + pool.subscriptionName + "' poolId=" + pool.poolId + ", Installed product '" + installedProduct.productName + "' which is provided for by the subscription stack should have this status.");
} else {
if (installedProduct.statusDetails.isEmpty())
log.warning("Status Details appears empty. Is your candlepin server older than 0.8.6?");
Assert.assertTrue(isEqualNoOrder(installedProduct.statusDetails, expectedStatusDetails), "After an incremental attachment of one stackable '" + attribute + "' subscription for '" + pool.subscriptionName + "' poolId=" + pool.poolId + ", Installed product '" + installedProduct.productName + "' which is provided for by the subscription stack should have status details " + expectedStatusDetails + " (actual= " + installedProduct.statusDetails + ")");
Assert.assertEquals(installedProduct.status, "Partially Subscribed", "After an incremental attachment of one stackable '" + attribute + "' subscription for '" + pool.subscriptionName + "' poolId=" + pool.poolId + ", Installed product '" + installedProduct.productName + "' which is provided for by the subscription stack should have this status.");
}
} else {
if (productIdsProvidedForByAllStackableSubscriptionPools.contains(installedProduct.productId)) {
// Message changed by candlepin commit 43a17952c724374c3fee735642bce52811a1e386 covers -> supports
List<String> expectedStatusDetails = Arrays.asList(new String[] { "Not supported by a valid subscription." });
if (installedProduct.statusDetails.isEmpty())
log.warning("Status Details appears empty. Is your candlepin server older than 0.8.6?");
Assert.assertEquals(installedProduct.status, "Not Subscribed", "After an incremental attachment of one stackable subscription for '" + pool.subscriptionName + "' poolId=" + pool.poolId + ", Installed product '" + installedProduct.productName + "' which is NOT YET provided for by the subscription stack THUS FAR should have this status.");
Assert.assertEquals(installedProduct.statusDetails, expectedStatusDetails, "After an incremental attachment of one stackable subscription for '" + pool.subscriptionName + "' poolId=" + pool.poolId + ", Installed product '" + installedProduct.productName + "' which is NOT YET provided for by the subscription stack THUS FAR should have these status details: " + expectedStatusDetails);
// Assert.assertTrue(isEqualNoOrder(installedProduct.statusDetails,expectedStatusDetails), "After an incremental attachment of one stackable subscription for '"+pool.subscriptionName+"' poolId="+pool.poolId+", Installed product '"+installedProduct.productName+"' which is NOT YET provided for by the subscription stack THUS FAR should have these status details: "+expectedStatusDetails);
} else {
/* These asserts are valid, but not really relevant to this test. Commented out to reduce noisy logging.
List<String> expectedStatusDetails = Arrays.asList(new String[]{"Not supported by a valid subscription."}); // Message changed by candlepin commit 43a17952c724374c3fee735642bce52811a1e386 covers -> supports
Assert.assertEquals(installedProduct.status,"Not Subscribed","After subscribing to stackable subscription for '"+pool.subscriptionName+"' poolId="+pool.poolId+", Installed product '"+installedProduct.productName+"' which is NOT provided for by the subscription stack should have this status.");
Assert.assertTrue(isEqualNoOrder(installedProduct.statusDetails,expectedStatusDetails), "After subscribing to stackable subscription for '"+pool.subscriptionName+"' poolId="+pool.poolId+", Installed product '"+installedProduct.productName+"' which is NOT provided for by the subscription stack should have these status details: "+expectedStatusDetails);
*/
}
}
}
}
}
use of rhsm.data.InstalledProduct in project rhsm-qe by RedHatQE.
the class StatusTests method testStatusOnFutureDate.
@// update=true, // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-19967", "RHEL7-33081" }, 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 = "run subscription-manager status ondate (tomorrow and a future date after one of today's entitlements expire)", groups = { "Tier1Tests", "blockedByBug-1500106" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testStatusOnFutureDate() throws JSONException, Exception {
if (clienttasks.isPackageVersion("subscription-manager", "<", "1.9.2-1"))
throw new SkipException("Installed package '" + clienttasks.installedPackageVersionMap.get("subscription-manager") + "' does not support status --ondate option. It was introduced in subscription-manager-1.9.2-1.");
// register with autosubscribe to establish today's status
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.subscribeToTheCurrentlyAvailableSubscriptionPoolsCollectively();
// make sure at least one installed product was subscribed, otherwise this test is not applicable
List<InstalledProduct> installedProducts = clienttasks.getCurrentlyInstalledProducts();
boolean noInstalledProducts = installedProducts.isEmpty();
boolean areAnyInstalledProductsSubscribable = false;
for (InstalledProduct installedProduct : installedProducts) {
if (installedProduct.status.equals("Subscribed") || installedProduct.status.equals("Partially Subscribed")) {
areAnyInstalledProductsSubscribable = true;
break;
}
}
// get today's status
SSHCommandResult statusResultToday = clienttasks.status(null, null, null, null, null);
Map<String, String> statusMapToday = getProductStatusMapFromStatusResult(statusResultToday);
// get tomorrow's status
DateFormat yyyy_MM_dd_DateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar tomorrow = new GregorianCalendar();
tomorrow.add(Calendar.HOUR, 24);
String onDateTomorrow = yyyy_MM_dd_DateFormat.format(tomorrow.getTime());
SSHCommandResult statusResultTomorrow = clienttasks.status(onDateTomorrow, null, null, null, null);
Map<String, String> statusMapTomorrow = getProductStatusMapFromStatusResult(statusResultTomorrow);
// assert tomorrow's status is identical to today's (assumes no change in coverage)
Assert.assertTrue(statusMapTomorrow.equals(statusMapToday), "Asserting the assumption that the status --ondate=tomorrow will be identical to the status ondate=today (default).");
// now let's find the most future endDate of all current entitlement and assert that the status on the following day is different and Invalid
List<ProductSubscription> consumedProductSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
if (consumedProductSubscriptions.isEmpty())
throw new SkipException("The remainder of this test cannot be executed because we expect this system to have at least one consumed entitlement.");
Calendar future = consumedProductSubscriptions.get(0).startDate;
for (ProductSubscription productSubscription : consumedProductSubscriptions) if (productSubscription.endDate.after(future))
future = productSubscription.endDate;
// add one day
future.add(Calendar.HOUR, 24);
String onDateFuture = yyyy_MM_dd_DateFormat.format(future.getTime());
SSHCommandResult statusResultFuture = clienttasks.status(onDateFuture, null, null, null, null);
Map<String, String> statusMapFuture = getProductStatusMapFromStatusResult(statusResultFuture);
// assert future status is NOT identical to today's (assumes entitlements have expired)
log.info("Status Map ondate=today: " + statusMapToday);
log.info("Status Map ondate=future: " + statusMapFuture);
if (areAnyInstalledProductsSubscribable || noInstalledProducts) {
Assert.assertTrue(!statusMapFuture.equals(statusMapToday), "Asserting that the status --ondate=future (the day after an entitlement expires) will NOT be identical to the status ondate=today (default).");
} else {
Assert.assertTrue(statusMapFuture.equals(statusMapToday), "Asserting that the status --ondate=future (the day after an entitlement expires) will be identical to the status ondate=today (default) because none of the subscriptions applied today provide coverage for the products installed today.");
}
// assert future status
if (noInstalledProducts) {
String expectedStatus = "Overall Status: Current";
Assert.assertTrue(statusResultFuture.getStdout().contains(expectedStatus), "Expecting '" + expectedStatus + "' onDate '" + onDateFuture + "' which is one day beyond the most future endDate of the currently consumed subscriptions - when there are no installed products.");
} else {
String expectedStatus = "Overall Status: Invalid";
Assert.assertTrue(statusResultFuture.getStdout().contains(expectedStatus), "Expecting '" + expectedStatus + "' onDate '" + onDateFuture + "' which is one day beyond the most future endDate of the currently consumed subscriptions.");
}
}
Aggregations