Search in sources :

Example 86 with SubscriptionPool

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

the class ListTests method testListInstalledWithWildcardMatches.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36559", "RHEL7-51339" }, 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 = "Tier2")
@Test(description = "subscription-manager: subcription manager list --installed with wildcard --matches on Product Name, Product ID.  Note: wildcard match means * matches zero or more char and ? matches one char and is case insensitive.", groups = { "Tier2Tests", "blockedByBug-1146125" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testListInstalledWithWildcardMatches() throws JSONException, Exception {
    if (clienttasks.isPackageVersion("subscription-manager", "<", "1.13.6-1"))
        throw new SkipException("The list --matches function was not implemented in this version of subscription-manager.");
    String matchesString;
    List<InstalledProduct> actualInstalledProductMatches;
    // register if necessary
    if (clienttasks.getCurrentlyRegisteredOwnerKey() == null) {
        clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, true, null, null, null, null, null);
        clienttasks.autoheal(null, null, true, null, null, null, null);
    } else
        clienttasks.unsubscribe_(true, (BigInteger) null, null, null, null, null, null);
    // attach one of all the currently available subscriptions (attaching only one so that some installed products might remain noncompliant)
    // assemble a list of all the available SubscriptionPool ids
    List<String> poolIds = new ArrayList<String>();
    List<SubscriptionPool> subscriptionPools = clienttasks.getCurrentlyAvailableSubscriptionPools();
    for (SubscriptionPool pool : subscriptionPools) poolIds.add(pool.poolId);
    if (!poolIds.isEmpty())
        clienttasks.subscribe(null, null, poolIds, null, null, "1", null, null, null, null, null, null, null);
    // get all the installed products
    List<InstalledProduct> installedProducts = InstalledProduct.parse(clienttasks.list(null, null, null, true, null, null, null, null, null, null, null, null, null, null).getStdout());
    // randomly choose one of the installed products
    InstalledProduct randomInstalledProduct = getRandomListItem(installedProducts);
    // [root@jsefler-os7 ~]# subscription-manager list --installed
    // Product Name:   Red Hat Enterprise Linux Server
    // Product ID:     69
    // Version:        7.0
    // Arch:           x86_64
    // Status:         Not Subscribed
    // Status Details: Not supported by a valid subscription.
    // Starts:
    // Ends:
    // Test 1: test wildcard --matches on Product Name:
    matchesString = randomInstalledProduct.productName;
    // drop first word
    matchesString = matchesString.replaceFirst("^\\S+\\s+", "*");
    actualInstalledProductMatches = InstalledProduct.parse(clienttasks.list(null, null, null, true, null, null, null, null, matchesString, null, null, null, null, null).getStdout());
    assertActualResultOfListInstalledWithMatches(matchesString, actualInstalledProductMatches, installedProducts);
    // also test case insensitivity
    matchesString = randomizeCaseOfCharactersInString(matchesString);
    // and drop last word
    matchesString = matchesString.replaceFirst("\\s+\\S+$", "*");
    actualInstalledProductMatches = InstalledProduct.parse(clienttasks.list(null, null, null, true, null, null, null, null, matchesString, null, null, null, null, null).getStdout());
    assertActualResultOfListInstalledWithMatches(matchesString, actualInstalledProductMatches, installedProducts);
    // Test 2: test wildcard --matches on Product ID:
    matchesString = randomInstalledProduct.productId;
    int i = randomGenerator.nextInt(matchesString.length());
    matchesString = matchesString.replaceAll(String.valueOf(matchesString.charAt(i)), "?");
    actualInstalledProductMatches = InstalledProduct.parse(clienttasks.list(null, null, null, true, null, null, null, null, matchesString, null, null, null, null, null).getStdout());
    assertActualResultOfListInstalledWithMatches(matchesString, actualInstalledProductMatches, installedProducts);
// also test case insensitivity
/* not necessary since productId is an integer
		matchesString = randomizeCaseOfCharactersInString(matchesString);
		actualInstalledProductMatches = InstalledProduct.parse(clienttasks.list(null, null, null, true, null, null, null, null, matchesString, null, null, null).getStdout());
		assertActualResultOfListInstalledWithMatches(matchesString,actualInstalledProductMatches,installedProducts);
		*/
}
Also used : InstalledProduct(rhsm.data.InstalledProduct) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) 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)

Example 87 with SubscriptionPool

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

