use of rhsm.data.ProductNamespace in project rhsm-qe by RedHatQE.
the class DataCenterTests method testAvailabilityOfDerivedProductSubpools.
// 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-19987", "RHEL7-33089" }, 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 data center pool, consume it and assert that a pool for the derivedProduct is generated and available only to its guests", groups = { "Tier1Tests", "VerifyAvailabilityOfDerivedProductSubpools_Test" }, dataProvider = "getAvailableDataCenterSubscriptionPoolsData", enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testAvailabilityOfDerivedProductSubpools(Object bugzilla, /*Boolean systemIsGuest, Integer systemSockets,*/
SubscriptionPool pool) throws NumberFormatException, JSONException, Exception {
String expectedTemporaryPoolIndicator = " (Temporary)";
// make sure we are unsubscribed from all subscriptions
// clienttasks.unsubscribe(true, (BigInteger)null, null, null, null);
// unsubscribe this way to ensure the newest serial is removed first
clienttasks.unsubscribeFromTheCurrentlyConsumedSerialsCollectively();
// get some attributes from the subscription pool
String poolDerivedProductId = (String) CandlepinTasks.getPoolValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "derivedProductId");
String poolDerivedProductName = (String) CandlepinTasks.getPoolValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "derivedProductName");
String poolDerivedProductArch = (String) CandlepinTasks.getPoolDerivedProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "arch");
// Note: the arch attribute can be a comma separated list of values
List<String> poolDerivedProductArches = new ArrayList<String>(Arrays.asList(poolDerivedProductArch.trim().split(" *, *")));
List<String> poolDerivedProvidedProductIds = CandlepinTasks.getPoolDerivedProvidedProductIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId);
String poolVirtLimit = CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "virt_limit");
List<String> poolProvidedProductIds = CandlepinTasks.getPoolProvidedProductIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId);
// TEMPORARY WORKAROUND FOR BUG
if (sm_serverType.equals(CandlepinType.hosted)) {
// Bug 1214001 - after stage refresh, Virtual Data Center SKUs no longer have a host_limited pool productAttributes
String bugId = "1214001";
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("Skipping this Virtual Data Center test against SKU '" + pool.productId + "' while bug '" + bugId + "' is open.");
}
}
// TEMPORARY WORKAROUND FOR BUG
if (sm_serverType.equals(CandlepinType.hosted)) {
// Bug 1261193 - Datacenter subscriptions in stage candlepin-0.9.51.5-1 should create Temporary pools for their derived products
String bugId = "1261193";
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("Skipping this Virtual Data Center test against SKU '" + pool.productId + "' while bug '" + bugId + "' is open.");
}
}
// END OF WORKAROUND
// assert that this virtual data center SKU is host_limited
Assert.assertTrue(CandlepinTasks.isPoolProductHostLimited(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId), "As a functional requirement for Virtual Data Center SKUs, asserting that the pool's productAttributes contains host_limited=true so that a subscription pool for derivedProductId '" + poolDerivedProductId + "' is available ONLY to mapped virtual guests.");
// assert that the derivedProductId is different from the host pool's productId
Assert.assertTrue(!pool.productId.equals(poolDerivedProductId), "The host pool's data center subscription product Id '" + pool.productId + "' should be different than its derived pool's product Id '" + poolDerivedProductId + "'.");
// NOT NECESSARILY TRUE // assert that the derivedProductName is different from the host pool's subscription name
// NOT NECESSARILY TRUE Assert.assertNotSame(pool.subscriptionName, poolDerivedProductName, "The host pool's data center subscription name '"+pool.subscriptionName+"' should be different than its derived pool's product name '"+poolDerivedProductName+"'.");
// instrument the system facts to behave as a physical host
factsMap.put("virt.is_guest", String.valueOf(false));
clienttasks.createFactsFileWithOverridingValues(factsMap);
// update facts
clienttasks.facts(null, true, null, null, null, null);
// reset a few fake guest ids for this host consumer
String systemUuid = clienttasks.getCurrentConsumerId();
// [root@jsefler-5 ~]# curl -k -u testuser1:password --request PUT --data '{"guestIds":["e6f55b91-aae1-44d6-f0db-c8f25ec73ef5","abcd"]}' --header 'accept:application/json' --header 'content-type: application/json' https://jsefler-f14-candlepin.usersys.redhat.com:8443/candlepin/consumers/d2ee0c6e-a57d-4e37-8be3-228a44ca2739
JSONObject jsonConsumer = CandlepinTasks.setGuestIdsForConsumer(sm_clientUsername, sm_clientPassword, sm_serverUrl, systemUuid, Arrays.asList(new String[] { "abc", "def" }));
// assert that only Physical pools are available for consumption for this data center sku
for (SubscriptionPool subscriptionPool : SubscriptionPool.findAllInstancesWithMatchingFieldFromList("productId", pool.productId, clienttasks.getCurrentlyAllAvailableSubscriptionPools())) {
Assert.assertEquals(subscriptionPool.machineType, "Physical", "Only physical pools to '" + pool.productId + "' should be available to a physical host system.");
}
// subscribe the host to the data center pool
File hostEntitlementFile = clienttasks.subscribeToSubscriptionPool(pool, /*sm_serverAdminUsername*/
sm_clientUsername, /*sm_serverAdminPassword*/
sm_clientPassword, sm_serverUrl);
EntitlementCert hostEntitlementCert = clienttasks.getEntitlementCertFromEntitlementCertFile(hostEntitlementFile);
client.runCommandAndWait("rct cat-cert " + hostEntitlementFile);
// the following general asserts are not true against a production datacenter SKU...
if (false) {
// Subscription Name: Red Hat Enterprise Linux for Virtual Datacenters, Premium
// Provides: Red Hat Enterprise Linux Atomic Host
// SKU: RH00001
// Contract: 10472273
// Pool ID: 8a99f98146b4fa9d0146b5d3c0005253
// Available: 98
// Suggested: 1
// Service Level: Premium
// Service Type: L1-L3
// Subscription Type: Stackable
// Ends: 12/30/2014
// System Type: Physical
// in general the data center pool will not provide any engineering products
Assert.assertTrue(poolProvidedProductIds.isEmpty(), "In general, a data center product subscription will not provide any engineering products (productId= '" + pool.productId + "'). Asserting the providedProducts from the subscription is empty...");
Assert.assertTrue(hostEntitlementCert.productNamespaces.isEmpty(), "In general, a data center product subscription will not provide any engineering products (productId= '" + pool.productId + "'). Asserting the productNamespaces from the granted entitlement are empty...");
// in general the data center pool will not provide any content
Assert.assertTrue(hostEntitlementCert.contentNamespaces.isEmpty(), "In general, a data center product subscription will not provide any content sets (productId= '" + pool.productId + "').");
}
// assert that the derivedProductId is NOT available to the Physical host system
List<SubscriptionPool> availablePoolsForDerivedProductId = SubscriptionPool.findAllInstancesWithMatchingFieldFromList("productId", poolDerivedProductId, clienttasks.getCurrentlyAllAvailableSubscriptionPools());
Assert.assertTrue(availablePoolsForDerivedProductId.isEmpty(), "A subpool for the derivedProductId '" + poolDerivedProductId + "' should NOT be available to the host after (or before) it consumes the data center product subscription.");
// now we can assert that a host_limited subpool was generated from consumption of this physical pool and is only available to guests of this physical system
// first, let's flip the virt.is_guest to true and assert that the virtual guest subpool is not (yet) available since the virtUuid is not on the host consumer's list of guestIds
factsMap.put("virt.is_guest", String.valueOf(true));
clienttasks.createFactsFileWithOverridingValues(factsMap);
// update facts
clienttasks.facts(null, true, null, null, null, null);
availablePoolsForDerivedProductId = SubscriptionPool.findAllInstancesWithMatchingFieldFromList("productId", poolDerivedProductId, clienttasks.getCurrentlyAllAvailableSubscriptionPools());
if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, "<", "0.9.45-1")) {
// this assertion was valid prior to introduction of Temporary pools for unmapped guests
Assert.assertTrue(availablePoolsForDerivedProductId.isEmpty(), "A subpool for the derivedProductId '" + poolDerivedProductId + "' should NOT be available to a guest system when its virt_uuid is not on the host's list of guestIds.");
} else {
// this assertion is valid after the introduction of Temporary pools for unmapped guests
Assert.assertTrue(!availablePoolsForDerivedProductId.isEmpty(), "Starting with candlepin version 0.9.45-1, a temporary subpool for the derivedProductId '" + poolDerivedProductId + "' should NOW be available to a guest system when its virt_uuid is not on the host's list of guestIds.");
if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "0.9.47-1")) {
// commit dfd7e68ae83642f77c80590439353a0d66fe2961 // Bug 1201520 - [RFE] Usability suggestions to better identify a temporary (aka 24 hour) entitlement
for (SubscriptionPool subscriptionPool : availablePoolsForDerivedProductId) {
Assert.assertTrue(subscriptionPool.subscriptionType.endsWith(expectedTemporaryPoolIndicator), "Starting with candlepin version 0.9.47-1, a temporary subpool (indicated by subscription type ending in '" + expectedTemporaryPoolIndicator + "') for the derivedProductId '" + poolDerivedProductId + "' should NOW be available to a guest system when its virt_uuid is not on the host's list of guestIds: " + subscriptionPool);
}
}
}
// now fake this consumer's facts and guestIds to make it think it is a guest of itself (a trick for testing)
factsMap.put("virt.uuid", systemUuid);
clienttasks.createFactsFileWithOverridingValues(factsMap);
// update facts
clienttasks.facts(null, true, null, null, null, null);
// [root@jsefler-5 ~]# curl -k -u testuser1:password --request PUT --data '{"guestIds":["e6f55b91-aae1-44d6-f0db-c8f25ec73ef5","abcd"]}' --header 'accept:application/json' --header 'content-type: application/json' https://jsefler-f14-candlepin.usersys.redhat.com:8443/candlepin/consumers/d2ee0c6e-a57d-4e37-8be3-228a44ca2739
jsonConsumer = CandlepinTasks.setGuestIdsForConsumer(sm_clientUsername, sm_clientPassword, sm_serverUrl, systemUuid, Arrays.asList(new String[] { "abc", systemUuid, "def" }));
// now the host_limited subpool to the derivedProductId for this virtual system should be available
availablePoolsForDerivedProductId = SubscriptionPool.findAllInstancesWithMatchingFieldFromList("productId", poolDerivedProductId, clienttasks.getCurrentlyAllAvailableSubscriptionPools());
Assert.assertTrue(!availablePoolsForDerivedProductId.isEmpty(), "Host_limited subpool from data center product id '" + pool.productId + "' to derived product id '" + poolDerivedProductId + "' is available to its guest.");
Assert.assertEquals(availablePoolsForDerivedProductId.size(), 1, "Only one host_limited subpool to derived product id '" + poolDerivedProductId + "' is available to its guest.");
SubscriptionPool derivedPool = availablePoolsForDerivedProductId.get(0);
Assert.assertTrue(!derivedPool.subscriptionType.endsWith(expectedTemporaryPoolIndicator), "The host_limited subpool to derived product id '" + poolDerivedProductId + "' available to its guest should NOT indicate that the subscription type '" + derivedPool.subscriptionType + "' is temporary.");
Assert.assertEquals(derivedPool.subscriptionName, poolDerivedProductName, "Subscription name for the derived product id '" + poolDerivedProductId + "'.");
Assert.assertEquals(derivedPool.quantity.toLowerCase(), poolVirtLimit, "The quantity of entitlements from the host_limited subpool to derived product subscription '" + poolDerivedProductName + "' should be the same as the host data center subscription's virt_limit '" + poolVirtLimit + "'.");
// now subscribe to the derived subpool and we'll assert the entitlement values come from the derived product and not the originating data center subscription
// subscribe the guest to the derived product subscription
File derivedEntitlementFile = clienttasks.subscribeToSubscriptionPool(derivedPool, /*sm_serverAdminUsername*/
sm_clientUsername, /*sm_serverAdminPassword*/
sm_clientPassword, sm_serverUrl);
EntitlementCert derivedEntitlementCert = clienttasks.getEntitlementCertFromEntitlementCertFile(derivedEntitlementFile);
client.runCommandAndWait("rct cat-cert " + derivedEntitlementFile);
// assert all of the derived provided products are included in the entitlement
List<String> actualDerivedProvidedProductIds = new ArrayList<String>();
for (ProductNamespace productNamespace : derivedEntitlementCert.productNamespaces) {
actualDerivedProvidedProductIds.add(productNamespace.id);
}
Assert.assertTrue(actualDerivedProvidedProductIds.containsAll(poolDerivedProvidedProductIds) && poolDerivedProvidedProductIds.containsAll(actualDerivedProvidedProductIds), "The actual product ids " + actualDerivedProvidedProductIds + " provided by an entitlement cert from the derived subpool '" + derivedPool.subscriptionName + "' match the expected derivedProvidedProducts " + poolDerivedProvidedProductIds + " from the data center subscription '" + pool.subscriptionName + "'.");
// assert the derivedProductAttributes are reflected in the entitlement cert granted from the derived subpool
// Order: Order:
// Name: Awesome OS Server Basic (data center) Name: Awesome OS Server Basic (dc-virt)
// Number: order-8675309 Number: order-8675309
// SKU: awesomeos-server-basic-dc SKU: awesomeos-server-basic-vdc
// Contract: 18 Contract: 18
// Account: 12331131231 Account: 12331131231
// Service Level: None Service Level: Full-Service
// Service Type: Self-Support Service Type: Drive-Through
// Quantity: 5 Quantity: 5
// Quantity Used: 1 Quantity Used: 1
// Socket Limit: 4 Socket Limit: 2
// RAM Limit: RAM Limit: 2
// Core Limit: Core Limit: 4
// Virt Limit: Virt Limit:
// Virt Only: False Virt Only: True
// Subscription: Subscription:
// Stacking ID: Stacking ID:
// Warning Period: 30 Warning Period: 0
// Provides Management: False Provides Management: False
// Name: Awesome OS Server Basic (data center) Name: Awesome OS Server Basic (dc-virt)
Assert.assertEquals(hostEntitlementCert.orderNamespace.productName, pool.subscriptionName, "hostEntitlementCert.orderNamespace.productName should match the data center pool's subscription name");
Assert.assertEquals(derivedEntitlementCert.orderNamespace.productName, poolDerivedProductName, "derivedEntitlementCert.orderNamespace.productName should match the derivedProductName");
// Number: order-8675309 Number: order-8675309
Assert.assertEquals(derivedEntitlementCert.orderNamespace.orderNumber, hostEntitlementCert.orderNamespace.orderNumber, "Order Number from the derived entitlement should match the host entitlement");
// SKU: awesomeos-server-basic-dc SKU: awesomeos-server-basic-vdc
Assert.assertEquals(hostEntitlementCert.orderNamespace.productId, pool.productId, "hostEntitlementCert.orderNamespace.productId should match the data center pool's productId");
Assert.assertEquals(derivedEntitlementCert.orderNamespace.productId, poolDerivedProductId, "derivedEntitlementCert.orderNamespace.productId should match the derivedProductId");
// Contract: 18 Contract: 18
Assert.assertEquals(derivedEntitlementCert.orderNamespace.contractNumber, hostEntitlementCert.orderNamespace.contractNumber, "Contract Number from the derived entitlement should match the host entitlement");
// Account: 12331131231 Account: 12331131231
Assert.assertEquals(derivedEntitlementCert.orderNamespace.accountNumber, hostEntitlementCert.orderNamespace.accountNumber, "Account Number from the derived entitlement should match the host entitlement");
// Service Level: None Service Level: Full-Service
Assert.assertEquals(hostEntitlementCert.orderNamespace.supportLevel, pool.serviceLevel, "hostEntitlementCert.orderNamespace.supportLevel should match the data center pool's serviceLevel");
Assert.assertEquals(derivedEntitlementCert.orderNamespace.supportLevel, CandlepinTasks.getPoolDerivedProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "support_level"), "derivedEntitlementCert.orderNamespace.supportLevel should match the derivedProductAttribute support_level");
// Service Type: Self-Support Service Type: Drive-Through
Assert.assertEquals(hostEntitlementCert.orderNamespace.supportType, pool.serviceType, "hostEntitlementCert.orderNamespace.supportType should match the data center pool's serviceType");
Assert.assertEquals(derivedEntitlementCert.orderNamespace.supportType, CandlepinTasks.getPoolDerivedProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "support_type"), "derivedEntitlementCert.orderNamespace.supportType should match the derivedProductAttribute support_type");
// Quantity: 5 Quantity: 5
JSONObject jsonPool = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/pools/" + pool.poolId));
Assert.assertEquals(hostEntitlementCert.orderNamespace.quantity, String.valueOf(jsonPool.getInt("quantity")), "hostEntitlementCert.orderNamespace.quantity should match the data center subscription pool's total quantity");
// TEMPORARY WORKAROUND FOR BUG
String bugId = "983193";
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) {
log.warning("Skipping the assertion of quantity while bug '" + bugId + "' is open.");
} else {
// END OF WORKAROUND
if (// Bug 1011961 - rct cat-cert should display "Unlimited" for Quantity instead of "-1"; subscription-manager commit 7554c869608a0276151993d34fee4ddb54185f7a
clienttasks.isPackageVersion("subscription-manager", "<", "1.10.3-1") && derivedEntitlementCert.orderNamespace.quantity.equals("-1")) // Bug 1011961 - rct cat-cert should display "Unlimited" for Quantity instead of "-1"; subscription-manager commit 7554c869608a0276151993d34fee4ddb54185f7a
{
log.warning("The rct cat-cert tool encountered a Quantity of -1 which is fixed in subscription-manager-1.10.3-1. Skipping assertion.");
} else
Assert.assertEquals(derivedEntitlementCert.orderNamespace.quantity, derivedPool.quantity, "derivedEntitlementCert.orderNamespace.quantity should match the derivedPool's quantity");
}
// Quantity Used: 1 Quantity Used: 1
// TODO for derivedEntitlementCert only
// Socket Limit: 4 Socket Limit: 2
Assert.assertEquals(hostEntitlementCert.orderNamespace.socketLimit, CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "sockets"), "hostEntitlementCert.orderNamespace.socketLimit should match the data center pool's productAttribute sockets");
Assert.assertEquals(derivedEntitlementCert.orderNamespace.socketLimit, CandlepinTasks.getPoolDerivedProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "sockets"), "derivedEntitlementCert.orderNamespace.socketLimit should match the derivedProductAttribute sockets");
// RAM Limit: RAM Limit: 2
Assert.assertEquals(hostEntitlementCert.orderNamespace.ramLimit, CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "ram"), "hostEntitlementCert.orderNamespace.ramLimit should match the data center pool's productAttribute ram");
Assert.assertEquals(derivedEntitlementCert.orderNamespace.ramLimit, CandlepinTasks.getPoolDerivedProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "ram"), "derivedEntitlementCert.orderNamespace.ramLimit should match the derivedProductAttribute ram");
// Core Limit: Core Limit: 4
Assert.assertEquals(hostEntitlementCert.orderNamespace.coreLimit, CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "cores"), "hostEntitlementCert.orderNamespace.coreLimit should match the data center pool's productAttribute cores");
Assert.assertEquals(derivedEntitlementCert.orderNamespace.coreLimit, CandlepinTasks.getPoolDerivedProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "cores"), "derivedEntitlementCert.orderNamespace.coreLimit should match the derivedProductAttribute cores");
// Virt Limit: Virt Limit:
// TODO ignoring for now based on https://bugzilla.redhat.com/show_bug.cgi?id=983193#c2
// Virt Only: False Virt Only: True
String virtOnly = CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "virt_only");
Assert.assertEquals(hostEntitlementCert.orderNamespace.virtOnly, virtOnly == null ? Boolean.valueOf(false) : Boolean.valueOf(virtOnly), "hostEntitlementCert.orderNamespace.virtOnly should match the data center pool's productAttribute virt_only");
// CandlepinTasks.getPoolDerivedProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "virt_only");
virtOnly = String.valueOf(true);
/* the derived pool virt_only should ALWAYS be true */
Assert.assertEquals(derivedEntitlementCert.orderNamespace.virtOnly, virtOnly == null ? Boolean.valueOf(false) : Boolean.valueOf(virtOnly), "derivedEntitlementCert.orderNamespace.virtOnly should match the derivedProductAttribute virt_only");
// Subscription: Subscription:
Assert.assertEquals(derivedEntitlementCert.orderNamespace.subscriptionNumber, hostEntitlementCert.orderNamespace.subscriptionNumber, "Subscription from the derived entitlement should match the host entitlement");
// Stacking ID: Stacking ID:
Assert.assertEquals(hostEntitlementCert.orderNamespace.stackingId, CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "stacking_id"), "hostEntitlementCert.orderNamespace.stackingId should match the data center pool's productAttribute stacking_id");
Assert.assertEquals(derivedEntitlementCert.orderNamespace.stackingId, CandlepinTasks.getPoolDerivedProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "stacking_id"), "derivedEntitlementCert.orderNamespace.stackingId should match the derivedProductAttribute stacking_id");
// Warning Period: 30 Warning Period: 0
String warningPeriod = CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "warning_period");
Assert.assertEquals(hostEntitlementCert.orderNamespace.warningPeriod, warningPeriod == null ? "0" : warningPeriod, "hostEntitlementCert.orderNamespace.warningPeriod should match the data center pool's productAttribute warning_period");
warningPeriod = CandlepinTasks.getPoolDerivedProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "warning_period");
Assert.assertEquals(derivedEntitlementCert.orderNamespace.warningPeriod, warningPeriod == null ? "0" : warningPeriod, "derivedEntitlementCert.orderNamespace.warningPeriod should match the derivedProductAttribute warning_period");
// Provides Management: False Provides Management: False
String providesManagement = CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "management_enabled");
Assert.assertEquals(hostEntitlementCert.orderNamespace.providesManagement, providesManagement == null ? Boolean.valueOf(false) : Boolean.valueOf(providesManagement), "hostEntitlementCert.orderNamespace.providesManagement should match the data center pool's productAttribute management_enabled");
providesManagement = CandlepinTasks.getPoolDerivedProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "management_enabled");
Assert.assertEquals(derivedEntitlementCert.orderNamespace.providesManagement, providesManagement == null ? Boolean.valueOf(false) : Boolean.valueOf(providesManagement), "derivedEntitlementCert.orderNamespace.providesManagement should match the derivedProductAttribute management_enabled");
// for the sake of cleanup and to avoid this candlepin errors, let's unsubscribe from derivedEntitlementCert and then hostEntitlementCert
// ssh root@jsefler-6server.usersys.redhat.com subscription-manager unregister
// Stdout: Runtime Error No row with the given identifier exists: [org.candlepin.model.ProvidedProduct#8a90869341e61f7c0141e84e9ade3efd] at org.hibernate.UnresolvableObjectException.throwIfNull:65
// Stderr:
// ExitCode: 255
//
// ssh root@jsefler-6server.usersys.redhat.com subscription-manager unsubscribe --all
// Stdout:
// Stderr: Runtime Error No row with the given identifier exists: [org.candlepin.model.DerivedProvidedProduct#8a90869341e61f7c0141e84f2b9a3f0e] at org.hibernate.UnresolvableObjectException.throwIfNull:65
// ExitCode: 255
clienttasks.unsubscribeFromSerialNumber(derivedEntitlementCert.serialNumber);
clienttasks.unsubscribeFromSerialNumber(hostEntitlementCert.serialNumber);
}
use of rhsm.data.ProductNamespace 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.ProductNamespace in project rhsm-qe by RedHatQE.
the class BrandingTests method getEligibleBrandNamesFromCurrentEntitlementCerts.
/**
* @param entitlementCerts TODO
* @return the eligible brand names based on the current entitlement certs and the currently installed product certs
*/
Set<String> getEligibleBrandNamesFromCurrentEntitlementCerts() {
// Rules:
// - eligible brand names come from the currently entitled productNamespaces and are identified by a brandType = "OS"
// - the corresponding productId must be among the currently installed product certs to be eligible
Set<String> eligibleInstalledProductIdSet = new HashSet<String>();
Set<String> eligibleBrandNamesSet = new HashSet<String>();
List<String> eligibleBrandNamesList = new ArrayList<String>();
List<ProductCert> currentProductCerts = clienttasks.getCurrentProductCerts();
for (EntitlementCert entitlementCert : clienttasks.getCurrentEntitlementCerts()) {
for (ProductNamespace productNamespace : entitlementCert.productNamespaces) {
if (ProductCert.findFirstInstanceWithMatchingFieldFromList("productId", productNamespace.id, currentProductCerts) != null) {
if (productNamespace.brandType != null) {
if (productNamespace.brandType.equals("OS")) {
/* THE ORIGINAL FLEX BRANDING IMPLEMENTATION DUAL-PURPOSED THE PRODUCT NAME AS THE SOURCE OF THE BRANDING NAME
eligibleBrandNamesList.add(productNamespace.name);
eligibleBrandNamesSet.add(productNamespace.name);
*/
eligibleBrandNamesList.add(productNamespace.brandName);
eligibleBrandNamesSet.add(productNamespace.brandName);
eligibleInstalledProductIdSet.add(productNamespace.id);
}
}
}
}
}
if (eligibleBrandNamesList.size() > eligibleBrandNamesSet.size()) {
log.warning("Currently there are multiple entitled OS brand products by the same name " + eligibleBrandNamesList + ". This can happen when multiple OS subscriptions have been stacked.");
}
if (eligibleInstalledProductIdSet.size() > 1) {
log.warning("Currently there are multiple entitled OS brand product ids installed " + eligibleInstalledProductIdSet + ". This is likely caused by a RHEL installation or redhat-release bug. In this case a warning is logged to " + clienttasks.rhsmLogFile + " and no update is made to the branding file '" + brandingFile + "'.");
// 2017-10-25 13:56:44,700 [DEBUG] subscription-manager:26339:MainThread @certdirectory.py:217 - Installed product IDs: ['68', '69', '71', '76']
// 2017-10-25 13:56:44,772 [WARNING] subscription-manager:26339:MainThread @rhelentbranding.py:114 - More than one installed product with RHEL brand information is installed
eligibleBrandNamesSet.clear();
// TEMPORARY WORKAROUND
boolean invokeWorkaroundWhileBugIsOpen = true;
// Bug 1506271 - redhat-release is providing more than 1 variant specific product cert
String bugId = "1506271";
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("Skipping this test while bug '" + bugId + "' is open.");
}
// END OF WORKAROUND
}
return eligibleBrandNamesSet;
}
use of rhsm.data.ProductNamespace in project rhsm-qe by RedHatQE.
the class ContentIntegrationTests method assertEngProductsAreProvidedInEntitlementCert.
protected void assertEngProductsAreProvidedInEntitlementCert(String engProductId, EntitlementCert entitlementCert) {
// assert that the entitlementCert contains productNamespaces for the engProductId(s)
if (engProductId != null) {
// Note: the arch attribute can be a comma separated list of values
List<String> engProductIds = new ArrayList<String>(Arrays.asList(engProductId.trim().toUpperCase().split(" *, *")));
for (String id : engProductIds) {
boolean foundId = false;
for (ProductNamespace productNamespace : entitlementCert.productNamespaces) {
if (productNamespace.id.equals(id)) {
foundId = true;
break;
}
}
// Assert.assertTrue(foundId, "After subscribing to product '"+productId+"', found the expected engineering product id '"+id+"' amongst the granted entitlement cert productNamespaces: "+entitlementCert.productNamespaces);
Assert.assertTrue(foundId, "Found the expected engineering product id '" + id + "' amongst the granted entitlement cert productNamespaces: " + entitlementCert.productNamespaces);
}
// Assert.assertEquals(entitlementCert.productNamespaces.size(), engProductIds.size(), "After subscribing to product '"+productId+"', the number of possible provided engineering product ids from the granted entitlement cert matches the expected list: "+engProductIds);
Assert.assertEquals(entitlementCert.productNamespaces.size(), engProductIds.size(), "The number of possible provided engineering product ids from the granted entitlement cert matches the expected list: " + engProductIds);
}
}
use of rhsm.data.ProductNamespace in project rhsm-qe by RedHatQE.
the class SubscriptionManagerTasks method getEntitlementCertsProvidingProductCert.
public List<EntitlementCert> getEntitlementCertsProvidingProductCert(ProductCert productCert) {
List<EntitlementCert> correspondingEntitlementCerts = new ArrayList<EntitlementCert>();
ProductNamespace productNamespaceMatchingProductCert = null;
for (EntitlementCert entitlementCert : getCurrentEntitlementCerts()) {
productNamespaceMatchingProductCert = ProductNamespace.findFirstInstanceWithMatchingFieldFromList("id", productCert.productId, entitlementCert.productNamespaces);
if (productNamespaceMatchingProductCert != null) {
correspondingEntitlementCerts.add(entitlementCert);
}
}
return correspondingEntitlementCerts;
}
Aggregations