Search in sources :

Example 51 with SSHCommandResult

use of com.redhat.qe.tools.SSHCommandResult in project rhsm-qe by RedHatQE.

the class SubscriptionManagerTasks method config.

/**
 * "subscription-manager config"
 */
public SSHCommandResult config(Boolean list, Boolean remove, Boolean set, List<String[]> listOfSectionNameValues) {
    // store what is currently configured to assist during assertion of remove stdout
    String rhsmConfFileContents = sshCommandRunner.runCommandAndWaitWithoutLogging("egrep -v  \"^\\s*(#|$)\" " + rhsmConfFile).getStdout();
    SSHCommandResult sshCommandResult = config_(list, remove, set, listOfSectionNameValues);
    // assert results...
    // assert the exit code was a success
    Assert.assertEquals(sshCommandResult.getExitCode(), Integer.valueOf(0), "The exit code from the config command indicates a success.");
    // assert remove stdout indicates a success
    if (remove != null && remove) {
        for (String[] section_name_value : listOfSectionNameValues) {
            String section = section_name_value[0];
            String name = section_name_value[1];
            // String value	= section_name_value[2];
            // [root@jsefler-6 ~]# subscription-manager config --remove=server.repo_ca_cert
            // You have removed the value for section server and name repo_ca_cert.
            // The default value for repo_ca_cert will now be used.
            // OR
            // [root@jsefler-7 ~]# subscription-manager config --remove=server.repo_ca_cert
            // Section server and name repo_ca_cert cannot be removed.
            String value = getSectionParameterFromConfigFileContents(section, name, rhsmConfFileContents);
            // if (value!=null) {
            if (value != null || Integer.valueOf(redhatReleaseX) < 7) {
                // added OR check after Bug 927350 was CLOSED NOTABUG
                Assert.assertTrue(sshCommandResult.getStdout().contains(String.format("You have removed the value for section %s and name %s.", section, name.toLowerCase())), "The stdout indicates the removal of config parameter name '" + name + "' from section '" + section + "'.");
                Assert.assertEquals(sshCommandResult.getStdout().contains(String.format("The default value for %s will now be used.", name.toLowerCase())), defaultConfFileParameterNames(section, true).contains(name), "The stdout indicates the default value for '" + name + "' will now be used after having removed it from section '" + section + "'.");
            } else {
                Assert.assertTrue(sshCommandResult.getStdout().contains(String.format("Section %s and name %s cannot be removed.", section, name.toLowerCase())), "The stdout indicates that config parameter name '" + name + "' from section '" + section + "' cannot be removed since it is not set.");
            }
        }
    }
    // from the orgs command
    return sshCommandResult;
}
Also used : SSHCommandResult(com.redhat.qe.tools.SSHCommandResult)

Example 52 with SSHCommandResult

use of com.redhat.qe.tools.SSHCommandResult in project rhsm-qe by RedHatQE.

the class SubscriptionManagerTasks method subscribeToSubscriptionPool.

/**
 * subscribe to the given SubscriptionPool (assumes pool came from the list of available pools)
 * @return the newly installed EntitlementCert file to the newly consumed ProductSubscriptions
 */
