Search in sources :

Example 66 with SubscriptionPool

use of rhsm.data.SubscriptionPool in project rhsm-qe by RedHatQE.

the class ProxyTests method testReposListWithProxyTimeoutBug968820.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-26756", "RHEL7-98223" }, 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 = "Tier3")
@Test(description = "subscription-manager : repos list with proxy set to a real server that is not truely a proxy (e.g. www.redhat.com)", groups = { "Tier3Tests", "blockedByBug-968820", "blockedByBug-1301215", "blockedByBug-1345962" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testReposListWithProxyTimeoutBug968820() {
    // register
    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);
    // subscribe
    List<SubscriptionPool> pools = clienttasks.getCurrentlyAvailableSubscriptionPools();
    if (pools.isEmpty())
        log.warning("Cound not find an available pool.");
    // randomly pick a pool
    SubscriptionPool pool = pools.get(randomGenerator.nextInt(pools.size()));
    // clienttasks.subscribeToSubscriptionPool(pool);
    clienttasks.subscribe(null, null, pool.poolId, null, null, null, null, null, null, null, null, null, null);
    // repos --list --proxy=www.redhat.com
    String command = clienttasks.command + " repos --list --proxy=www.redhat.com";
    // do not wait any longer than this many milliseconds
    Long timeoutMS = Long.valueOf(8 * /*min*/
    60 * 1000);
    SSHCommandResult result = client.runCommandAndWait(command, timeoutMS);
    // expected results
    Integer expectedExitCode = new Integer(255);
    String expectedStdout = nErrMsg;
    String expectedStderr = "";
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.13.8-1")) {
        // post commit df95529a5edd0be456b3528b74344be283c4d258 bug 1119688
        // EX_SOFTWARE
        expectedExitCode = new Integer(70);
    }
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.13.9-1")) {
        // post commit a695ef2d1da882c5f851fde90a24f957b70a63ad
        // 201503301409:07.031 - FINE: ssh root@jsefler-os6.usersys.redhat.com subscription-manager repos --list --proxy=www.redhat.com
        // 201503301410:07.487 - FINE: Stdout:
        // 201503301410:07.487 - FINE: Stderr: Network error, unable to connect to server. Please see /var/log/rhsm/rhsm.log for more information.
        // 201503301410:07.487 - FINE: ExitCode: 70
        // ^^ one minute timeout observed (but I have also seen this take 4m16.286s)
        // EX_SOFTWARE
        expectedExitCode = new Integer(70);
        expectedStdout = "";
        expectedStderr = nErrMsg;
    }
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.17.6-1")) {
        // post commit 7ce6801fc1cc38edcdeb75dfb5f0d1f8a6398c68	1176219: Stop before cache is returned when using bad proxy options	// Bug 1301215 - The cmd "repos --list --proxy" with a fake proxy server url will not stop running.
        // 201612121142:43.748 - FINE: ssh root@jsefler-rhel6.usersys.redhat.com subscription-manager repos --list --proxy=www.redhat.com
        // 201612121142:54.320 - FINE: Stdout:
        // 201612121142:54.321 - FINE: Stderr: Proxy connection failed, please check your settings.
        // 201612121142:54.321 - FINE: ExitCode: 69
        // EX_UNAVAILABLE
        expectedExitCode = new Integer(69);
        expectedStdout = "";
        expectedStderr = pErrMsg;
    }
    // assert results
    Assert.assertEquals(result.getExitCode(), expectedExitCode, "ExitCode from command '" + command + "' with a timeout of '" + timeoutMS + "' MS.");
    Assert.assertEquals(result.getStdout().trim(), expectedStdout, "Stdout from command '" + command + "' with a timeout of '" + timeoutMS + "' MS.");
    Assert.assertEquals(result.getStderr().trim(), expectedStderr, "Stderr from command '" + command + "' with a timeout of '" + timeoutMS + "' MS.");
}
Also used : BigInteger(java.math.BigInteger) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 67 with SubscriptionPool

use of rhsm.data.SubscriptionPool in project rhsm-qe by RedHatQE.

the class ProxyTests method testSubscribeAttemptsUsingProxyServer.

