Search in sources :

Example 6 with ContentNamespace

use of rhsm.data.ContentNamespace 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 7 with ContentNamespace

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

the class ContentIntegrationTests method getContentNamespaceDataAsListOfLists.

protected List<List<Object>> getContentNamespaceDataAsListOfLists(boolean enabledValue) throws JSONException {
    List<List<Object>> ll = new ArrayList<List<Object>>();
    for (List<Object> row : entitlementCertData) {
        String username = (String) row.get(0);
        String password = (String) row.get(1);
        ConsumerType type = (ConsumerType) row.get(2);
        String productId = (String) row.get(3);
        Integer sockets = (Integer) row.get(4);
        EntitlementCert entitlementCert = (EntitlementCert) row.get(5);
        for (ContentNamespace contentNamespace : entitlementCert.contentNamespaces) {
            if (!contentNamespace.type.equalsIgnoreCase("yum"))
                continue;
            if (contentNamespace.enabled.equals(enabledValue)) {
                // 
                ll.add(Arrays.asList(new Object[] { username, password, type, productId, sockets, contentNamespace }));
            }
        }
    }
    return ll;
}
Also used : ContentNamespace(rhsm.data.ContentNamespace) EntitlementCert(rhsm.data.EntitlementCert) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) JSONObject(org.json.JSONObject) ConsumerType(rhsm.base.ConsumerType)

Example 8 with ContentNamespace

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

the class ContentTests method getEnabledRepoAndSubscriptionPoolDataAsListOfLists.

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

Example 9 with ContentNamespace

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

the class ContentTests method testArchRestrictedContentSetsEntitledAfterSubscribeAllSatisfiesTheSystemArch.

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

Example 10 with ContentNamespace

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

the class ContentTests method testEnableDisableManageReposAndVerifyContentAvailable.

