Search in sources :

Example 16 with InstalledProduct

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

the class BugzillaTests method testAutohealForPartialSubscription.

/**
 * @author skallesh
 * @throws JSONException
 * @throws Exception
 */
@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-21936", "RHEL7-51798" }, 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 = "Auto-heal for partial subscription", groups = { "Tier3Tests", "autohealPartial", "blockedByBug-746218", "blockedByBug-907638", "blockedByBug-907400" }, enabled = true)
public void testAutohealForPartialSubscription() throws Exception {
    Integer moreSockets = 0;
    List<String> productIds = new ArrayList<String>();
    List<String> poolId = new ArrayList<String>();
    Map<String, String> factsMap = new HashMap<String, String>();
    factsMap.put("virt.is_guest", Boolean.FALSE.toString());
    clienttasks.createFactsFileWithOverridingValues(factsMap);
    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);
    // disable
    clienttasks.autoheal(null, null, true, null, null, null, null);
    // autoheal
    for (SubscriptionPool pool : clienttasks.getCurrentlyAvailableSubscriptionPools()) {
        if (CandlepinTasks.isPoolProductMultiEntitlement(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId)) {
            String poolProductSocketsAttribute = CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "stacking_id");
            if ((!(poolProductSocketsAttribute == null)) && (poolProductSocketsAttribute.equals("1"))) {
                String SocketsCount = CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "sockets");
                poolId.add(pool.poolId);
                moreSockets += Integer.valueOf(SocketsCount);
                productIds.addAll(CandlepinTasks.getPoolProvidedProductIds(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId));
            }
        }
    }
    if (moreSockets == 0)
        throw new SkipException("Expected to find a sockets based multi-entitlement pool with stacking_id 1 for this test.");
    factsMap.put("cpu.cpu_socket(s)", String.valueOf((++moreSockets) + Integer.valueOf(clienttasks.sockets)));
    clienttasks.createFactsFileWithOverridingValues(factsMap);
    clienttasks.facts(null, true, null, null, null, null);
    for (InstalledProduct installedProduct : clienttasks.getCurrentlyInstalledProducts()) {
        if (productIds.contains(installedProduct.productId)) {
            Assert.assertEquals(installedProduct.status, "Partially Subscribed");
        }
    }
    Assert.assertTrue(!productIds.isEmpty(), "Found installed products that are partially subscribed after adding " + moreSockets + " more cpu.cpu_socket(s).");
    // enable
    clienttasks.autoheal(null, true, null, null, null, null, null);
    // autoheal
    // trigger autoheal
    clienttasks.run_rhsmcertd_worker(true);
    for (InstalledProduct installedProduct : clienttasks.getCurrentlyInstalledProducts()) {
        for (String productId : productIds) {
            if (productId.equals(installedProduct.productId))
                Assert.assertEquals(installedProduct.status, "Subscribed", "Status of installed product '" + installedProduct.productName + "' after auto-healing.");
        }
    }
}
Also used : BigInteger(java.math.BigInteger) HashMap(java.util.HashMap) InstalledProduct(rhsm.data.InstalledProduct) ArrayList(java.util.ArrayList) 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 17 with InstalledProduct

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

the class SubscriptionManagerTasks method isRhelProductCertSubscribed.

public boolean isRhelProductCertSubscribed() {
    ProductCert rhelProductCert = getCurrentRhelProductCert();
    // rhel product cert cannot be subscribed if a rhel product cert is not installed
    if (rhelProductCert == null)
        return false;
    InstalledProduct installedRhelProduct = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productId", rhelProductCert.productId, getCurrentlyInstalledProducts());
    if (installedRhelProduct == null)
        Assert.fail("Could not find the installed product corresponding to the current RHEL product cert: " + rhelProductCert);
    return installedRhelProduct.status.equals("Subscribed");
}
Also used : InstalledProduct(rhsm.data.InstalledProduct) ProductCert(rhsm.data.ProductCert)

Example 18 with InstalledProduct

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