// SUBSCRIBE 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-21835", "RHEL7-51654" }, 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 = "Tier3")
@Test(description = "subscription-manager : subscribe using a proxy server (Positive and Negative Variations)", groups = { "Tier3Tests", "blockedByBug-664603" }, dataProvider = "getSubscribeAttemptsUsingProxyServerData", enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testSubscribeAttemptsUsingProxyServer(Object blockedByBug, String username, String password, String org, String proxy, String proxyuser, String proxypassword, Integer exitCode, String stdout, String stderr) {
    // setup for test
    String moduleTask = "subscribe";
    if (!username.equals(sm_clientUsername) || !password.equals(sm_clientPassword))
        throw new SkipException("These dataProvided parameters are either superfluous or not meaningful for this test.");
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, null, false, null, null, null, null);
    List<SubscriptionPool> pools = clienttasks.getCurrentlyAvailableSubscriptionPools();
    // randomly pick a pool
    SubscriptionPool pool = pools.get(randomGenerator.nextInt(pools.size()));
    SSHCommandResult attemptResult = clienttasks.subscribe_(null, null, pool.poolId, null, null, null, null, null, null, proxy, proxyuser, proxypassword, null);
    if (exitCode != null)
        Assert.assertEquals(attemptResult.getExitCode(), exitCode, "The exit code from an attempt to " + moduleTask + " using a proxy server.");
    if (stdout != null)
        Assert.assertEquals(attemptResult.getStdout().trim(), stdout, "The stdout from an attempt to " + moduleTask + " using a proxy server.");
    if (stderr != null)
        Assert.assertEquals(attemptResult.getStderr().trim(), stderr, "The stderr from an attempt to " + moduleTask + " using a proxy server.");
}
Also used : SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) SkipException(org.testng.SkipException) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 68 with SubscriptionPool

use of rhsm.data.SubscriptionPool in project rhsm-qe by RedHatQE.

the class ProxyTests method testSubscribeAttemptsUsingProxyServerViaRhsmConfig.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-21838", "RHEL7-51657" }, 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 = "Tier3")
@Test(description = "subscription-manager : subscribe using a proxy server after setting rhsm.config parameters (Positive and Negative Variations)", groups = { "Tier3Tests", "blockedByBug-664603" }, dataProvider = "getSubscribeAttemptsUsingProxyServerViaRhsmConfigData", enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testSubscribeAttemptsUsingProxyServerViaRhsmConfig(Object blockedByBug, String username, String password, String org, String proxy, String proxyuser, String proxypassword, String proxy_hostnameConfig, String proxy_portConfig, String proxy_userConfig, String proxy_passwordConfig, Integer exitCode, String stdout, String stderr, SSHCommandRunner proxyRunner, String proxyLog, String proxyLogGrepPattern) {
    // setup for test
    String moduleTask = "subscribe";
    if (!username.equals(sm_clientUsername) || !password.equals(sm_clientPassword))
        throw new SkipException("These dataProvided parameters are either superfluous or not meaningful for this test.");
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, null, false, null, null, null, null);
    List<SubscriptionPool> pools = clienttasks.getCurrentlyAvailableSubscriptionPools();
    // randomly pick a pool
    SubscriptionPool pool = pools.get(randomGenerator.nextInt(pools.size()));
    // pad the tail of basicauthproxyLog with a message
    String proxyLogMarker = System.currentTimeMillis() + " Testing " + moduleTask + " AttemptsUsingProxyServerViaRhsmConfig_Test from " + clienttasks.hostname + "...";
    // RemoteFileTasks.runCommandAndAssert(proxyRunner,"echo '"+proxyLogMarker+"'  >> "+proxyLog, Integer.valueOf(0));
    RemoteFileTasks.markFile(proxyRunner, proxyLog, proxyLogMarker);
    // set the config parameters
    updateConfFileProxyParameters(proxy_hostnameConfig, proxy_portConfig, proxy_userConfig, proxy_passwordConfig, "");
    RemoteFileTasks.runCommandAndWait(client, "grep proxy " + clienttasks.rhsmConfFile, TestRecords.action());
    // attempt the moduleTask with the proxy options
    SSHCommandResult attemptResult = clienttasks.subscribe_(null, null, pool.poolId, null, null, null, null, null, null, proxy, proxyuser, proxypassword, null);
    if (exitCode != null)
        Assert.assertEquals(attemptResult.getExitCode(), exitCode, "The exit code from an attempt to " + moduleTask + " using a proxy server.");
    if (stdout != null)
        Assert.assertEquals(attemptResult.getStdout().trim(), stdout, "The stdout from an attempt to " + moduleTask + " using a proxy server.");
    if (stderr != null)
        Assert.assertEquals(attemptResult.getStderr().trim(), stderr, "The stderr from an attempt to " + moduleTask + " using a proxy server.");
    // assert the tail of proxyLog shows the proxyLogGrepPattern
    if (proxyLogGrepPattern != null) {
        // SSHCommandResult proxyLogResult = RemoteFileTasks.runCommandAndAssert(proxyRunner,"tail -1 "+proxyLog, Integer.valueOf(0));
        // SSHCommandResult proxyLogResult = proxyRunner.runCommandAndWait("(LINES=''; IFS=$'\n'; for line in $(tac "+proxyLog+"); do if [[ $line = '"+proxyLogMarker+"' ]]; then break; fi; LINES=${LINES}'\n'$line; done; echo -e $LINES) | grep "+clienttasks.ipaddr);	// accounts for multiple tests hitting the same proxy simultaneously
        // Assert.assertContainsMatch(proxyLogResult.getStdout(), proxyLogGrepPattern, "The proxy server appears to be logging the expected connection attempts to the candlepin server.");
        // accounts for multiple tests hitting the same proxy server simultaneously
        String proxyLogResult = RemoteFileTasks.getTailFromMarkedFile(proxyRunner, proxyLog, proxyLogMarker, ipv4_address);
        // Assert.assertContainsMatch(proxyLogResult, proxyLogGrepPattern, "The proxy server appears to be logging the expected connection attempts to the candlepin server.");	// TOO MUCH LOGGING
        Assert.assertTrue(proxyLogResult.contains(proxyLogGrepPattern), "The tail of proxy server log '" + proxyLog + "' following marker '" + proxyLogMarker + "' contains expected connection '" + proxyLogGrepPattern + "' attempts from " + ipv4_address + " to the candlepin server.");
    }
}
Also used : SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) SkipException(org.testng.SkipException) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 69 with SubscriptionPool

