use of com.redhat.qe.tools.SSHCommandResult in project rhsm-qe by RedHatQE.
the class SubscriptionManagerTasks method listConsumedProductSubscriptions.
/**
* @return SSHCommandResult from "subscription-manager-cli list --consumed"
*/
public SSHCommandResult listConsumedProductSubscriptions() {
SSHCommandResult sshCommandResult = list(null, null, Boolean.TRUE, null, null, null, null, null, null, null, null, null, null, null);
List<File> entitlementCertFiles = getCurrentEntitlementCertFiles();
String expectedConsumedListMessage = "No consumed subscription pools to list";
if (isPackageVersion("subscription-manager", ">=", "1.20.2-1")) {
// commit da72dfcbbb2c3a44393edb9e46e1583d05cc140a
expectedConsumedListMessage = "No consumed subscription pools were found.";
}
if (entitlementCertFiles.isEmpty()) {
Assert.assertEquals(sshCommandResult.getStdout().trim(), expectedConsumedListMessage, "Expected message when there are no consumed subscription pools.");
} else {
String title = "Consumed Product Subscriptions";
// changed in https://bugzilla.redhat.com/show_bug.cgi?id=806986#c10
title = "Consumed Subscriptions";
// Assert.assertContainsMatch(sshCommandResult.getStdout(), title); // produces too much logging
Assert.assertTrue(sshCommandResult.getStdout().contains(title), "The list of consumed products is entitled '" + title + "'.");
}
return sshCommandResult;
}
use of com.redhat.qe.tools.SSHCommandResult in project rhsm-qe by RedHatQE.
the class SubscriptionManagerTasks method unsubscribeFromTheCurrentlyConsumedProductSubscriptionSerialsCollectively.
/**
* Collectively unsubscribe from all of the currently consumed product subscriptions.
* This will ultimately issue a single call to unsubscribe --serial SERIAL1 --serial SERIAL2 --serial SERIAL3 for each of the product subscriptions being consumed.
* @throws Exception
*/
public SSHCommandResult unsubscribeFromTheCurrentlyConsumedProductSubscriptionSerialsCollectively() throws Exception {
log.info("Unsubscribing from all of the currently consumed product subscription serials in one collective call...");
List<BigInteger> serials = new ArrayList<BigInteger>();
// THIS AVOIDS PROBLEMS WHEN MODIFIER ENTITLEMENTS ARE BEING CONSUMED
for (ProductSubscription productSubscription : getCurrentlyConsumedProductSubscriptions()) {
EntitlementCert entitlementCert = getEntitlementCertCorrespondingToProductSubscription(productSubscription);
JSONObject jsonEntitlement = CandlepinTasks.getEntitlementUsingRESTfulAPI(this.currentlyRegisteredUsername, this.currentlyRegisteredPassword, candlepinUrl, entitlementCert.id);
String poolHref = jsonEntitlement.getJSONObject("pool").getString("href");
JSONObject jsonPool = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(this.currentlyRegisteredUsername, this.currentlyRegisteredPassword, candlepinUrl, poolHref));
String poolId = jsonPool.getString("id");
if (CandlepinTasks.isPoolAModifier(this.currentlyRegisteredUsername, this.currentlyRegisteredPassword, poolId, candlepinUrl)) {
// serials to entitlements that modify others should be at the front of the list to be removed, otherwise they will get re-issued under a new serial number when the modified entitlement is removed first.
serials.add(0, productSubscription.serialNumber);
} else {
serials.add(productSubscription.serialNumber);
}
}
// unsubscribe from all serials collectively
SSHCommandResult result = unsubscribe(false, serials, null, null, null, null, null);
Assert.assertTrue(getCurrentlyConsumedProductSubscriptions().size() == 0, "Currently no product subscriptions are consumed.");
Assert.assertTrue(getCurrentEntitlementCertFiles().size() == 0, "This machine has no entitlement certificate files.");
return result;
}
use of com.redhat.qe.tools.SSHCommandResult in project rhsm-qe by RedHatQE.
the class SubscriptionManagerTasks method getYumListAvailable.
// public ArrayList<String> yumListAvailable (String disableplugin, String disablerepo, String enablerepo, String globExpression) {
/**
* @param options
* @return array of packages returned from a call to yum list available [options]
*/
public ArrayList<String> getYumListAvailable(String options) {
ArrayList<String> packages = new ArrayList<String>();
sshCommandRunner.runCommandAndWaitWithoutLogging("killall -9 yum");
if (options == null)
options = "";
// String command = "yum list available";
// if (disableplugin!=null) command += " --disableplugin="+disableplugin;
// if (disablerepo!=null) command += " --disablerepo="+disablerepo;
// if (enablerepo!=null) command += " --enablerepo="+enablerepo;
// if (globExpression!=null) command += " "+globExpression;
// --disableplugin=rhnplugin helps avoid: up2date_client.up2dateErrors.AbuseError
String command = "yum list available " + options + " --disableplugin=rhnplugin";
// execute the yum command to list available packages
int min = 5;
log.fine("Using a timeout of " + min + " minutes for next ssh command...");
SSHCommandResult result = sshCommandRunner.runCommandAndWait(command, Long.valueOf(min * 60000));
// FINE: ExitCode: 1
if (result.getStderr().contains("Error 500: Internal Server Error")) {
log.warning(result.getStderr());
Assert.fail("Encountered an Internal Server Error while running: " + command);
}
// Error: No matching Packages to list
if (result.getStderr().contains("Error: No matching Packages to list")) {
log.info("No matching Packages to list from: " + command);
return packages;
}
// Example result.getStdout()
// Loaded plugins: product-id, refresh-packagekit, subscription-manager
// No plugin match for: rhnplugin
// Updating certificate-based repositories.
// Available Packages
// xmltex.noarch 20020625-16.el6 red-hat-enterprise-linux-6-entitlement-alpha-rpms
// xmlto.x86_64 0.0.23-3.el6 red-hat-enterprise-linux-6-entitlement-alpha-rpms
// xmlto-tex.noarch 0.0.23-3.el6 red-hat-enterprise-linux-6-entitlement-alpha-rpms
// xorg-x11-apps.x86_64 7.4-10.el6 red-hat-enterprise-linux-6-entitlement-alpha-rpms
// pacemaker-libs-devel.i686 1.1.7-6.el6 rhel-ha-for-rhel-6-server-rpms
// pacemaker-libs-devel.x86_64 1.1.7-6.el6 rhel-ha-for-rhel-6-server-rpms
// perl-Net-Telnet.noarch 3.03-11.el6 rhel-ha-for-rhel-6-server-rpms
// pexpect.noarch 2.3-6.el6 rhel-ha-for-rhel-6-server-rpms
// python-repoze-what-plugins-sql.noarch
// 1.0-0.6.rc1.el6 rhel-ha-for-rhel-6-server-rpms
// python-repoze-what-quickstart.noarch
// 1.0.1-1.el6 rhel-ha-for-rhel-6-server-rpms
// python-repoze-who-friendlyform.noarch
// 1.0-0.3.b3.el6 rhel-ha-for-rhel-6-server-rpms
// python-repoze-who-plugins-sa.noarch
// 1.0-0.4.rc1.el6 rhel-ha-for-rhel-6-server-rpms
// python-suds.noarch 0.4.1-3.el6 rhel-ha-for-rhel-6-server-rpms
// python-tw-forms.noarch 0.9.9-1.el6 rhel-ha-for-rhel-6-server-rpms
// resource-agents.x86_64 3.9.2-12.el6_3.2 rhel-ha-for-rhel-6-server-rpms
// cluster-cim.x86_64 0.12.1-8.el5_9
// rhel-ha-for-rhel-5-server-rpms
// cluster-snmp.x86_64 0.12.1-8.el5_9
// rhel-ha-for-rhel-5-server-rpms
// ipvsadm.x86_64 1.24-13.el5 rhel-ha-for-rhel-5-server-rpms
String availablePackadesTable = result.getStdout();
String prefix = "Available Packages";
if (availablePackadesTable.contains(prefix)) {
// strip leading info before the list of "Availabile Packages"
availablePackadesTable = availablePackadesTable.substring(availablePackadesTable.indexOf(prefix) + prefix.length(), availablePackadesTable.length()).trim();
}
// if (enablerepo==null||enablerepo.equals("*")) enablerepo="(\\S+)";
// String regex="^(\\S+) +(\\S+) +"+enablerepo+"$";
// String regex="^(\\S+) +(\\S+) +(\\S+)$"; // assume all the packages are on a line with three words
// String regex="^(\\S+)(?:\\n)? +(\\S+) +(\\S+)$"; // works when the second and third word are on the next line, but not just the third
String regex = "^(\\S+)(?:\\n)? +(\\S+)(?: +(\\S+)$|\\n +(\\S+)$)";
Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
Matcher matcher = pattern.matcher(availablePackadesTable);
if (!matcher.find()) {
log.info("Did NOT find any available packages from: " + command);
return packages;
}
// assemble the list of packages and return them
do {
// group(1) is the pkg, group(2) is the version, group(3) is the repo
packages.add(matcher.group(1));
} while (matcher.find());
// flip the packages since the ones at the end of the list are usually easier to install
ArrayList<String> packagesCloned = (ArrayList<String>) packages.clone();
packages.clear();
for (int p = packagesCloned.size() - 1; p >= 0; p--) packages.add(packagesCloned.get(p));
return packages;
}
use of com.redhat.qe.tools.SSHCommandResult in project rhsm-qe by RedHatQE.
the class SubscriptionManagerTasks method plugins.
/**
* plugins with asserting results
*/
public SSHCommandResult plugins(Boolean list, Boolean listslots, Boolean listhooks, Boolean verbose) {
SSHCommandResult sshCommandResult = plugins_(list, listslots, listhooks, verbose);
// assert results for a successful call to plugins
Assert.assertEquals(sshCommandResult.getExitCode(), Integer.valueOf(0), "The exit code from the plugins command indicates a success.");
Assert.assertEquals(sshCommandResult.getStderr(), "", "Stderr from the plugins command indicates a success.");
// from the plugins command
return sshCommandResult;
}
use of com.redhat.qe.tools.SSHCommandResult in project rhsm-qe by RedHatQE.
the class SubscriptionManagerTasks method facts.
/**
* @param list
* @param update
* @param proxy TODO
* @param proxyuser TODO
* @param proxypassword TODO
* @param noproxy TODO
* @return
*/
public SSHCommandResult facts(Boolean list, Boolean update, String proxy, String proxyuser, String proxypassword, String noproxy) {
SSHCommandResult sshCommandResult = facts_(list, update, proxy, proxyuser, proxypassword, noproxy);
// assert results for a successful facts
Assert.assertEquals(sshCommandResult.getExitCode(), Integer.valueOf(0), "The exit code from the facts command indicates a success.");
String regex = "";
if (list != null && list) {
// list of the current facts
regex = ".*:.*";
// Assert.assertTrue(SubscriptionManagerCLITestScript.doesStringContainMatches(sshCommandResult.getStdout().trim(), regex), "The list of facts contains matches to regex '"+regex+"'.");
List<String> facts = SubscriptionManagerCLITestScript.getSubstringMatches(sshCommandResult.getStdout().trim(), regex);
Assert.assertTrue(facts.size() > 1, "A list of facts matching regex '" + regex + "' was reported.");
}
if (update != null && update) {
// expectedMsg=getCurrentConsumerCert().consumerid; // consumerid // RHEL57 RHEL61
String expectedMsg = "Successfully updated the system facts.";
Assert.assertTrue(sshCommandResult.getStdout().trim().contains(expectedMsg), "The facts update feedback contains expected message '" + expectedMsg + "'.");
}
// from the facts command
return sshCommandResult;
}
Aggregations