use of rhsm.data.InstalledProduct in project rhsm-qe by RedHatQE.
the class RAMTests method testPartialSubscriptionOfRamBasedSubscription.
/**
* @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-36683", "RHEL7-51528" }, 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 = "verify Partial subscription of Ram subscription. ", groups = { "Tier2Tests", "PartialSubscriptionOfRamBasedSubscription" }, enabled = true)
public void testPartialSubscriptionOfRamBasedSubscription() throws JSONException, Exception {
testAutoSubscribeRamBasedProducts();
// GB
int ram = 100;
factsMap.put("memory.memtotal", String.valueOf(GBToKBConverter(ram)));
clienttasks.createFactsFileWithOverridingValues(factsMap);
clienttasks.facts(null, true, null, null, null, null);
for (InstalledProduct installed : getRamBasedProducts()) {
Assert.assertEquals(installed.status.trim(), "Partially Subscribed", "Status of installed ram product '" + installed.productName + "' on a '" + ram + "' GB system.");
}
}
use of rhsm.data.InstalledProduct in project rhsm-qe by RedHatQE.
the class RAMTests method getRamBasedProducts.
public List<InstalledProduct> getRamBasedProducts() {
// "RAM Limiting Product"
String ramProductName = "RAM";
List<InstalledProduct> RAMBasedProducts = new ArrayList<InstalledProduct>();
for (InstalledProduct installedProduct : clienttasks.getCurrentlyInstalledProducts()) {
if (installedProduct.productName.contains(ramProductName)) {
RAMBasedProducts.add(installedProduct);
}
}
if (RAMBasedProducts.isEmpty())
throw new SkipException("Could not find any installed products containing name '" + ramProductName + "'.");
return RAMBasedProducts;
}
use of rhsm.data.InstalledProduct in project rhsm-qe by RedHatQE.
the class RAMTests method testSubscribeToRamBasedSubscription.
/**
* @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-36686", "RHEL7-51531" }, 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 = "verify subscription of Ram based subscription", groups = { "Tier2Tests", "SubscribeToRamBasedSubscription", "blockedByBug-907315" }, enabled = true)
public void testSubscribeToRamBasedSubscription() throws JSONException, Exception {
factsMap.clear();
factsMap.put("uname.machine", "x86_64");
factsMap.put("cpu.core(s)_per_socket", "1");
factsMap.put("memory.memtotal", String.valueOf(KBToGBConverter(1)));
factsMap.put("cpu.cpu_socket(s)", "1");
clienttasks.createFactsFileWithOverridingValues(factsMap);
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);
int ramvalue = KBToGBConverter(Integer.parseInt(clienttasks.getFactValue("memory.memtotal")));
for (SubscriptionPool pool : getRamBasedSubscriptions()) {
if (pool.subscriptionName.contains("8GB")) {
clienttasks.subscribe(null, null, pool.poolId, null, null, "1", null, null, null, null, null, null, null);
for (String productName : pool.provides) {
for (InstalledProduct installed : InstalledProduct.findAllInstancesWithMatchingFieldFromList("productName", productName, clienttasks.getCurrentlyInstalledProducts())) {
if (ramvalue <= 4) {
Assert.assertEquals(installed.status.trim(), "Subscribed", "Status of installed product '" + installed.productName + "'.");
factsMap.put("memory.memtotal", String.valueOf(GBToKBConverter(5)));
clienttasks.createFactsFileWithOverridingValues(factsMap);
clienttasks.facts(null, true, null, null, null, null);
ramvalue = KBToGBConverter(Integer.parseInt(clienttasks.getFactValue("memory.memtotal")));
} else if (ramvalue > 4 && ramvalue <= 8) {
Assert.assertEquals(installed.status.trim(), "Subscribed", "Status of installed product '" + installed.productName + "'.");
factsMap.put("memory.memtotal", String.valueOf(GBToKBConverter(9)));
clienttasks.createFactsFileWithOverridingValues(factsMap);
clienttasks.facts(null, true, null, null, null, null);
ramvalue = KBToGBConverter(Integer.parseInt(clienttasks.getFactValue("memory.memtotal")));
} else {
Assert.assertEquals(installed.status.trim(), "Partially Subscribed", "Status of installed product '" + installed.productName + "'.");
}
}
}
}
}
}
use of rhsm.data.InstalledProduct in project rhsm-qe by RedHatQE.
the class RegisterTests method testRegisterWithAutosubscribe_DEPRECATED_2.
@Test(description = "subscription-manager-cli: register to a Candlepin server using autosubscribe functionality", groups = { "Tier1Tests", "RegisterWithAutosubscribe_Test", "blockedByBug-602378", "blockedByBug-616137", "blockedByBug-678049", "blockedByBug-737762", "blockedByBug-743082" }, enabled = false)
@Deprecated
public void testRegisterWithAutosubscribe_DEPRECATED_2() throws JSONException, Exception {
log.info("RegisterWithAutosubscribe_Test Strategy:");
log.info(" 1. Change the rhsm.conf configuration for productCertDir to point to a new temporary product cert directory.");
log.info(" 2. Register with autosubscribe and assert that no product binding has occurred.");
log.info(" 3. Using the candlepin REST API, we will find an available pool that provides a product that we have installed.");
log.info(" 4. Copy the installed product to a temporary product cert directory so that we can isolate the expected product that will be autosubscribed.");
log.info(" 5. Reregister with autosubscribe and assert that the temporary product has been bound.");
// get the product certs that are currently installed
List<ProductCert> installedProductCerts = clienttasks.getCurrentProductCerts();
// create a clean temporary productCertDir and change the rhsm.conf to point to it
// incase something was leftover from a prior run
RemoteFileTasks.runCommandAndAssert(client, "rm -rf " + tmpProductCertDir, Integer.valueOf(0));
RemoteFileTasks.runCommandAndAssert(client, "mkdir " + tmpProductCertDir, Integer.valueOf(0));
// store the original productCertDir
this.productCertDir = clienttasks.productCertDir;
clienttasks.updateConfFileParameter(clienttasks.rhsmConfFile, "productCertDir", tmpProductCertDir);
// Register and assert that no products appear to be installed since we changed the productCertDir to a temporary directory
SSHCommandResult sshCommandResult = clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, Boolean.TRUE, null, null, (String) null, null, null, null, true, false, null, null, null, null);
// [root@jsefler-r63-server ~]# subscription-manager register --username testuser1 --password password --auto --org admin
// The system has been registered with id: 243ea73d-01bb-458d-a7a5-2d61fde69494
// Installed Product Current Status:
// pre-fix for blockedByBug-678049 Assert.assertContainsNoMatch(sshCommandResult.getStdout().trim(), "^Subscribed to Products:", "register with autosubscribe should NOT appear to have subscribed to something when there are no installed products.");
Assert.assertTrue(InstalledProduct.parse(sshCommandResult.getStdout()).isEmpty(), "The Installed Product Current Status should be empty when attempting to register with autosubscribe without any product certs installed.");
Assert.assertEquals(clienttasks.list_(null, null, null, Boolean.TRUE, null, null, null, null, null, null, null, null, null, null).getStdout().trim(), "No installed products to list", "Since we changed the productCertDir configuration to an empty location, we should not appear to have any products installed.");
// subscribe to the first available pool that provides one product (whose product cert was also originally installed)
File tmpProductCertFile = null;
OUTERLOOP: for (SubscriptionPool pool : clienttasks.getCurrentlyAvailableSubscriptionPools()) {
JSONObject jsonPool = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/pools/" + pool.poolId));
JSONArray jsonProvidedProducts = jsonPool.getJSONArray("providedProducts");
if (jsonProvidedProducts.length() == 1) {
// FIXME: I doubt this check is needed anymore
JSONObject jsonProvidedProduct = jsonProvidedProducts.getJSONObject(0);
String productId = jsonProvidedProduct.getString("productId");
// now search for an existing installed product that matches and install it as our new tmpProductCert
for (ProductCert productCert : installedProductCerts) {
if (productCert.productId.equals(productId)) {
tmpProductCertFile = new File(tmpProductCertDir + File.separator + "AutosubscribeProduct_" + productId + ".pem");
client.runCommandAndWait("cp " + productCert.file + " " + tmpProductCertFile);
break OUTERLOOP;
}
}
}
}
if (tmpProductCertFile == null)
throw new SkipException("Could not find an available pool that provides only one product with which to test register with --autosubscribe.");
ProductCert tmpProductCert = clienttasks.getProductCertFromProductCertFile(tmpProductCertFile);
// reregister with autosubscribe and assert that the product is bound
sshCommandResult = clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, Boolean.TRUE, null, null, (String) null, null, null, null, true, false, null, null, null, null);
// assert that the sshCommandResult from register indicates the tmpProductCert was subscribed
/* # subscription-manager register --username=testuser1 --password=password --org=admin --autosubscribe
The system has been registered with id: f95fd9bb-4cc8-428e-b3fd-d656b14bfb89
Installed Product Current Status:
ProductName: Awesome OS for S390X Bits
Status: Subscribed
*/
// assert that our tmp product install appears to have been autosubscribed
InstalledProduct autoSubscribedProduct = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("status", "Subscribed", InstalledProduct.parse(clienttasks.list_(null, null, null, Boolean.TRUE, null, null, null, null, null, null, null, null, null, null).getStdout()));
Assert.assertNotNull(autoSubscribedProduct, "We appear to have autosubscribed to our fake product install.");
// pre-fix for blockedByBug-678049 Assert.assertContainsMatch(sshCommandResult.getStdout().trim(), "^Subscribed to Products:", "The stdout from register with autotosubscribe indicates that we have subscribed to something");
// pre-fix for blockedByBug-678049 Assert.assertContainsMatch(sshCommandResult.getStdout().trim(), "^\\s+"+autoSubscribedProduct.productName.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)"), "Expected ProductName '"+autoSubscribedProduct.productName+"' was reported as autosubscribed in the output from register with autotosubscribe.");
// Assert.assertContainsMatch(sshCommandResult.getStdout().trim(), ".* - Subscribed", "The stdout from register with autotosubscribe indicates that we have automatically subscribed at least one of this system's installed products to an available subscription pool.");
List<InstalledProduct> autosubscribedProductStatusList = InstalledProduct.parse(sshCommandResult.getStdout());
Assert.assertEquals(autosubscribedProductStatusList.size(), 1, "Only one product appears installed.");
Assert.assertEquals(autosubscribedProductStatusList.get(0), new InstalledProduct(tmpProductCert.productName, null, null, null, "Subscribed", null, null, null), "As expected, ProductName '" + tmpProductCert.productName + "' was reported as subscribed in the output from register with autotosubscribe.");
}
use of rhsm.data.InstalledProduct in project rhsm-qe by RedHatQE.
the class RegisterTests method testRegisterWithAutosubscribe_DEPRECATED.
@Test(description = "subscription-manager-cli: register to a Candlepin server using autosubscribe functionality", groups = { "Tier1Tests", "RegisterWithAutosubscribe_Test", "blockedByBug-602378", "blockedByBug-616137", "blockedByBug-678049", "blockedByBug-737762", "blockedByBug-743082" }, // the strategy for this test has been improved in the new implementation of RegisterWithAutosubscribe_Test()
enabled = false)
@Deprecated
public void testRegisterWithAutosubscribe_DEPRECATED() throws JSONException, Exception {
log.info("RegisterWithAutosubscribe_Test Strategy:");
log.info(" For DEV and QA testing purposes, we may not have valid products installed on the client, therefore we will fake an installed product by following this strategy:");
log.info(" 1. Change the rhsm.conf configuration for productCertDir to point to a new temporary product cert directory.");
log.info(" 2. Register with autosubscribe and assert that no product binding has occurred.");
log.info(" 3. Subscribe to a randomly available pool");
log.info(" 4. Copy the downloaded entitlement cert to the temporary product cert directory.");
log.info(" (this will fake rhsm into believing that the same product is installed)");
log.info(" 5. Reregister with autosubscribe and assert that a product has been bound.");
// create a clean temporary productCertDir and change the rhsm.conf to point to it
// incase something was leftover from a prior run
RemoteFileTasks.runCommandAndAssert(client, "rm -rf " + tmpProductCertDir, Integer.valueOf(0));
RemoteFileTasks.runCommandAndAssert(client, "mkdir " + tmpProductCertDir, Integer.valueOf(0));
// store the original productCertDir
this.productCertDir = clienttasks.productCertDir;
clienttasks.updateConfFileParameter(clienttasks.rhsmConfFile, "productCertDir", tmpProductCertDir);
// Register and assert that no products appear to be installed since we changed the productCertDir to a temporary directory
clienttasks.unregister(null, null, null, null);
SSHCommandResult sshCommandResult = clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, Boolean.TRUE, null, null, (String) null, null, null, null, null, false, null, null, null, null);
// [root@jsefler-r63-server ~]# subscription-manager register --username testuser1 --password password --auto --org admin
// The system has been registered with id: 243ea73d-01bb-458d-a7a5-2d61fde69494
// Installed Product Current Status:
// ProductName: Awesome OS for S390 Bits
// Status: Not Subscribed
//
// ProductName: Stackable with Awesome OS for x86_64 Bits
// Status: Subscribed
// pre-fix for blockedByBug-678049 Assert.assertContainsNoMatch(sshCommandResult.getStdout().trim(), "^Subscribed to Products:", "register with autosubscribe should NOT appear to have subscribed to something when there are no installed products.");
Assert.assertTrue(InstalledProduct.parse(sshCommandResult.getStdout()).isEmpty(), "The Installed Product Current Status should be empty when attempting to register with autosubscribe without any product certs installed.");
Assert.assertEquals(clienttasks.list_(null, null, null, Boolean.TRUE, null, null, null, null, null, null, null, null, null, null).getStdout().trim(), "No installed products to list", "Since we changed the productCertDir configuration to an empty location, we should not appear to have any products installed.");
// List <InstalledProduct> currentlyInstalledProducts = InstalledProduct.parse(clienttasks.list_(null, null, null, Boolean.TRUE, null, null, null).getStdout());
// for (String status : new String[]{"Not Subscribed","Subscribed"}) {
// Assert.assertNull(InstalledProduct.findFirstInstanceWithMatchingFieldFromList("status", status, currentlyInstalledProducts),
// "When no product certs are installed, then we should not be able to find a installed product with status '"+status+"'.");
// }
// subscribe to a randomly available pool
/* This is too random
List<SubscriptionPool> pools = clienttasks.getCurrentlyAvailableSubscriptionPools();
SubscriptionPool pool = pools.get(randomGenerator.nextInt(pools.size())); // randomly pick a pool
File entitlementCertFile = clienttasks.subscribeToSubscriptionPoolUsingPoolId(pool);
*/
// subscribe to the first available pool that provides one product
File entitlementCertFile = null;
for (SubscriptionPool pool : clienttasks.getCurrentlyAvailableSubscriptionPools()) {
JSONObject jsonPool = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/pools/" + pool.poolId));
JSONArray jsonProvidedProducts = jsonPool.getJSONArray("providedProducts");
if (jsonProvidedProducts.length() == 1) {
entitlementCertFile = clienttasks.subscribeToSubscriptionPool(pool, /*sm_serverAdminUsername*/
sm_clientUsername, /*sm_serverAdminPassword*/
sm_clientPassword, sm_serverUrl);
break;
}
}
if (entitlementCertFile == null)
throw new SkipException("Could not find an available pool that provides only one product with which to test register with --autosubscribe.");
// copy the downloaded entitlement cert to the temporary product cert directory (this will fake rhsm into believing that the same product is installed)
RemoteFileTasks.runCommandAndAssert(client, "cp " + entitlementCertFile.getPath() + " " + tmpProductCertDir, Integer.valueOf(0));
File tmpProductCertFile = new File(tmpProductCertDir + File.separator + entitlementCertFile.getName());
ProductCert fakeProductCert = clienttasks.getProductCertFromProductCertFile(tmpProductCertFile);
// reregister with autosubscribe and assert that the product is bound
clienttasks.unregister(null, null, null, null);
sshCommandResult = clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, Boolean.TRUE, null, null, (String) null, null, null, null, null, false, null, null, null, null);
// assert that the sshCommandResult from register indicates the fakeProductCert was subscribed
/* # subscription-manager register --username=testuser1 --password=password
d67df9c8-f381-4449-9d17-56094ea58092 testuser1
Subscribed to Products:
RHEL for Physical Servers SVC(37060)
Red Hat Enterprise Linux High Availability (for RHEL Entitlement)(4)
*/
/* # subscription-manager register --username=testuser1 --password=password
cadf825a-6695-41e3-b9eb-13d7344159d3 jsefler-onprem03.usersys.redhat.com
Installed Products:
Clustering Bits - Subscribed
Awesome OS Server Bits - Not Installed
*/
/* # subscription-manager register --username=testuser1 --password=password --org=admin --autosubscribe
The system has been registered with id: f95fd9bb-4cc8-428e-b3fd-d656b14bfb89
Installed Product Current Status:
ProductName: Awesome OS for S390X Bits
Status: Subscribed
*/
// assert that our fake product install appears to have been autosubscribed
InstalledProduct autoSubscribedProduct = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("status", "Subscribed", InstalledProduct.parse(clienttasks.list_(null, null, null, Boolean.TRUE, null, null, null, null, null, null, null, null, null, null).getStdout()));
Assert.assertNotNull(autoSubscribedProduct, "We appear to have autosubscribed to our fake product install.");
// pre-fix for blockedByBug-678049 Assert.assertContainsMatch(sshCommandResult.getStdout().trim(), "^Subscribed to Products:", "The stdout from register with autotosubscribe indicates that we have subscribed to something");
// pre-fix for blockedByBug-678049 Assert.assertContainsMatch(sshCommandResult.getStdout().trim(), "^\\s+"+autoSubscribedProduct.productName.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)"), "Expected ProductName '"+autoSubscribedProduct.productName+"' was reported as autosubscribed in the output from register with autotosubscribe.");
// Assert.assertContainsMatch(sshCommandResult.getStdout().trim(), ".* - Subscribed", "The stdout from register with autotosubscribe indicates that we have automatically subscribed at least one of this system's installed products to an available subscription pool.");
List<InstalledProduct> autosubscribedProductStatusList = InstalledProduct.parse(sshCommandResult.getStdout());
Assert.assertEquals(autosubscribedProductStatusList.size(), 1, "Only one product was autosubscribed.");
Assert.assertEquals(autosubscribedProductStatusList.get(0), new InstalledProduct(fakeProductCert.productName, null, null, null, "Subscribed", null, null, null), "As expected, ProductName '" + fakeProductCert.productName + "' was reported as subscribed in the output from register with autotosubscribe.");
// WARNING The following two asserts lead to misleading failures when the entitlementCertFile that we using to fake as a tmpProductCertFile happens to have multiple bundled products inside. This is why we search for an available pool that provides one product early in this test.
// Assert.assertContainsMatch(sshCommandResult.getStdout().trim(), "^\\s+"+autoSubscribedProduct.productName.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)")+" - Subscribed", "Expected ProductName '"+autoSubscribedProduct.productName+"' was reported as autosubscribed in the output from register with autotosubscribe.");
// Assert.assertNotNull(ProductSubscription.findFirstInstanceWithMatchingFieldFromList("productName", autoSubscribedProduct.productName, clienttasks.getCurrentlyConsumedProductSubscriptions()),"Expected ProductSubscription with ProductName '"+autoSubscribedProduct.productName+"' is consumed after registering with autosubscribe.");
}
Aggregations