Search in sources :

Example 1 with InstalledProduct

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

the class SearchDisabledReposTests method testRhelSubscriptionBaseAndOptionalReposAreAvailable.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-20089", "RHEL7-55192" }, 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 we can register with auto-subscribe to cover the base RHEL product cert; assert enablement of base rhel and optional repo", groups = { "Tier1Tests" }, priority = 20, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testRhelSubscriptionBaseAndOptionalReposAreAvailable() throws JSONException, Exception {
    // get the currently installed RHEL product cert
    ProductCert rhelProductCert = clienttasks.getCurrentRhelProductCert();
    Assert.assertNotNull(rhelProductCert, "Expecting a RHEL Product Cert to be installed.");
    log.info("RHEL product cert installed: " + rhelProductCert);
    // register with auto-subscribe
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, true, null, null, (String) null, null, null, null, true, null, null, null, null, null);
    // is rhelProductCert subscribed?
    InstalledProduct rhelInstalledProduct = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productId", rhelProductCert.productId, clienttasks.getCurrentlyInstalledProducts());
    if (!rhelInstalledProduct.status.equals("Subscribed") && sm_serverType.equals(CandlepinType.standalone))
        throw new SkipException("Skipping this test against a standalone Candlepin server that has no RHEL subscriptions available.");
    Assert.assertEquals(rhelInstalledProduct.status, "Subscribed", "Autosubscribed status of installed RHEL productId '" + rhelProductCert.productId + "'");
    // get the yum repos
    List<Repo> subscribedRepos = clienttasks.getCurrentlySubscribedRepos();
    // Enabled: 1
    if (clienttasks.redhatReleaseX.equals("7") && clienttasks.variant.equals("Server") && clienttasks.arch.equals("aarch64") && rhelProductCert.productId.equals("294")) /*Red Hat Enterprise Linux Server for ARM*/
    {
        rhelBaseRepoId = "rhel-7-for-arm-rpms";
    }
    // Enabled: 0
    if (clienttasks.redhatReleaseX.equals("7") && clienttasks.variant.equals("Server") && clienttasks.arch.equals("ppc64le") && rhelProductCert.productId.equals("279")) /*Red Hat Enterprise Linux for Power, little endian*/
    {
        rhelBaseRepoId = "rhel-7-for-power-le-rpms";
    }
    // Enabled: 1
    if (clienttasks.redhatReleaseX.equals("7") && clienttasks.variant.equals("Server") && clienttasks.arch.equals("ppc64")) {
        rhelBaseRepoId = "rhel-7-for-power-rpms";
    }
    // Enabled: 1
    if (clienttasks.redhatReleaseX.equals("7") && clienttasks.variant.equals("Server") && clienttasks.arch.equals("s390x")) {
        rhelBaseRepoId = "rhel-7-for-system-z-rpms";
    }
    // Enabled: 1
    if (clienttasks.redhatReleaseX.equals("7") && clienttasks.variant.equals("Server") && clienttasks.arch.equals("x86_64")) {
        rhelBaseRepoId = "rhel-7-server-rpms";
    }
    // Enabled: 1
    if (clienttasks.redhatReleaseX.equals("7") && clienttasks.variant.equals("Client") && clienttasks.arch.equals("x86_64")) {
        rhelBaseRepoId = "rhel-7-desktop-rpms";
    }
    // Enabled: 1
    if (clienttasks.redhatReleaseX.equals("7") && clienttasks.variant.equals("ComputeNode") && clienttasks.arch.equals("x86_64")) {
        rhelBaseRepoId = "rhel-7-hpc-node-rpms";
    }
    // Enabled: 1
    if (clienttasks.redhatReleaseX.equals("7") && clienttasks.variant.equals("Workstation") && clienttasks.arch.equals("x86_64")) {
        rhelBaseRepoId = "rhel-7-workstation-rpms";
    }
    // NOTE: BETA PRODUCT 362 AND GA PRODUCT 420 BOTH PROVIDE THE SAME TAGS "rhel-alt-7,rhel-alt-7-power9" WHICH MEANS THEY CAN ACCESS THE SAME CONTENT AND ARE EFFECTIVELY THE SAME PRODUCT (ASSUMING ALL POWER9 SKUS PROVIDE BOTH 362 AND 420)
    if (clienttasks.redhatReleaseX.equals("7") && clienttasks.variant.equals("Server") && clienttasks.arch.equals("ppc64le") && (rhelProductCert.productId.equals("362") || /*Red Hat Enterprise Linux for Power 9 Beta*/
    rhelProductCert.productId.equals("420"))) {
        rhelBaseRepoId = "rhel-7-for-power-9-rpms";
    }
    // NOTE: BETA PRODUCT 433 AND GA PRODUCT 434 BOTH PROVIDE THE SAME TAGS "rhel-alt-7,rhel-alt-7-system-z-a" WHICH MEANS THEY CAN ACCESS THE SAME CONTENT AND ARE EFFECTIVELY THE SAME PRODUCT (ASSUMING ALL SYSTEMZ SKUS PROVIDE BOTH 433 AND 434)
    if (clienttasks.redhatReleaseX.equals("7") && clienttasks.variant.equals("Server") && clienttasks.arch.equals("s390x") && (rhelProductCert.productId.equals("433") || /*Red Hat Enterprise Linux for IBM System z (Structure A) Beta*/
    rhelProductCert.productId.equals("434"))) {
        rhelBaseRepoId = "rhel-7-for-system-z-a-rpms";
    }
    // NOTE: BETA PRODUCT 363 AND GA PRODUCT 419 BOTH PROVIDE THE SAME TAGS "rhel-alt-7,rhel-alt-7-armv8-a" WHICH MEANS THEY CAN ACCESS THE SAME CONTENT AND ARE EFFECTIVELY THE SAME PRODUCT (ASSUMING ALL SYSTEMZ SKUS PROVIDE BOTH 363 AND 419)
    if (clienttasks.redhatReleaseX.equals("7") && clienttasks.variant.equals("Server") && clienttasks.arch.equals("aarch64") && (rhelProductCert.productId.equals("363") || /*Red Hat Enterprise Linux for ARM 64 Beta*/
    rhelProductCert.productId.equals("419"))) {
        rhelBaseRepoId = "rhel-7-for-arm-64-rpms";
    }
    // Repo ID:   rhel-6-server-optional-rpms
    if (clienttasks.redhatReleaseX.equals("6") && clienttasks.variant.equals("Server") && (clienttasks.arch.matches("i\\d86|x86_64"))) {
        rhelBaseRepoId = "rhel-6-server-rpms";
    }
    // Repo ID:   rhel-6-for-power-beta-rpms
    if (clienttasks.redhatReleaseX.equals("6") && clienttasks.variant.equals("Server") && (clienttasks.arch.equals("ppc64"))) {
        rhelBaseRepoId = "rhel-6-for-power-rpms";
    }
    // Repo ID:   rhel-6-for-system-z-beta-rpms
    if (clienttasks.redhatReleaseX.equals("6") && clienttasks.variant.equals("Server") && (clienttasks.arch.equals("s390x"))) {
        rhelBaseRepoId = "rhel-6-for-system-z-rpms";
    }
    // Repo ID:   rhel-6-desktop-optional-rpms
    if (clienttasks.redhatReleaseX.equals("6") && clienttasks.variant.equals("Client") && (clienttasks.arch.matches("i\\d86|x86_64"))) {
        rhelBaseRepoId = "rhel-6-desktop-rpms";
    }
    // Repo ID:   rhel-6-hpc-node-optional-rpms
    if (clienttasks.redhatReleaseX.equals("6") && clienttasks.variant.equals("ComputeNode") && (clienttasks.arch.equals("x86_64"))) {
        rhelBaseRepoId = "rhel-6-hpc-node-rpms";
    }
    // PLATFORM=RedHatEnterpriseLinux6-Workstation-x86_64
    if (clienttasks.redhatReleaseX.equals("6") && clienttasks.variant.equals("Workstation") && (clienttasks.arch.matches("i\\d86|x86_64"))) {
        rhelBaseRepoId = "rhel-6-workstation-rpms";
    }
    // predict the disabled optional repo and potential presence of other enabled repos
    if (rhelBaseRepoId != null) {
        rhelOptionalRepoId = rhelBaseRepoId.replaceFirst("-rpms$", "-optional-rpms");
        rhelEusRepoId = rhelBaseRepoId.replaceFirst("-rpms$", "-eus-rpms");
        rhelBetaRepoId = rhelBaseRepoId.replaceFirst("-rpms$", "-beta-rpms");
        rhelHtbRepoId = rhelBaseRepoId.replaceFirst("-rpms$", "-htb-rpms");
        rhelOptionalHtbRepoId = rhelBaseRepoId.replaceFirst("-rpms$", "-optional-htb-rpms");
    } else {
        Assert.fail("Additional automation development is needed in this test to predict the name of the enabled base RHEL repo for RHEL" + clienttasks.redhatReleaseX + " " + clienttasks.variant + " " + clienttasks.arch + "; Installed Product Cert: " + rhelProductCert);
    }
    // expected rhelBaseRepoId and rhelOptionalRepoId to the corresponding HTB repos
    if (rhelProductCert.productId.equals("230") || /*Red Hat Enterprise Linux 7 Server High Touch Beta*/
    rhelProductCert.productId.equals("231")) /*Red Hat Enterprise Linux 7 Workstation High Touch Beta)*/
    {
        log.info("Adjusting the expected base and optional repos because the default installed RHEL product appears to be High Touch Beta (this is expected for Snapshot composes).");
        rhelBaseRepoId = rhelHtbRepoId;
        rhelOptionalRepoId = rhelOptionalHtbRepoId;
    }
    // assert the base rhel repo is enabled by default
    Repo rhelBaseRepo = Repo.findFirstInstanceWithMatchingFieldFromList("repoId", rhelBaseRepoId, subscribedRepos);
    Assert.assertNotNull(rhelBaseRepo, "RHEL base repo id '" + rhelBaseRepoId + "' was found in subscribed repos.");
    Assert.assertTrue(rhelBaseRepo.enabled, "RHEL base repo id '" + rhelBaseRepoId + "' is enabled by default.");
    // assert the optional rhel repo is disabled by default
    Repo rhelOptionalRepo = Repo.findFirstInstanceWithMatchingFieldFromList("repoId", rhelOptionalRepoId, subscribedRepos);
    Assert.assertNotNull(rhelOptionalRepo, "RHEL optional repo id '" + rhelOptionalRepoId + "' was found in subscribed repos.");
    Assert.assertTrue(!rhelOptionalRepo.enabled, "RHEL optional repo id '" + rhelOptionalRepoId + "' is disabled by default.");
    // determine if beta rhel repo is entitled; if not then set it to null
    // assert the beta rhel repo is disabled by default
    Repo rhelBetaRepo = Repo.findFirstInstanceWithMatchingFieldFromList("repoId", rhelBetaRepoId, subscribedRepos);
    if (rhelBetaRepo == null)
        rhelBetaRepoId = null;
    if (rhelBetaRepo != null)
        Assert.assertTrue(!rhelBetaRepo.enabled, "RHEL beta repo id '" + rhelBetaRepoId + "' is disabled by default.");
    // determine if htb rhel repo is entitled; if not then set it to null
    Repo rhelHtbRepo = Repo.findFirstInstanceWithMatchingFieldFromList("repoId", rhelHtbRepoId, subscribedRepos);
    if (rhelHtbRepo == null)
        rhelHtbRepoId = null;
    // determine if optional htb rhel repo is entitled; if not then set it to null
    Repo rhelOptionalHtbRepo = Repo.findFirstInstanceWithMatchingFieldFromList("repoId", rhelOptionalHtbRepoId, subscribedRepos);
    if (rhelOptionalHtbRepo == null)
        rhelOptionalHtbRepoId = null;
    // determine if eus rhel repo is entitled; if not then set it to null
    Repo rhelEusRepo = Repo.findFirstInstanceWithMatchingFieldFromList("repoId", rhelEusRepoId, subscribedRepos);
    if (rhelEusRepo == null)
        rhelEusRepoId = null;
}
Also used : Repo(rhsm.data.Repo) InstalledProduct(rhsm.data.InstalledProduct) ProductCert(rhsm.data.ProductCert) SkipException(org.testng.SkipException) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 2 with InstalledProduct

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

