Search in sources :

Example 1 with ProductNamespace

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

the class CertificateTests method testEntitlementCertContainsExpectedOIDs.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-20029", "RHEL7-51904" }, 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 = "Make sure the entitlement cert contains all expected OIDs", groups = { "Tier1Tests", "VerifyEntitlementCertContainsExpectedOIDs_Test", "blockedByBug-744259", "blockedByBug-754426", "blockedByBug-962520", "blockedByBug-997970", "blockedByBug-1021581", "blockedByBug-1443693" }, dataProvider = "getAllAvailableSubscriptionPoolsData", enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testEntitlementCertContainsExpectedOIDs(SubscriptionPool pool) throws JSONException, Exception {
    // skip RAM-based subscriptions since they were are not supported on v1 certificates
    if (CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "ram") != null) {
        throw new SkipException("This test is not designed for RAM-based product subscriptions.");
    }
    // skip CORES-based subscriptions since they were are not supported on v1 certificates
    if (CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "cores") != null) {
        throw new SkipException("This test is not designed for CORES-based product subscriptions.");
    }
    // skip physical_only subscriptions when run on a virtual system
    if (CandlepinTasks.isPoolRestrictedToPhysicalSystems(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId) && Boolean.valueOf(clienttasks.getFactValue("virt.is_guest"))) {
        throw new SkipException("This test is not designed for physical_only subscriptions on a virtual machine.");
    }
    // skip virt_only subscriptions when run on a physical system
    if (CandlepinTasks.isPoolRestrictedToVirtualSystems(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId) && !Boolean.valueOf(clienttasks.getFactValue("virt.is_guest"))) {
        throw new SkipException("This test is not designed for virt_only subscriptions on a physical machine.");
    }
    // adjust quantity for instance_multiplier pools
    String instance_multiplier = CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, pool.poolId, "instance_multiplier");
    String quantity = null;
    /*if (clienttasks.isPackageVersion("subscription-manager",">=","1.10.3-1"))*/
    if (pool.suggested != null) {
        if (pool.suggested < 1 && instance_multiplier != null) {
            quantity = instance_multiplier;
        }
    }
    // subscribe to the pool and get the EntitlementCert
    // File entitlementCertFile = clienttasks.subscribeToSubscriptionPool(pool);
    // EntitlementCert entitlementCert = clienttasks.getEntitlementCertFromEntitlementCertFile(entitlementCertFile);
    // ^ replaced with the following to save logging/assertion time
    SSHCommandResult result = clienttasks.subscribe_(null, null, pool.poolId, null, null, quantity, null, null, null, null, null, null, null);
    if (result.getStderr().startsWith("Too many content sets"))
        throw new SkipException("This test is only designed for system.certificate_version=1.0 compatible subscriptions.");
    // if (result.getStdout().startsWith("Pool is restricted to")) throw new SkipException("This test is not designed for this subscription pool: "+pool);	// Pool is restricted to physical systems: '8a9087e3443db08f01443db1847a142a'.
    EntitlementCert entitlementCert = clienttasks.getEntitlementCertCorrespondingToSubscribedPool(pool);
    Assert.assertNotNull(entitlementCert, "Successfully retrieved the entitlement cert granted after subscribing to pool: " + pool);
    // re-scan the entitlement cert using openssl because it better distinguishes between a "" OID value and a null OID value.
    entitlementCert = clienttasks.getEntitlementCertFromEntitlementCertFileUsingOpensslX509(entitlementCert.file);
    // Commented out the following log of rawCertificate to conserve logFile size
    // log.info("Raw entitlement certificate: \n"+entitlementCert.rawCertificate);
    boolean allMandatoryOIDsFound = true;
    // Reference	https://docspace.corp.redhat.com/docs/DOC-30244
    // asserting all expected OIDS in the OrderNamespace
    // 1.3.6.1.4.1.2312.9.4.1 (Name): Red Hat Enterprise Linux Server
    // 1.3.6.1.4.1.2312.9.4.2 (Order Number) : ff8080812c3a2ba8012c3a2cbe63005b
    // 1.3.6.1.4.1.2312.9.4.3 (SKU) : MCT0982
    // 1.3.6.1.4.1.2312.9.4.4 (Subscription Number) : abcd-ef12-1234-5678   <- SHOULD ONLY EXIST IF ORIGINATED FROM A REGTOKEN
    // 1.3.6.1.4.1.2312.9.4.5 (Quantity) : 100
    // 1.3.6.1.4.1.2312.9.4.6 (Entitlement Start Date) : 2010-10-25T04:00:00Z
    // 1.3.6.1.4.1.2312.9.4.7 (Entitlement End Date) : 2011-11-05T00:00:00Z
    // 1.3.6.1.4.1.2312.9.4.8 (Virtualization Limit) : 4						<- ONLY EXISTS WHEN VIRT POOLS ARE TO BE GENERATED
    // 1.3.6.1.4.1.2312.9.4.9 (Socket Limit) : None							<- ONLY EXISTS WHEN THE SUBSCRIPTION IS USED TO SATISFY HARDWARE
    // 1.3.6.1.4.1.2312.9.4.10 (Contract Number): 152341643
    // 1.3.6.1.4.1.2312.9.4.11 (Quantity Used): 4
    // 1.3.6.1.4.1.2312.9.4.12 (Warning Period): 30
    // 1.3.6.1.4.1.2312.9.4.13 (Account Number): 9876543210
    // 1.3.6.1.4.1.2312.9.4.14 (Provides Management): 0 (boolean, 1 for true)<- NEEDINFO
    // 1.3.6.1.4.1.2312.9.4.15 (Support Level): Premium						<- NEEDINFO
    // 1.3.6.1.4.1.2312.9.4.16 (Support Type): Level 3						<- NEEDINFO
    // 1.3.6.1.4.1.2312.9.4.17 (Stacking Id): 23456							<- ONLY EXISTS WHEN SUBSCRIPTION IS STACKABLE
    // 1.3.6.1.4.1.2312.9.4.18 (Virt Only): 1								<- ONLY EXISTS WHEN POOLS ARE INTENTED FOR VIRT MACHINES ONLY
    OrderNamespace orderNamespace = entitlementCert.orderNamespace;
    if (orderNamespace.productName != null) {
        Assert.assertNotNull(orderNamespace.productName, "Mandatory OrderNamespace OID 1.3.6.1.4.1.2312.9.4.1 (Name) is present with value '" + orderNamespace.productName + "'");
    } else {
        log.warning("Mandatory OrderNamespace OID 1.3.6.1.4.1.2312.9.4.1 (Name) is missing");
        allMandatoryOIDsFound = false;
    }
    if (orderNamespace.orderNumber != null) {
        Assert.assertNotNull(orderNamespace.orderNumber, "Mandatory OrderNamespace OID 1.3.6.1.4.1.2312.9.4.2 (Order Number) is present with value '" + orderNamespace.orderNumber + "'");
    } else {
        log.warning("Mandatory OrderNamespace OID 1.3.6.1.4.1.2312.9.4.2 (Order Number) is missing");
        allMandatoryOIDsFound = false;
    }
    if (orderNamespace.productId != null) {
        Assert.assertNotNull(orderNamespace.productId, "Mandatory OrderNamespace OID 1.3.6.1.4.1.2312.9.4.3 (SKU) is present with value '" + orderNamespace.productId + "'");
    } else {
        log.warning("Mandatory OrderNamespace OID 1.3.6.1.4.1.2312.9.4.3 (SKU) is missing");
        allMandatoryOIDsFound = false;
    }
    if (orderNamespace.subscriptionNumber != null) {
        Assert.assertNotNull(orderNamespace.subscriptionNumber, "Optional OrderNamespace OID 1.3.6.1.4.1.2312.9.4.4 (Subscription Number) is present with value '" + orderNamespace.subscriptionNumber + "'");
    } else {
        log.warning("Optional OrderNamespace OID 1.3.6.1.4.1.2312.9.4.4 (Subscription Number) is missing");
    }
    if (orderNamespace.quantity != null) {
        Assert.assertNotNull(orderNamespace.quantity, "Mandatory OrderNamespace OID 1.3.6.1.4.1.2312.9.4.5 (Quantity) is present with value '" + orderNamespace.quantity + "'");
    } else {
        log.warning("Mandatory OrderNamespace OID 1.3.6.1.4.1.2312.9.4.5 (Quantity) is missing");
        allMandatoryOIDsFound = false;
    }
    if (orderNamespace.startDate != null) {
        Assert.assertNotNull(orderNamespace.startDate, "Mandatory OrderNamespace OID 1.3.6.1.4.1.2312.9.4.6 (Entitlement Start Date) is present with value '" + orderNamespace.startDate + "'");
    } else {
        log.warning("Mandatory OrderNamespace OID 1.3.6.1.4.1.2312.9.4.6 (Entitlement Start Date) is missing");
        allMandatoryOIDsFound = false;
    }
    if (orderNamespace.endDate != null) {
        Assert.assertNotNull(orderNamespace.endDate, "Mandatory OrderNamespace OID 1.3.6.1.4.1.2312.9.4.7 (Entitlement End Date) is present with value '" + orderNamespace.endDate + "'");
    } else {
        log.warning("Mandatory OrderNamespace OID 1.3.6.1.4.1.2312.9.4.7 (Entitlement End Date) is missing");
        allMandatoryOIDsFound = false;
    }
    if (orderNamespace.virtualizationLimit != null) {
        Assert.assertNotNull(orderNamespace.virtualizationLimit, "Optional OrderNamespace OID 1.3.6.1.4.1.2312.9.4.8 (Virtualization Limit) is present with value '" + orderNamespace.virtualizationLimit + "'");
    } else {
        log.warning("Optional OrderNamespace OID 1.3.6.1.4.1.2312.9.4.8 (Virtualization Limit) is missing");
    }
    if (orderNamespace.socketLimit != null) {
        Assert.assertNotNull(orderNamespace.socketLimit, "Optional OrderNamespace OID 1.3.6.1.4.1.2312.9.4.9 (Socket Limit) is present with value '" + orderNamespace.socketLimit + "'");
    } else {
        log.warning("Optional OrderNamespace OID 1.3.6.1.4.1.2312.9.4.9 (Socket Limit) is missing");
    }
    // if (orderNamespace.contractNumber!=null)		{Assert.assertNotNull(orderNamespace.contractNumber,		"Mandatory OrderNamespace OID 1.3.6.1.4.1.2312.9.4.10 (Contract Number) is present with value '"+ orderNamespace.contractNumber+"'");}			else {log.warning("Mandatory OrderNamespace OID 1.3.6.1.4.1.2312.9.4.10 (Contract Number) is missing"); allMandatoryOIDsFound = false;}
    if (orderNamespace.contractNumber != null) {
        Assert.assertNotNull(orderNamespace.contractNumber, "Optional OrderNamespace OID 1.3.6.1.4.1.2312.9.4.10 (Contract Number) is present with value '" + orderNamespace.contractNumber + "'");
    } else {
        log.warning("Optional OrderNamespace OID 1.3.6.1.4.1.2312.9.4.10 (Contract Number) is missing.  This subscription was probably granted to a test account.");
    }
    if (orderNamespace.quantityUsed != null) {
        Assert.assertNotNull(orderNamespace.quantityUsed, "Mandatory OrderNamespace OID 1.3.6.1.4.1.2312.9.4.11 (Quantity Used) is present with value '" + orderNamespace.quantityUsed + "'");
    } else {
        log.warning("Mandatory OrderNamespace OID 1.3.6.1.4.1.2312.9.4.11 (Quantity Used) is missing");
        allMandatoryOIDsFound = false;
    }
    if (orderNamespace.warningPeriod != null) {
        Assert.assertNotNull(orderNamespace.warningPeriod, "Mandatory OrderNamespace OID 1.3.6.1.4.1.2312.9.4.12 (Warning Period) is present with value '" + orderNamespace.warningPeriod + "'");
    } else {
        log.warning("Mandatory OrderNamespace OID 1.3.6.1.4.1.2312.9.4.12 (Warning Period) is missing");
        allMandatoryOIDsFound = false;
    }
    // if (orderNamespace.accountNumber!=null)			{Assert.assertNotNull(orderNamespace.accountNumber,			"Mandatory OrderNamespace OID 1.3.6.1.4.1.2312.9.4.13 (Account Number) is present with value '"+ orderNamespace.accountNumber+"'");}			else {log.warning("Mandatory OrderNamespace OID 1.3.6.1.4.1.2312.9.4.13 (Account Number) is missing"); allMandatoryOIDsFound = false;}
    if (orderNamespace.accountNumber != null) {
        Assert.assertNotNull(orderNamespace.accountNumber, "Optional OrderNamespace OID 1.3.6.1.4.1.2312.9.4.13 (Account Number) is present with value '" + orderNamespace.accountNumber + "'");
    } else {
        log.warning("Optional OrderNamespace OID 1.3.6.1.4.1.2312.9.4.13 (Account Number) is missing.  This subscription was probably granted to a test account.");
    }
    if (orderNamespace.providesManagement != null) {
        Assert.assertNotNull(orderNamespace.providesManagement, "Mandatory OrderNamespace OID 1.3.6.1.4.1.2312.9.4.14 (Provides Management) is present with value '" + orderNamespace.providesManagement + "'");
    } else {
        log.warning("Mandatory OrderNamespace OID 1.3.6.1.4.1.2312.9.4.14 (Provides Management) is missing");
        allMandatoryOIDsFound = false;
    }
    if (orderNamespace.supportLevel != null) {
        Assert.assertNotNull(orderNamespace.supportLevel, "Optional OrderNamespace OID 1.3.6.1.4.1.2312.9.4.15 (Support Level) is present with value '" + orderNamespace.supportLevel + "'");
    } else {
        log.warning("Optional OrderNamespace OID 1.3.6.1.4.1.2312.9.4.15 (Support Level) is missing");
    }
    if (orderNamespace.supportType != null) {
        Assert.assertNotNull(orderNamespace.supportType, "Optional OrderNamespace OID 1.3.6.1.4.1.2312.9.4.16 (Support Type) is present with value '" + orderNamespace.supportType + "'");
    } else {
        log.warning("Optional OrderNamespace OID 1.3.6.1.4.1.2312.9.4.16 (Support Type) is missing");
    }
    if (orderNamespace.stackingId != null) {
        Assert.assertNotNull(orderNamespace.stackingId, "Optional OrderNamespace OID 1.3.6.1.4.1.2312.9.4.17 (Stacking Id) is present with value '" + orderNamespace.stackingId + "'");
    } else {
        log.warning("Optional OrderNamespace OID 1.3.6.1.4.1.2312.9.4.17 (Stacking Id) is missing");
    }
    if (orderNamespace.virtOnly != null) {
        Assert.assertNotNull(orderNamespace.virtOnly, "Optional OrderNamespace OID 1.3.6.1.4.1.2312.9.4.18 (Virt Only) is present with value '" + orderNamespace.virtOnly + "'");
    } else {
        log.warning("Optional OrderNamespace OID 1.3.6.1.4.1.2312.9.4.18 (Virt Only) is missing");
    }
    for (ProductNamespace productNamespace : entitlementCert.productNamespaces) {
        // 1.3.6.1.4.1.2312.9.1.<product_hash>.4 (Provides) : String1, String2, String3
        if (productNamespace.name != null) {
            Assert.assertNotNull(productNamespace.name, "Mandatory ProductNamespace OID 1.3.6.1.4.1.2312.9.1." + productNamespace.id + ".1 (Name) is present with value '" + productNamespace.name + "'");
        } else {
            log.warning("Mandatory ProductNamespace OID 1.3.6.1.4.1.2312.9.1." + productNamespace.id + ".1 (Name) is missing");
            allMandatoryOIDsFound = false;
        }
        // if (productNamespace.version!=null)			{Assert.assertNotNull(productNamespace.version,			"Mandatory ProductNamespace OID 1.3.6.1.4.1.2312.9.1."+productNamespace.id+".2 (Version) is present with value '"+ productNamespace.version+"'");}		else {log.warning("Mandatory ProductNamespace OID 1.3.6.1.4.1.2312.9.1."+productNamespace.id+".2 (Version) is missing"); allMandatoryOIDsFound = false;}
        if (productNamespace.version != null) {
            Assert.assertNotNull(productNamespace.version, "Optional ProductNamespace OID 1.3.6.1.4.1.2312.9.1." + productNamespace.id + ".2 (Version) is present with value '" + productNamespace.version + "'");
        } else {
            log.warning("Optional ProductNamespace OID 1.3.6.1.4.1.2312.9.1." + productNamespace.id + ".2 (Version) is missing");
        }
        if (// the TESTDATA imported into a standalone candlepin does not honor the assertion that the product version OID must be blank since rel-eng creates product certs with valid version outside of candlepin
        !sm_serverType.equals(CandlepinType.standalone))
            if (productNamespace.version != null) {
                Assert.assertEquals(productNamespace.version, "", "Optional ProductNamespace OID 1.3.6.1.4.1.2312.9.1." + productNamespace.id + ".2 (Version) can be present but must always be blank.");
            }
        if (productNamespace.arch != null) {
            Assert.assertNotNull(productNamespace.arch, "Mandatory ProductNamespace OID 1.3.6.1.4.1.2312.9.1." + productNamespace.id + ".3 (Architecture) is present with value '" + productNamespace.arch + "'");
        } else {
            log.warning("Mandatory ProductNamespace OID 1.3.6.1.4.1.2312.9.1." + productNamespace.id + ".3 (Architecture) is missing");
            allMandatoryOIDsFound = false;
        }
        if (productNamespace.providedTags != null) {
            Assert.assertNotNull(productNamespace.providedTags, "Optional ProductNamespace OID 1.3.6.1.4.1.2312.9.1." + productNamespace.id + ".4 (Provides) is present with value '" + productNamespace.providedTags + "'");
        } else {
            log.warning("Optional ProductNamespace OID 1.3.6.1.4.1.2312.9.1." + productNamespace.id + ".4 (Provides) is missing");
        }
        if (productNamespace.providedTags != null) {
            Assert.assertEquals(productNamespace.providedTags, "", "Optional ProductNamespace OID 1.3.6.1.4.1.2312.9.1." + productNamespace.id + ".4 (Provides) can be present but must always be blank.");
        }
    }
    for (ContentNamespace contentNamespace : entitlementCert.contentNamespaces) {
        if (!contentNamespace.type.equalsIgnoreCase("yum"))
            continue;
        // 1.3.6.1.4.1.2312.9.2.<content_hash>.1.10 (Required Tags): TAG1,TAG2,TAG3
        if (contentNamespace.name != null) {
            Assert.assertNotNull(contentNamespace.name, "Mandatory ContentNamespace OID 1.3.6.1.4.1.2312.9.2." + contentNamespace.hash + ".1.1 (Name) is present with value '" + contentNamespace.name + "'");
        } else {
            log.warning("Mandatory ContentNamespace OID 1.3.6.1.4.1.2312.9.2." + contentNamespace.hash + ".1.1 (Name) is missing");
            allMandatoryOIDsFound = false;
        }
        if (contentNamespace.label != null) {
            Assert.assertNotNull(contentNamespace.label, "Mandatory ContentNamespace OID 1.3.6.1.4.1.2312.9.2." + contentNamespace.hash + ".1.2 (Label) is present with value '" + contentNamespace.label + "'");
        } else {
            log.warning("Mandatory ContentNamespace OID 1.3.6.1.4.1.2312.9.2." + contentNamespace.hash + ".1.2 (Label) is missing");
            allMandatoryOIDsFound = false;
        }
        // REMOVED						//if (contentNamespace.physicalEntitlement!=null)		{Assert.assertNotNull(contentNamespace.physicalEntitlement,		"Mandatory ContentNamespace OID 1.3.6.1.4.1.2312.9.2."+contentNamespace.hash+".1.3 (Physical Entitlements) is present with value '"+ contentNamespace.physicalEntitlement+"'");}	else {log.warning("Mandatory ContentNamespace OID 1.3.6.1.4.1.2312.9.2."+contentNamespace.hash+".1.3 (Physical Entitlements) is missing"); allMandatoryOIDsFound = false;}
        Assert.assertNull(contentNamespace.physicalEntitlement, "ContentNamespace OID 1.3.6.1.4.1.2312.9.2." + contentNamespace.hash + ".1.3 (Physical Entitlements) has been removed from the generation of entitlements.  Its current value is '" + contentNamespace.physicalEntitlement + "'");
        // REMOVED blockedByBug-754426	//if (contentNamespace.flexGuestEntitlement!=null)	{Assert.assertNotNull(contentNamespace.flexGuestEntitlement,	"Mandatory ContentNamespace OID 1.3.6.1.4.1.2312.9.2."+contentNamespace.hash+".1.4 (Flex Guest Entitlements) is present with value '"+ contentNamespace.flexGuestEntitlement+"'");}	else {log.warning("Mandatory ContentNamespace OID 1.3.6.1.4.1.2312.9.2."+contentNamespace.hash+".1.4 (Flex Guest Entitlements) is missing"); allMandatoryOIDsFound = false;}
        Assert.assertNull(contentNamespace.flexGuestEntitlement, "ContentNamespace OID 1.3.6.1.4.1.2312.9.2." + contentNamespace.hash + ".1.4 (Flex Guest Entitlements) has been removed from the generation of entitlements.  Its current value is '" + contentNamespace.flexGuestEntitlement + "'");
        if (contentNamespace.vendorId != null) {
            Assert.assertNotNull(contentNamespace.vendorId, "Mandatory ContentNamespace OID 1.3.6.1.4.1.2312.9.2." + contentNamespace.hash + ".1.5 (Vendor ID) is present with value '" + contentNamespace.vendorId + "'");
        } else {
            log.warning("Mandatory ContentNamespace OID 1.3.6.1.4.1.2312.9.2." + contentNamespace.hash + ".1.5 (Vendor ID) is missing");
            allMandatoryOIDsFound = false;
        }
        if (contentNamespace.downloadUrl != null) {
            Assert.assertNotNull(contentNamespace.downloadUrl, "Mandatory ContentNamespace OID 1.3.6.1.4.1.2312.9.2." + contentNamespace.hash + ".1.6 (Download URL) is present with value '" + contentNamespace.downloadUrl + "'");
        } else {
            log.warning("Mandatory ContentNamespace OID 1.3.6.1.4.1.2312.9.2." + contentNamespace.hash + ".1.6 (Download URL) is missing");
            allMandatoryOIDsFound = false;
        }
        // if (contentNamespace.gpgKeyUrl!=null)				{Assert.assertNotNull(contentNamespace.gpgKeyUrl,				"Mandatory ContentNamespace OID 1.3.6.1.4.1.2312.9.2."+contentNamespace.hash+".1.7 (GPG Key URL) is present with value '"+ contentNamespace.gpgKeyUrl+"'");}						else {if ("content-emptygpg".equals(contentNamespace.name)||"content-nogpg".equals(contentNamespace.name)) {log.info("Skipping assertion of Mandatory ContentNamespace OID 1.3.6.1.4.1.2312.9.2."+contentNamespace.hash+".1.7 (GPG Key URL) for negative test content '"+contentNamespace.name+"'");} else {log.warning("Mandatory ContentNamespace OID 1.3.6.1.4.1.2312.9.2."+contentNamespace.hash+".1.7 (GPG Key URL) is missing"); allMandatoryOIDsFound = false;}}
        if (contentNamespace.gpgKeyUrl != null) {
            Assert.assertNotNull(contentNamespace.gpgKeyUrl, "Optional ContentNamespace OID 1.3.6.1.4.1.2312.9.2." + contentNamespace.hash + ".1.7 (GPG Key URL) is present with value '" + contentNamespace.gpgKeyUrl + "'");
        } else {
            log.warning("Optional ContentNamespace OID 1.3.6.1.4.1.2312.9.2." + contentNamespace.hash + ".1.7 (GPG Key URL) is missing");
        }
        if (contentNamespace.enabled != null) {
            Assert.assertNotNull(contentNamespace.enabled, "Mandatory ContentNamespace OID 1.3.6.1.4.1.2312.9.2." + contentNamespace.hash + ".1.8 (Enabled) is present with value '" + contentNamespace.enabled + "'");
        } else {
            log.warning("Mandatory ContentNamespace OID 1.3.6.1.4.1.2312.9.2." + contentNamespace.hash + ".1.8 (Enabled) is missing");
            allMandatoryOIDsFound = false;
        }
        if (contentNamespace.metadataExpire != null) {
            Assert.assertNotNull(contentNamespace.metadataExpire, "Optional ContentNamespace OID 1.3.6.1.4.1.2312.9.2." + contentNamespace.hash + ".1.9 (Metadata Expire Seconds) is present with value '" + contentNamespace.metadataExpire + "'");
        } else {
            log.warning("Optional ContentNamespace OID 1.3.6.1.4.1.2312.9.2." + contentNamespace.hash + ".1.9 (Metadata Expire Seconds) is missing");
        }
        if (contentNamespace.requiredTags != null) {
            Assert.assertNotNull(contentNamespace.requiredTags, "Optional ContentNamespace OID 1.3.6.1.4.1.2312.9.2." + contentNamespace.hash + ".1.10 (Required Tags) is present with value '" + contentNamespace.requiredTags + "'");
        } else {
            log.warning("Optional ContentNamespace OID 1.3.6.1.4.1.2312.9.2." + contentNamespace.hash + ".1.10 (Required Tags) is missing");
        }
    }
    if (!allMandatoryOIDsFound)
        Assert.fail("Could not find all mandatory entitlement cert OIDs. (see warnings above)");
}
Also used : ContentNamespace(rhsm.data.ContentNamespace) EntitlementCert(rhsm.data.EntitlementCert) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) SkipException(org.testng.SkipException) OrderNamespace(rhsm.data.OrderNamespace) ProductNamespace(rhsm.data.ProductNamespace) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 2 with ProductNamespace

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