the class ListTests method testListAndListInstalledAreTheSame.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-37702", "RHEL7-51347" }, 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 = "Tier2")
@Test(description = "subscription-manager: ensure list [--installed] produce the same results", groups = { "Tier2Tests" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testListAndListInstalledAreTheSame() throws JSONException, Exception {
    clienttasks.unregister(null, null, null, null);
    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);
    // assert same results when no subscribed to anything...
    log.info("assert list [--installed] produce same results when not subscribed to anything...");
    SSHCommandResult listResult = clienttasks.list_(null, null, null, null, null, null, null, null, null, null, null, null, null, null);
    SSHCommandResult listInstalledResult = clienttasks.list_(null, null, null, Boolean.TRUE, null, null, null, null, null, null, null, null, null, null);
    Assert.assertEquals(listResult.getStdout(), listInstalledResult.getStdout(), "'list' and 'list --installed' produce the same stdOut results.");
    Assert.assertEquals(listResult.getStderr(), listInstalledResult.getStderr(), "'list' and 'list --installed' produce the same stdErr results.");
    Assert.assertEquals(listResult.getExitCode(), listInstalledResult.getExitCode(), "'list' and 'list --installed' produce the same exitCode results.");
    // assert same results when subscribed to something...
    log.info("assert list [--installed] produce same results when subscribed to something...");
    List<SubscriptionPool> pools = clienttasks.getCurrentlyAvailableSubscriptionPools();
    // randomly pick a pool
    SubscriptionPool pool = pools.get(randomGenerator.nextInt(pools.size()));
    clienttasks.subscribeToSubscriptionPool_(pool);
    listResult = clienttasks.list_(null, null, null, null, null, null, null, null, null, null, null, null, null, null);
    listInstalledResult = clienttasks.list_(null, null, null, Boolean.TRUE, null, null, null, null, null, null, null, null, null, null);
    Assert.assertEquals(listResult.getStdout(), listInstalledResult.getStdout(), "'list' and 'list --installed' produce the same stdOut results.");
    Assert.assertEquals(listResult.getStderr(), listInstalledResult.getStderr(), "'list' and 'list --installed' produce the same stdErr results.");
    Assert.assertEquals(listResult.getExitCode(), listInstalledResult.getExitCode(), "'list' and 'list --installed' produce the same exitCode results.");
}
Also used : SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 88 with SubscriptionPool

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

the class ListTests method testListConsumedWithMatchesNothing.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36560", "RHEL7-51340" }, 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 = "Tier2")
@Test(description = "subscription-manager: subcription manager list --consumed with --matches='nothing'", groups = { "Tier2Tests", "blockedByBug-1146125", "blockedByBug-1493711" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testListConsumedWithMatchesNothing() throws JSONException, Exception {
    if (clienttasks.isPackageVersion("subscription-manager", "<", "1.13.6-1"))
        throw new SkipException("The list --matches function was not implemented in this version of subscription-manager.");
    String matchesString = "nothing";
    // register if necessary
    if (clienttasks.getCurrentlyRegisteredOwnerKey() == null) {
        clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, true, null, null, null, null, null);
    }
    // attach any random pool
    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()));
    clienttasks.subscribe_(null, null, pool.poolId, null, null, null, null, null, null, null, null, null, null);
    // test
    SSHCommandResult result = clienttasks.list(null, null, true, null, null, null, null, null, matchesString, null, null, null, null, null);
    String expectedStdout = "No consumed subscription pools matching the specified criteria were found.";
    // commit 2884e33acb35ab4e336fe12dc23de7ab26cc0572	// Bug 1159348 - list --matched should show the filter string when warning about empty matches
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.13.12-1"))
        expectedStdout = String.format("No consumed subscription pools were found matching the expression \"%s\".", matchesString);
    Assert.assertEquals(result.getExitCode(), new Integer(0), "Exitcode expected from calling list --consumed --matches with no expected matches.");
    Assert.assertEquals(result.getStdout().trim(), expectedStdout, "Stdout expected from calling list --available --consumed with no expected matches.");
    Assert.assertEquals(result.getStderr().trim(), "", "Stderr expected from calling list --consumed --matches with no expected matches.");
}
Also used : BigInteger(java.math.BigInteger) 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) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 89 with SubscriptionPool

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