the class ServiceLevelTests method testAutoSubscribeWithServiceLevelIsCaseInsensitive.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-19994", "RHEL7-51026" }, 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 = "subscription-manager: autosubscribe while specifying an valid service level; assert the installed product status is independent of the specified SerViceLeVEL case.", groups = { "Tier1Tests", "blockedByBug-818319", "blockedByBug-859652" }, // dataProvider="getAllAvailableServiceLevelData",	// 06/05/2014 takes too long; rarely reveals a bug
dataProvider = "getRandomSubsetOfAllAvailableServiceLevelData", enabled = true)
// 157226 //157225
@ImplementsNitrateTest(caseId = 157227)
public void testAutoSubscribeWithServiceLevelIsCaseInsensitive(Object bugzilla, String serviceLevel) throws JSONException, Exception {
    // TEMPORARY WORKAROUND FOR BUG
    if (sm_serverType.equals(CandlepinType.hosted)) {
        String bugId = "818319";
        boolean invokeWorkaroundWhileBugIsOpen = true;
        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) {
            throw new SkipException("This test is blocked by Bugzilla https://bugzilla.redhat.com/show_bug.cgi?id=" + bugId);
        }
    }
    // system was already registered by dataProvider="getSubscribeWithAutoAndServiceLevelData"
    if (clienttasks.getCurrentConsumerId() == 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);
    }
    // start fresh by returning all entitlements
    clienttasks.unsubscribeFromAllOfTheCurrentlyConsumedProductSubscriptions();
    // autosubscribe specifying a valid service level and get the installed product status
    List<InstalledProduct> installedProductsAfterAutosubscribingWithServiceLevel = InstalledProduct.parse(clienttasks.subscribe(true, serviceLevel, (String) null, (String) null, (String) null, null, null, null, null, null, null, null, null).getStdout());
    // unsubscribe from all entitlements
    clienttasks.unsubscribeFromAllOfTheCurrentlyConsumedProductSubscriptions();
    // autosubscribe specifying a mixed case service level and get the installed product status
    String mixedCaseServiceLevel = randomizeCaseOfCharactersInString(serviceLevel);
    List<InstalledProduct> installedProductsAfterAutosubscribingWithMixedCaseServiceLevel = InstalledProduct.parse(clienttasks.subscribe(true, mixedCaseServiceLevel, (String) null, (String) null, (String) null, null, null, null, null, null, null, null, null).getStdout());
    // assert that the two lists are identical (independent of the serviceLevel case specified during autosubscribe)
    Assert.assertEquals(installedProductsAfterAutosubscribingWithMixedCaseServiceLevel.size(), clienttasks.getCurrentProductIds().size(), "The subscribe output displayed the same number of installed product status's as the current number of installed product certs.");
    Assert.assertTrue(installedProductsAfterAutosubscribingWithServiceLevel.containsAll(installedProductsAfterAutosubscribingWithMixedCaseServiceLevel) && installedProductsAfterAutosubscribingWithMixedCaseServiceLevel.containsAll(installedProductsAfterAutosubscribingWithServiceLevel), "Autosubscribe with serviceLevel '" + mixedCaseServiceLevel + "' yielded the same installed product status as autosubscribe with serviceLevel '" + serviceLevel + "'.");
    // get the current exempt service levels
    List<String> exemptServiceLevels = CandlepinTasks.getServiceLevelsForOrgKey(sm_clientUsername, sm_clientPassword, sm_serverUrl, clienttasks.getCurrentlyRegisteredOwnerKey(), true);
    List<String> exemptServiceLevelsInUpperCase = new ArrayList<String>();
    for (String exemptServiceLevel : exemptServiceLevels) exemptServiceLevelsInUpperCase.add(exemptServiceLevel.toUpperCase());
    // assert that each of the consumed ProductSubscriptions match the specified service level
    List<ProductSubscription> consumedProductSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
    if (consumedProductSubscriptions.isEmpty())
        log.warning("No entitlements were granted after autosubscribing with service level '" + mixedCaseServiceLevel + "'.");
    for (ProductSubscription productSubscription : consumedProductSubscriptions) {
        // tolerate ProductSubscriptions with a null/"" serviceLevel. (result of candlepin Bug 1223560)
        if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", /*TODO ">" is technically correct*/
        "2.0.2-1")) {
            // commit 9cefb6e23baefcc4ee2e14423f205edd37eecf22	// Bug 1223560 - Service levels on an activation key prevent custom products from attaching at registration if auto-attach enabled
            if (productSubscription.serviceLevel == null || productSubscription.serviceLevel.isEmpty()) {
                log.warning("After autosubscribe with service level '" + mixedCaseServiceLevel + "', this consumed ProductSubscription provides no service level '" + productSubscription.serviceLevel + "'.  (New behavior modification from Bug 1223560)");
                continue;
            }
        }
        // tolerate ProductSubscriptions with exemptServiceLevels
        if (/*sm_*/
        exemptServiceLevelsInUpperCase.contains(productSubscription.serviceLevel.toUpperCase())) {
            log.warning("After autosubscribe with service level '" + mixedCaseServiceLevel + "', this consumed ProductSubscription provides an exempt service level '" + productSubscription.serviceLevel + "'.");
            continue;
        }
        Assert.assertTrue(productSubscription.serviceLevel.equalsIgnoreCase(mixedCaseServiceLevel), "After autosubscribe with service level '" + mixedCaseServiceLevel + "', this consumed ProductSubscription provides a service level '" + productSubscription.serviceLevel + "' that is a case insensitive match to '" + mixedCaseServiceLevel + "'.");
    }
}
Also used : InstalledProduct(rhsm.data.InstalledProduct) ArrayList(java.util.ArrayList) ProductSubscription(rhsm.data.ProductSubscription) SkipException(org.testng.SkipException) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 3 with InstalledProduct

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