the class ComplianceTests method getServiceLevelToProductIdsMapFromEntitlementCerts.

protected Map<String, Set<String>> getServiceLevelToProductIdsMapFromEntitlementCerts(List<EntitlementCert> entitlementCerts) {
    // {Standard=[37065, 27060, 37069, 37068, 37067, 37070,        37060],
    // None    =[37060],
    // Premium =[37065,        37069, 37068, 37067, 37070,        37060]}
    // 
    // 
    // {27060=[Standard],
    // 37065=[Standard, Premium],
    // 37069=[Standard, Premium],
    // 37068=[Standard, Premium],
    // 37067=[Standard, Premium],
    // 37070=[Standard, Premium],
    // 37060=[Standard, Premium, None]}
    // create maps of serviceLevel-to-productIds and productIds-to-serviceLevel
    Map<String, Set<String>> serviceLevelToProductIdsMap = new HashMap<String, Set<String>>();
    for (EntitlementCert entitlementCert : entitlementCerts) {
        String serviceLevel = entitlementCert.orderNamespace.supportLevel;
        // skip all entitlements without a service level
        if (serviceLevel == null || serviceLevel.equals(""))
            continue;
        // skip all entitlements with an exempt service level
        if (sm_exemptServiceLevelsInUpperCase.contains(serviceLevel.toUpperCase()))
            continue;
        if (!serviceLevelToProductIdsMap.containsKey(serviceLevel))
            serviceLevelToProductIdsMap.put(serviceLevel, new HashSet<String>());
        HashSet<String> productIdSet = (HashSet<String>) serviceLevelToProductIdsMap.get(serviceLevel);
        for (ProductNamespace productNamespace : entitlementCert.productNamespaces) {
            // /*debugTesting*/ if (productNamespace.id.equals("27060")) continue;
            productIdSet.add(productNamespace.id);
        }
    }
    return serviceLevelToProductIdsMap;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) EntitlementCert(rhsm.data.EntitlementCert) HashMap(java.util.HashMap) ProductNamespace(rhsm.data.ProductNamespace) HashSet(java.util.HashSet)