the class ListTests method testListAllAvailableWithMatchInstalled.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36553", "RHEL7-51330" }, 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 = "Tier2")
@Test(description = "subscription-manager: subcription manager list all with --match-installed option", groups = { "Tier2Tests", "blockedByBug-654501", "blockedByBug-1493711" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testListAllAvailableWithMatchInstalled() throws JSONException, Exception {
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, false, null, null, null, null, null);
    clienttasks.autoheal(null, null, true, null, null, null, null);
    // assemble a list of currently installed product ids
    List<ProductCert> installedProductCerts = clienttasks.getCurrentProductCerts();
    List<String> installedProductIds = new ArrayList<String>();
    for (ProductCert productCert : installedProductCerts) installedProductIds.add(productCert.productId);
    // get all the available subscription pools
    List<SubscriptionPool> allAvailableSubscriptionPools = SubscriptionPool.parse(clienttasks.list(true, true, null, null, null, null, false, null, null, null, null, null, null, null).getStdout());
    List<SubscriptionPool> allAvailableSubscriptionPoolsMatchingInstalled = SubscriptionPool.parse(clienttasks.list(true, true, null, null, null, null, true, null, null, null, null, null, null, null).getStdout());
    // loop through the list of all available subscription pools with match-installed and assert they really do provide at least one product that is installed.
    for (SubscriptionPool subscriptionPool : allAvailableSubscriptionPoolsMatchingInstalled) {
        ProductCert matchedInstalledProductCert = null;
        for (String providedProductId : CandlepinTasks.getPoolProvidedProductIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, subscriptionPool.poolId)) {
            matchedInstalledProductCert = ProductCert.findFirstInstanceWithMatchingFieldFromList("productId", providedProductId, installedProductCerts);
            if (matchedInstalledProductCert != null)
                break;
        }
        if (matchedInstalledProductCert != null)
            Assert.assertTrue(matchedInstalledProductCert != null, "Available subscription pool '" + subscriptionPool.subscriptionName + "' provides=" + subscriptionPool.provides + " includes product id '" + matchedInstalledProductCert.productId + "' which was found among the product ids of the currently installed product certs. " + installedProductIds);
        else
            Assert.fail("Subscription-manager list all available with match-installed option erroneously reported SubscriptionPool '" + subscriptionPool.subscriptionName + "' provides=" + subscriptionPool.provides + " which does NOT provide a product whose id was found among the currently installed product certs. " + installedProductIds);
    }
    // loop through the list of all available subscription without match-installed and make sure those that provide an installed product id are included in the filtered list
    for (SubscriptionPool subscriptionPool : allAvailableSubscriptionPools) {
        boolean providesAnInstalledProductId = false;
        for (String providedProductId : CandlepinTasks.getPoolProvidedProductIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, subscriptionPool.poolId)) {
            if (installedProductIds.contains(providedProductId))
                providesAnInstalledProductId = true;
        }
        if (providesAnInstalledProductId)
            Assert.assertTrue(allAvailableSubscriptionPoolsMatchingInstalled.contains(subscriptionPool), "The list of all available subscriptions with match-installed option includes '" + subscriptionPool.subscriptionName + "' provides=" + subscriptionPool.provides);
        else
            Assert.assertTrue(!allAvailableSubscriptionPoolsMatchingInstalled.contains(subscriptionPool), "The list of all available subscriptions with match-installed option does NOT include '" + subscriptionPool.subscriptionName + "' provides=" + subscriptionPool.provides);
    }
}
Also used : ArrayList(java.util.ArrayList) ProductCert(rhsm.data.ProductCert) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 90 with SubscriptionPool

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

the class ManagementAddOnTests method getAddOnSubscriptionDataAsListOfLists.

protected List<List<Object>> getAddOnSubscriptionDataAsListOfLists() throws JSONException, Exception {
    List<List<Object>> ll = new ArrayList<List<Object>>();
    if (!isSetupBeforeSuiteComplete)
        return ll;
    clienttasks.unsubscribeFromAllOfTheCurrentlyConsumedProductSubscriptions();
    List<SubscriptionPool> allAvailablePools = clienttasks.getCurrentlyAllAvailableSubscriptionPools();
    // iterate through all available pools looking for those that contain no provided products (A Management AddOn Subscription contains no products)
    for (SubscriptionPool pool : allAvailablePools) {
        JSONObject jsonPool = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/pools/" + pool.poolId));
        JSONArray jsonProvidedProducts = jsonPool.getJSONArray("providedProducts");
        if (jsonProvidedProducts.length() == 0) {
            Set<String> bugIds = new HashSet<String>();
            // Bug 1204311 - derivedProvidedProducts should not show up on a consumed subscription from a temporary pool
            if (CandlepinTasks.isPoolRestrictedToUnmappedVirtualSystems(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId)) {
                bugIds.add("1204311");
            }
            // found a subscription to a Management Add-on, add it to the list of subscriptions to test
            BlockedByBzBug blockedByBzBug = new BlockedByBzBug(bugIds.toArray(new String[] {}));
            ll.add(Arrays.asList(new Object[] { blockedByBzBug, pool }));
        }
    }
    return ll;
}
Also used : JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) List(java.util.List) JSONObject(org.json.JSONObject) SubscriptionPool(rhsm.data.SubscriptionPool) BlockedByBzBug(com.redhat.qe.auto.bugzilla.BlockedByBzBug) HashSet(java.util.HashSet)

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