the class ServiceLevelTests method testRegisterWithServiceLevelIsCaseInsensitive.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-19995", "RHEL7-51028" }, 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 = "subscription-manager: register with autosubscribe while specifying an valid random case SeRviCEleVel; assert the installed product status is independent of the specified service level case.", groups = { "Tier1Tests", "blockedByBug-859652", "blockedByBug-859652", "blockedByBug-919700" }, // dataProvider="getAllAvailableServiceLevelData",	// 06/05/2014 takes too long; rarely reveals a bug
dataProvider = "getRandomSubsetOfAllAvailableServiceLevelData", enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testRegisterWithServiceLevelIsCaseInsensitive(Object bugzilla, String serviceLevel) {
    // TEMPORARY WORKAROUND FOR BUG
    if (sm_serverType.equals(CandlepinType.hosted)) {
        String bugId = "818319";
        boolean invokeWorkaroundWhileBugIsOpen = true;
        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) {
            throw new SkipException("Hosted candlepin server '" + sm_serverHostname + "' does not yet support this test execution.");
        }
    }
    // END OF WORKAROUND
    // register with autosubscribe specifying a valid service level and get the installed product status
    List<InstalledProduct> installedProductsAfterAutosubscribedRegisterWithServiceLevel = InstalledProduct.parse(clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, true, serviceLevel, null, (String) null, null, null, null, true, null, null, null, null, null).getStdout());
    // register with autosubscribe specifying a mixed case service level and get the installed product status
    String mixedCaseServiceLevel = randomizeCaseOfCharactersInString(serviceLevel);
    List<InstalledProduct> installedProductsAfterAutosubscribedRegisterWithMixedCaseServiceLevel = InstalledProduct.parse(clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, true, mixedCaseServiceLevel, null, (String) null, null, null, null, true, null, null, null, null, null).getStdout());
    // assert that the two lists are identical (independent of the serviceLevel case specified during registration)
    Assert.assertEquals(installedProductsAfterAutosubscribedRegisterWithMixedCaseServiceLevel.size(), clienttasks.getCurrentProductIds().size(), "The registration output displayed the same number of installed product status's as the number of installed product certs.");
    Assert.assertTrue(installedProductsAfterAutosubscribedRegisterWithServiceLevel.containsAll(installedProductsAfterAutosubscribedRegisterWithMixedCaseServiceLevel) && installedProductsAfterAutosubscribedRegisterWithMixedCaseServiceLevel.containsAll(installedProductsAfterAutosubscribedRegisterWithServiceLevel), "Autosubscribed registration with serviceLevel '" + mixedCaseServiceLevel + "' yielded the same installed product status as autosubscribed registration with serviceLevel '" + serviceLevel + "'.");
    // assert that each of the consumed ProductSubscriptions match the specified service level
    List<ProductSubscription> consumedProductSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
    if (consumedProductSubscriptions.isEmpty())
        log.warning("No entitlements were granted after registering with autosubscribe and service level '" + mixedCaseServiceLevel + "'.");
    for (ProductSubscription productSubscription : consumedProductSubscriptions) {
        // tolerate ProductSubscriptions with a null/"" serviceLevel. (result of candlepin Bug 1223560)
        if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", /*TODO ">" is technically correct*/
        "2.0.2-1")) {
            // commit 9cefb6e23baefcc4ee2e14423f205edd37eecf22	// Bug 1223560 - Service levels on an activation key prevent custom products from attaching at registration if auto-attach enabled
            if (productSubscription.serviceLevel == null || productSubscription.serviceLevel.isEmpty()) {
                log.warning("After autosubscribed registration with service level '" + mixedCaseServiceLevel + "', this consumed ProductSubscription provides no service level '" + productSubscription.serviceLevel + "'.  (New behavior modification from Bug 1223560)");
                continue;
            }
        }
        // tolerate exemptServiceLevels
        if (sm_exemptServiceLevelsInUpperCase.contains(productSubscription.serviceLevel.toUpperCase())) {
            log.warning("After autosubscribed registration with service level '" + mixedCaseServiceLevel + "', this consumed ProductSubscription provides an exempt service level '" + productSubscription.serviceLevel + "'.");
            continue;
        }
        Assert.assertTrue(productSubscription.serviceLevel.equalsIgnoreCase(mixedCaseServiceLevel), "After autosubscribed registration with service level '" + mixedCaseServiceLevel + "', this consumed ProductSubscription provides a service level '" + productSubscription.serviceLevel + "' that is a case insensitive match to '" + mixedCaseServiceLevel + "'.");
    }
}
Also used : InstalledProduct(rhsm.data.InstalledProduct) ProductSubscription(rhsm.data.ProductSubscription) SkipException(org.testng.SkipException) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 4 with InstalledProduct

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