use of rhsm.data.SubscriptionPool in project rhsm-qe by RedHatQE.

the class ContentTests method getEnabledRepoAndSubscriptionPoolDataAsListOfLists.

protected List<List<Object>> getEnabledRepoAndSubscriptionPoolDataAsListOfLists() throws JSONException, Exception {
    List<List<Object>> ll = new ArrayList<List<Object>>();
    if (!isSetupBeforeSuiteComplete)
        return ll;
    if (clienttasks == null)
        return ll;
    if (sm_clientUsername == null)
        return ll;
    if (sm_clientPassword == null)
        return ll;
    // get the currently installed product certs to be used when checking for conditional content tagging
    List<ProductCert> currentProductCerts = clienttasks.getCurrentProductCerts();
    // assure we are freshly registered and process all available subscription pools
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, ConsumerType.system, null, null, null, null, null, (String) null, null, null, null, Boolean.TRUE, false, null, null, null, null);
    for (SubscriptionPool pool : clienttasks.getCurrentlyAvailableSubscriptionPools()) {
        // /*debugTesting*/if (!pool.productId.equals("RH2501844")) continue;
        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 != null)
            if (pool.suggested < 1)
                quantity = CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "instance_multiplier");
        /*if (clienttasks.isPackageVersion("subscription-manager",">=","1.10.3-1"))*/
        File entitlementCertFile = clienttasks.subscribeToSubscriptionPool_(pool, quantity);
        Assert.assertNotNull(entitlementCertFile, "Found the entitlement cert file that was granted after subscribing to pool: " + pool);
        EntitlementCert entitlementCert = clienttasks.getEntitlementCertFromEntitlementCertFile(entitlementCertFile);
        for (ContentNamespace contentNamespace : entitlementCert.contentNamespaces) {
            if (!contentNamespace.type.equalsIgnoreCase("yum"))
                continue;
            if (contentNamespace.enabled && clienttasks.areAllRequiredTagsInContentNamespaceProvidedByProductCerts(contentNamespace, currentProductCerts)) {
                String repoLabel = contentNamespace.label;
                // String availableGroup, String installedGroup, String repoLabel, SubscriptionPool pool, String quantity
                ll.add(Arrays.asList(new Object[] { repoLabel, pool, quantity }));
            }
        }
        // minimize the number of dataProvided rows (useful during automated testcase development)
        if (Boolean.valueOf(getProperty("sm.debug.dataProviders.minimize", "false")))
            break;
    }
    // no reason to remain subscribed to any subscriptions
    clienttasks.unsubscribeFromAllOfTheCurrentlyConsumedProductSubscriptions();
    return ll;
}
Also used : ContentNamespace(rhsm.data.ContentNamespace) EntitlementCert(rhsm.data.EntitlementCert) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) JSONObject(org.json.JSONObject) ProductCert(rhsm.data.ProductCert) SubscriptionPool(rhsm.data.SubscriptionPool) File(java.io.File)

Example 70 with SubscriptionPool

use of rhsm.data.SubscriptionPool in project rhsm-qe by RedHatQE.