public File subscribeToSubscriptionPool(SubscriptionPool pool, String quantity, String authenticator, String password, String serverUrl) {
    List<ProductSubscription> beforeProductSubscriptions = getCurrentlyConsumedProductSubscriptions();
    List<File> beforeEntitlementCertFiles = getCurrentEntitlementCertFiles();
    log.info("Subscribing to subscription pool: " + pool);
    SSHCommandResult sshCommandResult = subscribe(null, null, pool.poolId, null, null, quantity, null, null, null, null, null, null, null);
    // is this pool multi-entitleable?
    /* This information is now in the SubscriptionPool itself
		boolean isPoolMultiEntitlement = false;
		try {
			isPoolMultiEntitlement = CandlepinTasks.isPoolProductMultiEntitlement(this.currentlyRegisteredUsername,this.currentlyRegisteredPassword,SubscriptionManagerBaseTestScript.sm_serverUrl,pool.poolId);
		} catch (Exception e) {
			e.printStackTrace();
			Assert.fail(e.getMessage());
		}
		*/
    // get the pool's product "arch" attribute that this subscription pool supports
    String poolProductAttributeArch = "";
    List<String> poolProductAttributeArches = new ArrayList<String>();
    if (authenticator != null && password != null && serverUrl != null) {
        try {
            poolProductAttributeArch = CandlepinTasks.getPoolProductAttributeValue(authenticator, password, serverUrl, pool.poolId, "arch");
            if (poolProductAttributeArch != null && !poolProductAttributeArch.trim().isEmpty()) {
                // Note: the arch attribute can be a comma separated list of values
                poolProductAttributeArches.addAll(Arrays.asList(poolProductAttributeArch.trim().split(" *, *")));
                // Note: x86 is a general arch to cover all 32-bit intel microprocessors
                if (poolProductAttributeArches.contains("x86"))
                    poolProductAttributeArches.addAll(Arrays.asList("i386", "i486", "i586", "i686"));
            // if (productSupportedArches.contains("ALL")) productSupportedArches.add(arch);
            }
        } catch (Exception e) {
            e.printStackTrace();
            Assert.fail(e.getMessage());
        }
    }
    // assert that the remaining SubscriptionPools does NOT contain the pool just subscribed to (unless it is multi-entitleable)
    List<SubscriptionPool> afterSubscriptionPools = getCurrentlyAvailableSubscriptionPools();
    if (pool.subscriptionType != null && pool.subscriptionType.equals("Other")) {
        Assert.fail("Encountered a subscription pool of type '" + pool.subscriptionType + "'.  Do not know how to assert the remaining availability of this pool after subscribing to it: " + pool);
    } else if (pool.multiEntitlement == null && pool.subscriptionType != null && pool.subscriptionType.isEmpty()) {
        log.warning("Encountered a pool with an empty value for subscriptionType (indicative of an older candlepin server): " + pool);
        log.warning("Skipping assertion of the pool's expected availability after having subscribed to it.");
    } else if (!pool.quantity.equalsIgnoreCase("unlimited") && Integer.valueOf(pool.quantity) <= 1) {
        Assert.assertTrue(!afterSubscriptionPools.contains(pool), "When the final quantity from the pool was consumed, the remaining available subscription pools no longer contains the just subscribed to pool: " + pool);
    } else if (pool.multiEntitlement != null && !pool.multiEntitlement) {
        Assert.assertTrue(!afterSubscriptionPools.contains(pool), "When the pool is not multi-entitleable, the remaining available subscription pools no longer contains the just subscribed to pool: " + pool);
    } else if (pool.subscriptionType != null && (!pool.subscriptionType.equals("Stackable") && !pool.subscriptionType.equals("Multi-Entitleable") && !pool.subscriptionType.equals("Instance Based") && !pool.subscriptionType.equals("Stackable (Temporary)") && !pool.subscriptionType.equals("Multi-Entitleable (Temporary)") && !pool.subscriptionType.equals("Instance Based (Temporary)"))) {
        // see https://bugzilla.redhat.com/show_bug.cgi?id=1029968#c2
        Assert.assertTrue(!afterSubscriptionPools.contains(pool), "When the pool is not multi-entitleable (not Stackable && not Multi-Entitleable && not Instance Based), the remaining available subscription pools no longer contains the just subscribed to pool: " + pool);
    } else if (!poolProductAttributeArches.isEmpty() && !poolProductAttributeArches.contains("ALL") && !poolProductAttributeArches.contains(arch)) {
        Assert.assertTrue(!afterSubscriptionPools.contains(pool), "When the pools product attribute arch '" + poolProductAttributeArch + "' does not support this system arch '" + arch + "', the remaining available subscription pools should never contain the just subscribed to pool: " + pool);
    } else {
        Assert.assertTrue(afterSubscriptionPools.contains(pool), // TODO fix the assertions for "if this fails"
        "When the pool is multi-entitleable, the remaining available subscription pools still contains the just subscribed to pool: " + pool + " (TODO: if this fails, then we likely attached the final entitlements from the pool)");
    }
    // assert that the remaining SubscriptionPools do NOT contain the same productId just subscribed to
    // log.warning("We will no longer assert that the remaining available pools do not contain the same productId ("+pool.productId+") as the pool that was just subscribed.  Reference: https://bugzilla.redhat.com/show_bug.cgi?id=663455");
    /*
		for (SubscriptionPool afterSubscriptionPool : afterSubscriptionPools) {
			Assert.assertTrue(!afterSubscriptionPool.productId.equals(pool.productId),
					"This remaining available pool "+afterSubscriptionPool+" does NOT contain the same productId ("+pool.productId+") after subscribing to pool: "+pool);
		}
		*/
    // is this a personal subpool?
    String poolProductId = pool.productId;
    boolean isSubpool = false;
    try {
        JSONArray personSubscriptionPoolProductData;
        // personSubscriptionPoolProductData = new JSONArray(System.getProperty("sm.person.subscriptionPoolProductData", "<>").replaceAll("<", "[").replaceAll(">", "]")); // hudson parameters use <> instead of []
        // hudson JSONArray parameters get surrounded with double quotes that need to be stripped
        personSubscriptionPoolProductData = new JSONArray(SubscriptionManagerBaseTestScript.getProperty("sm.person.subscriptionPoolProductData", "[]").replaceFirst("^\"", "").replaceFirst("\"$", "").replaceAll("<", "[").replaceAll(">", "]"));
        for (int j = 0; j < personSubscriptionPoolProductData.length(); j++) {
            JSONObject poolProductDataAsJSONObject = (JSONObject) personSubscriptionPoolProductData.get(j);
            String personProductId = poolProductDataAsJSONObject.getString("personProductId");
            JSONObject subpoolProductDataAsJSONObject = poolProductDataAsJSONObject.getJSONObject("subPoolProductData");
            String systemProductId = subpoolProductDataAsJSONObject.getString("systemProductId");
            if (poolProductId.equals(systemProductId)) {
                // special case when pool's productId is really a personal subpool
                poolProductId = personProductId;
                isSubpool = true;
                break;
            }
        }
    } catch (JSONException e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
    // figure out which entitlement cert file has been newly installed into /etc/pki/entitlement after attempting to subscribe to pool
    /* OLD - THIS ALGORITHM BREAKS DOWN WHEN MODIFIER ENTITLEMENTS ARE IN PLAY
		File newCertFile = null;
		List<File> afterEntitlementCertFiles = getCurrentEntitlementCertFiles();
		for (File file : afterEntitlementCertFiles) {
			if (!beforeEntitlementCertFiles.contains(file)) {
				newCertFile = file; break;
			}
		}
		*/
    /* VALID BUT INEFFICIENT
		List<File> afterEntitlementCertFiles = getCurrentEntitlementCertFiles();
		File newCertFile = null;
		Map<BigInteger, SubscriptionPool> map = new HashMap<BigInteger, SubscriptionPool>();
		try {
			map = getCurrentSerialMapToSubscriptionPools(this.currentAuthenticator,this.currentAuthenticatorPassword);
		} catch (Exception e) {
			e.printStackTrace();
			Assert.fail(e.getMessage());
		}
		for (BigInteger serial: map.keySet()) {
			if (map.get(serial).poolId.equals(pool.poolId)) {
				newCertFile = new File(this.entitlementCertDir+"/"+serial+".pem");
				break;
			}
		}
		*/
    // NOTE: this block of code is somewhat duplicated in getEntitlementCertCorrespondingToSubscribedPool(...)
    File newCertFile = null;
    List<File> afterEntitlementCertFiles = getCurrentEntitlementCertFiles("-t");
    if (authenticator != null && password != null && serverUrl != null) {
        for (File entitlementCertFile : afterEntitlementCertFiles) {
            if (!beforeEntitlementCertFiles.contains(entitlementCertFile)) {
                EntitlementCert entitlementCert = getEntitlementCertFromEntitlementCertFile(entitlementCertFile);
                try {
                    // JSONObject jsonEntitlement = CandlepinTasks.getEntitlementUsingRESTfulAPI(authenticator,password,serverUrl,entitlementCert.id);	// is throwing a 500 in stage, but only for qa@redhat.com credentials - I don't know why
                    JSONObject jsonEntitlement = CandlepinTasks.getEntitlementUsingRESTfulAPI(currentlyRegisteredUsername, currentlyRegisteredPassword, serverUrl, entitlementCert.id);
                    JSONObject jsonPool = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(authenticator, password, serverUrl, jsonEntitlement.getJSONObject("pool").getString("href")));
                    if (jsonPool.getString("id").equals(pool.poolId)) {
                        newCertFile = entitlementCertFile;
                        break;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    Assert.fail(e.getMessage());
                }
            }
        }
    }
    // when the pool is already subscribed to...
    if (sshCommandResult.getStdout().startsWith("This consumer is already subscribed")) {
        // assert that NO new entitlement cert file has been installed in /etc/pki/entitlement
        /*Assert.assertNull(newCertFile,
					"A new entitlement certificate has NOT been installed after attempting to subscribe to an already subscribed to pool: "+pool);
			*/
        Assert.assertEquals(beforeEntitlementCertFiles.size(), afterEntitlementCertFiles.size(), "The existing entitlement certificate count remains unchanged after attempting to subscribe to an already subscribed to pool: " + pool);
        // find the existing entitlement cert file corresponding to the already subscribed pool
        /* ALREADY FOUND USING ALGORITHM ABOVE 
			EntitlementCert entitlementCert = null;
			for (File thisEntitlementCertFile : getCurrentEntitlementCertFiles()) {
				EntitlementCert thisEntitlementCert = getEntitlementCertFromEntitlementCertFile(thisEntitlementCertFile);
				if (thisEntitlementCert.orderNamespace.productId.equals(poolProductId)) {
					entitlementCert = thisEntitlementCert;
					break;
				}
			}
			Assert.assertNotNull(entitlementCert, isSubpool?
					"Found an already existing Entitlement Cert whose personal productId matches the system productId from the subscription pool: "+pool:
					"Found an already existing Entitlement Cert whose productId matches the productId from the subscription pool: "+pool);
			newCertFile = getEntitlementCertFileFromEntitlementCert(entitlementCert); // not really new, just already existing
			*/
        // assert that consumed ProductSubscriptions has NOT changed
        List<ProductSubscription> afterProductSubscriptions = getCurrentlyConsumedProductSubscriptions();
        Assert.assertTrue(afterProductSubscriptions.size() == beforeProductSubscriptions.size() && afterProductSubscriptions.size() > 0, "The list of currently consumed product subscriptions has not changed (from " + beforeProductSubscriptions.size() + " to " + afterProductSubscriptions.size() + ") since the productId of the pool we are trying to subscribe to is already consumed.");
    // when no free entitlements exist...		// No entitlements are available from the pool with id '8a90f8143611c33f013611c4797b0456'.	// No subscriptions are available from the pool with id '8a90f8303c98703a013c98715ca80494'.  Bug 876758
    } else if (sshCommandResult.getStdout().startsWith("No entitlements are available") || sshCommandResult.getStdout().startsWith("No subscriptions are available")) {
        // assert that the depleted pool Quantity is zero
        SubscriptionPool depletedPool = SubscriptionPool.findFirstInstanceWithMatchingFieldFromList("poolId", pool.poolId, getCurrentlyAllAvailableSubscriptionPools());
        /* behavior changed on list --all --available  (3/4/2011)
			Assert.assertNotNull(depletedPool,
					"Found the depleted pool amongst --all --available after having consumed all of its available entitlements: ");
			*/
        Assert.assertNull(depletedPool, "Should no longer find the depleted pool amongst --all --available after having consumed all of its available entitlements: ");
        // "Asserting the pool's quantity after having consumed all of its available entitlements is zero.");
        if (authenticator != null && password != null && serverUrl != null) {
            JSONObject jsonPool = null;
            int consumed = 0;
            int quantityAvailable = Integer.valueOf(pool.quantity);
            try {
                jsonPool = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(authenticator, password, serverUrl, "/pools/" + pool.poolId));
                consumed = jsonPool.getInt("consumed");
                quantityAvailable = jsonPool.getInt("quantity");
            } catch (Exception e) {
                e.printStackTrace();
                Assert.fail(e.getMessage());
            }
            Assert.assertEquals(consumed, quantityAvailable, "Asserting the pool's consumed attribute equals it's total quantity after having consumed all of its available entitlements.");
        }
        // assert that NO new entitlement cert file has been installed in /etc/pki/entitlement
        Assert.assertNull(newCertFile, "A new entitlement certificate has NOT been installed after attempting to subscribe to depleted pool: " + depletedPool);
        Assert.assertEquals(beforeEntitlementCertFiles.size(), afterEntitlementCertFiles.size(), "The existing entitlement certificate count remains unchanged after attempting to subscribe to depleted pool: " + depletedPool);
    // otherwise, the pool is NOT already subscribe to...
    } else {
        // assert that only ONE new entitlement cert file has been installed in /etc/pki/entitlement
        // https://bugzilla.redhat.com/show_bug.cgi?id=640338
        Assert.assertTrue(afterEntitlementCertFiles.size() == beforeEntitlementCertFiles.size() + 1, "Only ONE new entitlement certificate has been installed (count was '" + beforeEntitlementCertFiles.size() + "'; is now '" + afterEntitlementCertFiles.size() + "') after subscribing to pool: " + pool);
        if (authenticator != null && password != null && serverUrl != null) {
            // assert the new entitlement cert file has been installed in /etc/pki/entitlement
            Assert.assertNotNull(newCertFile, "A new entitlement certificate has been installed after subscribing to pool: " + pool);
            log.info("The new entitlement certificate file is: " + newCertFile);
            // assert that the productId from the pool matches the entitlement productId
            // TEMPORARY WORKAROUND FOR BUG: https://bugzilla.redhat.com/show_bug.cgi?id=650278 - jsefler 11/05/2010
            // TEMPORARY WORKAROUND FOR BUG: https://bugzilla.redhat.com/show_bug.cgi?id=806986 - jsefler 06/28/2012
            boolean invokeWorkaroundWhileBugIsOpen = true;
            String bugId1 = "650278";
            String bugId2 = "806986";
            try {
                if (invokeWorkaroundWhileBugIsOpen && (BzChecker.getInstance().isBugOpen(bugId1) || BzChecker.getInstance().isBugOpen(bugId2))) {
                    log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId1).toString() + " Bugzilla " + bugId1 + ".  (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId1 + ")");
                    SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId1);
                    log.fine("Invoking workaround for " + BzChecker.getInstance().getBugState(bugId2).toString() + " Bugzilla " + bugId2 + ".  (https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId2 + ")");
                    SubscriptionManagerCLITestScript.addInvokedWorkaround(bugId2);
                } else {
                    invokeWorkaroundWhileBugIsOpen = false;
                }
            } catch (BugzillaAPIException be) {
            /* ignore exception */
            } catch (RuntimeException re) {
            /* ignore exception */
            }
            if (invokeWorkaroundWhileBugIsOpen) {
                log.warning("Skipping assert that the productId from the pool matches the entitlement productId");
            } else {
                // END OF WORKAROUND
                EntitlementCert entitlementCert = getEntitlementCertFromEntitlementCertFile(newCertFile);
                File newCertKeyFile = getEntitlementCertKeyFileFromEntitlementCert(entitlementCert);
                Assert.assertEquals(entitlementCert.orderNamespace.productId, poolProductId, isSubpool ? "New EntitlementCert productId '" + entitlementCert.orderNamespace.productId + "' matches originating Personal SubscriptionPool productId '" + poolProductId + "' after subscribing to the subpool." : "New EntitlementCert productId '" + entitlementCert.orderNamespace.productId + "' matches originating SubscriptionPool productId '" + poolProductId + "' after subscribing to the pool.");
                Assert.assertTrue(RemoteFileTasks.testExists(sshCommandRunner, newCertFile.getPath()), "New EntitlementCert file exists after subscribing to SubscriptionPool '" + pool.poolId + "'.");
                Assert.assertTrue(RemoteFileTasks.testExists(sshCommandRunner, newCertKeyFile.getPath()), "New EntitlementCert key file exists after subscribing to SubscriptionPool '" + pool.poolId + "'.");
            }
        }
        // assert that consumed ProductSubscriptions has NOT decreased
        List<ProductSubscription> afterProductSubscriptions = getCurrentlyConsumedProductSubscriptions();
        // this assertion was valid prior to bug Bug 801187 - collapse list of provided products for subscription-manager list --consumed
        // Assert.assertTrue(afterProductSubscriptions.size() >= beforeProductSubscriptions.size() && afterProductSubscriptions.size() > 0,
        // "The list of currently consumed product subscriptions has increased (from "+beforeProductSubscriptions.size()+" to "+afterProductSubscriptions.size()+"), or has remained the same after subscribing (using poolID="+pool.poolId+") to pool: "+pool+"  Note: The list of consumed product subscriptions can remain the same when all the products from this subscription pool are a subset of those from a previously subscribed pool.");
        Assert.assertTrue(afterProductSubscriptions.size() == beforeProductSubscriptions.size() + 1, "The list of currently consumed product subscriptions has increased by 1 (from " + beforeProductSubscriptions.size() + " to " + afterProductSubscriptions.size() + "), after subscribing to pool: " + pool);
    }
    return newCertFile;
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) ProductSubscription(rhsm.data.ProductSubscription) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) SkipException(org.testng.SkipException) JSONException(org.json.JSONException) IOException(java.io.IOException) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) JSONObject(org.json.JSONObject) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) SubscriptionPool(rhsm.data.SubscriptionPool)