the class StatusTests method testStatusWhileRegisteredWithoutEntitlements.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-19969", "RHEL7-51008" }, 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 = "run subscription-manager status when registered without entitlements", groups = { "Tier1Tests" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testStatusWhileRegisteredWithoutEntitlements() {
    int numberOfInstalledProducts = clienttasks.getCurrentProductCertFiles().size();
    SSHCommandResult statusResult;
    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);
    List<InstalledProduct> installedProducts = clienttasks.getCurrentlyInstalledProducts();
    statusResult = clienttasks.status(null, null, null, null, null);
    // [root@jsefler-5 ~]# subscription-manager status
    // +-------------------------------------------+
    // System Status Details
    // +-------------------------------------------+
    // Overall Status: Invalid
    // 
    // Awesome OS Modifier Bits:
    // - Not covered by a valid subscription.
    // assert the overall status
    String expectedStatus;
    if (numberOfInstalledProducts == 0) {
        // translation for "valid"
        expectedStatus = "Overall Status: Current";
    } else {
        // translation for "invalid"
        expectedStatus = "Overall Status: Invalid";
    }
    Assert.assertTrue(statusResult.getStdout().contains(expectedStatus), "Expecting '" + expectedStatus + "' when registered without entitlements and '" + numberOfInstalledProducts + "' installed products.");
    // assert the individual installed product status details
    for (InstalledProduct installedProduct : installedProducts) {
        for (String statusDetail : installedProduct.statusDetails) {
            Assert.assertTrue(!getSubstringMatches(statusResult.getStdout(), "^" + installedProduct.productName.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)") + ":(\\n- .*)*?\\n- " + statusDetail.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)")).isEmpty(), "Expecting the status detail '" + statusDetail + "' of installed product '" + installedProduct.productName + "' to appear in the list of overall status details.");
            Assert.assertTrue(!doesStringContainMatches(statusResult.getStdout(), statusDetail.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)") + "(\\n- .*)*?\\n- " + statusDetail.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)")), "Status detail '" + statusDetail + "' of installed product '" + installedProduct.productName + "' should not appear in duplicate.");
        }
    }
    if (installedProducts.isEmpty()) {
        Assert.assertTrue(statusResult.getStdout().trim().endsWith(expectedStatus), "There should be no report of installed product details when there are no installed products; only expected '" + expectedStatus + "'.");
    }
}
Also used : SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) InstalledProduct(rhsm.data.InstalledProduct) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 5 with InstalledProduct

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

