use of rhsm.cli.tasks.SubscriptionManagerTasks in project rhsm-qe by RedHatQE.
the class FactsTests method testBypassRulesDueToType.
@Test(description = "subscription-manager: facts and rules: bypass rules due to type", groups = { "Tier2Tests", "blockedByBug-641027" }, dependsOnGroups = {}, // 9/17/2013 this test has been disabled in favor of new BypassRulesDueToTypeAndCapabilities_Test
enabled = false)
// cores, ram, instance_multiplier, derived_product
@ImplementsNitrateTest(caseId = 56331)
public void testBypassRulesDueToType() throws Exception {
// determine which client is a RHEL Workstation
SSHCommandRunner client = null;
SubscriptionManagerTasks clienttasks = null;
if (client1 != null && client1tasks.getRedhatRelease().startsWith("Red Hat Enterprise Linux Workstation")) {
client = client1;
clienttasks = client1tasks;
} else if (client2 != null && client2tasks.getRedhatRelease().startsWith("Red Hat Enterprise Linux Workstation")) {
client = client2;
clienttasks = client2tasks;
} else {
throw new SkipException("This test requires a Red Hat Enterprise Linux Workstation.");
}
// on a RHEL workstation register to candlepin (as type system)
clienttasks.unregister(null, null, null, null);
clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, ConsumerType.system, null, null, null, null, null, (String) null, null, null, null, null, false, null, null, null, null);
// get a list of available pools and all available pools (for this system consumer)
List<SubscriptionPool> compatiblePoolsAsSystemConsumer = clienttasks.getCurrentlyAvailableSubscriptionPools();
List<SubscriptionPool> allPoolsAsSystemConsumer = clienttasks.getCurrentlyAllAvailableSubscriptionPools();
Assert.assertFalse(compatiblePoolsAsSystemConsumer.containsAll(allPoolsAsSystemConsumer), "Without bypassing the rules, not *all* pools are available for subscribing by a type=system consumer.");
Assert.assertTrue(allPoolsAsSystemConsumer.containsAll(compatiblePoolsAsSystemConsumer), "The pools available to a type=system consumer is a subset of --all --available pools.");
// now register to candlepin (as type candlepin)
clienttasks.unregister(null, null, null, null);
clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, ConsumerType.candlepin, null, null, null, null, null, (String) null, null, null, null, null, false, null, null, null, null);
// get a list of available pools and all available pools (for this candlepin consumer)
List<SubscriptionPool> compatiblePoolsAsCandlepinConsumer = clienttasks.getCurrentlyAvailableSubscriptionPools();
List<SubscriptionPool> allPoolsAsCandlepinConsumer = clienttasks.getCurrentlyAllAvailableSubscriptionPools();
Assert.assertTrue(compatiblePoolsAsCandlepinConsumer.containsAll(allPoolsAsCandlepinConsumer) && allPoolsAsCandlepinConsumer.containsAll(compatiblePoolsAsCandlepinConsumer), "The pools available to a type=candlepin consumer bypass the rules (list --all --available is identical to list --available).");
// now assert that all the pools can be subscribed to by the consumer (registered as type candlepin)
clienttasks.subscribeToTheCurrentlyAvailableSubscriptionPoolsCollectively();
}
use of rhsm.cli.tasks.SubscriptionManagerTasks 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.cli.tasks.SubscriptionManagerTasks in project rhsm-qe by RedHatQE.
the class SubscriptionManagerCLITestScript method unregisterClientsAfterSuite.
@AfterSuite(groups = { "cleanup" }, description = "subscription manager tear down")
public void unregisterClientsAfterSuite() {
for (SubscriptionManagerTasks clienttasks : Arrays.asList(client1tasks, client2tasks)) {
if (clienttasks != null) {
// release the entitlements consumed by the current registration
clienttasks.unregister_(null, null, null, null);
// in case the unregister fails, also clean the client
clienttasks.clean_();
}
}
}
use of rhsm.cli.tasks.SubscriptionManagerTasks in project rhsm-qe by RedHatQE.
the class SubscriptionManagerCLITestScript method deleteAllRegisteredConsumerEntitlementsAfterSuite.
@AfterSuite(groups = { "cleanup" }, description = "attempt to delete any abandoned entitlements granted during the run of this suite")
public void deleteAllRegisteredConsumerEntitlementsAfterSuite() {
// /*debugTestSSL*/ if(true) return;
for (SubscriptionManagerTasks clienttasks : Arrays.asList(client1tasks, client2tasks)) {
if (clienttasks != null) {
// determine the url to the server
String url = "https://" + clienttasks.getConfFileParameter(clienttasks.rhsmConfFile, "server", "hostname") + ":" + clienttasks.getConfFileParameter(clienttasks.rhsmConfFile, "server", "port") + clienttasks.getConfFileParameter(clienttasks.rhsmConfFile, "server", "prefix");
// for (String consumerCertPath : Arrays.asList(clienttasks.sshCommandRunner.runCommandAndWait("find "+allRegisteredConsumerCertsDir+" -name '*cert.pem'").getStdout().trim().split("\n"))) {
for (String consumerCertPath : Arrays.asList(clienttasks.sshCommandRunner.runCommandAndWait("ls -t1 " + allRegisteredConsumerCertsDir + "/*cert.pem").getStdout().trim().split("\n"))) {
// process consumers in reverse order of their creation
if (consumerCertPath.isEmpty())
continue;
// extract the uuid from the consumerCertPath
String uuid = consumerCertPath.replace(allRegisteredConsumerCertsDir, "").replace("_cert.pem", "").replace("/", "");
// extract the key from the consumerCertPath
String consumerKeyPath = consumerCertPath.replace("cert.pem", "key.pem");
// curl -k --cert /etc/pki/consumer/cert.pem --key /etc/pki/consumer/key.pem -X DELETE https://subscription.rhn.stage.redhat.com/subscription/consumers/2f801f45-3b79-42ee-9013-f4ad5bd35c3a/entitlements
clienttasks.sshCommandRunner.runCommandAndWait("curl --stderr /dev/null --insecure --cert " + consumerCertPath + " --key " + consumerKeyPath + " --request DELETE " + url + "/consumers/" + uuid + "/entitlements");
}
}
}
}
use of rhsm.cli.tasks.SubscriptionManagerTasks in project rhsm-qe by RedHatQE.
the class SELinuxTests method testAssertThatNoSELinuxDenialsWereLogged.
// 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-20117", "RHEL7-51117" }, 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 Tier2 Tier3")
@Test(description = "assert that no SELinux denials were logged during this TestSuite (this test should be executed at the end of all test run/suites)", groups = { "Tier1Tests", "Tier2Tests", "Tier3Tests", "FipsTests", "blockedByBug-694879", "blockedByBug-822402" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testAssertThatNoSELinuxDenialsWereLogged() {
log.info("Assuming this test is being executed last in the TestNG Suite...");
// ANY LOGIC/WORKAROUND CHANGES MADE HERE AND THERE. TODO, eliminate this dual maintenance
for (SubscriptionManagerTasks clienttasks : Arrays.asList(client1tasks, client2tasks)) {
if (clienttasks != null) {
String avcRegex;
String tailFromMarkedFile = RemoteFileTasks.getTailFromMarkedFile(clienttasks.sshCommandRunner, clienttasks.auditLogFile, selinuxSuiteMarker, "denied").trim();
// TEMPORARY WORKAROUND
// [root@jsefler-rhel7 ~]# tail -f /var/log/audit/audit.log | grep AVC
// type=USER_AVC msg=audit(1470087122.008:24063): pid=693 uid=81 auid=4294967295 ses=4294967295 subj=system_u:system_r:system_dbusd_t:s0-s0:c0.c1023 msg='avc: denied { 0x2 } for msgtype=signal interface=org.freedesktop.login1.Manager member=SessionNew dest=org.freedesktop.DBus spid=691 tpid=720 scontext=system_u:system_r:systemd_logind_t:s0 tcontext=system_u:system_r:modemmanager_t:s0 tclass=(null) exe="/usr/bin/dbus-daemon" sauid=81 hostname=? addr=? terminal=?'
// type=USER_AVC msg=audit(1470087122.226:24068): pid=693 uid=81 auid=4294967295 ses=4294967295 subj=system_u:system_r:system_dbusd_t:s0-s0:c0.c1023 msg='avc: denied { 0x2 } for msgtype=signal interface=org.freedesktop.login1.Manager member=SessionRemoved dest=org.freedesktop.DBus spid=691 tpid=720 scontext=system_u:system_r:systemd_logind_t:s0 tcontext=system_u:system_r:modemmanager_t:s0 tclass=(null) exe="/usr/bin/dbus-daemon" sauid=81 hostname=? addr=? terminal=?'
avcRegex = "type=USER_AVC .* msgtype=signal interface=org.freedesktop.login1.Manager member=Session(New|Removed) dest=org.freedesktop.DBus .* exe=\"/usr/bin/dbus-daemon\" .*";
if (!tailFromMarkedFile.isEmpty() && doesStringContainMatches(tailFromMarkedFile, avcRegex)) {
boolean invokeWorkaroundWhileBugIsOpen = true;
// Bug 1362273 - avc denied /var/log/audit/audit.log when "systemd: Started Session # of user root." is written to /var/log/messages every two minutes
String bugId = "1362273";
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("Ignoring the presence of AVC denials matching '" + avcRegex + "' while bug '" + bugId + "' is open.");
tailFromMarkedFile = tailFromMarkedFile.replaceAll(avcRegex, "");
}
}
// END OF WORKAROUND
Assert.assertTrue(tailFromMarkedFile.trim().isEmpty(), "No SELinux denials found in the audit log '" + clienttasks.auditLogFile + "' on client " + clienttasks.sshCommandRunner.getConnection().getRemoteHostname() + " while executing this test class.");
}
}
}
Aggregations