Example 53 with SSHCommandResult

use of com.redhat.qe.tools.SSHCommandResult in project rhsm-qe by RedHatQE.

the class SubscriptionManagerTasks method getCurrentRhnClassicChannels.

/**
 * Call rhn-channel --list to get the currently consumed RHN channels.
 * @return
 */
public List<String> getCurrentRhnClassicChannels() {
    // [root@jsefler-onprem-5server rhn]# rhn-channel --list
    // rhel-x86_64-server-5
    // rhel-x86_64-server-supplementary-5
    // rhel-x86_64-server-supplementary-5-debuginfo
    String command = String.format("rhn-channel --list");
    SSHCommandResult result = sshCommandRunner.runCommandAndWait(command);
    // assert result
    if (result.getExitCode() == 1 && result.getStderr().trim().equals("This system is not associated with any channel.")) {
        // [root@cloud-qe-7 ~]# rhn-channel --list
        // This system is not associated with any channel.
        // [root@cloud-qe-7 ~]# echo $?
        // 1
        log.warning(result.getStderr().trim());
    } else if (result.getExitCode() == 1 && result.getStderr().trim().equals("Unable to locate SystemId file. Is this system registered?")) {
        // [root@cloud-qe-7 ~]# rhn-channel --list
        // Unable to locate SystemId file. Is this system registered?
        // [root@cloud-qe-7 ~]# echo $?
        // 1
        log.warning(result.getStderr().trim());
    } else {
        Assert.assertEquals(result.getExitCode(), Integer.valueOf(0), "Exitcode from attempt to list currently consumed RHN Classic channels.");
        Assert.assertEquals(result.getStderr(), "", "Stderr from attempt to list currently consumed RHN Classic channels.");
    }
    // parse the rhnChannels from stdout
    List<String> rhnChannels = new ArrayList<String>();
    if (result.getExitCode() == 0) {
        // if (!result.getStdout().trim().equals("")) {
        rhnChannels = Arrays.asList(result.getStdout().trim().split("\\n"));
    }
    return rhnChannels;
}
Also used : SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) ArrayList(java.util.ArrayList)