the class CertificateTests method testYumUpdateWithDisabledRepoWillNotDeleteJBossProductId.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-20034", "RHEL7-55176" }, 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 = "When updating a RHEL package on a system with JBoss, verify that the JBoss productId is not deleted when calling yum update with --disablerepo=jb-eap-6-for-rhel-6-server-rpms", groups = { "Tier1Tests", "VerifyYumUpdateWithDisabledRepoWillNotDeleteJBossProductId_Test", "blockedByBug-1159163", "blockedByBug-1512948" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testYumUpdateWithDisabledRepoWillNotDeleteJBossProductId() throws JSONException, Exception {
    // fixed in https://bugzilla.redhat.com/show_bug.cgi?id=1159163#c12  subscription-manager commit 68d210bb9145e7ea65aea979fde694436e3e0373 subscription-manager-1.14.6-1
    clienttasks.unregister(null, null, null, null);
    restoreOriginalRhsmProductCertDirAndProductIdJsonFile();
    // hard data for this test...
    String rhelPackage = "zsh";
    // Required Tags: rhel-6-server Arches: x86_64, x86
    String rhelRepo = "rhel-6-server-rpms";
    rhelRepo = String.format("rhel-%s-server-rpms", clienttasks.redhatReleaseX);
    // Red Hat Enterprise Linux Server	// Tags: rhel-6,rhel-6-server Arch: x86_64
    String rhelProductId = "69";
    // rpm -q jline-eap6.noarch --requires  => rpmlib
    String jbossPackage = "jline-eap6";
    // Required Tags: rhel-6-server Arches: x86_64, x86
    String jbossRepo = "jb-eap-6-for-rhel-6-server-rpms";
    jbossRepo = String.format("jb-eap-6-for-rhel-%s-server-rpms", clienttasks.redhatReleaseX);
    // JBoss Enterprise Application Platform
    String jbossProductId = "183";
    if (clienttasks.arch.equals("ppc64")) {
        // Required Tags: rhel-6-ibm-power Arches: ppc64
        rhelRepo = "rhel-6-for-power-rpms";
        rhelRepo = String.format("rhel-%s-for-power-rpms", clienttasks.redhatReleaseX);
        // Red Hat Enterprise Linux for Power, big endian	// Tags: rhel-6,rhel-6-ibm-power Arch: ppc64
        rhelProductId = "74";
        // Required Tags: rhel-6-ibm-power Arches: ppc64
        jbossRepo = "jb-eap-6-for-rhel-6-for-power-rpms";
        jbossRepo = String.format("jb-eap-6-for-rhel-%s-for-power-rpms", clienttasks.redhatReleaseX);
        // JBoss Enterprise Application Platform
        jbossProductId = "183";
    }
    // need to disable the beaker repos (actually all repos that contain a productid in the metadata would be best) to prevent the yum product-id plugin from considering it for an update to the installed RHEL product cert
    if (clienttasks.isPackageInstalled(rhelPackage))
        clienttasks.yumRemovePackage(rhelPackage, "--disablerepo=beaker-*");
    // need to disable the beaker repos (actually all repos that contain a productid in the metadata would be best) to prevent the yum product-id plugin from considering it for an update to the installed RHEL product cert
    if (clienttasks.isPackageInstalled(jbossPackage))
        clienttasks.yumRemovePackage(jbossPackage, "--disablerepo=beaker-*");
    // determine the currently installed product certs
    List<ProductCert> currentProductCerts = clienttasks.getCurrentProductCerts();
    ProductCert rhelProductCert = ProductCert.findFirstInstanceWithMatchingFieldFromList("productId", rhelProductId, currentProductCerts);
    if (rhelProductCert == null)
        throw new SkipException("JBoss Enterprise Application Platform is not offered on this variant '" + clienttasks.variant + "' of RHEL.");
    ProductCert jbossProductCert = ProductCert.findFirstInstanceWithMatchingFieldFromList("productId", jbossProductId, currentProductCerts);
    Assert.assertNull(jbossProductCert, "Do not expect the JBoss product to be installed at the beginning of this test.");
    // configure a temporary productCertDir and backup the productid json database file
    log.info("Configuring a temporary product cert directory...");
    // remember the original so it can be restored later
    if (rhsmProductCertDir == null) {
        rhsmProductCertDir = clienttasks.getConfFileParameter(clienttasks.rhsmConfFile, "rhsm", "productCertDir");
        Assert.assertNotNull(rhsmProductCertDir);
    }
    RemoteFileTasks.runCommandAndAssert(client, "mkdir -p " + tmpProductCertDir, Integer.valueOf(0));
    RemoteFileTasks.runCommandAndAssert(client, "rm -f " + tmpProductCertDir + "/*.pem", Integer.valueOf(0));
    // due to /etc/pki/product-default/ certs, this assert will fail when /etc/pki/product/ is empty  RemoteFileTasks.runCommandAndAssert(client,"cp "+rhsmProductCertDir+"/*.pem "+tmpProductCertDir, Integer.valueOf(0));
    RemoteFileTasks.runCommandAndWait(client, "cp " + rhsmProductCertDir + "/*.pem " + tmpProductCertDir, TestRecords.action());
    clienttasks.updateConfFileParameter(clienttasks.rhsmConfFile, "productCertDir", tmpProductCertDir);
    // remember the original so it can be restored later
    if (productIdJsonFile == null) {
        productIdJsonFile = client.runCommandAndWait("cat " + clienttasks.productIdJsonFile).getStdout().replaceAll("\\s*\n\\s*", "");
        Assert.assertTrue(productIdJsonFile != null && !productIdJsonFile.isEmpty());
    }
    // register with autosubscribe for rhel content
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, true, null, null, (String) null, null, null, null, null, null, null, null, null, null);
    List<InstalledProduct> currentlyInstalledProducts = clienttasks.getCurrentlyInstalledProducts();
    InstalledProduct rhelInstalledProduct = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productId", rhelProductId, currentlyInstalledProducts);
    Assert.assertNotNull(rhelInstalledProduct, "Expecting the installed RHEL Server product '" + rhelProductId + "' to be installed.");
    if (!rhelInstalledProduct.status.equals("Subscribed") && CandlepinType.standalone.equals(sm_serverType))
        throw new SkipException("This test is designed for execution against a non-standalone candlepin server where available RHEL subscriptions are expected.");
    Assert.assertEquals(rhelInstalledProduct.status, "Subscribed", "Expecting the RHEL Server product to have been auto-subscribed during registration.");
    // subscribe to JBoss Enterprise Application Platform - Example SKU MW0167254 Red Hat JBoss Enterprise Application Platform with Management, 16 Core Standard, L3 Support Partner)
    String jbossPoolId = null;
    List<SubscriptionPool> jbossSubscriptionPools = clienttasks.getCurrentlyAvailableSubscriptionPools(jbossProductId, sm_serverUrl);
    if (jbossSubscriptionPools.isEmpty() && !CandlepinType.standalone.equals(sm_serverType))
        Assert.fail("Expected to find an available subscription pool for Red Hat JBoss Enterprise Application Platform.");
    if (jbossSubscriptionPools.isEmpty())
        throw new SkipException("Cannot run this test when there is no available subscription for Red Hat JBoss Enterprise Application Platform.");
    // too many asserts... clienttasks.subscribeToSubscriptionPool(jbossSubscriptionPools.get(0));
    clienttasks.subscribe_(null, null, jbossSubscriptionPools.get(0).poolId, null, null, null, null, null, null, null, null, null, null);
    // enable the jb-eap-6-for-rhel-6-server-rpms repo
    // Note: This is necessary. If only enabled during yum install --enablerepo=jb-eap-6-for-rhel-6-server-rpms then the jboss product id will install, but it will also be deleted during the yum install of a rhel package.
    clienttasks.repos(null, null, null, jbossRepo, null, null, null, null, null);
    // yum install jline-eap6 from repo jb-eap-6-for-rhel-6-server-rpms
    // clienttasks.yumInstallPackageFromRepo(jbossPackage, jbossRepo, null);
    clienttasks.yumInstallPackage(jbossPackage);
    // assert that the jboss product id 183 has been newly installed
    currentlyInstalledProducts = clienttasks.getCurrentlyInstalledProducts();
    InstalledProduct jbossInstalledProduct = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productId", jbossProductId, currentlyInstalledProducts);
    Assert.assertNotNull(jbossInstalledProduct, "After installing jboss package '" + jbossPackage + "' from enabled jboss repo '" + jbossRepo + "', the jboss product id '" + jbossProductId + "' is installed.");
    // now for the real test...  install a rhel package with yum --disablerepo and then verify that the jboss product cert remains installed...
    // clienttasks.repos(null, null, null, rhelRepo, null, null, null, null); // is already enabled by default
    clienttasks.yumInstallPackage(rhelPackage, "--disablerepo=" + jbossRepo);
    // verify that the jboss product cert remains installed - Bug 1159163 - RHSM product certificate gets deleted by product-id plugin on running 'yum update --disablerepo
    currentlyInstalledProducts = clienttasks.getCurrentlyInstalledProducts();
    jbossInstalledProduct = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productId", jbossProductId, currentlyInstalledProducts);
    Assert.assertNotNull(jbossInstalledProduct, "After installing rhel package '" + rhelPackage + "' while disabling the jboss repo '" + jbossRepo + "' in-line, the jboss product id '" + jbossProductId + "' remains installed.");
    // remove the only installed jboss package while disabling the rhel repo and verify the jboss product id has been removed, but the rhel product id remains
    // TEMPORARY WORKAROUND
    boolean invokeWorkaroundWhileBugIsOpen = true;
    // Bug 1222627 - deletion of JBOSS product certificate is neglected by product-id plugin on running 'yum remove JBOSS-PKG --disablerepo=RHEL-REPO'
    String bugId = "1222627";
    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) {
        log.warning("While bug '" + bugId + "' is open, we will exclude the --disablerepo=" + rhelRepo + " option from the yum removal of the jboss package.");
        // THIS PASSES THE FOLLOWING Assert.assertNull(jbossInstalledProduct,...
        clienttasks.yumRemovePackage(jbossPackage);
    } else
        // END OF WORKAROUND
        // THIS FAILS THE FOLLOWING Assert.assertNull(jbossInstalledProduct,...  due to Bug 1222627
        clienttasks.yumRemovePackage(jbossPackage, "--disablerepo=" + rhelRepo);
    // verify that the jboss product cert is removed
    currentlyInstalledProducts = clienttasks.getCurrentlyInstalledProducts();
    jbossInstalledProduct = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productId", jbossProductId, currentlyInstalledProducts);
    Assert.assertNull(jbossInstalledProduct, "After removing jboss package '" + jbossPackage + "' while disabling rhel repo '" + rhelRepo + "', the jboss product id '" + jbossProductId + "' is removed (because it is the final remaining package installed from jboss repo '" + jbossRepo + "').");
    // verify that the rhel product cert remains installed
    rhelInstalledProduct = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productId", rhelProductId, currentlyInstalledProducts);
    Assert.assertNotNull(rhelInstalledProduct, "After removing jboss package '" + jbossPackage + "' while disabling rhel repo '" + rhelRepo + "', the rhel product id '" + rhelProductId + "' remains installed (because there are many other rhel packages from rhel repo '" + rhelRepo + "' still installed).");
    // remove the rhel package
    clienttasks.yumRemovePackage(rhelPackage);
    // verify that the jboss product cert remains uninstalled
    currentlyInstalledProducts = clienttasks.getCurrentlyInstalledProducts();
    jbossInstalledProduct = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productId", jbossProductId, currentlyInstalledProducts);
    Assert.assertNull(jbossInstalledProduct, "After removing rhel package '" + rhelPackage + "', the jboss product id '" + jbossProductId + "' from enabled repo '" + jbossRepo + "' remains uninstalled.");
    // verify that the rhel product cert remains installed
    rhelInstalledProduct = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productId", rhelProductId, currentlyInstalledProducts);
    Assert.assertNotNull(rhelInstalledProduct, "After removing rhel package '" + rhelPackage + "' the rhel product id '" + rhelProductId + "' remains installed (because there are many other rhel packages from rhel repo '" + rhelRepo + "' still installed).");
}
Also used : InstalledProduct(rhsm.data.InstalledProduct) ProductCert(rhsm.data.ProductCert) SkipException(org.testng.SkipException) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 19 with InstalledProduct

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

