use of com.redhat.qe.auto.bugzilla.BugzillaAPIException in project rhsm-qe by RedHatQE.
the class DevSKUTests method testAutosubscribeAfterChangingDevSkuFacts.
@// update=true, // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-21993", "RHEL7-51855" }, 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 = "configure the system with custom facts for a dev_sku, register the system with auto-subscribe, alter the dev_sku facts, re-autosubscribe, and verify the initial entitlement was purged", groups = { "Tier1Tests", "blockedByBug-1295452" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testAutosubscribeAfterChangingDevSkuFacts() throws JSONException, Exception {
if (servertasks.statusStandalone) {
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).");
}
boolean isGuest = Boolean.valueOf(clienttasks.getFactValue("virt.is_guest"));
// register with force to get a fresh consumer
clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, false, null, null, (List<String>) null, null, null, null, true, false, null, null, null, null);
// find two value SKUs that can be used as a dev_sku
List<SubscriptionPool> subscriptionPools = clienttasks.getCurrentlyAvailableSubscriptionPools();
// /*debugTesting*/subscriptionPools = SubscriptionPool.findAllInstancesWithMatchingFieldFromList("productId", "awesomeos-virt-datacenter", subscriptionPools);
String devSku1 = null, devSku2 = null;
for (SubscriptionPool subscriptionPool : getRandomList(subscriptionPools)) {
// Unable to attach subscription for the product 'RH00003': rulefailed.quantity.mismatch.
if (!subscriptionPool.suggested.equals(Integer.valueOf(1))) {
boolean invokeWorkaroundWhileBugIsOpen = true;
// Bug 1463320 - choosing a dev_sku that requires a quantity>1 will fail to auto-attach with error: rulefailed.quantity.mismatch.
String bugId = "1463320";
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.info("Excluding subscription '" + subscriptionPool.productId + "' as a dev_sku candidate because its suggested quantity '" + subscriptionPool.suggested + "' is not 1 while bug '" + bugId + "' is open.");
continue;
}
}
// avoid "Unable to attach subscription for the product 'RH00003': rulefailed.quantity.mismatch." since Bug 1463320 was CLOSED NOTABUG
if (!subscriptionPool.suggested.equals(Integer.valueOf(1))) {
log.info("Excluding subscription '" + subscriptionPool.productId + "' as a dev_sku candidate because its suggested quantity '" + subscriptionPool.suggested + "' is not 1 which is NOT indicative of a realistic dev_sku subscription. Reference https://bugzilla.redhat.com/show_bug.cgi?id=1463320#c1");
continue;
}
// avoid "Unable to attach subscription for the product 'awesomeos-virt-datacenter': rulefailed.physical.only.
if (isGuest && CandlepinTasks.isPoolProductPhysicalOnly(sm_clientUsername, sm_clientPassword, subscriptionPool.poolId, sm_serverUrl)) {
log.info("Excluding subscription '" + subscriptionPool.productId + "' as a dev_sku candidate because its physical_only productAttribute is NOT indicative of a realistic dev_sku subscription.");
continue;
}
if (devSku1 == null)
devSku1 = subscriptionPool.productId;
if (devSku2 == null && devSku1 != null && devSku1 != subscriptionPool.productId)
devSku2 = subscriptionPool.productId;
if (devSku2 != null && devSku1 != null)
break;
}
if (devSku1 == null || devSku2 == null)
throw new SkipException("Could not find two available SKUs to execute this test.");
// instrument the system facts to behave as a vagrant image with devSku1
Map<String, String> factsMap = new HashMap<String, String>();
factsMap.put("dev_sku", devSku1);
factsMap.put("dev_platform", "dev_platform_for_" + devSku1);
clienttasks.createFactsFileWithOverridingValues(factsMap);
clienttasks.facts(null, true, null, null, null, null);
// autosubscribe
clienttasks.subscribe(true, null, null, null, (String) null, null, null, null, null, null, null, null, null);
// get the autosubscribed entitlement
List<ProductSubscription> productSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
if (clienttasks.getCurrentProductCertFiles().isEmpty()) {
// handle case when no products are installed
Assert.assertEquals(productSubscriptions.size(), 0, "After autosubscribing a system with dev_sku fact '" + devSku1 + "' that has no installed products, no product subscription should be consumed.");
throw new SkipException("This test requires at least one installed product, otherwise there is no need for a dev SKU entitlement.");
}
Assert.assertEquals(productSubscriptions.size(), 1, "After autosubscribing a system with dev_sku fact '" + devSku1 + "', only one product subscription should be consumed.");
ProductSubscription devSkuProductSubscription1 = productSubscriptions.get(0);
Assert.assertEquals(devSkuProductSubscription1.productId, devSku1, "The consumed entitlement SKU after autosubscribing a system with dev_sku fact '" + devSku1 + "'.");
// instrument the system facts to behave as a vagrant image with devSku2
factsMap.put("dev_sku", devSku2);
factsMap.put("dev_platform", "dev_platform_for_" + devSku2);
clienttasks.createFactsFileWithOverridingValues(factsMap);
clienttasks.facts(null, true, null, null, null, null);
// which will cause the final assert to fail because the system will have no need to re-autosubscribe to devSku2
if (clienttasks.getFactValue("system.entitlements_valid").equalsIgnoreCase("valid")) {
// simply remove the devSkuProductSubscription1 subscription
clienttasks.unsubscribe_(null, devSkuProductSubscription1.serialNumber, null, null, null, null, null);
}
// autosubscribe again
clienttasks.subscribe(true, null, null, null, (String) null, null, null, null, null, null, null, null, null);
// get the autosubscribed entitlement
productSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
// fails prior to the fix for Bug 1295452 - After altering the dev_sku value in the facts file , two CDK subscriptions exists on the machine
Assert.assertEquals(productSubscriptions.size(), 1, "After autosubscribing a system with dev_sku fact altered to '" + devSku2 + "', only one product subscription should be consumed (the '" + devSku1 + "' entitlement should have been purged)");
ProductSubscription devSkuProductSubscription2 = productSubscriptions.get(0);
Assert.assertEquals(devSkuProductSubscription2.productId, devSku2, "The consumed entitlement SKU after autosubscribing a system with dev_sku fact altered to '" + devSku2 + "'.");
}
use of com.redhat.qe.auto.bugzilla.BugzillaAPIException 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 com.redhat.qe.auto.bugzilla.BugzillaAPIException in project rhsm-qe by RedHatQE.
the class SubscriptionManagerTasks method listAllAvailableSubscriptionPools.
/**
* @return SSHCommandResult from "subscription-manager-cli list --all --available"
*/
public SSHCommandResult listAllAvailableSubscriptionPools() {
// TEMPORARY WORKAROUND FOR BUG: https://bugzilla.redhat.com/show_bug.cgi?id=638266 - jsefler 9/28/2010
boolean invokeWorkaroundWhileBugIsOpen = false;
String bugId = "638266";
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) {
return list_(Boolean.FALSE, Boolean.TRUE, null, null, null, null, null, null, null, null, null, null, null, null);
}
// END OF WORKAROUND
SSHCommandResult sshCommandResult = list(Boolean.TRUE, Boolean.TRUE, null, null, null, null, null, null, null, null, null, null, null, null);
return sshCommandResult;
}
use of com.redhat.qe.auto.bugzilla.BugzillaAPIException in project rhsm-qe by RedHatQE.
the class SubscriptionManagerTasks method registerToRhnClassic.
/**
* Call rhnreg_ks and assert the existence of a systemid file afterwards.
* @param rhnUsername - rhnreg_ks username
* @param rhnPassword - rhnreg_ks password
* @param rhnHostname
* @return the rhn system_id value from the contents of the systemid file
*/
public String registerToRhnClassic(String rhnUsername, String rhnPassword, String rhnHostname) {
// register to RHN Classic
SSHCommandResult result = registerToRhnClassic_(rhnUsername, rhnPassword, rhnHostname);
// assert result
Integer exitCode = result.getExitCode();
String stdout = result.getStdout();
String stderr = result.getStderr();
String msg;
msg = "ERROR: refreshing remote package list for System Profile";
if (stdout.contains(msg)) {
// ERROR: refreshing remote package list for System Profile
log.warning("Ignoring stdout result: " + msg);
stdout = stdout.replaceAll(msg, "");
}
msg = "forced skip_if_unavailable=True due to";
if (stderr.contains(msg)) {
// Repo content-label-72 forced skip_if_unavailable=True due to: /etc/pki/entitlement/2114809071147763952.pem
String regex = "Repo .+ " + msg + ": .+.pem";
log.warning("Ignoring stderr results matching: " + regex);
stderr = stderr.replaceAll(regex, "");
}
// this will occur on rhel7+ where there is no RHN Classic support. See bugzilla 906875
msg = "This system is not subscribed to any channels.\nRHN channel support will be disabled.";
if (stderr.contains(msg)) {
// This system is not subscribed to any channels.
// RHN channel support will be disabled.
log.warning("Ignoring stderr result: " + msg);
stderr = stderr.replaceAll(msg, "");
}
// this will occur on rhel5 while bug 924919 is open, but does not really affect the success of rhnreg_ks. See bugzilla 924919
msg = "WARNING:rhsm-app.subscription_manager.isodate:dateutil module not found, trying pyxml";
if (stderr.contains(msg)) {
log.warning("Ignoring stderr result: " + msg);
stderr = stderr.replaceAll(msg, "");
}
// this will occur on rhel7+ where Red Hat Network Classic is not supported. See bugzilla 906875
msg = "Red Hat Network Classic is not supported.";
if (stderr.contains(msg)) {
// FINE: ExitCode: 1
if (Integer.valueOf(redhatReleaseX) >= 7) {
log.warning(msg);
throw new SkipException("Skipping this test on RHEL '" + redhatReleaseX + "' which depends on RHN Classic registration.");
}
}
// 201609281555:16.285 - FINE: ExitCode: 1
if (stderr.contains("<type 'exceptions.TypeError'>")) {
// Bug 1380159 - <type 'exceptions.TypeError'>: 'str' object does not support item assignment
String bugId = "1380159";
boolean invokeWorkaroundWhileBugIsOpen = true;
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("The remainder of this test is blocked by bug " + bugId + ". There is no workaround.");
}
}
// END OF WORKAROUND
Assert.assertEquals(exitCode, new Integer(0), "Exitcode from attempt to register to RHN Classic.");
Assert.assertEquals(stderr.trim(), "", "Stderr from attempt to register to RHN Classic.");
// TEMPORARY WORKAROUND
boolean invokeWorkaroundWhileBugIsOpen = true;
// Bug 1282961 - Plugin "search-disabled-repos" requires API 2.7. Supported API is 2.6.
String bugId = "1282961";
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 && this.redhatReleaseX.equals("6") && this.isPackageVersion("subscription-manager", ">=", "1.15")) {
Assert.assertEquals(stdout.replace("Plugin \"search-disabled-repos\" requires API 2.7. Supported API is 2.6.", "").trim(), "", "Ignoring bug '" + bugId + "',Stdout from attempt to register to RHN Classic.");
} else
// END OF WORKAROUND
Assert.assertEquals(stdout.trim(), "", "Stdout from attempt to register to RHN Classic.");
// assert this system is registered using RHN Classic
Assert.assertTrue(isRhnSystemRegistered(), "This system is registered using RHN Classic.");
// get the value of the systemid
// [root@jsefler-onprem-5server rhn]# grep ID- /etc/sysconfig/rhn/systemid
// <value><string>ID-1021538137</string></value>
String command = String.format("grep ID- %s", rhnSystemIdFile);
// return 1021538137
return sshCommandRunner.runCommandAndWait(command).getStdout().trim().replaceAll("\\<.*?\\>", "").replaceFirst("ID-", "");
}
use of com.redhat.qe.auto.bugzilla.BugzillaAPIException in project rhsm-qe by RedHatQE.
the class SubscriptionManagerTasks method subscribe.
/**
* subscribe and assert all results are successful
* @param noproxy TODO
*/
public SSHCommandResult subscribe(Boolean auto, String servicelevel, List<String> poolIds, List<String> productIds, List<String> regtokens, String quantity, String email, String locale, String file, String proxy, String proxyuser, String proxypassword, String noproxy) {
SSHCommandResult sshCommandResult = subscribe_(auto, servicelevel, poolIds, productIds, regtokens, quantity, email, locale, file, proxy, proxyuser, proxypassword, noproxy);
// the non-null default value for auto is false
auto = auto == null ? false : auto;
// assert results...
String stdoutMessage;
// just return the result for any of the following cases:
if (// This consumer is already subscribed to the product matching pool with id 'ff8080812c71f5ce012c71f6996f0132'.
sshCommandResult.getStdout().trim().startsWith("This consumer is already subscribed") || // This unit has already had the subscription matching pool ID '8a99f98340114f880140766376dc00cf' attached.
sshCommandResult.getStdout().trim().startsWith("This unit has already had the subscription") || // No entitlements are available from the pool with id '8a90f8143611c33f013611c4797b0456'. (Bug 719743)
sshCommandResult.getStdout().trim().startsWith("No entitlements are available") || // No subscriptions are available from the pool with id '8a90f8303c98703a013c98715ca80494'. (Bug 846758)
sshCommandResult.getStdout().trim().startsWith("No subscriptions are available") || // Pool is restricted to virtual guests: '8a90f85734205a010134205ae8d80403'.
sshCommandResult.getStdout().trim().startsWith("Pool is restricted") || // sshCommandResult.getStderr().trim().startsWith("Development units may only be used on") || // Development units may only be used on hosted servers and with orgs that have active subscriptions.
sshCommandResult.getStdout().trim().startsWith(// All installed products are covered by valid entitlements. No need to update subscriptions at this time.
"All installed products are covered") || // No Installed products on system. No need to attach subscriptions.
sshCommandResult.getStdout().trim().startsWith("No Installed products on system.") || sshCommandResult.getStdout().trim().startsWith("Unable to entitle consumer")) {
// Unable to entitle consumer to the pool with id '8a90f8b42e3e7f2e012e3e7fc653013e'.: rulefailed.virt.only
// Unable to entitle consumer to the pool with id '8a90f85734160df3013417ac68bb7108'.: Entitlements for awesomeos-virt-4 expired on: 12/7/11 3:43 AM
log.warning(sshCommandResult.getStdout().trim());
return sshCommandResult;
}
// assert the subscribe does NOT report "The system is unable to complete the requested transaction"
// Assert.assertContainsNoMatch(sshCommandResult.getStdout(), "The system is unable to complete the requested transaction","The system should always be able to complete the requested transaction.");
stdoutMessage = "The system is unable to complete the requested transaction";
Assert.assertFalse(sshCommandResult.getStdout().contains(stdoutMessage), "The subscribe stdout should NOT report: " + stdoutMessage);
// assert the subscribe does NOT report "Entitlement Certificate\\(s\\) update failed due to the following reasons:"
// Assert.assertContainsNoMatch(sshCommandResult.getStdout(), "Entitlement Certificate\\(s\\) update failed due to the following reasons:","Entitlement Certificate updates should be successful when subscribing.");
stdoutMessage = "Entitlement Certificate(s) update failed due to the following reasons:";
Assert.assertFalse(sshCommandResult.getStdout().contains(stdoutMessage), "The subscribe stdout should NOT report: " + stdoutMessage);
// Assert.assertFalse(sshCommandResult.getStdout().contains(stdoutMessage), "The subscribe stdout should NOT report: "+stdoutMessage);
if (poolIds != null) {
for (String poolId : poolIds) {
// Subscription pool {0} does not exist.
stdoutMessage = "Subscription pool " + poolId + " does not exist.";
Assert.assertFalse(sshCommandResult.getStdout().contains(stdoutMessage), "The subscribe stdout should NOT report: " + stdoutMessage);
}
}
// assert the stdout msg was a success
if (servicelevel != null && !servicelevel.equals(""))
Assert.assertTrue(sshCommandResult.getStdout().contains("Service level set to: " + servicelevel), "The autosubscribe stdout reports: Service level set to: " + servicelevel);
if (auto)
Assert.assertTrue(sshCommandResult.getStdout().contains("Installed Product Current Status:"), "The autosubscribe stdout reports: Installed Product Current Status");
else if (// defaults to auto
!auto && file == null && (poolIds == null || poolIds.isEmpty()) && isPackageVersion("subscription-manager", ">=", "1.14.1-1"))
Assert.assertTrue(sshCommandResult.getStdout().contains("Installed Product Current Status:"), "The subscribe stdout reports: Installed Product Current Status (when the default behavior implies to autosubscribe)");
else {
// Assert.assertTrue(sshCommandResult.getStdout().startsWith("Success"), "The subscribe stdout reports 'Success'.");
if (file != null || poolIds.size() == 1) {
Assert.assertTrue(workaroundForBug906550(sshCommandResult.getStdout()).startsWith("Success"), "The subscribe stdout reports a 'Success'fully attached subscription.");
} else {
Assert.assertTrue(workaroundForBug906550(sshCommandResult.getStdout()).contains("Success"), "The subscribe stdout reports at least one 'Success'fully attached subscription.");
}
}
// assert the exit code was not a failure
if (auto)
Assert.assertTrue(Integer.valueOf(sshCommandResult.getExitCode()) <= 1, "The exit code (" + sshCommandResult.getExitCode() + ") from the subscribe --auto command does not indicate a failure (exit code 0 indicates an entitlement was granted, 1 indicates an entitlement was not granted, 255 indicates a failure).");
else if (// defaults to auto
!auto && file == null && (poolIds == null || poolIds.isEmpty()) && isPackageVersion("subscription-manager", ">=", "1.14.1-1"))
Assert.assertTrue(Integer.valueOf(sshCommandResult.getExitCode()) <= 1, "The exit code (" + sshCommandResult.getExitCode() + ") from the subscribe command (defaulting to autosubscribe) does not indicate a failure (exit code 0 indicates an entitlement was granted, 1 indicates an entitlement was not granted, 255 indicates a failure).");
else {
// TEMPORARY WORKAROUND
boolean invokeWorkaroundWhileBugIsOpen = true;
// Bug 1287610 - yum message in output when FIPS is enabled
String bugId = "1287610";
try {
if (redhatReleaseX.equals("7") && isFipsEnabled && 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("Skipping the stderr assertion from subscribe on rhel '" + redhatReleaseXY + "' while FIPS bug '" + bugId + "' is open");
} else
// END OF WORKAROUND
Assert.assertEquals(sshCommandResult.getExitCode(), Integer.valueOf(0), "The exit code from the subscribe command indicates a success.");
}
return sshCommandResult;
}
Aggregations