Example 54 with SSHCommandResult

use of com.redhat.qe.tools.SSHCommandResult in project rhsm-qe by RedHatQE.

the class SubscriptionManagerTasks method yumGroupList.

public ArrayList<String> yumGroupList(String Installed_or_Available, String options) {
    ArrayList<String> groups = new ArrayList<String>();
    sshCommandRunner.runCommandAndWaitWithoutLogging("killall -9 yum");
    // --disableplugin=rhnplugin helps avoid: up2date_client.up2dateErrors.AbuseError
    String command = "yum grouplist " + 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));
    // Example result.getStdout()
    // [root@jsefler-betaqa-1 product]# yum grouplist --disablerepo=* --enablerepo=rhel-entitlement-beta
    // Loaded plugins: product-id, refresh-packagekit, rhnplugin, subscription-manager
    // Updating Red Hat repositories.
    // INFO:rhsm-app.repolib:repos updated: 0
    // This system is not registered with RHN.
    // RHN support will be disabled.
    // Setting up Group Process
    // rhel-entitlement-beta                                                                                                                                 | 4.0 kB     00:00
    // rhel-entitlement-beta/group_gz                                                                                                                        | 190 kB     00:00
    // Installed Groups:
    // Additional Development
    // Assamese Support
    // Base
    // Available Groups:
    // Afrikaans Support
    // Albanian Support
    // Amazigh Support
    // Done
    String regex = Installed_or_Available + " Groups:((\\n\\s{3}.*)+)";
    Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
    Matcher matcher = pattern.matcher(result.getStdout());
    if (!matcher.find()) {
        log.info("Did NOT find any " + Installed_or_Available + " Groups from: " + command);
        return groups;
    }
    // assemble the list of groups and return them
    for (String group : matcher.group(1).trim().split("\\n\\s{3}")) groups.add(group);
    return groups;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) ArrayList(java.util.ArrayList)