the class ComplianceTests method testSystemCompliantFactWhenAllProductsAreSubscribable.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-21716", "RHEL7-51081" }, 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: verify the system.compliant fact is True when all installed products are subscribable", groups = { "Tier1Tests", "configureProductCertDirForAllProductsSubscribable", "cli.tests", "blockedbyBug-1183175" }, priority = 400, enabled = true)
public // @ImplementsTCMS(id="")
void testSystemCompliantFactWhenAllProductsAreSubscribable() throws JSONException, Exception {
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, Boolean.TRUE, false, null, null, null, null);
    // to avoid unmapped_guests_only pools
    if (Boolean.valueOf(clienttasks.getFactValue("virt.is_guest")))
        clienttasks.mapSystemAsAGuestOfItself();
    Assert.assertFalse(clienttasks.getCurrentlyInstalledProducts().isEmpty(), "Products are currently installed for which the compliance of ALL are covered by currently available subscription pools.");
    Assert.assertEquals(clienttasks.getFactValue(factNameForSystemCompliance), factValueForSystemNonCompliance, "Before attempting to subscribe and become compliant for all the currently installed products, the system should be non-compliant (see value for fact '" + factNameForSystemCompliance + "').");
    clienttasks.subscribeToTheCurrentlyAvailableSubscriptionPoolsCollectively();
    for (InstalledProduct installedProduct : clienttasks.getCurrentlyInstalledProducts()) {
        Assert.assertEquals(installedProduct.status, "Subscribed", "When config rhsm.productcertdir is populated with product certs for which ALL are covered by the currently available subscriptions, then each installed product status should be Subscribed.");
    }
    Assert.assertEquals(clienttasks.getFactValue(factNameForSystemCompliance), factValueForSystemCompliance, "When a system has products installed for which ALL are covered by available subscription pools, the system should become compliant (see value for fact '" + factNameForSystemCompliance + "') after having subscribed to every available subscription pool.");
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.13.10-1")) {
        // commit 13fe8ffd8f876d27079b961fb6675424e65b9a10	Bug 1171602 - subscription-manager status always exits 1
        Assert.assertEquals(clienttasks.status_(null, null, null, null, null).getExitCode(), new Integer(0), "Expected exitCode from a call to status when the system is '" + factValueForSystemCompliance + "'.");
    }
}
Also used : BigInteger(java.math.BigInteger) InstalledProduct(rhsm.data.InstalledProduct) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 20 with InstalledProduct

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