// Test methods ***********************************************************************
@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-25987", "RHEL7-51485" }, 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 Yum plugin: enable/disable", groups = { "Tier2Tests", "FipsTests", "EnableDisableManageReposAndVerifyContentAvailable_Test", "blockedByBug-804227", "blockedByBug-871146", "blockedByBug-905546", "blockedByBug-1017866" }, // dataProvider="getAvailableSubscriptionPoolsData",	// very thorough, but takes too long to execute and rarely finds more bugs
dataProvider = "getRandomSubsetOfAvailableSubscriptionPoolsData", enabled = true)
@ImplementsNitrateTest(caseId = 41696, fromPlan = 2479)
public void testEnableDisableManageReposAndVerifyContentAvailable(SubscriptionPool pool) throws JSONException, Exception {
    // get the currently installed product certs to be used when checking for conditional content tagging
    List<ProductCert> currentProductCerts = clienttasks.getCurrentProductCerts();
    log.info("Before beginning this test, we will stop the rhsmcertd so that it does not interfere with this test and make sure we are not subscribed...");
    clienttasks.stop_rhsmcertd();
    clienttasks.unsubscribe_(true, (BigInteger) null, null, null, null, null, null);
    // Enable rhsm manage_repos configuration
    clienttasks.config(null, null, true, new String[] { "rhsm", "manage_repos", "1" });
    log.info("Subscribe to the pool and start testing that yum repolist reports the expected repo id/labels...");
    File entitlementCertFile = clienttasks.subscribeToSubscriptionPool_(pool);
    Assert.assertNotNull(entitlementCertFile, "Found the entitlement cert file that was granted after subscribing to pool: " + pool);
    EntitlementCert entitlementCert = clienttasks.getEntitlementCertFromEntitlementCertFile(entitlementCertFile);
    // 1. Run a 'yum repolist' and get a list of all of the available repositories corresponding to your entitled products
    // 1. Repolist contains repositories corresponding to your entitled products
    ArrayList<String> repolist = clienttasks.getYumRepolist("enabled");
    for (ContentNamespace contentNamespace : entitlementCert.contentNamespaces) {
        if (!contentNamespace.type.equalsIgnoreCase("yum"))
            continue;
        if (!clienttasks.areAllRequiredTagsInContentNamespaceProvidedByProductCerts(contentNamespace, currentProductCerts)) {
            Assert.assertFalse(repolist.contains(contentNamespace.label), "Yum repolist enabled excludes repo id/label '" + contentNamespace.label + "' after having subscribed to Subscription ProductId '" + entitlementCert.orderNamespace.productId + "' with the manage_repos configuration enabled because not all requiredTags (" + contentNamespace.requiredTags + ") in the contentNamespace are provided by the currently installed productCerts.");
            continue;
        }
        if (contentNamespace.enabled) {
            Assert.assertTrue(repolist.contains(contentNamespace.label), "Yum repolist enabled includes enabled repo id/label '" + contentNamespace.label + "' after having subscribed to Subscription ProductId '" + entitlementCert.orderNamespace.productId + "' with manage_repos configuration enabled.");
        } else {
            Assert.assertFalse(repolist.contains(contentNamespace.label), "Yum repolist enabled excludes disabled repo id/label '" + contentNamespace.label + "' after having subscribed to Subscription ProductId '" + entitlementCert.orderNamespace.productId + "' with manage_repos configuration enabled.");
        }
    }
    repolist = clienttasks.getYumRepolist("disabled");
    for (ContentNamespace contentNamespace : entitlementCert.contentNamespaces) {
        if (!contentNamespace.type.equalsIgnoreCase("yum"))
            continue;
        if (!clienttasks.areAllRequiredTagsInContentNamespaceProvidedByProductCerts(contentNamespace, currentProductCerts)) {
            Assert.assertFalse(repolist.contains(contentNamespace.label), "Yum repolist disabled excludes repo id/label '" + contentNamespace.label + "' after having subscribed to Subscription ProductId '" + entitlementCert.orderNamespace.productId + "' with manage_repos configuration enabled because not all requiredTags (" + contentNamespace.requiredTags + ") in the contentNamespace are provided by the currently installed productCerts.");
            continue;
        }
        if (contentNamespace.enabled) {
            Assert.assertFalse(repolist.contains(contentNamespace.label), "Yum repolist disabled excludes enabled repo id/label '" + contentNamespace.label + "' after having subscribed to Subscription ProductId '" + entitlementCert.orderNamespace.productId + "' with manage_repos configuration enabled.");
        } else {
            Assert.assertTrue(repolist.contains(contentNamespace.label), "Yum repolist disabled includes disabled repo id/label '" + contentNamespace.label + "' after having subscribed to Subscription ProductId '" + entitlementCert.orderNamespace.productId + "' with manage_repos configuration enabled.");
        }
    }
    repolist = clienttasks.getYumRepolist("all");
    for (ContentNamespace contentNamespace : entitlementCert.contentNamespaces) {
        if (!contentNamespace.type.equalsIgnoreCase("yum"))
            continue;
        if (clienttasks.areAllRequiredTagsInContentNamespaceProvidedByProductCerts(contentNamespace, currentProductCerts)) {
            Assert.assertTrue(repolist.contains(contentNamespace.label), "Yum repolist all includes repo id/label '" + contentNamespace.label + "' after having subscribed to Subscription ProductId '" + entitlementCert.orderNamespace.productId + "' with manage_repos configuration enabled.");
        } else {
            Assert.assertFalse(repolist.contains(contentNamespace.label), "Yum repolist all excludes repo id/label '" + contentNamespace.label + "' after having subscribed to Subscription ProductId '" + entitlementCert.orderNamespace.productId + "' with manage_repos configuration enabled because not all requiredTags (" + contentNamespace.requiredTags + ") in the contentNamespace are provided by the currently installed productCerts.");
        }
    }
    log.info("Unsubscribe from the pool and verify that yum repolist no longer reports the expected repo id/labels...");
    clienttasks.unsubscribeFromSerialNumber(entitlementCert.serialNumber);
    repolist = clienttasks.getYumRepolist("all");
    for (ContentNamespace contentNamespace : entitlementCert.contentNamespaces) {
        if (!contentNamespace.type.equalsIgnoreCase("yum"))
            continue;
        Assert.assertFalse(repolist.contains(contentNamespace.label), "Yum repolist all excludes repo id/label '" + contentNamespace.label + "' after having unsubscribed from Subscription ProductId '" + entitlementCert.orderNamespace.productId + "' with manage_repos configuration enabled.");
    }
    // Disable rhsm manage_repos configuration
    log.info("Now we will disable the rhsm manage_repos configuration with enabled=0..");
    clienttasks.config(null, null, true, new String[] { "rhsm", "manage_repos", "0" });
    log.info("Again let's subscribe to the same pool and verify that yum repolist does NOT report any of the entitled repo id/labels since the manage_repos has been disabled...");
    entitlementCertFile = clienttasks.subscribeToSubscriptionPool_(pool);
    Assert.assertNotNull(entitlementCertFile, "Found the entitlement cert file that was granted after subscribing to pool: " + pool);
    entitlementCert = clienttasks.getEntitlementCertFromEntitlementCertFile(entitlementCertFile);
    // 2. Run a 'yum repolist' and get a list of all of the available repositories corresponding to your entitled products
    // 2. Repolist does not contain repositories corresponding to your entitled products
    repolist = clienttasks.getYumRepolist("all");
    for (ContentNamespace contentNamespace : entitlementCert.contentNamespaces) {
        if (!contentNamespace.type.equalsIgnoreCase("yum"))
            continue;
        Assert.assertFalse(repolist.contains(contentNamespace.label), "Yum repolist all excludes repo id/label '" + contentNamespace.label + "' after having subscribed to Subscription ProductId '" + entitlementCert.orderNamespace.productId + "' with the manage_repos configuration disabled.");
    }
    log.info("Now we will enable manage_repos and expect the repo list to be updated");
    clienttasks.config(null, null, true, new String[] { "rhsm", "manage_repos", "1" });
    repolist = clienttasks.getYumRepolist("all");
    for (ContentNamespace contentNamespace : entitlementCert.contentNamespaces) {
        if (!contentNamespace.type.equalsIgnoreCase("yum"))
            continue;
        if (clienttasks.areAllRequiredTagsInContentNamespaceProvidedByProductCerts(contentNamespace, currentProductCerts)) {
            Assert.assertTrue(repolist.contains(contentNamespace.label), "Yum repolist all now includes repo id/label '" + contentNamespace.label + "' after having subscribed to Subscription ProductId '" + entitlementCert.orderNamespace.productId + "' followed by manage_repos configuration enabled.");
        } else {
            Assert.assertFalse(repolist.contains(contentNamespace.label), "Yum repolist all still excludes repo id/label '" + contentNamespace.label + "' after having subscribed to Subscription ProductId '" + entitlementCert.orderNamespace.productId + "' followed by manage_repos configuration enabled because not all requiredTags (" + contentNamespace.requiredTags + ") in the contentNamespace are provided by the currently installed productCerts.");
        }
    }
}
Also used : ContentNamespace(rhsm.data.ContentNamespace) EntitlementCert(rhsm.data.EntitlementCert) ProductCert(rhsm.data.ProductCert) File(java.io.File) 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)

Aggregations

ContentNamespace (rhsm.data.ContentNamespace)26 EntitlementCert (rhsm.data.EntitlementCert)26 ProductCert (rhsm.data.ProductCert)15 ArrayList (java.util.ArrayList)14 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)13 Test (org.testng.annotations.Test)13 File (java.io.File)12 SkipException (org.testng.SkipException)11 JSONObject (org.json.JSONObject)10 List (java.util.List)9 SSHCommandResult (com.redhat.qe.tools.SSHCommandResult)7 SubscriptionPool (rhsm.data.SubscriptionPool)7 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)6 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)4 BigInteger (java.math.BigInteger)4 HashSet (java.util.HashSet)4 YumRepo (rhsm.data.YumRepo)4 HashMap (java.util.HashMap)3 ProductNamespace (rhsm.data.ProductNamespace)3 Calendar (java.util.Calendar)2