use of rhsm.data.ProductCert in project rhsm-qe by RedHatQE.
the class SubscribeTests method testAutoSubscribeOnVirtualSystemsFavorVirtualPools.
@// update=true, // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36577", "RHEL7-51378" }, 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 on a virtual system should favor virtual pools", groups = { "Tier2Tests", "blockedByBug-927101", "AutoSubscribeOnVirtualSystemsFavorVirtualPools_Test" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testAutoSubscribeOnVirtualSystemsFavorVirtualPools() throws JSONException, Exception {
// force the system to be virtual
Map<String, String> factsMap = new HashMap<String, String>();
factsMap.put("virt.is_guest", String.valueOf(Boolean.TRUE));
clienttasks.createFactsFileWithOverridingValues(factsMap);
// get the current product certs
List<ProductCert> productCerts = clienttasks.getCurrentProductCerts();
if (rhsmProductCertDir == null) {
rhsmProductCertDir = clienttasks.getConfFileParameter(clienttasks.rhsmConfFile, "rhsm", "productCertDir");
}
// register
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);
// get the available pools
List<SubscriptionPool> availablePools = clienttasks.getCurrentlyAvailableSubscriptionPools();
// find available subscriptions for which both a Virtual and a Physical pool is available
boolean testAttempted = false;
for (SubscriptionPool virtualPool : SubscriptionPool.findAllInstancesWithMatchingFieldFromList("machineType", "Virtual", availablePools)) {
for (SubscriptionPool physicalPool : SubscriptionPool.findAllInstancesWithMatchingFieldFromList("machineType", "Physical", availablePools)) {
if (virtualPool.productId.equals(physicalPool.productId)) {
// found a pair of subscriptions that we can test
// get the product certs that are provided by these pools
List<String> virtualProductIds = CandlepinTasks.getPoolProvidedProductIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, virtualPool.poolId);
List<String> physicalProductIds = CandlepinTasks.getPoolProvidedProductIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, physicalPool.poolId);
// TEMPORARY WORKAROUND
if (virtualPool.subscriptionType.contains("(Temporary)") && virtualProductIds.isEmpty() && !physicalProductIds.isEmpty()) {
boolean invokeWorkaroundWhileBugIsOpen = true;
// Bug 1394401 - The list of provided products for Temporary Subscriptions is empty
String bugId = "1394401";
try {
if (invokeWorkaroundWhileBugIsOpen && BzChecker.getInstance().isBugOpen(bugId)) {
log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId).toString() + " Bugzilla " + bugId + ". (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId + ")");
SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId);
} else {
invokeWorkaroundWhileBugIsOpen = false;
}
} catch (BugzillaAPIException be) {
/* ignore exception */
} catch (RuntimeException re) {
/* ignore exception */
}
if (invokeWorkaroundWhileBugIsOpen) {
log.warning("Virtual pool '" + virtualPool.poolId + "' and and Physical pool '" + physicalPool.poolId + "' are not good candidates for this test while bug '" + bugId + "' is open. Looking for another pair.");
continue;
}
}
// END OF WORKAROUND
Assert.assertTrue(virtualProductIds.containsAll(physicalProductIds) && physicalProductIds.containsAll(virtualProductIds), "Provided product ids from virtual pool '" + virtualPool.poolId + "' and physical pool '" + physicalPool.poolId + "' sharing a common productId '" + virtualPool.productId + "' should be the same.");
// configure a temporary product cert directory containing only these provided product certs
RemoteFileTasks.runCommandAndAssert(client, "mkdir -p " + tmpProductCertDir, Integer.valueOf(0));
RemoteFileTasks.runCommandAndAssert(client, "rm -f " + tmpProductCertDir + "/*.pem", Integer.valueOf(0));
List<String> productCertIdsFound = new ArrayList<String>();
List<String> productCertNamesFound = new ArrayList<String>();
for (ProductCert productCert : productCerts) {
if (virtualProductIds.contains(productCert.productId)) {
RemoteFileTasks.runCommandAndAssert(client, "cp " + productCert.file + " " + tmpProductCertDir, Integer.valueOf(0));
productCertIdsFound.add(productCert.productId);
productCertNamesFound.add(productCert.productName);
}
}
clienttasks.updateConfFileParameter(clienttasks.rhsmConfFile, "productCertDir", tmpProductCertDir);
if (!productCertIdsFound.isEmpty()) {
// start testing... autosubscribe and assert the consumed subscriptions are Virtual
clienttasks.unsubscribe(true, (BigInteger) null, null, null, null, null, null);
clienttasks.subscribe(true, null, null, (String) null, null, null, null, null, null, null, null, null, null);
for (ProductSubscription productSubscription : clienttasks.getCurrentlyConsumedProductSubscriptions()) {
Assert.assertEquals(productSubscription.machineType, "Virtual", "Autosubscribing a virtual system should favor granting an entitlement from a Virtual pool that provides " + productCertIdsFound + " over a Physical pool that provides " + productCertIdsFound + "'.");
// TODO We may need to comment this out or fix it if it starts failing due to changes in the subscription data.
Assert.assertTrue(productSubscription.provides.containsAll(productCertNamesFound), "The autosubscribed virtual subscription '" + productSubscription + "' provides for all of the installed products " + productCertNamesFound + ". (Note: This could potentially fail when the provided product names are do not exactly match the installed product cert names which is okay since the productIds are what really matter).");
testAttempted = true;
}
// testAttempted = true; // relocated to inside of loop above
} else {
log.info("Did not find any installed product certs provided by Virtual and Physical subscriptions '" + virtualPool.productId + "'.");
}
}
}
}
if (!testAttempted)
throw new SkipException("Did not find all the resources needed to attempt this test.");
}
use of rhsm.data.ProductCert in project rhsm-qe by RedHatQE.
the class ReleaseTests method verifyReleaseListMatchesCDN.
protected void verifyReleaseListMatchesCDN(String proxy_hostname, String proxy_port, String proxy_username, String proxy_password) {
// assemble the proxy from the proxy_hostname and proxy_port
String proxy = proxy_hostname;
if (proxy_hostname != null && proxy_port != null)
proxy += ":" + proxy_port;
// get the current base RHEL product cert
ProductCert rhelProductCert = clienttasks.getCurrentRhelProductCert();
Assert.assertNotNull(rhelProductCert, "Only one RHEL product cert is installed.");
// make sure we are newly registered
SSHCommandResult registerResult = clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, true, null, null, (List<String>) null, null, null, null, true, null, proxy, proxy_username, proxy_password, null);
// if (!InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productId", rhelProductCert.productId, clienttasks.getCurrentlyInstalledProducts()).status.equals("Subscribed")) {
if (!InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productName", rhelProductCert.productName, InstalledProduct.parse(registerResult.getStdout())).status.equals("Subscribed")) {
clienttasks.listAvailableSubscriptionPools();
throw new SkipException("Autosubscribe could not find an available subscription that provides RHEL content for installed RHEL product:" + rhelProductCert.productNamespace);
}
// ^^ that is faster, but the following is more reliable...
/*
// find an available RHEL subscription pool that provides for this base RHEL product cert
List<SubscriptionPool> rhelSubscriptionPools = clienttasks.getCurrentlyAvailableSubscriptionPools(rhelProductCert.productId, sm_serverUrl);
if (rhelSubscriptionPools.isEmpty()) throw new SkipException("Cannot find an available SubscriptionPool that provides for this installed RHEL Product: "+rhelProductCert);
SubscriptionPool rhelSubscriptionPool = rhelSubscriptionPools.get(0); // choose one
// subscribe to the RHEL subscription
File rhelEntitlementCertFile = clienttasks.subscribeToSubscriptionPool(rhelSubscriptionPool);
File rhelEntitlementCertKeyFile = clienttasks.getEntitlementCertKeyFileCorrespondingToEntitlementCertFile(rhelEntitlementCertFile);
*/
// get the currently expected release listing based on the currently enabled repos
List<String> expectedReleases = clienttasks.getCurrentlyExpectedReleases();
// get the actual release listing
List<String> actualReleases = clienttasks.getCurrentlyAvailableReleases(proxy, proxy_username, proxy_password, null);
// TEMPORARY WORKAROUND FOR BUG
boolean invokeWorkaroundWhileBugIsOpen = true;
String bugId = "1108257";
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) {
if (rhelProductCert.productNamespace.providedTags.contains("rhel-5-client-workstation")) {
throw new SkipException("Skipping this test while bug '" + bugId + "' is open. (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId + ")");
}
}
// TEMPORARY WORKAROUND FOR BUG
if (actualReleases.isEmpty() && !expectedReleases.isEmpty()) {
invokeWorkaroundWhileBugIsOpen = true;
// Bug 1518886 - RHEL-ALT-7.5 product certs should also provide tag "rhel-7"
bugId = "1518886";
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) {
if (Arrays.asList(new String[] { // this is a RHEL-ALT system
"419", /* Red Hat Enterprise Linux for ARM 64 */
"420", /* Red Hat Enterprise Linux for Power 9 */
"434", /* Red Hat Enterprise Linux for IBM System z (Structure A) */
"363", /* Red Hat Enterprise Linux for ARM 64 Beta */
"362", /* Red Hat Enterprise Linux for Power 9 Beta */
"433" /* Red Hat Enterprise Linux for IBM System z (Structure A) Beta */
}).contains(rhelProductCert.productId)) {
throw new SkipException("subscription-manager release listings on RHEL-ALT will be empty until bug '" + bugId + "' is fixed.");
}
}
}
// END OF WORKAROUND
// assert that they are equivalent
Assert.assertTrue(expectedReleases.containsAll(actualReleases) && actualReleases.containsAll(expectedReleases), "The actual subscription-manager releases list " + actualReleases + " matches the expected consolidated CDN listing " + expectedReleases + " after successfully autosubscribing to installed RHEL product: " + rhelProductCert.productName);
}
use of rhsm.data.ProductCert in project rhsm-qe by RedHatQE.
the class ReleaseTests method testGetReleaseListWithoutHavingAnyEntitlements.
@// update=true // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-19996", "RHEL7-51029" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.NEGATIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier1")
@Test(description = "attempt to get the subscription-manager release list without having subscribed to any entitlements", groups = { "Tier1Tests", "blockedByBug-824979" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testGetReleaseListWithoutHavingAnyEntitlements() {
// make sure we are newly registered
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);
// make sure we are not auto healing ourself with any entitlements
clienttasks.autoheal(null, null, true, null, null, null, null);
clienttasks.unsubscribe(true, (List<BigInteger>) null, null, null, null, null, null);
// assert no releases are listed
Assert.assertTrue(clienttasks.getCurrentlyAvailableReleases(null, null, null, null).isEmpty(), "No releases should be available without having been entitled to anything.");
// assert feedback from release --list
SSHCommandResult result = clienttasks.release_(null, true, null, null, null, null, null, null);
Integer expectedExitCode = new Integer(255);
// EX_CONFIG // post commit df95529a5edd0be456b3528b74344be283c4d258 bug 1119688
if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.13.8-1"))
expectedExitCode = new Integer(78);
String rhelTag = "rhel-" + clienttasks.redhatReleaseX;
if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.20.10-1")) {
// commit 76273403e6e3f7fa9811ef252a5a7ce4d84f7aa3 // bug 1510024: Handle rhel-alt product tags properly
rhelTag = "rhel-" + clienttasks.redhatReleaseX + "|" + "rhel-alt-" + clienttasks.redhatReleaseX;
}
List<ProductCert> productCertsProvidingRhelTag = clienttasks.getCurrentProductCerts(rhelTag);
productCertsProvidingRhelTag = clienttasks.filterTrumpedDefaultProductCerts(productCertsProvidingRhelTag);
if (productCertsProvidingRhelTag.size() > 1) {
// Bug 1506271 - redhat-release is providing more than 1 variant specific product cert
log.warning("Installed product cert providing rhel tag '" + rhelTag + "': " + productCertsProvidingRhelTag);
Assert.assertEquals(result.getStdout().trim(), "", "stdout from release --list when more than one product cert with tag '" + rhelTag + "' is installed.");
String expectedStderr = "Error: More than one release product certificate installed.";
if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.20.8-1")) {
// commit 286b4fcdc8dba6e75a7b50e5db912a99c8f7ada2 // bug 1464571: 'sub-man release' prints error for more prod. certs.
Assert.assertTrue(result.getStderr().trim().startsWith(expectedStderr), "stderr from release --list when more than one product cert with tag '" + rhelTag + "' is installed should be '" + expectedStderr + "'.");
} else {
Assert.assertEquals(result.getStderr().trim(), expectedStderr, "stderr from release --list when more than one product cert with tag '" + rhelTag + "' is installed should be '" + expectedStderr + "'.");
}
} else {
Assert.assertEquals(result.getStdout().trim(), "", "stdout from release --list without any entitlements");
Assert.assertEquals(result.getStderr().trim(), "No release versions available, please check subscriptions.", "stderr from release --list without any entitlements");
}
Assert.assertEquals(result.getExitCode(), expectedExitCode, "exitCode from release --list without any entitlements");
}
use of rhsm.data.ProductCert in project rhsm-qe by RedHatQE.
the class ReleaseTests method testReleaseListExcludes60OnRHEL6System.
@// update=true // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6 }, testCaseID = { "RHEL6-20004" }, 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 = "register to a RHEL subscription and verify that release --list excludes 6.0", groups = { "Tier1Tests", "blockedByBug-802245" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testReleaseListExcludes60OnRHEL6System() throws JSONException, Exception {
if (!clienttasks.redhatReleaseX.equals("6"))
throw new SkipException("This test is only applicable on RHEL6.");
// make sure we are newly registered with autosubscribe
clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, true, null, null, (List<String>) null, null, null, null, true, null, null, null, null, null);
// get the current base RHEL product cert
/* this block of logic does not account for the presence of a /etc/pki/product-default/ cert
String providingTag = "rhel-"+clienttasks.redhatReleaseX;
List<ProductCert> rhelProductCerts = clienttasks.getCurrentProductCerts(providingTag);
Assert.assertEquals(rhelProductCerts.size(), 1, "Only one product cert is installed that provides RHEL tag '"+providingTag+"'");
ProductCert rhelProductCert = rhelProductCerts.get(0);
*/
ProductCert rhelProductCert = clienttasks.getCurrentRhelProductCert();
// assert that it was autosubscribed
InstalledProduct rhelInstalledProduct = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productId", rhelProductCert.productId, clienttasks.getCurrentlyInstalledProducts());
Assert.assertNotNull(rhelInstalledProduct, "Our base installed RHEL product was autosubscribed during registration.");
// get the actual release listing
List<String> actualReleases = clienttasks.getCurrentlyAvailableReleases(null, null, null, null);
// assert that the list excludes 6.0, but includes the current X.Y release
String release60 = "6.0";
Assert.assertTrue(!actualReleases.contains(release60), "The subscription-manager releases list should exclude '" + release60 + "' since '" + clienttasks.command + "' did not exist in RHEL Release '" + release60 + "'.");
// NOT PRACTICAL SINCE CONTENT FROM THIS Y-STREAM MAY NOT BE AVAILABLE UNTIL GA Assert.assertTrue(actualReleases.contains(clienttasks.redhatReleaseXY), "The subscription-manager releases list should include '"+clienttasks.redhatReleaseXY+"' since it is the current RHEL Release under test.");
}
use of rhsm.data.ProductCert in project rhsm-qe by RedHatQE.
the class ServiceLevelTests method getExemptInstalledProductAndServiceLevelDataAsListOfLists.
/**
* @return List of [Object bugzilla, String installedProductId, String serviceLevel]
*/
protected List<List<Object>> getExemptInstalledProductAndServiceLevelDataAsListOfLists() throws JSONException, Exception {
List<List<Object>> ll = new ArrayList<List<Object>>();
if (!isSetupBeforeSuiteComplete)
return ll;
// get the available service levels
List<String> serviceLevels = new ArrayList<String>();
for (List<Object> availableServiceLevelData : getAllAvailableServiceLevelDataAsListOfLists()) {
// availableServiceLevelData : Object bugzilla, String serviceLevel
serviceLevels.add((String) availableServiceLevelData.get(1));
}
// get all of the installed products
List<ProductCert> installedProductCerts = clienttasks.getCurrentProductCerts();
// process the available SubscriptionPools looking for provided productIds from a pool that has an exempt service level
for (List<Object> subscriptionPoolsData : getAvailableSubscriptionPoolsDataAsListOfLists()) {
SubscriptionPool subscriptionPool = (SubscriptionPool) subscriptionPoolsData.get(0);
JSONObject jsonPool = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/pools/" + subscriptionPool.poolId));
JSONArray jsonProvidedProducts = jsonPool.getJSONArray("providedProducts");
String value = CandlepinTasks.getPoolProductAttributeValue(jsonPool, "support_level_exempt");
// skip this subscriptionPool when "support_level_exempt" productAttribute is NOT true
if (value == null)
continue;
if (!Boolean.valueOf(value))
continue;
// process each of the provided products (exempt) to see if it is installed
for (int i = 0; i < jsonProvidedProducts.length(); i++) {
JSONObject jsonProvidedProduct = (JSONObject) jsonProvidedProducts.get(i);
String productId = jsonProvidedProduct.getString("productId");
// is productId installed?
if (ProductCert.findFirstInstanceWithMatchingFieldFromList("productId", productId, installedProductCerts) != null) {
// found an installed exempt product, add a row for each of the service levels
for (String serviceLevel : serviceLevels) {
// Object bugzilla, String installedProductId, String serviceLevel
ll.add(Arrays.asList(new Object[] { null, productId, serviceLevel }));
}
}
}
}
return ll;
}
Aggregations