the class ContentTests method testArchRestrictedContentSetsEntitledAfterSubscribeAllSatisfiesTheSystemArch.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-20080", "RHEL7-33076" }, 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 = "Verify that all content sets granted from a subscription pool that are restricted to specific arches satisfy the current system's arch.", groups = { "Tier1Tests", "blockedByBug-706187", "blockedByBug-975520", "VerifyArchRestrictedContentSetsEntitledAfterSubscribeAllSatisfiesTheSystemArch_Test" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testArchRestrictedContentSetsEntitledAfterSubscribeAllSatisfiesTheSystemArch() throws JSONException, Exception {
    // get a list of all of the available poolIds that provide arch-based content sets
    List<List<Object>> subscriptionPoolsDataList = getAllAvailableSubscriptionPoolsProvidingArchBasedContentDataAsListOfLists();
    List<String> archBasedSubscriptionPoolIds = new ArrayList<String>();
    for (List<Object> subscriptionPoolsData : subscriptionPoolsDataList) {
        SubscriptionPool pool = (SubscriptionPool) subscriptionPoolsData.get(0);
        archBasedSubscriptionPoolIds.add(pool.poolId);
    }
    if (archBasedSubscriptionPoolIds.isEmpty())
        throw new SkipException("No subscriptions were found providing non-empty arch-based content.");
    // iterate over several possible system arches
    Map<String, String> factsMap = new HashMap<String, String>();
    for (String systemArch : Arrays.asList(new String[] { "i386", "i586", "i686", "x86_64", "ppc", "ppc64", "ia64", "arm", "s390", "s390x" })) {
        // avoid throttling RateLimitExceededException from IT-Candlepin
        if (CandlepinType.hosted.equals(sm_serverType)) {
            // strategically get a new consumer to avoid 60 repeated API calls from the same consumer
            // re-register as a new consumer
            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);
        } else
            // clienttasks.unsubscribe(true, (BigInteger)null, null, null, null);
            // return all current entitlements (Note: system is already registered by getAllAvailableSubscriptionPoolsProvidingArchBasedContentDataAsListOfLists())
            clienttasks.unsubscribe(true, (BigInteger) null, null, null, null, null, null);
        // fake the system's arch and update the facts
        log.info("Manipulating the system facts into thinking this is a '" + systemArch + "' system...");
        factsMap.put("uname.machine", String.valueOf(systemArch));
        clienttasks.createFactsFileWithOverridingValues(factsMap);
        clienttasks.facts(null, true, null, null, null, null);
        // subscribe to all the arch-based content set pools
        clienttasks.subscribe(false, null, archBasedSubscriptionPoolIds, null, null, null, null, null, null, null, null, null, null);
        // iterate over all of the granted entitlements
        for (EntitlementCert entitlementCert : clienttasks.getCurrentEntitlementCerts()) {
            for (ContentNamespace contentNamespace : entitlementCert.contentNamespaces) {
                if (contentNamespace.arches == null)
                    Assert.fail("This version of subscription-manager does not appear to parse arch restricted content.  Upgrade to a newer build of subscription-manager.");
                List<String> arches = new ArrayList<String>();
                // Note: the arches field can be a comma separated list of values
                if (!contentNamespace.arches.trim().isEmpty())
                    arches.addAll(Arrays.asList(contentNamespace.arches.trim().split(" *, *")));
                // Note: x86 is a general arch to cover all 32-bit intel microprocessors
                if (arches.contains("x86")) {
                    arches.addAll(Arrays.asList("i386", "i486", "i586", "i686"));
                }
                Assert.assertTrue(arches.isEmpty() || arches.contains("ALL") || arches.contains("noarch") || arches.contains(systemArch), "Content label '" + contentNamespace.label + "' restricted to arches '" + contentNamespace.arches + "' granted by entitlement cert '" + entitlementCert.orderNamespace.productName + "' matches the system's arch '" + systemArch + "'.");
            }
        }
    }
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ContentNamespace(rhsm.data.ContentNamespace) BigInteger(java.math.BigInteger) ArrayList(java.util.ArrayList) List(java.util.List) JSONObject(org.json.JSONObject) SkipException(org.testng.SkipException) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Aggregations

SubscriptionPool (rhsm.data.SubscriptionPool)195 Test (org.testng.annotations.Test)155 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)137 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)112 SkipException (org.testng.SkipException)90 ArrayList (java.util.ArrayList)87 JSONObject (org.json.JSONObject)66 SSHCommandResult (com.redhat.qe.tools.SSHCommandResult)53 ProductSubscription (rhsm.data.ProductSubscription)38 BigInteger (java.math.BigInteger)37 File (java.io.File)34 List (java.util.List)33 EntitlementCert (rhsm.data.EntitlementCert)33 HashMap (java.util.HashMap)32 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)28 InstalledProduct (rhsm.data.InstalledProduct)25 ProductCert (rhsm.data.ProductCert)24 JSONArray (org.json.JSONArray)22 Calendar (java.util.Calendar)12 GregorianCalendar (java.util.GregorianCalendar)11