Example 55 with SSHCommandResult

use of com.redhat.qe.tools.SSHCommandResult in project rhsm-qe by RedHatQE.

the class SubscriptionManagerTasks method getCurrentlyAvailableReleases.

/**
 * @param proxy TODO
 * @param proxyusername TODO
 * @param proxypassword TODO
 * @param noproxy TODO
 * @return list of the releases returned by subscription-manager release --list (must already be registered)
 */
public List<String> getCurrentlyAvailableReleases(String proxy, String proxyusername, String proxypassword, String noproxy) {
    SSHCommandResult result = release_(null, true, null, null, proxy, proxyusername, proxypassword, noproxy);
    String stdout = result.getStdout().trim();
    // [root@jsefler-r63-workstation ~]# subscription-manager release --list
    // 5.7
    // 5.8
    // 5Client
    // 6.0
    // 6.1
    // 6.2
    // 6Workstation
    // Bug 824979 - No message for "subscription-manager release --list" with no subscriptions
    // result when no releases are available
    // FINE: ssh root@jsefler-59server.usersys.redhat.com subscription-manager release --list
    // FINE: Stdout:
    // FINE: Stderr: No release versions available, please check subscriptions.
    // FINE: ExitCode: 255
    // Bug 808217 - [RFE] a textural output banner would be nice for subscription-manager release --list
    // [root@jsefler-6 ~]# subscription-manager release --list
    // +-------------------------------------------+
    // Available Releases
    // +-------------------------------------------+
    // 6.1
    // 6.2
    // 6.3
    // 6Server
    // strip off the banner (added by bug 808217 in RHEL64)
    String bannerRegex = "\\+-+\\+\\n\\s*Available Releases\\s*\\n\\+-+\\+";
    stdout = stdout.replaceFirst(bannerRegex, "");
    List<String> releases = new ArrayList<String>();
    for (String release : stdout.split("\\s*\\n\\s*")) {
        if (!release.isEmpty())
            releases.add(release);
    }
    return releases;
}
Also used : SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) ArrayList(java.util.ArrayList)

Aggregations

SSHCommandResult (com.redhat.qe.tools.SSHCommandResult)553 Test (org.testng.annotations.Test)416 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)401 SkipException (org.testng.SkipException)219 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)201 ArrayList (java.util.ArrayList)101 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)79 BigInteger (java.math.BigInteger)68 File (java.io.File)58 SubscriptionPool (rhsm.data.SubscriptionPool)53 JSONObject (org.json.JSONObject)47 HashMap (java.util.HashMap)42 ProductSubscription (rhsm.data.ProductSubscription)31 EntitlementCert (rhsm.data.EntitlementCert)30 List (java.util.List)21 YumRepo (rhsm.data.YumRepo)18 ProductCert (rhsm.data.ProductCert)17 Repo (rhsm.data.Repo)16 InstalledProduct (rhsm.data.InstalledProduct)15 Calendar (java.util.Calendar)13