the class ComplianceTests method testComplianceConsidersSystemArch.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-20064", "RHEL7-51070" }, 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 = "when a subscription is attached that does not match the system's arch, assert the installed product status is blocked from going green", groups = { "Tier1Tests", "cli.tests", "VerifyComplianceConsidersSystemArch_Test", "blockedByBug-909467" }, dataProvider = "getSubscriptionPoolProvidingProductIdOnArchData", enabled = true)
public // @ImplementsTCMS(id="")
void testComplianceConsidersSystemArch(Object bugzilla, SubscriptionPool pool, String providingProductId, String poolArch) {
    clienttasks.deleteFactsFileWithOverridingValues(fakeArchFactsFilename);
    clienttasks.unsubscribe(true, (BigInteger) null, null, null, null, null, null);
    // OVERKILL InstalledProduct installedProduct = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productId", providingProductId, clienttasks.getCurrentlyInstalledProducts());
    // OVERKILL Assert.assertEquals(installedProduct.status, "Not Subscribed");
    clienttasks.subscribe(null, null, pool.poolId, null, null, null, null, null, null, null, null, null, null);
    ProductSubscription productSubscription = ProductSubscription.findFirstInstanceWithMatchingFieldFromList("poolId", pool.poolId, clienttasks.getCurrentlyConsumedProductSubscriptions());
    InstalledProduct installedProduct = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productId", providingProductId, clienttasks.getCurrentlyInstalledProducts());
    // expand the arches that the granted entitlement from this subscription pool covers
    // Note: the arch can be a comma separated list of values
    List<String> poolArches = new ArrayList<String>(Arrays.asList(poolArch.trim().split(" *, *")));
    // Note: x86 is a general term to cover all 32-bit intel microprocessors
    if (poolArches.contains("x86")) {
        poolArches.addAll(Arrays.asList("i386", "i486", "i586", "i686"));
    }
    // expand the ALL alias
    if (poolArches.contains("ALL")) {
        poolArches.addAll(Arrays.asList("i386", "i486", "i586", "i686", "x86_64", "ia64", "ppc64", "s390x"));
    }
    // expand the arches that this installed product is valid on
    // Note: the arch can be a comma separated list of values
    List<String> installedProductArches = new ArrayList<String>(Arrays.asList(installedProduct.arch.trim().split(" *, *")));
    // Note: x86 is a general term to cover all 32-bit intel microprocessors
    if (installedProductArches.contains("x86")) {
        installedProductArches.addAll(Arrays.asList("i386", "i486", "i586", "i686"));
    }
    // expand the ALL alias
    if (installedProductArches.contains("ALL")) {
        installedProductArches.addAll(Arrays.asList("i386", "i486", "i586", "i686", "x86_64", "ia64", "ppc64", "s390x"));
    }
    // assert the statusDetails for the consumed entitlement
    if (poolArches.contains(clienttasks.arch)) {
        // empty
        List<String> expectedStatusDetails = new ArrayList<String>();
        if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.13.13-1")) {
            // commit 252ec4520fb6272b00ae379703cd004f558aac63	// bug 1180400: "Status Details" are now populated on CLI
            // Bug 1180400 - Status datails is blank in list consumed output
            expectedStatusDetails = Arrays.asList(new String[] { "Subscription is current" });
        }
        Assert.assertEquals(productSubscription.statusDetails, expectedStatusDetails, "The statusDetails from the consumed product subscription '" + productSubscription.productName + "' poolId='" + productSubscription.poolId + "' should be " + expectedStatusDetails + " when the system's arch '" + clienttasks.arch + "' is covered by the product subscription arches '" + poolArch.trim() + "'.");
    } else {
        if (productSubscription.statusDetails.isEmpty())
            log.warning("Status Details from the consumed product subscription '" + productSubscription.productName + "' poolId='" + productSubscription.poolId + "' appears empty.  Is your candlepin server older than 0.8.6?");
        // Message changed by candlepin commit 43a17952c724374c3fee735642bce52811a1e386 covers -> supports
        Assert.assertEquals(productSubscription.statusDetails.get(0), /*assumes only one detail*/
        String.format("Supports architecture %s but the system is %s.", poolArch.trim(), clienttasks.arch), "The statusDetails from the consumed product subscription '" + productSubscription.productName + "' poolId='" + productSubscription.poolId + "' when the system's arch '" + clienttasks.arch + "' is NOT covered by the product subscription arches '" + poolArch.trim() + "'.");
    }
    // assert the status and statusDetails for the installed product
    if (poolArches.contains(clienttasks.arch)) {
        // if (CandlepinTasks.isPoolRestrictedToUnmappedVirtualSystems(sm_clientUsername,sm_clientPassword, sm_serverUrl, pool.poolId)) {
        // // handle the system status of when entitled by a unmapped_guests_only pool
        // Assert.assertEquals(installedProduct.status, "Partially Subscribed", "When installed product '"+installedProduct.productName+"' is covered by subscription '"+pool.subscriptionName+"' whose arches '"+poolArch+"' cover the system's arch '"+clienttasks.arch+"', then the installed product can achieve full green compliance.  However, since this pool '"+pool.poolId+"' is restricted to unmapped guests only, then the status is yellow.");
        // Assert.assertEquals(installedProduct.statusDetails.get(0), "Guest has not been reported on any host and is using a temporary unmapped guest subscription.", "The statusDetails for installed product '"+installedProduct.productName+"' productId='"+providingProductId+"' when the system's arch '"+clienttasks.arch+"' is covered by the product subscription arches '"+poolArch.trim()+"' and the entitlement was granted from a unmapped guests only pool '"+pool.poolId+"'. (Note: the installed products arches '"+installedProduct.arch+"' are not considered)");
        // Assert.assertEquals(installedProduct.statusDetails.toArray(new String[]{}), new String[]{"Guest has not been reported on any host and is using a temporary unmapped guest subscription."}, "The statusDetails for installed product '"+installedProduct.productName+"' productId='"+providingProductId+"' when the system's arch '"+clienttasks.arch+"' is covered by the product subscription arches '"+poolArch.trim()+"' and the entitlement was granted from a unmapped guests only pool '"+pool.poolId+"'. (Note: the installed products arches '"+installedProduct.arch+"' are not considered)");
        // } else {
        Assert.assertEquals(installedProduct.status, "Subscribed", "When installed product '" + installedProduct.productName + "' is covered by subscription '" + pool.subscriptionName + "' whose arches '" + poolArch + "' cover the system's arch '" + clienttasks.arch + "', then the installed product can achieve full green compliance.");
        Assert.assertTrue(installedProduct.statusDetails.isEmpty(), "The statusDetails for installed product '" + installedProduct.productName + "' productId='" + providingProductId + "' should be empty when the system's arch '" + clienttasks.arch + "' is covered by the product subscription arches '" + poolArch.trim() + "'. (Note: the installed products arches '" + installedProduct.arch + "' are not considered)");
    // }
    } else {
        if (installedProduct.statusDetails.isEmpty())
            log.warning("Status Details appears empty.  Is your candlepin server older than 0.8.6?");
        Assert.assertEquals(installedProduct.status, "Partially Subscribed", "When installed product '" + installedProduct.productName + "' is covered by subscription '" + pool.subscriptionName + "' whose arches '" + poolArch + "' do NOT cover the system's arch '" + clienttasks.arch + "', then the installed product is limited to yellow compliance.");
        // Message changed by candlepin commit 43a17952c724374c3fee735642bce52811a1e386 covers -> supports
        Assert.assertEquals(installedProduct.statusDetails.get(0), /*assumes only one detail*/
        String.format("Supports architecture %s but the system is %s.", poolArch.trim(), clienttasks.arch), "The statusDetails of the installed product '" + installedProduct.productName + "' when the system's arch '" + clienttasks.arch + "' is NOT covered by the product subscription arches '" + poolArch.trim() + "'.");
    }
    // now let's fake the system's arch fact "uname.machine" forcing it to NOT match the providing productSubscription
    if (productSubscription.statusDetails.isEmpty() && !poolArches.contains("ALL")) {
        String fakeArch = "amd64";
        Map<String, String> factsMap = new HashMap<String, String>();
        factsMap.put("uname.machine", fakeArch);
        clienttasks.createFactsFileWithOverridingValues(fakeArchFactsFilename, factsMap);
        clienttasks.facts(null, true, null, null, null, null);
        productSubscription = ProductSubscription.findFirstInstanceWithMatchingFieldFromList("poolId", pool.poolId, clienttasks.getCurrentlyConsumedProductSubscriptions());
        if (productSubscription.statusDetails.isEmpty())
            log.warning("Status Details appears empty.  Is your candlepin server older than 0.8.6?");
        // Message changed by candlepin commit 43a17952c724374c3fee735642bce52811a1e386 covers -> supports
        Assert.assertEquals(productSubscription.statusDetails.get(0), /*assumes only one detail*/
        String.format("Supports architecture %s but the system is %s.", poolArch.trim(), fakeArch), "The statusDetails from the consumed product subscription when the system's arch '" + fakeArch + "' is NOT covered by the product subscription arches '" + poolArch.trim() + "'.");
        installedProduct = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productId", providingProductId, clienttasks.getCurrentlyInstalledProducts());
        if (installedProduct.statusDetails.isEmpty())
            log.warning("Status Details appears empty.  Is your candlepin server older than 0.8.6?");
        // Message changed by candlepin commit 43a17952c724374c3fee735642bce52811a1e386 covers -> supports
        Assert.assertEquals(installedProduct.statusDetails.get(0), /*assumes only one detail*/
        String.format("Supports architecture %s but the system is %s.", poolArch.trim(), fakeArch), "The statusDetails of the installed product '" + installedProduct.productName + "' when the system's arch '" + clienttasks.arch + "' is NOT covered by the product subscription arches '" + poolArch.trim() + "'.");
    }
}
Also used : HashMap(java.util.HashMap) InstalledProduct(rhsm.data.InstalledProduct) ProductSubscription(rhsm.data.ProductSubscription) ArrayList(java.util.ArrayList) 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