the class StatusTests method testStatusWhileRegisteredWithEntitlements.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-19968", "RHEL7-51007" }, 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 = "run subscription-manager status when registered with entitlements", groups = { "Tier1Tests", "blockedByBug-958827", "StatusWhileRegisteredWithEntitlements_Test" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testStatusWhileRegisteredWithEntitlements() throws JSONException, Exception {
    SSHCommandResult statusResult;
    // override the system facts setting the attribute count to a value for which all the stackable subscriptions are needed to achieve compliance
    Map<String, String> factsMap = new HashMap<String, String>();
    factsMap.put("memory.memtotal", "75");
    factsMap.put("cpu.cpu_socket(s)", "100");
    factsMap.put("cpu.core(s)_per_socket", "2");
    clienttasks.createFactsFileWithOverridingValues(factsMap);
    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);
    clienttasks.subscribeToTheCurrentlyAvailableSubscriptionPoolsCollectively();
    String systemEntitlementsValid = clienttasks.getFactValue("system.entitlements_valid");
    statusResult = clienttasks.status(null, null, null, null, null);
    // [root@jsefler-5 ~]# subscription-manager status
    // +-------------------------------------------+
    // System Status Details
    // +-------------------------------------------+
    // Overall Status: Invalid
    // 
    // Large File Support Bits:
    // - Not covered by a valid subscription.
    // 
    // Awesome OS for x86 Bits:
    // - Not covered by a valid subscription.
    // 
    // Stackable Cores Package (8 cores)/Stackable Cores Package (8 cores):
    // - Only covers 16 of 200 cores.
    // 
    // Awesome OS for S390X Bits:
    // - Not covered by a valid subscription.
    // 
    // Awesome OS for S390 Bits:
    // - Not covered by a valid subscription.
    // 
    // Load Balancing Bits:
    // - Not covered by a valid subscription.
    // 
    // Awesome OS Workstation Bits:
    // - Not covered by a valid subscription.
    // 
    // Clustering Bits:
    // - Not covered by a valid subscription.
    // 
    // Awesome OS for i386 Bits:
    // - Not covered by a valid subscription.
    // 
    // Stackable with Awesome OS for x86_64/Awesome OS for x86_64/Stackable with Awesome OS for x86_64/Awesome OS for x86_64:
    // - Only covers 4 of 100 sockets.
    // 
    // Multi-Attribute (non-stackable) (6 cores, 8GB):
    // - Only covers 6 of 200 cores.
    // 
    // Awesome OS for ia64 Bits:
    // - Not covered by a valid subscription.
    // 
    // Awesome OS Developer Basic:
    // - Not covered by a valid subscription.
    // 
    // Multi-Attribute (multi-entitlement only) (8 cores, 4GB):
    // - Only covers 8 of 200 cores.
    // 
    // Cores Package (26 cores):
    // - Only covers 26 of 200 cores.
    // 
    // Multiplier Product Bits:
    // - Not covered by a valid subscription.
    // 
    // RAM/Cores Package (8GB, 4 cores):
    // - Only covers 4 of 200 cores.
    // 
    // Shared Storage Bits:
    // - Not covered by a valid subscription.
    // 
    // Awesome OS for ppc64 Bits:
    // - Not covered by a valid subscription.
    // 
    // Awesome OS for i686 Bits:
    // - Not covered by a valid subscription.
    // 
    // Awesome OS Premium Architecture Bits:
    // - Not covered by a valid subscription.
    // 
    // Multi-Attribute Stackable (4 cores)/Multi-Attribute Stackable (2 GB, 2 Cores)/Multi-Attribute Stackable (4 cores)/Multi-Attribute Stackable (2 GB, 2 Cores)/Multi-Attribute Stackable (16
    // cores, 4 sockets, 8GB RAM)/Multi-Attribute Stackable (2 sockets)/Multi-Attribute Stackable (2 GB)/Multi-Attribute Stackable (2 sockets)/Multi-Attribute Stackable (16 cores, 4 sockets, 8GB
    // RAM)/Multi-Attribute Stackable (2 GB):
    // - Only covers 44 of 200 cores.
    // - Only covers 12 of 100 sockets.
    // 
    // Management Bits:
    // - Not covered by a valid subscription.
    // 
    // Virt Only Awesome OS for i386 Bits:
    // - Not covered by a valid subscription.
    // 
    // Awesome OS Developer Bits:
    // - Not covered by a valid subscription.
    // 
    // Awesome OS for x86_64/i686/ia64/ppc/ppc64/s390x/s390 Bits:
    // - Not covered by a valid subscription.
    // Awesome OS Server Bits:
    // - Guest has not been reported on any host and is using a temporary unmapped guest subscription.
    // assert the overall status
    String expectedStatus = null;
    if (systemEntitlementsValid.equals("valid")) {
        // translation for "valid"
        expectedStatus = "Overall Status: Current";
    } else if (systemEntitlementsValid.equals("invalid")) {
        // translation for "invalid"
        expectedStatus = "Overall Status: Invalid";
    } else if (systemEntitlementsValid.equals("partial")) {
        // translation for "partial"	// Bug 959124 - "Compliant status" of the system set to "Insufficient" if any partial subscription is attached to a product (which is not exsiting )
        expectedStatus = "Overall Status: Insufficient";
    } else if (systemEntitlementsValid.equals("unknown")) {
        // translation for "unknown"
        expectedStatus = "Overall Status: Unknown";
    } else {
        Assert.fail("Encountered an unexpected value for systemEntitlementsValid '" + systemEntitlementsValid + "'.");
    }
    Assert.assertTrue(statusResult.getStdout().contains(expectedStatus), "Expecting '" + expectedStatus + "'.");
    // if (clienttasks.isPackageVersion("subscription-manager",">=","1.13.8-1")) {		// post commit 7957b8df95c575e6e8713c2f1a0f8f754e32aed3 bug 1119688
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.13.10-1")) {
        // exit code of 0 indicates valid compliance, otherwise exit code is 1
        if (systemEntitlementsValid.equals("valid")) {
            Assert.assertEquals(statusResult.getExitCode(), new Integer(0), "When the system's overall status is valid, an exit code of 0 should be returned.");
        } else {
            Assert.assertEquals(statusResult.getExitCode(), new Integer(1), "When the system's overall status is NOT valid, an exit code of 1 should be returned.");
        }
    }
    // assert the individual installed product status details
    for (InstalledProduct installedProduct : clienttasks.getCurrentlyInstalledProducts()) {
        // status details from the individual installed products is only included in the status report when the product is Not Subscribed
        if (installedProduct.status.equals("Not Subscribed")) {
            // expectedDetails "Not covered by a valid subscription."
            if (installedProduct.statusDetails.isEmpty())
                log.warning("Status Details appears empty.  Is your candlepin server older than 0.8.6?");
            Assert.assertTrue(!getSubstringMatches(statusResult.getStdout(), "^" + installedProduct.productName.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)") + ":").isEmpty(), "Installed product '" + installedProduct.productName + "' should be included in the overall status details report when its own status is Not Subscribed.");
            for (String statusDetail : installedProduct.statusDetails) {
                Assert.assertTrue(!getSubstringMatches(statusResult.getStdout(), "^" + installedProduct.productName.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)") + ":(\\n- .*)*?\\n- " + statusDetail.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)")).isEmpty(), "Expecting the status detail '" + statusDetail + "' of installed product '" + installedProduct.productName + "' to appear in the list of overall status details.");
                // Assert.assertTrue(!doesStringContainMatches(listStatusResult.getStdout(), "(\\n^- "+statusDetail+"){2,}"),
                // "Status detail '"+statusDetail+"' of installed product '"+installedProduct.productName+"' should NOT appear in duplicate.");
                Assert.assertTrue(!doesStringContainMatches(statusResult.getStdout(), statusDetail.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)") + "(\\n- .*)*?\\n- " + statusDetail.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)")), "Status detail '" + statusDetail + "' of installed product '" + installedProduct.productName + "' should not appear in duplicate.");
            }
        } else {
            // TEMPORARY WORKAROUND FOR BUG:
            boolean invokeWorkaroundWhileBugIsOpen = true;
            // Bug 1197897 - subscription-manager status is yellow due to 24-hour subscription despite redundant coverage from a green subscription
            String bugId = "1197897";
            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 && !getSubstringMatches(statusResult.getStdout(), "^" + installedProduct.productName.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)") + ":").isEmpty()) {
                String expectedReason = "Guest has not been reported on any host and is using a temporary unmapped guest subscription.";
                log.warning("Verifying that the reason product '" + installedProduct.productName + "' appears in the status report is because a temporary 24 hour subscription has been attached since '" + expectedReason + "'.");
                Assert.assertTrue(!getSubstringMatches(statusResult.getStdout(), "^" + installedProduct.productName.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)") + ":" + "\n- " + expectedReason).isEmpty(), "Installed product '" + installedProduct.productName + "' appears to be covered by a temporary 24 hours entitlement because the status module reports '" + expectedReason + "'");
            } else
                // assert
                // END OF WORKAROUND
                Assert.assertTrue(getSubstringMatches(statusResult.getStdout(), "^" + installedProduct.productName.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)") + ":").isEmpty(), "Installed product '" + installedProduct.productName + "' should NOT be included in the overall status details report when its own status '" + installedProduct.status + "' is something other than Not Subscribed.");
        }
    }
    // assert the individual consumed subscription status details
    List<ProductSubscription> currentlyConsumedProductSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
    for (ProductSubscription productSubscription : currentlyConsumedProductSubscriptions) {
        // if (productSubscription.statusDetails.isEmpty()) {	// is not sufficient after bug 1180400 implementation
        if (productSubscription.statusDetails.isEmpty() && clienttasks.isPackageVersion("subscription-manager", "<", "1.13.13-1")) {
            // since this productSubscription is empty, it should NOT be reported in the Status report
            Assert.assertTrue(getSubstringMatches(statusResult.getStdout(), "(^|/)" + productSubscription.productName.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)") + "(|/.+):").isEmpty(), "Expecting the empty status details " + productSubscription.statusDetails + " of consumed subscription '" + productSubscription.productName + "' to NOT appear in the list of overall status details of the installed products.");
        } else if (productSubscription.statusDetails.size() == 1 && productSubscription.statusDetails.get(0).trim().equals("Subscription is current") && clienttasks.isPackageVersion("subscription-manager", ">=", "1.13.13-1")) {
            // commit 252ec4520fb6272b00ae379703cd004f558aac63	// bug 1180400: "Status Details" are now populated on CLI
            // since this productSubscription appears to be current, it should NOT be reported in the Status report, UNLESS there is another overconsumed subscription by the same name that is not current.
            // assume
            boolean allOtherConsumedProductSubscriptionsWithThisProductNameAreCurrent = true;
            for (ProductSubscription otherConsumedProductSubscription : currentlyConsumedProductSubscriptions) {
                if (otherConsumedProductSubscription.productName.equals(productSubscription.productName) && !otherConsumedProductSubscription.poolId.equals(productSubscription.poolId) && !otherConsumedProductSubscription.statusDetails.isEmpty() && !otherConsumedProductSubscription.statusDetails.get(0).equals("Subscription is current")) {
                    allOtherConsumedProductSubscriptionsWithThisProductNameAreCurrent = false;
                    log.warning("There are multiple consumed subscriptions for '" + productSubscription.productName + "'.  Not all of them are current.");
                }
            }
            boolean statusReportIncludesProductSubscriptionProductName = getSubstringMatches(statusResult.getStdout(), "(^|/)" + productSubscription.productName.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)") + "(|/.+):").isEmpty();
            if (allOtherConsumedProductSubscriptionsWithThisProductNameAreCurrent) {
                Assert.assertTrue(statusReportIncludesProductSubscriptionProductName, "Since the status details of consumed subscription '" + productSubscription.productName + "' states Subscription is current, product '" + productSubscription.productName + "' should NOT appear in the list of overall status details of the installed products.");
            }
        // else the actual status report will be asserted when the outer for loop hits the otherConsumedProductSubscriptionsWithThisProductName
        } else {
            // since this productSubscription is not current, its status details should be reported in the Status report under the subscription's name.
            for (String statusDetail : productSubscription.statusDetails) {
                Assert.assertTrue(!getSubstringMatches(statusResult.getStdout(), "(^|/)" + productSubscription.productName.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)") + "(|/.+):(\\n- .*)*?\\n- " + statusDetail.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)")).isEmpty(), "Expecting the status detail '" + statusDetail + "' of consumed subscription '" + productSubscription.productName + "' to appear in the list of overall status details.");
                // Assert.assertTrue(!doesStringContainMatches(listStatusResult.getStdout(), "(\\n^- "+statusDetail+"){2,}"),
                // "Status detail '"+statusDetail+"' of consumed subscription '"+productSubscription+"' should NOT appear in duplicate.");
                Assert.assertTrue(!doesStringContainMatches(statusResult.getStdout(), statusDetail.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)") + "(\\n- .*)*?\\n- " + statusDetail.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)")), "Status detail '" + statusDetail + "' of consumed subscription '" + productSubscription.productName + "' should not appear in duplicate.");
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) InstalledProduct(rhsm.data.InstalledProduct) ProductSubscription(rhsm.data.ProductSubscription) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Aggregations

InstalledProduct (rhsm.data.InstalledProduct)77 Test (org.testng.annotations.Test)71 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)66 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)33 SkipException (org.testng.SkipException)27 SubscriptionPool (rhsm.data.SubscriptionPool)25 ArrayList (java.util.ArrayList)22 ProductCert (rhsm.data.ProductCert)21 ProductSubscription (rhsm.data.ProductSubscription)16 SSHCommandResult (com.redhat.qe.tools.SSHCommandResult)15 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)14 HashMap (java.util.HashMap)13 BigInteger (java.math.BigInteger)12 JSONObject (org.json.JSONObject)10 File (java.io.File)9 Calendar (java.util.Calendar)7 HashSet (java.util.HashSet)7 EntitlementCert (rhsm.data.EntitlementCert)6 GregorianCalendar (java.util.GregorianCalendar)5 JSONArray (org.json.JSONArray)5