Example 3 with ProductNamespace

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

the class ContentIntegrationTests method testInstallAndRemoveUniquePackageFromContentNamespace.

@Test(description = "ensure a unique available package can be installed/removed from the enabled repo ", groups = { "Tier2Tests" }, dependsOnMethods = { "testRegisterAndSubscribe" }, alwaysRun = true, dependsOnGroups = { "VerifyPackagesAreAvailable" }, dataProvider = "getContentNamespaceData", // disabled in favor of various ContentTests which do not depend on the maintenance of dataProvider="getSubscribeData"
enabled = false)
public // @ImplementsNitrateTest(caseId=) //TODO Find a tcms caseId
void testInstallAndRemoveUniquePackageFromContentNamespace(String username, String password, ConsumerType type, String productId, Integer sockets, ContentNamespace contentNamespace) {
    EntitlementCert entitlementCert = recallTheEntitlementCertGrantedAfterSubscribing(username, password, type, productId, sockets);
    // if (!contentNamespace.label.equals("rhel-6-server-beta-debug-rpms")) throw new SkipException("debugging");
    // register
    registerConsumerWhenNotAlreadyRegistered(username, password, type, sockets);
    // subscribe
    if (!currentlySubscribedProductIds.contains(productId)) {
        // try to save some time by not re-subscribing
        clienttasks.subscribeToProductId(productId);
        currentlySubscribedProductIds.add(productId);
    } else {
        log.info("Saving time by assuming that we are already subscribed to productId='" + productId + "'");
    // clienttasks.list_(null,null,null, Boolean.TRUE, null, null, null, null);
    }
    // make sure that the products required for this repo are installed
    /* not needed anymore since this case is already filtered out by the dataProvider
		if (!clienttasks.areAllRequiredTagsInContentNamespaceProvidedByProductCerts(contentNamespace, currentProductCerts)) {
			throw new SkipException("This contentNamespace has requiredTags '"+contentNamespace.requiredTags+"' that were not found amongst all of the currently installed products.  Therefore we cannot install and remove any package from repo '"+contentNamespace.label+"'.");
		}
		*/
    // make sure there is a positive package count provided by this repo
    /* not needed anymore since this case is already filtered out by the dataProvider
		Integer packageCount = clienttasks.getYumRepolistPackageCount(contentNamespace.label+" --enablerepo="+contentNamespace.label);
		if (packageCount==0) {
			throw new SkipException("Cannot install a package from this repo '"+contentNamespace.label+"' since it is not providing any packages.");
		}
		*/
    // find an available package that is uniquely provided by this repo
    String pkg = clienttasks.findUniqueAvailablePackageFromRepo(contentNamespace.label);
    if (pkg == null) {
        throw new SkipException("Could NOT find a unique available package from this repo '" + contentNamespace.label + "' to attempt an install/remove test.");
    }
    // pkg="cairo-spice-debuginfo.x86_64";
    // install the package and assert that it is successfully installed
    // pkgInstalled = true;
    clienttasks.yumInstallPackageFromRepo(pkg, contentNamespace.label, null);
    // 06/09/2011 TODO Would also like to add an assert that the productid.pem file is also installed.
    /* To do this, we need to also include the List of ProductNamepaces from the entitlement cert as another argument to this test,
		 * Then after the yum install, we need to make sure that at least one of the hash values in the list of product ids is
		 * included in the installed products.  If the list of ProductNamespaces from the entitlement cert is one, then this is
		 * a definitive test.  If the list is greater than one, then we don't know for sure if the product hash(s) that is installed is actually the 
		 * right one.  But we do know that if none of the product hashes are installed, then the repo is missing the product ids and this test should fail.
		 * Also note that we should probably make this assertion after removing the package so that we don't over install all the packages in the repo.
		 */
    // 06/10/2011 Mostly Done in the following blocks of code; jsefler
    // determine if at least one of the productids from the productNamespaces was found installed on the client after running yumInstallPackageFromRepo(...)
    // ideally there is only one ProductNamespace in productNamespaces in which case we can definitively know that the correct product cert is installed
    // when there are more than one ProductNamespace in productNamespaces, then we can't say for sure if the product cert installed actually corresponds to the repo under test
    // however if none of the productNamespaces ends up installed, then the yum product-id plugin is not installing the expected product cert
    int numberOfProductNamespacesInstalled = 0;
    ProductCert productCertInstalled = null;
    for (ProductCert productCert : clienttasks.getCurrentProductCerts()) {
        for (ProductNamespace productNamespace : entitlementCert.productNamespaces) {
            if (productNamespace.id.equals(productCert.productId)) {
                numberOfProductNamespacesInstalled++;
                productCertInstalled = productCert;
            }
        }
    }
    // FIXME check if the package was obsolete and its replacement was installed instead
    // if (!obsoletedByPkg.isEmpty()) pkg = obsoletedByPkg;
    // now remove the package
    clienttasks.yumRemovePackage(pkg);
    // Note: I am making this assertion after the yumRemovePackage call to avoid leaving packages installed in case this assert fails.
    if (numberOfProductNamespacesInstalled > 1) {
        log.info("Found product certs installed that match the ProductNamespaces from the entitlement cert that granted the right to install package '" + pkg + "' from repo '" + contentNamespace.label + "'.");
    } else if (numberOfProductNamespacesInstalled == 1) {
        Assert.assertTrue(true, "An installed product cert (productName='" + productCertInstalled.productName + "' productId='" + productCertInstalled.productId + "') corresponding to installed package '" + pkg + "' from repo '" + contentNamespace.label + "' was found after it was installed.");
    } else {
        Assert.fail("After installing package '" + pkg + "' from repo '" + contentNamespace.label + "', there was no product cert installed.  Expected one of the following product certs to get installed via the yum product-id plugin: " + entitlementCert.productNamespaces);
    }
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) ProductCert(rhsm.data.ProductCert) SkipException(org.testng.SkipException) ProductNamespace(rhsm.data.ProductNamespace) Test(org.testng.annotations.Test)

