use of rhsm.data.SubscriptionPool in project rhsm-qe by RedHatQE.
the class OrgsTests method testAttemptToAttachSubscriptionsFromOtherOrgs.
@// update=true // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36570", "RHEL7-51358" }, 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 = "Tier2")
@Test(description = "consumers should NOT be able to attach subscriptions from other orgs", groups = { "Tier2Tests", "AttemptToAttachSubscriptionsFromOtherOrgs_Test", "blockedByBug-994711" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testAttemptToAttachSubscriptionsFromOtherOrgs() throws JSONException, Exception {
boolean skipTest = true;
Set<String> poolIdsTested = new HashSet<String>();
clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, true, false, null, null, null, null);
String ownerKey = clienttasks.getCurrentlyRegisteredOwnerKey();
for (RegistrationData registrationDatum : getRandomSubsetOfList(findGoodRegistrationData(false, sm_clientUsername, false, ownerKey), 3)) {
for (SubscriptionPool subscriptionPool : getRandomSubsetOfList(registrationDatum.allAvailableSubscriptionPools, 3)) {
if (!poolIdsTested.contains(subscriptionPool.poolId)) {
SSHCommandResult sshCommandResult = clienttasks.subscribe_(false, null, subscriptionPool.poolId, null, null, null, null, null, null, null, null, null, null);
// Assert.assertEquals(sshCommandResult.getStdout().trim(), "Insufficient permissions", "Stdout from an attempt to subscribe to pool id '"+subscriptionPool.poolId+"' belonging to a different org '"+registrationDatum.ownerKey+"'."); // server response 403 Forbidden
// new server response 404 Not Found from candlepin pull request https://github.com/candlepin/candlepin/pull/444 'Update auth system to allow "my system" administrators'
Assert.assertEquals(sshCommandResult.getStdout().trim(), String.format("Pool with id %s could not be found.", subscriptionPool.poolId), "Stdout from an attempt to subscribe to pool id '" + subscriptionPool.poolId + "' belonging to a different org '" + registrationDatum.ownerKey + "'.");
Assert.assertEquals(sshCommandResult.getStderr().trim(), "", "Stderr from an attempt to subscribe to pool id '" + subscriptionPool.poolId + "' belonging to a different org '" + registrationDatum.ownerKey + "'.");
Assert.assertEquals(sshCommandResult.getExitCode(), Integer.valueOf(1), "Exitcode from an attempt to subscribe to pool id '" + subscriptionPool.poolId + "' from a different org '" + registrationDatum.ownerKey + "'.");
Assert.assertTrue(clienttasks.getCurrentlyConsumedProductSubscriptions().isEmpty(), "The currently consumed subscriptions should be empty.");
// remember what pool ids were tested so we only test it once
poolIdsTested.add(subscriptionPool.poolId);
skipTest = false;
}
}
}
if (skipTest)
throw new SkipException("Could not find any subscription pools from orgs other than '" + ownerKey + "' to execute this test.");
}
use of rhsm.data.SubscriptionPool in project rhsm-qe by RedHatQE.
the class OstreeTests method getOstreeSubscriptionPoolsDataAsListOfLists.
protected List<List<Object>> getOstreeSubscriptionPoolsDataAsListOfLists() throws JSONException, Exception {
List<List<Object>> ll = new ArrayList<List<Object>>();
if (!isSetupBeforeSuiteComplete)
return ll;
if (!checkPackageVersionBeforeClass())
return ll;
// disable /etc/rhsm/pluginconf.d/ostree_content.OstreeContentPlugin.conf while this dataProvider runs
clienttasks.updateConfFileParameter(ostreeContentPluginFile.getPath(), "enabled", "0");
// register the host
clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, false, null, null, (String) null, null, null, null, true, false, null, null, null, null);
// attach each available pool in search of ones that provide content of type="ostree"
List<SubscriptionPool> currentlyAvailableSubscriptionPools = clienttasks.getCurrentlyAvailableSubscriptionPools();
// 37091 Product Name: Awesome OS OStree Bits
if (sm_serverType.equals(CandlepinType.standalone))
currentlyAvailableSubscriptionPools = clienttasks.getCurrentlyAvailableSubscriptionPools("37091", sm_serverUrl);
// /*debugTesting DO NOT COMMIT THIS LINE UNCOMMENTED */ if (sm_serverType.equals(CandlepinType.hosted)) currentlyAvailableSubscriptionPools = clienttasks.getCurrentlyAvailableSubscriptionPools("272", sm_serverUrl); // 272 Product Name: Red Hat Enterprise Linux Atomic Host Beta
for (SubscriptionPool subscriptionPool : currentlyAvailableSubscriptionPools) {
File serialPemFile = clienttasks.subscribeToSubscriptionPool_(subscriptionPool);
EntitlementCert entitlementCert = clienttasks.getEntitlementCertFromEntitlementCertFile(serialPemFile);
if (ContentNamespace.findFirstInstanceWithMatchingFieldFromList("type", "ostree", entitlementCert.contentNamespaces) != null) {
BlockedByBzBug blockedByBzBug = null;
// Bug 1153366 - SKU RH00004 should not provide more than one Atomic product
if (subscriptionPool.productId.equals("RH00004"))
blockedByBzBug = new BlockedByBzBug("1153366");
if (subscriptionPool.productId.equals("RH00003"))
blockedByBzBug = new BlockedByBzBug("1153366");
// Object bugzilla, SubscriptionPool osTreeSubscriptionPool
ll.add(Arrays.asList(new Object[] { blockedByBzBug, subscriptionPool }));
}
}
// remove all entitlements
clienttasks.unsubscribe_(true, (BigInteger) null, null, null, null, null, null);
// re-register the host to reduce the chance of a RateLimitExceededException
clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, false, null, null, (String) null, null, null, null, true, false, null, null, null, null);
// re-enable /etc/rhsm/pluginconf.d/ostree_content.OstreeContentPlugin.conf
clienttasks.updateConfFileParameter(ostreeContentPluginFile.getPath(), "enabled", "1");
return ll;
}
use of rhsm.data.SubscriptionPool in project rhsm-qe by RedHatQE.
the class OverconsumptionTests method testBasicAttemptToOversubscribe.
// 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-36655", "RHEL7-51495" }, 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 = "Tier2")
@Test(description = "subscription-manager: Basic attempt to oversubscribe the pool quantity", groups = { "Tier2Tests" }, enabled = true)
public // @ImplementsTCMS(id="")
void testBasicAttemptToOversubscribe() throws JSONException, Exception {
// find the pool with the least positive quantity available >= 2
client1tasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, registereeName, null, null, null, null, (String) null, null, null, null, Boolean.TRUE, false, null, null, null, null);
int quantity = 1000000;
for (SubscriptionPool pool : client1tasks.getCurrentlyAvailableSubscriptionPools()) {
// debugging if (pool.productId.equals("awesomeos-all-just-86_64-cont")) {testPool=pool;quantity = Integer.valueOf(pool.quantity);break;} else {if (true) continue;}
if (pool.quantity.equalsIgnoreCase("unlimited"))
continue;
int pool_quantity = Integer.valueOf(pool.quantity);
if (pool_quantity < quantity && pool_quantity >= 2) {
quantity = pool_quantity;
testPool = pool;
}
}
client1tasks.unregister(null, null, null, null);
Assert.assertNotNull(testPool, "Found an available pool with a quantity of available subscriptions >= 2.");
// consume each quantity available as a new consumer
log.info("Now we will register and subscribe new consumers until we exhaust all of the available subscriptions...");
systemConsumerIds.clear();
for (int i = quantity; i > 0; i--) {
// register a new system consumer
client1tasks.clean();
systemConsumerIds.add(client1tasks.getCurrentConsumerId(client1tasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, registereeName, null, null, null, null, (String) null, null, null, null, null, false, null, null, null, null)));
// subscribe to the pool
// client1tasks.subscribeToSubscriptionPool(testPool); // do not do this anymore because it could attach a quantity greater than 1 as a result of new feature bug 1008647
client1tasks.subscribe(null, null, testPool.poolId, null, null, "1", null, null, null, null, null, null, null);
// decrement this pool's quantity since we just consumed one
testPool.quantity = String.valueOf(Integer.valueOf(testPool.quantity) - 1);
}
log.info("Now we will register and subscribe the final subscriber as an attempt to oversubscribe to original pool: " + testPool);
client1tasks.clean();
systemConsumerIds.add(client1tasks.getCurrentConsumerId(client1tasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, registereeName, null, null, null, null, (String) null, null, null, null, null, false, null, null, null, null)));
SubscriptionPool pool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", testPool.poolId, client1tasks.getCurrentlyAllAvailableSubscriptionPools());
Assert.assertNull(pool, "The test pool is no longer in the --all --available list after having consumed all of its available subscriptions.");
pool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", testPool.poolId, client1tasks.getCurrentlyAvailableSubscriptionPools());
Assert.assertNull(pool, "The test pool is no longer in the --available list after having consumed all of its available subscriptions.");
// assert the consumed quantity
JSONObject jsonTestPool = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/pools/" + testPool.poolId));
Assert.assertEquals(jsonTestPool.getInt("consumed"), jsonTestPool.getInt("quantity"), "Asserting the test pool's consumed attribute matches it's original total quantity after having consumed all of its available entitlements.");
// now attempt to oversubscribe
log.info("Now we will attempt to oversubscribe to original pool: " + testPool);
// No entitlements are available from the pool with id '8a90f8143611c33f013611c4797b0456'.
Assert.assertNull(client1tasks.subscribeToSubscriptionPool(testPool, /*sm_serverAdminUsername*/
sm_clientUsername, /*sm_serverAdminPassword*/
sm_clientPassword, sm_serverUrl), "No entitlement cert is granted when the pool is already fully subscribed.");
// try again
// expected string changed by bug 876758
String expectedStdout = String.format("No entitlements are available from the pool with id '%s'.", testPool.poolId);
expectedStdout = String.format("No subscriptions are available from the pool with id '%s'.", testPool.poolId);
if (!clienttasks.workaroundForBug876764(sm_serverType))
expectedStdout = String.format("No subscriptions are available from the pool with ID '%s'.", testPool.poolId);
if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.3.1-1")) {
// commit 0d5fefcfa8c1c2485921d2dee6633879b1e06931 Correct incorrect punctuation in user messages
expectedStdout = String.format("No subscriptions are available from the pool with ID \"%s\".", testPool.poolId);
}
Assert.assertEquals(client1tasks.subscribe_(null, null, testPool.poolId, null, null, null, null, null, null, null, null, null, null).getStdout().trim(), expectedStdout);
// assert the consumed quantity again
jsonTestPool = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/pools/" + testPool.poolId));
Assert.assertEquals(jsonTestPool.getInt("consumed"), jsonTestPool.getInt("quantity"), "Asserting the test pool's consumed attribute has not overconsumed it's total quantity after attempting a basic overconsumption of its entitlements.");
}
use of rhsm.data.SubscriptionPool in project rhsm-qe by RedHatQE.
the class OverconsumptionTests method testConcurrentAttemptToOversubscribe.
@// update=true // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-37719", "RHEL7-51497" }, 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 = "Tier2")
@Test(description = "subscription-manager: Concurrent attempt to oversubscribe the pool quantity", groups = { "Tier2Tests", "blockedByBug-671195", "blockedByBug-1336054" }, dependsOnMethods = { "testConcurrentAttemptToSubscribe" }, enabled = true)
public // @ImplementsTCMS(id="")
void testConcurrentAttemptToOversubscribe() throws JSONException, Exception {
if (client1 == null || client2 == null)
throw new SkipException("This test requires two clients.");
// reregister the first systemConsumerId and unsubscribe from the test pool
client1tasks.clean();
client1tasks.register(sm_clientUsername, sm_clientPassword, null, null, null, registereeName, systemConsumerIds.get(0), null, null, null, (String) null, null, null, null, null, false, null, null, null, null);
client1tasks.unsubscribeFromAllOfTheCurrentlyConsumedProductSubscriptions();
// register from a second client too
client2tasks.clean();
systemConsumerIds.add(client2tasks.getCurrentConsumerId(client2tasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, registereeName, null, null, null, null, (String) null, null, null, null, null, false, null, null, null, null)));
// assert that the test pool has a quantity of 1 available
SubscriptionPool pool;
pool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", testPool.poolId, client1tasks.getCurrentlyAvailableSubscriptionPools());
Assert.assertNotNull(pool, "Found the test pool after having consumed available subscriptions.");
Assert.assertEquals(pool.quantity, "1", "Asserting the test pool quantity after having consumed almost all of its available subscriptions.");
pool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", testPool.poolId, client2tasks.getCurrentlyAvailableSubscriptionPools());
Assert.assertNotNull(pool, "Found the test pool after having consumed available subscriptions.");
Assert.assertEquals(pool.quantity, "1", "Asserting the test pool quantity after having consumed almost all of its available subscriptions.");
// attempt to concurrently subscribe to the test pool
log.info("Now we will attempt to subscribe both clients (only one should succeed) concurrently to pool: " + pool);
String client1command = String.format("%s subscribe --pool=%s", client1tasks.command, pool.poolId);
String client2command = String.format("%s subscribe --pool=%s", client2tasks.command, pool.poolId);
client1.runCommand(client1command, TestRecords.action());
client2.runCommand(client2command, TestRecords.action());
// timeout after 10 min
client1.waitForWithTimeout(new Long(10 * 60 * 1000));
// timeout after 10 min
client2.waitForWithTimeout(new Long(10 * 60 * 1000));
SSHCommandResult result1 = client1.getSSHCommandResult();
SSHCommandResult result2 = client2.getSSHCommandResult();
// assert that the test pool does NOT fall below zero
// pool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", testPool.poolId, client1tasks.getCurrentlyAllAvailableSubscriptionPools());
// Assert.assertNotNull(pool, "Found the test pool amongst --all --available after having consumed all of its available entitlements.");
// Assert.assertEquals(pool.quantity, "0", "Asserting the test pool quantity does not fall below zero after attempting a concurrent subscribe.");
// pool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", testPool.poolId, client2tasks.getCurrentlyAllAvailableSubscriptionPools());
// Assert.assertNotNull(pool, "Found the test pool amongst --all --available after having consumed all of its available entitlements.");
// Assert.assertEquals(pool.quantity, "0", "Asserting the test pool quantity does not fall below zero after attempting a concurrent subscribe.");
pool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", testPool.poolId, client1tasks.getCurrentlyAllAvailableSubscriptionPools());
Assert.assertNull(pool, "The test pool is no longer in the --all --available list after having consumed all of its available subscriptions.");
pool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", testPool.poolId, client2tasks.getCurrentlyAllAvailableSubscriptionPools());
Assert.assertNull(pool, "The test pool is no longer in the --all --available list after having consumed all of its available subscriptions.");
JSONObject jsonTestPool = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/pools/" + testPool.poolId));
Assert.assertEquals(jsonTestPool.getInt("consumed"), jsonTestPool.getInt("quantity"), "Asserting the consumed attribute of test pool '" + testPool.poolId + "' matches it's original total quantity after having consumed all of its available entitlements.");
// one of these command should have succeeded and one should have failed with "No entitlements are available"...
// decide who was the winner and who must have been the loser
SSHCommandResult sshWinner, sshLoser;
SubscriptionManagerTasks smtWinner, smtLoser;
// if (result1.getStdout().equals("")) { // client1 appears to be the winner, therefore client2 must be the loser
if (result1.getStdout().startsWith("Success")) {
// client1 appears to be the winner, therefore client2 must be the loser
sshWinner = result1;
smtWinner = client1tasks;
sshLoser = result2;
smtLoser = client2tasks;
} else {
// client2 must be the winner and client1 is the loser
sshWinner = result2;
smtWinner = client2tasks;
sshLoser = result1;
smtLoser = client1tasks;
}
// assert the Winner and Loser
log.info("SSHCommandResult from '" + smtWinner.hostname + "': " + sshWinner);
// Assert.assertEquals(sshWinner.getStdout().trim(), "","The lack of information in stdout from the subscribe command on '"+smtWinner.hostname+"' indicates that it won the subscribe race to the subscription pool's final entitlement.");
// Assert.assertEquals(sshWinner.getStdout().trim(), String.format("Successfully consumed a subscription from the pool with id %s.",testPool.poolId),"On '"+smtWinner.hostname+"' we successfully subscribed to poolid '"+testPool.poolId+"' indicating that it won the subscribe race to the subscription pool's final entitlement."); // Bug 812410 - Subscription-manager subscribe CLI feedback
// Assert.assertEquals(sshWinner.getStdout().trim(), String.format("Successfully consumed a subscription for: %s",testPool.subscriptionName),"On '"+smtWinner.hostname+"' we successfully subscribed to poolid '"+testPool.poolId+"' indicating that it won the subscribe race to the subscription pool's final entitlement."); // changed by Bug 874804 Subscribe -> Attach
Assert.assertEquals(sshWinner.getStdout().trim(), String.format("Successfully attached a subscription for: %s", testPool.subscriptionName), "On '" + smtWinner.hostname + "' we successfully subscribed to poolid '" + testPool.poolId + "' indicating that it won the subscribe race to the subscription pool's final entitlement.");
Assert.assertEquals(sshWinner.getStderr().trim(), "", "No stderr information is expected on '" + smtWinner.hostname + "'.");
// Assert.assertEquals(sshWinner.getExitCode(), Integer.valueOf(0),"The exit code from the subscribe command on '"+smtWinner.hostname+"' indicates the subscribe attempt was handled gracefully."); // assertion valid prior to RHEL63 fix for bug 689608
Assert.assertEquals(sshWinner.getExitCode(), Integer.valueOf(0), "The exit code from the subscribe command on '" + smtWinner.hostname + "' indicates the subscribe attempt successfully granted an entitlement.");
log.info("SSHCommandResult from '" + smtLoser.hostname + "': " + sshLoser);
// expected string changed by bug 876758
String expectedStdout = String.format("No entitlements are available from the pool with id '%s'.", testPool.poolId);
expectedStdout = String.format("No subscriptions are available from the pool with id '%s'.", testPool.poolId);
if (!clienttasks.workaroundForBug876764(sm_serverType))
expectedStdout = String.format("No subscriptions are available from the pool with ID '%s'.", testPool.poolId);
if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.3.1-1")) {
// commit 0d5fefcfa8c1c2485921d2dee6633879b1e06931 Correct incorrect punctuation in user messages
expectedStdout = String.format("No subscriptions are available from the pool with ID \"%s\".", testPool.poolId);
}
Assert.assertEquals(sshLoser.getStdout().trim(), expectedStdout, "Stdout must indicate to system '" + smtLoser.hostname + "' that there are no free entitlements left from poolId '" + testPool.poolId + "'.");
Assert.assertEquals(sshLoser.getStderr().trim(), "", "No stderr information is expected on '" + smtLoser.hostname + "'.");
// Assert.assertEquals(sshLoser.getExitCode(), Integer.valueOf(0),"The exit code from the subscribe command on '"+smtLoser.hostname+"' indicates the subscribe attempt was handled gracefully."); // assertion valid prior to RHEL63 fix for bug 689608
Assert.assertEquals(sshLoser.getExitCode(), Integer.valueOf(1), "The exit code from the subscribe command on '" + smtLoser.hostname + "' indicates the subscribe attempt did not grant an entitlement.");
}
use of rhsm.data.SubscriptionPool in project rhsm-qe by RedHatQE.
the class PluginTests method testEnabledSubscribeTestPluginHooksAreCalled.
@// update=true // uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-20054", "RHEL7-51062" }, 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 = "execute subscription-manager modules and verify the expected SubscribeTestPlugin hooks are called", groups = { "Tier1Tests" }, priority = 430, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testEnabledSubscribeTestPluginHooksAreCalled() throws JSONException, Exception {
truncateRhsmLog();
// get the pre-registered facts on the system
clienttasks.unregister(null, null, null, null);
Map<String, String> facts = clienttasks.getFacts();
// get the current rhsm logging level; INFO or DEBUG
String rhsmLogLevel = null;
if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.17.10-1")) {
// RHEL7.3 commit d84b15f42c2e4521e130b939039960c0846b849c 1334916: Move logging configuration to rhsm.conf
rhsmLogLevel = clienttasks.getConfFileParameter(clienttasks.rhsmConfFile, "logging", "default_log_level");
} else if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.14.2-1")) {
// commit 66aafd77dc629b921379f0e121421c1c21c0b787 Move to fileConfig based logging.
rhsmLogLevel = clienttasks.getConfFileParameter(clienttasks.rhsmLoggingConfFile, "handler_rhsm_log", "level");
} else {
// default
rhsmLogLevel = "DEBUG";
}
// register and get the current available subscription list
String consumerId = clienttasks.getCurrentConsumerId(clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (List<String>) null, null, null, null, true, null, null, null, null, null));
List<SubscriptionPool> pools = clienttasks.getCurrentlyAvailableSubscriptionPools();
if (pools.isEmpty())
throw new SkipException("Cannot randomly pick a pool for subscribing when there are no available pools for testing.");
// randomly pick a pool
SubscriptionPool pool = pools.get(randomGenerator.nextInt(pools.size()));
// when the Suggested quantity is 0, let's specify a quantity to avoid Stdout: Quantity '1' is not a multiple of instance multiplier '2'
String quantity = null;
// when the Suggested quantity is 0, let's specify a quantity to avoid Stdout: Quantity '1' is not a multiple of instance multiplier '2'
if (pool.suggested < 1)
quantity = CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "instance_multiplier");
// mark the rhsm.log file
String logMarker = System.currentTimeMillis() + " Testing verifyEnabledSubscribeTestPluginHooksAreCalled_Test...";
RemoteFileTasks.markFile(client, clienttasks.rhsmLogFile, logMarker);
// subscribe to a random pool (to generate calls to pre/post hooks)
clienttasks.subscribe(null, null, pool.poolId, null, null, quantity, null, null, null, null, null, null, null);
// sleep(5000); // give the plugin hooks a chance to be called; I think this is an async process
// get the tail of the marked rhsm.log file
String logTail = RemoteFileTasks.getTailFromMarkedFile(client, clienttasks.rhsmLogFile, logMarker, "Running p").trim();
// 2013-03-16 11:50:13,462 [DEBUG] @plugins.py:695 - Running post_facts_collection_hook in facts_collection_test.FactsCollectionTestPlugin
// 2013-03-16 11:50:13,462 [INFO] @facts_collection_test.py:33 - Running post_facts_collection_hook: consumer facts count is 100
// 2013-03-16 11:50:13,750 [DEBUG] @plugins.py:695 - Running pre_subscribe_hook in subscribe_test.SubscribeTestPlugin
// 2013-03-16 11:50:13,751 [INFO] @subscribe_test.py:30 - Running pre_subscribe_hook: system is about to subscribe.
// 2013-03-16 11:50:14,540 [DEBUG] @plugins.py:695 - Running post_subscribe_hook in subscribe_test.SubscribeTestPlugin
// 2013-03-16 11:50:14,540 [INFO] @subscribe_test.py:38 - Running post_subscribe_hook: system just subscribed.
// assert the pre/post_subscribe_hooks are called
List<String> expectedLogInfo = new ArrayList<String>();
// enabled in prior FactsCollectionTestPlugin Tests
if (rhsmLogLevel.equals("DEBUG"))
expectedLogInfo.add("Running post_facts_collection_hook in facts_collection_test.FactsCollectionTestPlugin");
// enabled in prior FactsCollectionTestPlugin Tests
if (rhsmLogLevel.equals("DEBUG") || rhsmLogLevel.equals("INFO"))
expectedLogInfo.add("Running post_facts_collection_hook: consumer facts count is " + facts.values().size());
if (rhsmLogLevel.equals("DEBUG"))
expectedLogInfo.add("Running pre_subscribe_hook in subscribe_test.SubscribeTestPlugin");
if (rhsmLogLevel.equals("DEBUG") || rhsmLogLevel.equals("INFO"))
expectedLogInfo.add("Running pre_subscribe_hook: system is about to subscribe");
if (rhsmLogLevel.equals("DEBUG") || rhsmLogLevel.equals("INFO"))
expectedLogInfo.add("Running pre_subscribe_hook: subscribing consumer is " + consumerId);
if (rhsmLogLevel.equals("DEBUG"))
expectedLogInfo.add("Running post_subscribe_hook in subscribe_test.SubscribeTestPlugin");
if (rhsmLogLevel.equals("DEBUG") || rhsmLogLevel.equals("INFO"))
expectedLogInfo.add("Running post_subscribe_hook: system just subscribed");
if (rhsmLogLevel.equals("DEBUG") || rhsmLogLevel.equals("INFO"))
expectedLogInfo.add("Running post_subscribe_hook: subscribed consumer is " + consumerId);
if (rhsmLogLevel.equals("DEBUG") || rhsmLogLevel.equals("INFO"))
expectedLogInfo.add("Running post_subscribe_hook: subscribed from pool id " + pool.poolId);
// used for debugging
if (logTail.replaceAll("\n", "").matches(".*" + joinListToString(expectedLogInfo, ".*") + ".*") == false)
RemoteFileTasks.getTailFromMarkedFile(client, clienttasks.rhsmLogFile, logMarker, null);
// used for debugging
if (logTail.replaceAll("\n", "").matches(".*" + joinListToString(expectedLogInfo, ".*") + ".*") == false)
clienttasks.plugins_(null, null, null, true);
Assert.assertTrue(logTail.replaceAll("\n", "").matches(".*" + joinListToString(expectedLogInfo, ".*") + ".*"), "The '" + clienttasks.rhsmLogFile + "' reports log messages: " + expectedLogInfo);
}
Aggregations