use of rhsm.data.ContentNamespace in project rhsm-qe by RedHatQE.
the class ContentTests method testYumRepoListsEnabledContent.
@// update=true // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-20085", "RHEL7-51099" }, 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 content flag : Default content flag should enable", groups = { "Tier1Tests", "blockedByBug-804227", "blockedByBug-871146", "blockedByBug-924919", "blockedByBug-962520" }, enabled = true)
@ImplementsNitrateTest(caseId = 47578, fromPlan = 2479)
public void testYumRepoListsEnabledContent() throws JSONException, Exception {
// Original code from ssalevan
// ArrayList<String> repos = this.getYumRepolist();
//
// for (EntitlementCert cert:clienttasks.getCurrentEntitlementCerts()){
// if(cert.enabled.contains("1"))
// Assert.assertTrue(repos.contains(cert.label),
// "Yum reports enabled content subscribed to repo: " + cert.label);
// else
// Assert.assertFalse(repos.contains(cert.label),
// "Yum reports enabled content subscribed to repo: " + cert.label);
// }
List<ProductCert> currentProductCerts = clienttasks.getCurrentProductCerts();
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);
if (clienttasks.subscribeToTheCurrentlyAvailableSubscriptionPoolsCollectively().size() <= 0)
throw new SkipException("No available subscriptions were found. Therefore we cannot perform this test.");
List<EntitlementCert> entitlementCerts = clienttasks.getCurrentEntitlementCerts();
// or maybe we should skip when nothing is consumed
Assert.assertTrue(!entitlementCerts.isEmpty(), "After subscribing to all available subscription pools, there must be some entitlements.");
ArrayList<String> repolist = clienttasks.getYumRepolist("enabled");
for (EntitlementCert entitlementCert : entitlementCerts) {
for (ContentNamespace contentNamespace : entitlementCert.contentNamespaces) {
if (!contentNamespace.type.equalsIgnoreCase("yum"))
continue;
if (contentNamespace.enabled) {
if (clienttasks.areAllRequiredTagsInContentNamespaceProvidedByProductCerts(contentNamespace, currentProductCerts)) {
Assert.assertTrue(repolist.contains(contentNamespace.label), "Yum repolist enabled includes enabled repo id/label '" + contentNamespace.label + "' after having subscribed to Subscription ProductId '" + entitlementCert.orderNamespace.productId + "'.");
} else {
Assert.assertFalse(repolist.contains(contentNamespace.label), "Yum repolist enabled excludes enabled repo id/label '" + contentNamespace.label + "' after having subscribed to Subscription ProductId '" + entitlementCert.orderNamespace.productId + "' because not all requiredTags (" + contentNamespace.requiredTags + ") in the contentNamespace are provided by the currently installed productCerts.");
}
} else {
Assert.assertFalse(repolist.contains(contentNamespace.label), "Yum repolist enabled excludes disabled repo id/label '" + contentNamespace.label + "' after having subscribed to Subscription ProductId '" + entitlementCert.orderNamespace.productId + "'.");
}
}
}
}
use of rhsm.data.ContentNamespace in project rhsm-qe by RedHatQE.
the class DevSKUTests method testDevSku.
// 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-25335", "RHEL7-52092" }, 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 = "given an available SKU, configure the system with custom facts dev_sku=SKU, register the system with auto-attach and verify several requirements of the attached entitlement", groups = { "Tier1Tests" }, dataProvider = "getDevSkuData", enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testDevSku(Object bugzilla, String devSku, String devPlatform) throws JSONException, Exception {
// get the JSON product representation of the devSku
String resourcePath = "/products/" + devSku;
String ownerKey = sm_clientOrg;
if (sm_clientOrg == null)
ownerKey = clienttasks.getCurrentlyRegisteredOwnerKey();
if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.0.0"))
resourcePath = "/owners/" + ownerKey + resourcePath;
JSONObject jsonDevSkuProduct = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, resourcePath));
if (jsonDevSkuProduct.has("displayMessage")) {
// indicative that: // Product with ID 'dev-mkt-product' could not be found.
}
// instrument the system facts to behave as a vagrant image
Map<String, String> factsMap = new HashMap<String, String>();
factsMap.put("dev_sku", devSku);
factsMap.put("dev_platform", devPlatform);
clienttasks.createFactsFileWithOverridingValues(factsMap);
// mark the rhsm.log file
String logMarker = System.currentTimeMillis() + " Testing VerifyDevSku_Test...";
RemoteFileTasks.markFile(client, clienttasks.rhsmLogFile, logMarker);
// register with auto subscribe and force (to unregister anyone that is already registered)
SSHCommandResult registerResult = clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, true, null, null, (String) null, null, null, null, true, null, null, null, null, null);
// get the tail of the marked rhsm.log file
String logTail = RemoteFileTasks.getTailFromMarkedFile(client, clienttasks.rhsmLogFile, logMarker, null).trim();
// assert when /etc/candlepin/candlepin.conf candlepin.standalone = true (FYI: candlepin.standalone=false is synonymous with a hosted candlepin deployment)
// 2016-01-05 17:02:34,527 [DEBUG] subscription-manager:20144 @connection.py:530 - Making request: POST /candlepin/consumers/21800967-1d20-43a9-9bf3-07c5c7d41f61/entitlements
// 2016-01-05 17:02:34,802 [DEBUG] subscription-manager:20144 @connection.py:562 - Response: status=403, requestUuid=b88c0d1c-0816-4097-89d5-114020d86af1
// 2016-01-05 17:02:34,804 [WARNING] subscription-manager:20144 @managercli.py:201 - Error during auto-attach.
// 2016-01-05 17:02:34,805 [ERROR] subscription-manager:20144 @managercli.py:202 - Development units may only be used on hosted servers and with orgs that have active subscriptions.
// Traceback (most recent call last):
// File "/usr/share/rhsm/subscription_manager/managercli.py", line 197, in autosubscribe
// ents = cp.bind(consumer_uuid) # new style
// File "/usr/lib64/python2.6/site-packages/rhsm/connection.py", line 1148, in bind
// return self.conn.request_post(method)
// File "/usr/lib64/python2.6/site-packages/rhsm/connection.py", line 657, in request_post
// return self._request("POST", method, params)
// File "/usr/lib64/python2.6/site-packages/rhsm/connection.py", line 571, in _request
// self.validateResponse(result, request_type, handler)
// File "/usr/lib64/python2.6/site-packages/rhsm/connection.py", line 621, in validateResponse
// raise RestlibException(response['status'], error_msg, response.get('headers'))
// RestlibException: Development units may only be used on hosted servers and with orgs that have active subscriptions.
String expectedStdError = "Development units may only be used on hosted servers and with orgs that have active subscriptions.";
String expectedLogError = "RestlibException: " + expectedStdError;
if (servertasks.statusStandalone) {
Assert.assertEquals(registerResult.getStderr().trim(), expectedStdError, "When attempting to autosubscribe a consumer with a dev_sku fact against a candlepin.standalone=true server, stderr reports '" + expectedStdError + "'.");
// TEMPORARY WORKAROUND
boolean invokeWorkaroundWhileBugIsOpen = true;
// Bug 1493299 - exception handling for a negative dev_sku test is no longer being logged to rhsm.log
String bugId = "1493299";
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) {
throw new SkipException("Detected that candlepin status standalone=true. DevSku support is only applicable when /etc/candlepin/candlepin candlepin.standalone=false (typical of a hosted candlepin server), but skipped assertion that an rhsm.log error is thrown while bug '" + bugId + "' is open.");
} else
// END OF WORKAROUND
Assert.assertTrue(logTail.contains(expectedLogError), "When attempting to autosubscribe a consumer with a dev_sku fact against a candlepin.standalone=true server, an rhsm.log error is thrown stating '" + expectedLogError + "'.");
throw new SkipException("Detected that candlepin status standalone=true. DevSku support is only applicable when /etc/candlepin/candlepin candlepin.standalone=false (typical of a hosted candlepin server).");
} else {
Assert.assertTrue(!registerResult.getStderr().trim().contains(expectedStdError), "When attempting to autosubscribe a consumer with a dev_sku fact against a candlepin.standalone=false server, stderr does NOT report '" + expectedStdError + "'.");
Assert.assertTrue(!logTail.contains(expectedLogError), "When attempting to autosubscribe a consumer with a dev_sku fact against a candlepin.standalone=false server, an rhsm.log error is NOT thrown stating '" + expectedLogError + "'.");
}
// RestlibException: SKU product not available to this development unit: 'dev-mkt-product'
if (jsonDevSkuProduct.has("displayMessage")) {
expectedStdError = String.format("SKU product not available to this development unit: '%s'", devSku);
if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.3.1-1")) {
// commit 0d5fefcfa8c1c2485921d2dee6633879b1e06931 Correct incorrect punctuation in user messages
expectedStdError = String.format("SKU product not available to this development unit: \"%s\"", devSku);
}
expectedLogError = "RestlibException: " + expectedStdError;
Assert.assertEquals(registerResult.getStderr().trim(), expectedStdError, "When attempting to autosubscribe a consumer with an unknown dev_sku fact against a candlepin.standalone=false server, stderr reports '" + expectedStdError + "'.");
// TEMPORARY WORKAROUND
boolean invokeWorkaroundWhileBugIsOpen = true;
// Bug 1493299 - exception handling for a negative dev_sku test is no longer being logged to rhsm.log
String bugId = "1493299";
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) {
throw new SkipException("Detected that dev_sku '" + devSku + "' was unknown, but skipped verification that a graceful error was logged to rhsm.log while bug '" + bugId + "' is open.");
} else
// END OF WORKAROUND
Assert.assertTrue(logTail.contains(expectedLogError), "When attempting to autosubscribe a consumer with an unknown dev_sku fact against a candlepin.standalone=false server, an rhsm.log error is thrown stating '" + expectedLogError + "'.");
throw new SkipException("Detected that dev_sku '" + devSku + "' was unknown. Verified that a graceful error was logged to rhsm.log.");
}
// assert only one entitlement was granted
List<EntitlementCert> entitlementCerts = clienttasks.getCurrentEntitlementCerts();
Assert.assertEquals(entitlementCerts.size(), 1, "After registering (with autosubscribe) a system with dev_sku fact '" + devSku + "', only one entitlement should be granted.");
EntitlementCert devSkuEntitlement = entitlementCerts.get(0);
ProductSubscription devSkuProductSubscription = clienttasks.getCurrentlyConsumedProductSubscriptions().get(0);
// assert that all of the known installed products are provided by the consumed entitlement
List<InstalledProduct> installedProducts = clienttasks.getCurrentlyInstalledProducts();
List<ProductCert> productCerts = clienttasks.getCurrentProductCerts();
Set installedProductIds = new HashSet<String>();
for (InstalledProduct installedProduct : installedProducts) {
// ignore installed products that are unknown to the candlepin product layer
resourcePath = "/products/" + installedProduct.productId;
if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.0.0"))
resourcePath = "/owners/" + ownerKey + resourcePath;
JSONObject jsonProduct = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, resourcePath));
if (jsonProduct.has("displayMessage")) {
// indicative that: // Product with ID '69' could not be found.
String expectedDisplayMessage = String.format("Product with UUID '%s' could not be found.", installedProduct.productId);
if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.0.0")) {
expectedDisplayMessage = String.format("Product with ID '%s' could not be found.", installedProduct.productId);
}
if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.3.1-1")) {
// commit 0d5fefcfa8c1c2485921d2dee6633879b1e06931 Correct incorrect punctuation in user messages
expectedDisplayMessage = String.format("Product with ID \"%s\" could not be found.", installedProduct.productId);
}
Assert.assertEquals(jsonProduct.getString("displayMessage"), expectedDisplayMessage);
log.info("Installed Product ID '" + installedProduct.productId + "' (" + installedProduct.productName + ") was not recognized by our candlepin server. Therefore this product will not be entitled by the devSku.");
} else {
installedProductIds.add(installedProduct.productId);
}
}
Set<String> entitledProductIds = new HashSet<String>();
for (ProductNamespace productNamespace : devSkuEntitlement.productNamespaces) entitledProductIds.add(productNamespace.id);
Assert.assertTrue(entitledProductIds.containsAll(installedProductIds) && entitledProductIds.size() == installedProductIds.size(), "All (and only) of the currently installed products known by the candlepin product layer are entitled by the devSku entitlement. (Actual entitled product ids " + entitledProductIds + ")");
// assert that all of the entitled product names are shown in the provides list of the consumed devSku product subscription
for (ProductNamespace productNamespace : devSkuEntitlement.productNamespaces) {
Assert.assertTrue(devSkuProductSubscription.provides.contains(productNamespace.name), "The consumed devSku Product Subscriptions provides installed product name '" + productNamespace.name + "'.");
}
// assert that all of the provided product content sets that match this system's arch and installed product tags are available in yum repos
List<String> yumRepos = clienttasks.getYumRepolist("all");
for (ContentNamespace contentNamespace : devSkuEntitlement.contentNamespaces) {
if (contentNamespace.type.equals("yum") && clienttasks.areAllRequiredTagsInContentNamespaceProvidedByProductCerts(contentNamespace, productCerts) && clienttasks.isArchCoveredByArchesInContentNamespace(clienttasks.arch, contentNamespace)) {
Assert.assertTrue(yumRepos.contains(contentNamespace.label), "Found entitled yum repo '" + contentNamespace.label + "' (" + contentNamespace.name + ") (which matches this system arch and installed product tags) among yum repolist all.");
} else {
Assert.assertTrue(!yumRepos.contains(contentNamespace.label), "Did NOT find entitled yum repo '" + contentNamespace.label + "' (" + contentNamespace.name + ") (which does not match this system arch and installed product tags) among yum repolist all.");
}
}
// assert that the entitled service_level defaults to "Self-Service" when not explicitly set by the dev_sku product
String devSkuServiceLevel = CandlepinTasks.getResourceAttributeValue(jsonDevSkuProduct, "support_level");
if (devSkuServiceLevel == null) {
String defaultServiceLevel = "Self-Service";
Assert.assertEquals(devSkuEntitlement.orderNamespace.supportLevel, defaultServiceLevel, "When no support_level attribute exists on the devSku product, the entitlement's order service level defaults to '" + defaultServiceLevel + "'.");
Assert.assertEquals(devSkuProductSubscription.serviceLevel, defaultServiceLevel, "When no support_level attribute exists on the devSku product, the entitled consumed product subscription service level defaults to '" + defaultServiceLevel + "'.");
} else {
Assert.assertEquals(devSkuEntitlement.orderNamespace.supportLevel, devSkuServiceLevel, "When a support_level attribute was set on the devSku product, the entitlement's order service level matches '" + devSkuServiceLevel + "'.");
Assert.assertEquals(devSkuProductSubscription.serviceLevel, devSkuServiceLevel, "When a support_level attribute was set on the devSku product, the consumed product subscription service level matches '" + devSkuServiceLevel + "'.");
}
// assert that the entitled expires_after defaults to 90 days after the registered consumer data when not explicitly set by the dev_sku product
ConsumerCert consumerCert = clienttasks.getCurrentConsumerCert();
Calendar expectedEndDate = Calendar.getInstance();
expectedEndDate.setTimeInMillis(consumerCert.validityNotBefore.getTimeInMillis());
if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.0.30-1")) {
// commit 9302c8f57f37dd5ec3c4020770ac1675a87d99ba 1419576: Pre-date certs to ease clock skew issues
expectedEndDate.add(Calendar.HOUR, Integer.valueOf(1));
log.info("Due to Candlepin RFE Bug 1419576, we need to increment the expected expires_after by one hour to account for pre-dating the consumer identity's validityNotBefore date by one hour.");
}
String devSkuExpiresAfter = CandlepinTasks.getResourceAttributeValue(jsonDevSkuProduct, "expires_after");
if (devSkuExpiresAfter == null) {
// days
String defaultExpiresAfter = "90";
// TEMPORARY WORKAROUND
boolean invokeWorkaroundWhileBugIsOpen = true;
// Bug 1297863 - to account for daylight savings events, dev_sku (CDK) entitlements should add Calendar.DATE units of expires_after to establish the subscription end date
String bugId = "1297863";
try {
if (invokeWorkaroundWhileBugIsOpen && BzChecker.getInstance().isBugOpen(bugId)) {
log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId).toString() + " Bugzilla " + bugId + ". (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId + ")");
SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId);
} else {
invokeWorkaroundWhileBugIsOpen = false;
}
} catch (BugzillaAPIException be) {
/* ignore exception */
} catch (RuntimeException re) {
/* ignore exception */
}
if (invokeWorkaroundWhileBugIsOpen && clienttasks.redhatReleaseX.equals("6") && clienttasks.isPackageVersion("subscription-manager", ">=", "1.15")) {
// NOTE: This will be an hour off when the duration crosses the "Fall" back or "Spring" forward daylight saving dates.
expectedEndDate.add(Calendar.HOUR, Integer.valueOf(defaultExpiresAfter) * 24);
} else
// END OF WORKAROUND
expectedEndDate.add(Calendar.DATE, Integer.valueOf(defaultExpiresAfter));
// /*debugTesting*/expectedEndDate.add(Calendar.SECOND, 20); // to force an expected failure
// Assert.assertEquals(ConsumerCert.formatDateString(devSkuEntitlement.validityNotAfter), ConsumerCert.formatDateString(expectedEndDate), "When no expires_after attribute exists on the devSku product, the entitlement's validityNotAfter date defaults to '"+defaultExpiresAfter+"' days after the date the consumer was registered ("+ConsumerCert.formatDateString(consumerCert.validityNotBefore)+").");
// java.lang.AssertionError: When no expires_after attribute exists on the devSku product, the entitlement's validityNotAfter date defaults to '90' days after the date the consumer was registered (Jul 6 2016 12:19:18 EDT). expected:<Oct 4 2016 12:19:18 EDT> but was:<Oct 4 2016 12:19:17 EDT>
// allow for a few seconds of tolerance
Calendar expectedEndDateUpperTolerance = (Calendar) expectedEndDate.clone();
expectedEndDateUpperTolerance.add(Calendar.SECOND, +5);
Calendar expectedEndDateLowerTolerance = (Calendar) expectedEndDate.clone();
expectedEndDateLowerTolerance.add(Calendar.SECOND, -5);
Assert.assertTrue(devSkuEntitlement.validityNotAfter.before(expectedEndDateUpperTolerance) && devSkuEntitlement.validityNotAfter.after(expectedEndDateLowerTolerance), "When no expires_after attribute exists on the devSku product, the entitlement's validityNotAfter date defaults to '" + defaultExpiresAfter + "' days after the date the consumer was registered (" + ConsumerCert.formatDateString(consumerCert.validityNotBefore) + "). devSkuEntitlement.validityNotAfter expected: <" + ConsumerCert.formatDateString(expectedEndDate) + "> (withn a few seconds of tolerance of) actual: <" + ConsumerCert.formatDateString(devSkuEntitlement.validityNotAfter) + ">");
} else {
// TEMPORARY WORKAROUND
boolean invokeWorkaroundWhileBugIsOpen = true;
// Bug 1297863 - to account for daylight savings events, dev_sku (CDK) entitlements should add Calendar.DATE units of expires_after to establish the subscription end date
String bugId = "1297863";
try {
if (invokeWorkaroundWhileBugIsOpen && BzChecker.getInstance().isBugOpen(bugId)) {
log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId).toString() + " Bugzilla " + bugId + ". (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId + ")");
SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId);
} else {
invokeWorkaroundWhileBugIsOpen = false;
}
} catch (BugzillaAPIException be) {
/* ignore exception */
} catch (RuntimeException re) {
/* ignore exception */
}
if (invokeWorkaroundWhileBugIsOpen && clienttasks.redhatReleaseX.equals("6") && clienttasks.isPackageVersion("subscription-manager", ">=", "1.15")) {
// NOTE: This will be an hour off when the duration crosses the "Fall" back or "Spring" forward daylight saving dates.
expectedEndDate.add(Calendar.HOUR, Integer.valueOf(devSkuExpiresAfter) * 24);
} else
// END OF WORKAROUND
expectedEndDate.add(Calendar.DATE, Integer.valueOf(devSkuExpiresAfter));
// /*debugTesting*/expectedEndDate.add(Calendar.SECOND, 20); // to force an expected failure
// Assert.assertEquals(ConsumerCert.formatDateString(devSkuEntitlement.validityNotAfter), ConsumerCert.formatDateString(expectedEndDate), "When an expires_after attribute exists on the devSku product, the entitlement's validityNotAfter is '"+devSkuExpiresAfter+"' days after the date the consumer was registered ("+ConsumerCert.formatDateString(consumerCert.validityNotBefore)+").");
// java.lang.AssertionError: When an expires_after attribute exists on the devSku product, the entitlement's validityNotAfter is '75' days after the date the consumer was registered (Jul 3 2016 21:43:03 EDT). expected:<Sep 16 2016 21:43:03 EDT> but was:<Sep 16 2016 21:43:02 EDT>
// allow for a few seconds of tolerance
Calendar expectedEndDateUpperTolerance = (Calendar) expectedEndDate.clone();
expectedEndDateUpperTolerance.add(Calendar.SECOND, +5);
Calendar expectedEndDateLowerTolerance = (Calendar) expectedEndDate.clone();
expectedEndDateLowerTolerance.add(Calendar.SECOND, -5);
Assert.assertTrue(devSkuEntitlement.validityNotAfter.before(expectedEndDateUpperTolerance) && devSkuEntitlement.validityNotAfter.after(expectedEndDateLowerTolerance), "When an expires_after attribute exists on the devSku product, the entitlement's validityNotAfter is '" + devSkuExpiresAfter + "' days after the date the consumer was registered (" + ConsumerCert.formatDateString(consumerCert.validityNotBefore) + "). devSkuEntitlement.validityNotAfter expected: <" + ConsumerCert.formatDateString(expectedEndDate) + "> (withn a few seconds of tolerance of) actual: <" + ConsumerCert.formatDateString(devSkuEntitlement.validityNotAfter) + ">");
}
// assert that the pool consumed exists with quantity 1
resourcePath = "/pools/" + devSkuProductSubscription.poolId;
JSONObject jsonDevSkuPool = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, resourcePath));
Assert.assertEquals(jsonDevSkuPool.getInt("quantity"), 1, "The quantity on pool '" + devSkuProductSubscription.poolId + "' generated for devSku product '" + devSku + "'.");
// assert that the pool consumed requires_consumer UUID that is currently registered
// "4a49b1a7-c616-42dd-b96d-62233a4c82b9"
String devSkuRequiresConsumer = CandlepinTasks.getPoolAttributeValue(jsonDevSkuPool, "requires_consumer");
Assert.assertEquals(devSkuRequiresConsumer, consumerCert.consumerid, "The requires_consumer attribute on pool '" + devSkuProductSubscription.poolId + "' generated for devSku product '" + devSku + "'.");
// assert that the pool generated has attribute dev_pool: true
// "true" or "false"
String devSkuDevPool = CandlepinTasks.getPoolAttributeValue(jsonDevSkuPool, "dev_pool");
Assert.assertEquals(Boolean.valueOf(devSkuDevPool), Boolean.TRUE, "The dev_pool attribute on pool '" + devSkuProductSubscription.poolId + "' generated for devSku product '" + devSku + "'.");
}
use of rhsm.data.ContentNamespace in project rhsm-qe by RedHatQE.
the class DockerTests method testContainerConfigurationsAreSetAfterAutoHealingAndUnsubscribing.
@// update=true, // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-26766", "RHEL7-51755" }, 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 = "Verify that entitlements providing containerimage content are copied to relevant directories when attached via auto-heal (as governed by the subscription-manager-plugin-container package)", groups = { "Tier1Tests", "blockedByBug-1165692", "blockedByBug-1344500", "blockedByBug-1343139" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testContainerConfigurationsAreSetAfterAutoHealingAndUnsubscribing() {
// get the list of registry_hostnames from /etc/rhsm/pluginconf.d/container_content.ContainerContentPlugin.conf
String registry_hostnames = clienttasks.getConfFileParameter(containerContentPluginFile.getPath(), "registry_hostnames");
List<String> registryHostnames = Arrays.asList(registry_hostnames.split(" *, *"));
// rhsm-test.redhat.com does NOT appear to come from a redhat.com CDN
if (!registryHostnames.contains("rhsm-test.redhat.com"))
clienttasks.updateConfFileParameter(containerContentPluginFile.getPath(), "registry_hostnames", registry_hostnames + "," + "rhsm-test.redhat.com");
// cdn.rhsm-test.redhat.com DOES appear to come from a redhat.com CDN because it matches regex ^cdn\.(?:.*\.)?redhat\.com$
if (!registryHostnames.contains("cdn.rhsm-test.redhat.com"))
clienttasks.updateConfFileParameter(containerContentPluginFile.getPath(), "registry_hostnames", registry_hostnames + "," + "cdn.rhsm-test.redhat.com");
registry_hostnames = clienttasks.getConfFileParameter(containerContentPluginFile.getPath(), "registry_hostnames");
registryHostnames = Arrays.asList(registry_hostnames.split(" *, *"));
// make sure we are Enforcing selinux
RemoteFileTasks.runCommandAndAssert(client, "setenforce 1", Integer.valueOf(0));
RemoteFileTasks.runCommandAndAssert(client, "getenforce", Integer.valueOf(0), "Enforcing", null);
// register the host, auto-heal, and get the granted entitlements
clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, false, null, null, (String) null, null, null, null, true, null, null, null, null, null);
clienttasks.autoheal(null, true, null, null, null, null, null);
clienttasks.restart_rhsmcertd(null, null, true);
List<EntitlementCert> entitlementCerts = clienttasks.getCurrentEntitlementCerts();
// verify that the entitlements which provide containerimage content are copied to registry_hostnames...
if (!verifyEntitlementsProvidingContainerImageContentAreCopiedToRegistryHostnames(entitlementCerts, registryHostnames))
throw new SkipException("None of the auto-attached subscriptions for this system provide content of type \"containerimage\".");
// individually unsubscribe from entitlements and assert the entitlement bearing a containerimage is also removed from registry_hostnames
for (EntitlementCert entitlementCert : entitlementCerts) {
List<ContentNamespace> containerImageContentNamespaces = ContentNamespace.findAllInstancesWithCaseInsensitiveMatchingFieldFromList("type", "containerimage", entitlementCert.contentNamespaces);
BigInteger serialNumber = clienttasks.getSerialNumberFromEntitlementCertFile(entitlementCert.file);
clienttasks.unsubscribeFromSerialNumber(serialNumber);
if (!containerImageContentNamespaces.isEmpty()) {
// after unsubscribing, assert that the entitlementCert was removed from the directory of registry_hostnames
for (String registryHostname : registryHostnames) {
File certFile = getRegistryHostnameCertFileFromEntitlementCert(registryHostname, entitlementCert);
File keyFile = getRegistryHostnameCertKeyFileFromEntitlementCert(registryHostname, entitlementCert);
Assert.assertTrue(!RemoteFileTasks.testExists(client, certFile.getPath()), "Entitlement cert '" + entitlementCert.orderNamespace.productName + "' providing a 'containerimage' (case insensitive) was removed from '" + certFile.getPath() + "' after unsubscribing.");
Assert.assertTrue(!RemoteFileTasks.testExists(client, keyFile.getPath()), "Corresponding entitlement key providing a 'containerimage' (case insensitive) was removed from '" + keyFile.getPath() + "' after unsubscribing.");
}
}
}
}
use of rhsm.data.ContentNamespace in project rhsm-qe by RedHatQE.
the class ContentIntegrationTests method getContentNamespaceDataAsListOfLists.
protected List<List<Object>> getContentNamespaceDataAsListOfLists() throws JSONException {
List<List<Object>> ll = new ArrayList<List<Object>>();
for (List<Object> row : contentNamespaceData) {
String username = (String) row.get(0);
String password = (String) row.get(1);
ConsumerType type = (ConsumerType) row.get(2);
String productId = (String) row.get(3);
Integer sockets = (Integer) row.get(4);
ContentNamespace contentNamespace = (ContentNamespace) row.get(5);
EntitlementCert entitlementCert = (EntitlementCert) row.get(6);
//
ll.add(Arrays.asList(new Object[] { username, password, type, productId, sockets, contentNamespace }));
}
return ll;
}
use of rhsm.data.ContentNamespace in project rhsm-qe by RedHatQE.
the class ManifestTests method verifyRCTCatManifestWithOptions.
protected void verifyRCTCatManifestWithOptions(File manifestFile, List<String> options) throws Exception {
// flatten the list of options into a single string for the runCommand
String optionsAsString = " ";
if (options != null)
for (String option : options) optionsAsString += option + " ";
// execute and assert rct cat-manifest MANIFEST_FILE
SSHCommandResult catManifestResult = RemoteFileTasks.runCommandAndAssert(client, "rct cat-manifest" + optionsAsString + manifestFile, 0);
// parse the output from catManifestResult into a Manifest object
List<Manifest> catManifests = Manifest.parse(catManifestResult.getStdout());
Assert.assertEquals(catManifests.size(), 1, "Parsed one manifest from '" + manifestFile + "'.");
Manifest catManifest = catManifests.get(0);
// create EntitlementCert objects representing the source for all of the entitlements provided by this manifest
if (manifestFileContentMap.get(manifestFile) == null)
throw new SkipException("Cannot execute this test until manifest file '" + manifestFile + "' has been successfully dumped.");
client.runCommandAndWaitWithoutLogging("find " + manifestFileContentMap.get(manifestFile).get(0).getParent() + "/export/entitlement_certificates" + " -regex \"/.+/[0-9]+.pem\" -exec rct cat-cert {} \\;");
String rawCertificates = client.getStdout();
List<EntitlementCert> entitlementCerts = EntitlementCert.parse(rawCertificates);
if (entitlementCerts.isEmpty())
Assert.fail("Manifest file '" + manifestFile + "' does not provide any entitlements.");
// loop through the manifest's entitlement certs and assert as much as possible...
// [root@jsefler-7 test-manifests]# rct cat-manifest manifest_SYS0395_RH0197181.zip
//
// +-------------------------------------------+
// Manifest
// +-------------------------------------------+
String bannerRegex = "\\+-+\\+\\n\\s*Manifest\\s*\\n\\+-+\\+";
Assert.assertTrue(Pattern.compile(".*" + bannerRegex + ".*", Pattern.DOTALL).matcher(catManifestResult.getStdout()).matches(), "stdout from rct cat-manifest contains a banner matching regex '" + bannerRegex + "'.");
if (catManifest.server == null) {
log.warning("Skipping assertion of non-null General and Consumer for what appears to be a manifest from an older candlepin server");
} else {
//
// General:
// Server: access.stage.redhat.com/management/distributors/
// Server Version: 0.7.13.10-1
// Date Created: 2013-01-21T21:24:16.193+0000
// Creator: qa@redhat.com
Assert.assertNotNull(catManifest.server, "General Server value is not null.");
Assert.assertNotNull(catManifest.serverVersion, "General Server Version value is not null.");
Assert.assertNotNull(catManifest.dateCreated, "General Date Created value is not null.");
Assert.assertNotNull(catManifest.creator, "General Creator value is not null.");
//
// Consumer:
// Name: jsefler
// UUID: b2837b9a-d2d9-4b41-acd9-34bdcf72af66
// Type: sam
Assert.assertNotNull(catManifest.consumerName, "Consumer Name value is not null.");
Assert.assertNotNull(catManifest.consumerUUID, "Consumer UUID value is not null.");
String consumerUUIDRegex = "[a-f,0-9,\\-]{36}";
Assert.assertTrue(Pattern.compile(consumerUUIDRegex).matcher(catManifest.consumerUUID).matches(), "Consumer UUID format matches the expected regex '" + consumerUUIDRegex + "'.");
Assert.assertNotNull(catManifest.consumerType, "Consumer Type value is not null.");
// TODO learn why there is a type distinction
Assert.assertTrue(catManifest.consumerType.equals("sam") || catManifest.consumerType.equals("cloudforms") || catManifest.consumerType.equals("satellite"), "Actual Consumer Type value '" + catManifest.consumerType + "' equals \"sam\" or \"cloudforms' or \"satellite\".");
// Content Access Mode: entitlement
if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.19.6-1")) {
Assert.assertNotNull(catManifest.consumerContentAccessMode, "Consumer Content Access Mode value is not null.");
Assert.assertTrue(catManifest.consumerContentAccessMode.equals("entitlement") || catManifest.consumerContentAccessMode.equals("org_environment"), "Actual Consumer Content Access Mode value '" + catManifest.consumerContentAccessMode + "' equals \"entitlement\" or \"org_environment\".");
if (SubscriptionManagerTasks.isVersion(catManifest.serverVersion, "<", "2.0.22-1")) {
// candlepin commit 18c20d0a1530910d5ca45fecb59f8f7db5e9a04f Golden Ticket
Assert.assertEquals(catManifest.consumerContentAccessMode, "entitlement", "Since this manifest was created by candlepin version prior to \"2.0.22-1\", the Consumer's Content Access Mode value must be the default value.");
}
}
}
// /content/beta/rhel/power/5/$releasever/$basearch/highavailability/source/SRPMS
for (EntitlementCert entitlementCert : entitlementCerts) {
ManifestSubscription manifestSubscription = ManifestSubscription.findFirstInstanceWithMatchingFieldFromList("certificateFile", entitlementCert.file.toString().replace(manifestFileContentMap.get(manifestFile).get(0).getParent() + File.separator, ""), catManifest.subscriptions);
if (manifestSubscription == null)
Assert.fail("Could not find the ManifestSubscription corresponding to Entitlement '" + entitlementCert.file + "'.");
Assert.assertEquals(manifestSubscription.name, entitlementCert.orderNamespace.productName, "Subscription Name value comes from entitlementCert.orderNamespace.productName");
Assert.assertEquals(manifestSubscription.quantity, entitlementCert.orderNamespace.quantityUsed, "Subscription Quantity value comes from entitlementCert.orderNamespace.quantityUsed (ASSUMING NO OTHER UPSTREAM CONSUMERS)");
// TODO assert Created:
Assert.assertEquals(manifestSubscription.startDate, entitlementCert.validityNotBefore, "Subscription Start Date comes from entitlementCert.validityNotBefore");
Assert.assertEquals(manifestSubscription.endDate, entitlementCert.validityNotAfter, "Subscription End Date comes from entitlementCert.validityNotAfter");
Assert.assertEquals(manifestSubscription.supportLevel, entitlementCert.orderNamespace.supportLevel, "Subscription Service Level value comes from entitlementCert.orderNamespace.supportLevel");
Assert.assertEquals(manifestSubscription.supportType, entitlementCert.orderNamespace.supportType, "Subscription Service Type value comes from entitlementCert.orderNamespace.supportType");
List<String> actualArchitectures = new ArrayList<String>();
if (manifestSubscription.architectures != null)
actualArchitectures.addAll(Arrays.asList(manifestSubscription.architectures.split("\\s*,\\s*")));
List<String> expectedArchitectures = new ArrayList<String>();
for (ProductNamespace productNamespace : entitlementCert.productNamespaces) if (productNamespace.arch != null)
expectedArchitectures.addAll(Arrays.asList(productNamespace.arch.split("\\s*,\\s*")));
// BAD ASSERT SEE https://bugzilla.redhat.com/show_bug.cgi?id=914799#c3 Assert.assertTrue(actualArchitectures.containsAll(expectedArchitectures)&&expectedArchitectures.containsAll(actualArchitectures), "Subscription Architectures contains the union of providedProduct arches: "+expectedArchitectures);
Assert.assertEquals(manifestSubscription.productId, entitlementCert.orderNamespace.productId, "Subscription SKU value comes from entitlementCert.orderNamespace.productId");
Assert.assertEquals(manifestSubscription.contract, entitlementCert.orderNamespace.contractNumber, "Subscription Contract value comes from entitlementCert.orderNamespace.contractNumber");
Assert.assertEquals(manifestSubscription.subscriptionId, entitlementCert.orderNamespace.orderNumber, "Subscription Order Number value comes from entitlementCert.orderNamespace.orderNumber");
// TODO assert Entitlement File in json format
Assert.assertTrue(entitlementCert.file.toString().endsWith(manifestSubscription.certificateFile), "Subscription Certificate File exists");
Assert.assertEquals(manifestSubscription.certificateVersion, entitlementCert.version, "Subscription Certificate Version value comes from entitlementCert.version");
List<String> actualProvidedProducts = manifestSubscription.providedProducts;
List<String> actualDerivedProducts = manifestSubscription.derivedProducts;
if (false) {
// This assertion was valid prior to the invention of data center skus that provide no products but do provide derived products to be added to a sub-pool
List<String> expectedProvidedProducts = new ArrayList<String>();
for (ProductNamespace productNamespace : entitlementCert.productNamespaces) expectedProvidedProducts.add(String.format("%s: %s", productNamespace.id, productNamespace.name));
Assert.assertTrue(actualProvidedProducts.containsAll(expectedProvidedProducts) && expectedProvidedProducts.containsAll(actualProvidedProducts), "Manifest Subscription '" + manifestSubscription.name + "' Provided Products " + actualProvidedProducts + " contains all entitlementCert.productNamespaces=>\"id: name\": " + expectedProvidedProducts);
} else {
// Instead, let's assume the following assertion is correct... TODO confirm with dev
// Note: this assertion can only be tested against manifests with data center skus using subscription-manager-1.18.6-1 and higher
List<String> expectedProducts = new ArrayList<String>();
for (ProductNamespace productNamespace : entitlementCert.productNamespaces) expectedProducts.add(String.format("%s: %s", productNamespace.id, productNamespace.name));
if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.18.6-1")) {
// subscription-manager commit 23c149907852767e51e7ddea8edf506697827203 Bug 1388207 - [RFE] rct cat-manifest command should show derived products
List<String> actualProvidedAndDerivedProducts = new ArrayList<String>();
for (String product : actualProvidedProducts) if (!actualProvidedAndDerivedProducts.contains(product))
actualProvidedAndDerivedProducts.add(product);
for (String product : actualDerivedProducts) if (!actualProvidedAndDerivedProducts.contains(product))
actualProvidedAndDerivedProducts.add(product);
Assert.assertTrue(actualProvidedAndDerivedProducts.containsAll(expectedProducts) && expectedProducts.containsAll(actualProvidedAndDerivedProducts), "The union of all Provided Products " + actualProvidedProducts + " and Derived Products " + actualDerivedProducts + " from manifest Subscription '" + manifestSubscription.name + "' contains all entitlementCert.productNamespaces=>\"id: name\": " + expectedProducts);
} else {
log.info("Cannot assert that the union of all provided and derived products from manifest Subscription '" + manifestSubscription.name + "' are represented in this entitlementCert.productNamespaces=>\"id: name\": " + expectedProducts + " because RFE Bug 1388207 is not present in this version of subscription-manager.");
log.info("We can only assert that the provided products from manifest Subscription '" + manifestSubscription.name + "' are a subset of this entitlementCert.productNamespaces=>\"id: name\": " + expectedProducts + " because RFE Bug 1388207 is not present in this version of subscription-manager to account for derived products.");
Assert.assertTrue(expectedProducts.containsAll(actualProvidedProducts), "The Provided Products " + actualProvidedProducts + " from manifest Subscription '" + manifestSubscription.name + "' are a subset of all entitlementCert.productNamespaces=>\"id: name\": " + expectedProducts);
}
}
List<String> actualContentSets = new ArrayList<String>();
if (manifestSubscription.contentSets != null)
actualContentSets.addAll(manifestSubscription.contentSets);
List<String> expectedContentSets = new ArrayList<String>();
for (ContentNamespace contentNamespace : entitlementCert.contentNamespaces) expectedContentSets.add(contentNamespace.downloadUrl);
if (options != null && options.contains("--no-content")) {
Assert.assertNull(manifestSubscription.contentSets, "The cat-manifest report does not include any Subscription Content Sets when the '--no-content' option is specified.");
} else {
Assert.assertTrue(actualContentSets.containsAll(expectedContentSets) && expectedContentSets.containsAll(actualContentSets), "Subscription Content Sets contains all entitlementCert.contentNamespaces=>downloadUrl: (too long to print)");
}
}
}
Aggregations