Example 4 with ProductNamespace

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

the class ListTests method testListConsumedMatchesProductsListedInTheEntitlementCerts.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-27117", "RHEL7-51343" }, 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: list of consumed entitlements should display the provided product marketing names", groups = { "Tier2Tests", "blockedByBug-878986", "blockedByBug-976924" }, dataProvider = "getAllEntitlementCertsData", // this new test implementation was implemented due to change in list of consumed product subscriptions (from many to one) - see bug 806986
enabled = true)
@ImplementsNitrateTest(caseId = 48092, fromPlan = 2481)
public void testListConsumedMatchesProductsListedInTheEntitlementCerts(EntitlementCert entitlementCert) {
    // find the consumed product subscription corresponding to this entitlement cert and assert there is only one found
    List<ProductSubscription> allConsumedProductSubscriptions = clienttasks.getCurrentlyConsumedProductSubscriptions();
    List<ProductSubscription> productSubscriptions = ProductSubscription.findAllInstancesWithMatchingFieldFromList("serialNumber", entitlementCert.serialNumber, allConsumedProductSubscriptions);
    Assert.assertEquals(productSubscriptions.size(), 1, "Found a single consumed product subscription with a matching serialNumber from this entitlementCert: " + entitlementCert);
    ProductSubscription productSubscription = productSubscriptions.get(0);
    List<String> providedProductNames = new ArrayList<String>();
    for (ProductNamespace productNamespace : entitlementCert.productNamespaces) providedProductNames.add(productNamespace.name);
    // TEMPORARY WORKAROUND FOR BUG
    if (entitlementCert.orderNamespace.supportLevel == null || entitlementCert.orderNamespace.supportType == null) {
        String bugId = "842170";
        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("While bug " + bugId + " is open, skipping assertion of consumed product subscription in list for entitlement's with a null support level/type.");
        }
    }
    // when the entitlement OID value parsed was null, it should effectively be reported as ""  (Reference related bugs 842170 847354)
    if (entitlementCert.orderNamespace.supportLevel == null)
        entitlementCert.orderNamespace.supportLevel = "";
    if (entitlementCert.orderNamespace.supportType == null)
        entitlementCert.orderNamespace.supportType = "";
    // Subscription Name:    	Awesome OS Server Bundled (2 Sockets, Standard Support)
    // Provides:             	Clustering Bits
    // Awesome OS Server Bits
    // Shared Storage Bits
    // Management Bits
    // Large File Support Bits
    // Load Balancing Bits
    // SKU:                  	awesomeos-server-2-socket-std
    // Contract:             	36
    // Account:              	12331131231
    // Serial Number:        	6683485045354827351
    // Active:               	True
    // Quantity Used:        	1
    // Service Level:        	Standard
    // Service Type:         	L1-L3
    // Starts:               	07/20/2012
    // Ends:                 	07/20/2013
    Calendar now = Calendar.getInstance();
    // TEMPORARY WORKAROUND FOR BUG
    boolean invokeWorkaroundWhileBugIsOpen = true;
    try {
        String bugId = "883486";
        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("The workaround while this bug is open is to compensate the expected entitlement start/end dates for daylight savings.");
        // adjust the expected entitlement dates for daylight savings time (changed by https://github.com/candlepin/subscription-manager/pull/385)
        // now.get(Calendar.DST_OFFSET) will equal 0 in the winter StandardTime; will equal 1000*60*60 in the summer DaylightSavingsTime (when the local time zone observes DST)
        entitlementCert.orderNamespace.startDate.add(Calendar.MILLISECOND, now.get(Calendar.DST_OFFSET) - entitlementCert.orderNamespace.startDate.get(Calendar.DST_OFFSET));
        entitlementCert.orderNamespace.endDate.add(Calendar.MILLISECOND, now.get(Calendar.DST_OFFSET) - entitlementCert.orderNamespace.endDate.get(Calendar.DST_OFFSET));
    }
    // END OF WORKAROUND
    // assert all of the product subscription's fields match the entitlement cert
    Assert.assertEquals(productSubscription.productName, entitlementCert.orderNamespace.productName, "productName from ProductSubscription in list --consumed matches productName from OrderNamespace in this entitlementCert");
    Assert.assertTrue(productSubscription.provides.containsAll(providedProductNames) && providedProductNames.containsAll(productSubscription.provides), "The consumed product subscription provides all the expected products " + providedProductNames + " from the provided ProductNamespaces in the entitlementCert.");
    Assert.assertEquals(productSubscription.productId, entitlementCert.orderNamespace.productId, "productId from ProductSubscription in list --consumed matches productId from OrderNamespace in this entitlementCert");
    Assert.assertEquals(productSubscription.contractNumber, entitlementCert.orderNamespace.contractNumber, "contractNumber from ProductSubscription in list --consumed matches contractNumber from OrderNamespace in this entitlementCert");
    Assert.assertEquals(productSubscription.accountNumber, entitlementCert.orderNamespace.accountNumber, "accountNumber from ProductSubscription in list --consumed matches accountNumber from OrderNamespace in this entitlementCert");
    if (now.after(entitlementCert.orderNamespace.startDate) && now.before(entitlementCert.orderNamespace.endDate)) {
        Assert.assertTrue(productSubscription.isActive, "isActive is True when the current time (" + EntitlementCert.formatDateString(now) + ") is between the start/end dates in this entitlementCert");
    } else {
        Assert.assertFalse(productSubscription.isActive, "isActive is False when the current time (" + EntitlementCert.formatDateString(now) + ") is NOT between the start/end dates in this entitlementCert");
    }
    Assert.assertEquals(productSubscription.quantityUsed.toString(), entitlementCert.orderNamespace.quantityUsed, "quantityUsed from ProductSubscription in list --consumed matches quantityUsed from OrderNamespace in this entitlementCert");
    Assert.assertEquals(productSubscription.serviceLevel, entitlementCert.orderNamespace.supportLevel, "serviceLevel from ProductSubscription in list --consumed matches supportLevel from OrderNamespace in this entitlementCert");
    Assert.assertEquals(productSubscription.serviceType, entitlementCert.orderNamespace.supportType, "serviceType from ProductSubscription in list --consumed matches serviceType from OrderNamespace in this entitlementCert");
    Assert.assertEquals(ProductSubscription.formatDateString(productSubscription.startDate), ProductSubscription.formatDateString(entitlementCert.orderNamespace.startDate), "startDate from ProductSubscription in list --consumed matches startDate from OrderNamespace (" + OrderNamespace.formatDateString(entitlementCert.orderNamespace.startDate) + ") after conversion from GMT in EntitlementCert to local time.");
    Assert.assertEquals(ProductSubscription.formatDateString(productSubscription.endDate), ProductSubscription.formatDateString(entitlementCert.orderNamespace.endDate), "endDate from ProductSubscription in list --consumed matches endDate from OrderNamespace (" + OrderNamespace.formatDateString(entitlementCert.orderNamespace.endDate) + ") after conversion from GMT in EntitlementCert to local time.");
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) ProductSubscription(rhsm.data.ProductSubscription) ArrayList(java.util.ArrayList) SkipException(org.testng.SkipException) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) ProductNamespace(rhsm.data.ProductNamespace) 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 5 with ProductNamespace

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

the class InteroperabilityTests method testYumPluginMessageCase0.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-36531", "RHEL7-51304" }, 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 = "When registered to RHSM (and all subscriptions have expired), the subscription-manager yum plugin should inform that: The subscription for following product(s) has expired: etc.", groups = { "Tier2Tests", "YumPluginMessageCase_Tests", "blockedByBug-818383", "blockedByBug-832119", "blockedByBug-871146", "blockedbyBug-901612", "blockedbyBug-1017354", "blockedByBug-1087620", "blockedByBug-1058380", "blockedByBug-1122772" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testYumPluginMessageCase0() throws JSONException, Exception {
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (List<String>) null, null, null, null, true, false, null, null, null, null);
    // import an expired certificate
    File expiredCertFile = new File(System.getProperty("automation.dir", null) + "/certs/Expiredcert.pem");
    RemoteFileTasks.putFile(client, expiredCertFile.getPath(), "/tmp/Expiredcert.pem", "0644");
    if (clienttasks.isPackageVersion("subscription-manager", "<", "1.17.10-1")) {
        // subscription-manager commit b93e59482563b9e3e972a928233bef7ebf885ea1	// Bug 1251516: Disable import when registered
        clienttasks.importCertificate("/tmp/Expiredcert.pem");
    } else {
        // after fix for bug 1251516, I can no longer use importCertificate while registered; instead we'll simply copy the expired cert to /etc/pki/entitlement ...
        client.runCommandAndWait("cp /tmp/Expiredcert.pem " + clienttasks.getConfFileParameter(clienttasks.rhsmConfFile, "rhsm", "entitlementCertDir"));
    // ... to avoid this usability error:
    // 201608261038:58.987 - FINE: ssh root@jsefler-rhel7.usersys.redhat.com subscription-manager import --certificate=/tmp/Expiredcert.pem
    // 201608261038:59.747 - FINE: Stdout:
    // 201608261038:59.747 - FINE: Stderr: Error: You may not import certificates into a system that is registered to a subscription management service.
    }
    EntitlementCert expiredEntitlementCert = clienttasks.getEntitlementCertFromEntitlementCertFile(new File("/tmp/Expiredcert.pem"));
    // assert the interoperable registration message (without any current subscriptions)
    SSHCommandResult result = client.runCommandAndWait("yum repolist --disableplugin=rhnplugin --enableplugin=subscription-manager");
    String expectedMsgRHSM = "This system is registered to Red Hat Subscription Management, but is not receiving updates. You can use subscription-manager to assign subscriptions.";
    // subscription-manager commit 5e4b42e1c99472085a44118dd231e7ddd161937a	// https://github.com/candlepin/subscription-manager/pull/1512
    if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.18.4-1"))
        expectedMsgRHSM = "This system is registered with an entitlement server, but is not receiving updates. You can use subscription-manager to assign subscriptions.";
    if (// Bug 901612 - Subscription-manager-s yum plugin prints warning to stdout instead of stderr.	// Bug 901612 was reverted by Bug 1017354
    clienttasks.isPackageVersion("subscription-manager", "<", "1.12.2-1"))
        // Bug 901612 - Subscription-manager-s yum plugin prints warning to stdout instead of stderr.	// Bug 901612 was reverted by Bug 1017354
        Assert.assertTrue(result.getStdout().contains(expectedMsgRHSM), "When registered to RHSM (and all subscriptions have expired), the subscription-manager yum plugin stdout should inform that:\n" + expectedMsgRHSM + "\n");
    else if (// Bug 1058380 was reverted by Bug 1122772
    clienttasks.isPackageVersion("subscription-manager", ">=", "1.12.11-1"))
        // Bug 1058380 was reverted by Bug 1122772
        Assert.assertTrue(result.getStdout().contains(expectedMsgRHSM), "When registered to RHSM (and all subscriptions have expired), the subscription-manager yum plugin stdout should inform that:\n" + expectedMsgRHSM + "\n");
    else
        Assert.assertTrue(!(result.getStdout() + result.getStderr()).contains(expectedMsgRHSM), "When registered to RHSM (and all subscriptions have expired), the subscription-manager yum plugin stdout should NO LONGER inform that:\n" + expectedMsgRHSM + "\nBugzilla https://bugzilla.redhat.com/show_bug.cgi?id=1058380 was used to remove this usability messaging implemented for https://bugzilla.redhat.com/show_bug.cgi?id=818383");
    // assert the expired subscriptions message
    expectedMsgRHSM = "*** WARNING ***\nThe subscription for following product(s) has expired:";
    for (ProductNamespace productNamespace : expiredEntitlementCert.productNamespaces) expectedMsgRHSM += "\n" + "  - " + productNamespace.name;
    expectedMsgRHSM += "\n" + "You no longer have access to the repositories that provide these products.  It is important that you apply an active subscription in order to resume access to security and other critical updates. If you don't have other active subscriptions, you can renew the expired subscription.";
    // Bug 901612 - Subscription-manager-s yum plugin prints warning to stdout instead of stderr.	// Bug 901612 was reverted by Bug 1017354
    Assert.assertTrue(result.getStdout().contains(expectedMsgRHSM), "When registered to RHSM (and all subscriptions have expired), the subscription-manager yum plugin stdout should inform that:\n" + expectedMsgRHSM + "\n");
    // assert the interoperable registration message (with current subscriptions)
    // clienttasks.subscribeToSubscriptionPool(clienttasks.getCurrentlyAvailableSubscriptionPools().get(0));	// will fail with java.lang.AssertionError: The list of consumed products is entitled 'Consumed Subscriptions'. expected:<true> but was:<false>
    clienttasks.subscribe(null, null, clienttasks.getCurrentlyAvailableSubscriptionPools().get(0).poolId, null, null, null, null, null, null, null, null, null, null);
    if (clienttasks.isPackageVersion("subscription-manager", "<", "1.17.10-1")) {
        // subscription-manager commit b93e59482563b9e3e972a928233bef7ebf885ea1	// Bug 1251516: Disable import when registered
        clienttasks.importCertificate("/tmp/Expiredcert.pem");
    } else {
        // after fix for bug 1251516, I can no longer use importCertificate while registered; instead we'll simply copy the expired cert to /etc/pki/entitlement ...
        client.runCommandAndWait("cp /tmp/Expiredcert.pem " + clienttasks.getConfFileParameter(clienttasks.rhsmConfFile, "rhsm", "entitlementCertDir"));
    // ... to avoid this usability error:
    // 201608261038:58.987 - FINE: ssh root@jsefler-rhel7.usersys.redhat.com subscription-manager import --certificate=/tmp/Expiredcert.pem
    // 201608261038:59.747 - FINE: Stdout:
    // 201608261038:59.747 - FINE: Stderr: Error: You may not import certificates into a system that is registered to a subscription management service.
    }
    result = client.runCommandAndWait("yum repolist --disableplugin=rhnplugin --enableplugin=subscription-manager");
    expectedMsgRHSM = "This system is receiving updates from Red Hat Subscription Management.";
    // NOT TRUE ANYMORE Assert.assertTrue(result.getStdout().contains(expectedMsgRHSM), "When registered to RHSM (and some subscriptions have expired), the subscription-manager yum plugin stdout should inform that:\n"+expectedMsgRHSM+"\n");	// Bug 901612 - Subscription-manager-s yum plugin prints warning to stdout instead of stderr.	// Bug 901612 was reverted by Bug 1017354
    // commit 39eadae14eead4bb79978e52d38da2b3e85cba57 1017354: remove msg printed to stderr via yum
    Assert.assertTrue(!(result.getStdout() + result.getStderr()).contains(expectedMsgRHSM), "When registered to RHSM, the subscription-manager yum plugin NO LONGER informs that:\n" + expectedMsgRHSM + "\nFor justification, see https://bugzilla.redhat.com/show_bug.cgi?id=1017354#c12");
    // assert the expired subscriptions message again
    expectedMsgRHSM = "*** WARNING ***\nThe subscription for following product(s) has expired:";
    for (ProductNamespace productNamespace : expiredEntitlementCert.productNamespaces) expectedMsgRHSM += "\n" + "  - " + productNamespace.name;
    expectedMsgRHSM += "\n" + "You no longer have access to the repositories that provide these products.  It is important that you apply an active subscription in order to resume access to security and other critical updates. If you don't have other active subscriptions, you can renew the expired subscription.";
    // Bug 901612 - Subscription-manager-s yum plugin prints warning to stdout instead of stderr.	// Bug 901612 was reverted by Bug 1017354
    Assert.assertTrue(result.getStdout().contains(expectedMsgRHSM), "When registered to RHSM (and some subscriptions have expired), the subscription-manager yum plugin stdout should inform that:\n" + expectedMsgRHSM + "\n");
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) File(java.io.File) ProductNamespace(rhsm.data.ProductNamespace) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Aggregations

ProductNamespace (rhsm.data.ProductNamespace)14 EntitlementCert (rhsm.data.EntitlementCert)11 Test (org.testng.annotations.Test)9 SkipException (org.testng.SkipException)8 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)7 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)7 ArrayList (java.util.ArrayList)7 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)6 ProductSubscription (rhsm.data.ProductSubscription)5 SSHCommandResult (com.redhat.qe.tools.SSHCommandResult)4 Calendar (java.util.Calendar)4 ProductCert (rhsm.data.ProductCert)4 File (java.io.File)3 GregorianCalendar (java.util.GregorianCalendar)3 HashSet (java.util.HashSet)3 JSONObject (org.json.JSONObject)3 ContentNamespace (rhsm.data.ContentNamespace)3 InstalledProduct (rhsm.data.InstalledProduct)3 BigInteger (java.math.BigInteger)2 HashMap (java.util.HashMap)2