Search in sources :

Example 1 with ManifestSubscription

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

the class ManifestTests method verifyRCTCatManifestWithOptions.

protected void verifyRCTCatManifestWithOptions(File manifestFile, List<String> options) throws Exception {
    // flatten the list of options into a single string for the runCommand
    String optionsAsString = " ";
    if (options != null)
        for (String option : options) optionsAsString += option + " ";
    // execute and assert rct cat-manifest MANIFEST_FILE
    SSHCommandResult catManifestResult = RemoteFileTasks.runCommandAndAssert(client, "rct cat-manifest" + optionsAsString + manifestFile, 0);
    // parse the output from catManifestResult into a Manifest object
    List<Manifest> catManifests = Manifest.parse(catManifestResult.getStdout());
    Assert.assertEquals(catManifests.size(), 1, "Parsed one manifest from '" + manifestFile + "'.");
    Manifest catManifest = catManifests.get(0);
    // create EntitlementCert objects representing the source for all of the entitlements provided by this manifest
    if (manifestFileContentMap.get(manifestFile) == null)
        throw new SkipException("Cannot execute this test until manifest file '" + manifestFile + "' has been successfully dumped.");
    client.runCommandAndWaitWithoutLogging("find " + manifestFileContentMap.get(manifestFile).get(0).getParent() + "/export/entitlement_certificates" + " -regex \"/.+/[0-9]+.pem\" -exec rct cat-cert {} \\;");
    String rawCertificates = client.getStdout();
    List<EntitlementCert> entitlementCerts = EntitlementCert.parse(rawCertificates);
    if (entitlementCerts.isEmpty())
        Assert.fail("Manifest file '" + manifestFile + "' does not provide any entitlements.");
    // loop through the manifest's entitlement certs and assert as much as possible...
    // [root@jsefler-7 test-manifests]# rct cat-manifest manifest_SYS0395_RH0197181.zip
    // 
    // +-------------------------------------------+
    // Manifest
    // +-------------------------------------------+
    String bannerRegex = "\\+-+\\+\\n\\s*Manifest\\s*\\n\\+-+\\+";
    Assert.assertTrue(Pattern.compile(".*" + bannerRegex + ".*", Pattern.DOTALL).matcher(catManifestResult.getStdout()).matches(), "stdout from rct cat-manifest contains a banner matching regex '" + bannerRegex + "'.");
    if (catManifest.server == null) {
        log.warning("Skipping assertion of non-null General and Consumer for what appears to be a manifest from an older candlepin server");
    } else {
        // 
        // General:
        // Server: access.stage.redhat.com/management/distributors/
        // Server Version: 0.7.13.10-1
        // Date Created: 2013-01-21T21:24:16.193+0000
        // Creator: qa@redhat.com
        Assert.assertNotNull(catManifest.server, "General Server value is not null.");
        Assert.assertNotNull(catManifest.serverVersion, "General Server Version value is not null.");
        Assert.assertNotNull(catManifest.dateCreated, "General Date Created value is not null.");
        Assert.assertNotNull(catManifest.creator, "General Creator value is not null.");
        // 
        // Consumer:
        // Name: jsefler
        // UUID: b2837b9a-d2d9-4b41-acd9-34bdcf72af66
        // Type: sam
        Assert.assertNotNull(catManifest.consumerName, "Consumer Name value is not null.");
        Assert.assertNotNull(catManifest.consumerUUID, "Consumer UUID value is not null.");
        String consumerUUIDRegex = "[a-f,0-9,\\-]{36}";
        Assert.assertTrue(Pattern.compile(consumerUUIDRegex).matcher(catManifest.consumerUUID).matches(), "Consumer UUID format matches the expected regex '" + consumerUUIDRegex + "'.");
        Assert.assertNotNull(catManifest.consumerType, "Consumer Type value is not null.");
        // TODO learn why there is a type distinction
        Assert.assertTrue(catManifest.consumerType.equals("sam") || catManifest.consumerType.equals("cloudforms") || catManifest.consumerType.equals("satellite"), "Actual Consumer Type value '" + catManifest.consumerType + "' equals \"sam\" or \"cloudforms' or \"satellite\".");
        // Content Access Mode: entitlement
        if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.19.6-1")) {
            Assert.assertNotNull(catManifest.consumerContentAccessMode, "Consumer Content Access Mode value is not null.");
            Assert.assertTrue(catManifest.consumerContentAccessMode.equals("entitlement") || catManifest.consumerContentAccessMode.equals("org_environment"), "Actual Consumer Content Access Mode value '" + catManifest.consumerContentAccessMode + "' equals \"entitlement\" or \"org_environment\".");
            if (SubscriptionManagerTasks.isVersion(catManifest.serverVersion, "<", "2.0.22-1")) {
                // candlepin commit 18c20d0a1530910d5ca45fecb59f8f7db5e9a04f Golden Ticket
                Assert.assertEquals(catManifest.consumerContentAccessMode, "entitlement", "Since this manifest was created by candlepin version prior to \"2.0.22-1\", the Consumer's Content Access Mode value must be the default value.");
            }
        }
    }
    // /content/beta/rhel/power/5/$releasever/$basearch/highavailability/source/SRPMS
    for (EntitlementCert entitlementCert : entitlementCerts) {
        ManifestSubscription manifestSubscription = ManifestSubscription.findFirstInstanceWithMatchingFieldFromList("certificateFile", entitlementCert.file.toString().replace(manifestFileContentMap.get(manifestFile).get(0).getParent() + File.separator, ""), catManifest.subscriptions);
        if (manifestSubscription == null)
            Assert.fail("Could not find the ManifestSubscription corresponding to Entitlement '" + entitlementCert.file + "'.");
        Assert.assertEquals(manifestSubscription.name, entitlementCert.orderNamespace.productName, "Subscription Name value comes from entitlementCert.orderNamespace.productName");
        Assert.assertEquals(manifestSubscription.quantity, entitlementCert.orderNamespace.quantityUsed, "Subscription Quantity value comes from entitlementCert.orderNamespace.quantityUsed (ASSUMING NO OTHER UPSTREAM CONSUMERS)");
        // TODO assert Created:
        Assert.assertEquals(manifestSubscription.startDate, entitlementCert.validityNotBefore, "Subscription Start Date comes from entitlementCert.validityNotBefore");
        Assert.assertEquals(manifestSubscription.endDate, entitlementCert.validityNotAfter, "Subscription End Date comes from entitlementCert.validityNotAfter");
        Assert.assertEquals(manifestSubscription.supportLevel, entitlementCert.orderNamespace.supportLevel, "Subscription Service Level value comes from entitlementCert.orderNamespace.supportLevel");
        Assert.assertEquals(manifestSubscription.supportType, entitlementCert.orderNamespace.supportType, "Subscription Service Type value comes from entitlementCert.orderNamespace.supportType");
        List<String> actualArchitectures = new ArrayList<String>();
        if (manifestSubscription.architectures != null)
            actualArchitectures.addAll(Arrays.asList(manifestSubscription.architectures.split("\\s*,\\s*")));
        List<String> expectedArchitectures = new ArrayList<String>();
        for (ProductNamespace productNamespace : entitlementCert.productNamespaces) if (productNamespace.arch != null)
            expectedArchitectures.addAll(Arrays.asList(productNamespace.arch.split("\\s*,\\s*")));
        // BAD ASSERT SEE https://bugzilla.redhat.com/show_bug.cgi?id=914799#c3 Assert.assertTrue(actualArchitectures.containsAll(expectedArchitectures)&&expectedArchitectures.containsAll(actualArchitectures), "Subscription Architectures contains the union of providedProduct arches: "+expectedArchitectures);
        Assert.assertEquals(manifestSubscription.productId, entitlementCert.orderNamespace.productId, "Subscription SKU value comes from entitlementCert.orderNamespace.productId");
        Assert.assertEquals(manifestSubscription.contract, entitlementCert.orderNamespace.contractNumber, "Subscription Contract value comes from entitlementCert.orderNamespace.contractNumber");
        Assert.assertEquals(manifestSubscription.subscriptionId, entitlementCert.orderNamespace.orderNumber, "Subscription Order Number value comes from entitlementCert.orderNamespace.orderNumber");
        // TODO assert Entitlement File in json format
        Assert.assertTrue(entitlementCert.file.toString().endsWith(manifestSubscription.certificateFile), "Subscription Certificate File exists");
        Assert.assertEquals(manifestSubscription.certificateVersion, entitlementCert.version, "Subscription Certificate Version value comes from entitlementCert.version");
        List<String> actualProvidedProducts = manifestSubscription.providedProducts;
        List<String> actualDerivedProducts = manifestSubscription.derivedProducts;
        if (false) {
            // This assertion was valid prior to the invention of data center skus that provide no products but do provide derived products to be added to a sub-pool
            List<String> expectedProvidedProducts = new ArrayList<String>();
            for (ProductNamespace productNamespace : entitlementCert.productNamespaces) expectedProvidedProducts.add(String.format("%s: %s", productNamespace.id, productNamespace.name));
            Assert.assertTrue(actualProvidedProducts.containsAll(expectedProvidedProducts) && expectedProvidedProducts.containsAll(actualProvidedProducts), "Manifest Subscription '" + manifestSubscription.name + "' Provided Products " + actualProvidedProducts + " contains all entitlementCert.productNamespaces=>\"id: name\": " + expectedProvidedProducts);
        } else {
            // Instead, let's assume the following assertion is correct... TODO confirm with dev
            // Note: this assertion can only be tested against manifests with data center skus using subscription-manager-1.18.6-1 and higher
            List<String> expectedProducts = new ArrayList<String>();
            for (ProductNamespace productNamespace : entitlementCert.productNamespaces) expectedProducts.add(String.format("%s: %s", productNamespace.id, productNamespace.name));
            if (clienttasks.isPackageVersion("subscription-manager", ">=", "1.18.6-1")) {
                // subscription-manager commit 23c149907852767e51e7ddea8edf506697827203  Bug 1388207 - [RFE] rct cat-manifest command should show derived products
                List<String> actualProvidedAndDerivedProducts = new ArrayList<String>();
                for (String product : actualProvidedProducts) if (!actualProvidedAndDerivedProducts.contains(product))
                    actualProvidedAndDerivedProducts.add(product);
                for (String product : actualDerivedProducts) if (!actualProvidedAndDerivedProducts.contains(product))
                    actualProvidedAndDerivedProducts.add(product);
                Assert.assertTrue(actualProvidedAndDerivedProducts.containsAll(expectedProducts) && expectedProducts.containsAll(actualProvidedAndDerivedProducts), "The union of all Provided Products " + actualProvidedProducts + " and Derived Products " + actualDerivedProducts + " from manifest Subscription '" + manifestSubscription.name + "' contains all entitlementCert.productNamespaces=>\"id: name\": " + expectedProducts);
            } else {
                log.info("Cannot assert that the union of all provided and derived products from manifest Subscription '" + manifestSubscription.name + "' are represented in this entitlementCert.productNamespaces=>\"id: name\": " + expectedProducts + " because RFE Bug 1388207 is not present in this version of subscription-manager.");
                log.info("We can only assert that the provided products from manifest Subscription '" + manifestSubscription.name + "' are a subset of this entitlementCert.productNamespaces=>\"id: name\": " + expectedProducts + " because RFE Bug 1388207 is not present in this version of subscription-manager to account for derived products.");
                Assert.assertTrue(expectedProducts.containsAll(actualProvidedProducts), "The Provided Products " + actualProvidedProducts + " from manifest Subscription '" + manifestSubscription.name + "' are a subset of all entitlementCert.productNamespaces=>\"id: name\": " + expectedProducts);
            }
        }
        List<String> actualContentSets = new ArrayList<String>();
        if (manifestSubscription.contentSets != null)
            actualContentSets.addAll(manifestSubscription.contentSets);
        List<String> expectedContentSets = new ArrayList<String>();
        for (ContentNamespace contentNamespace : entitlementCert.contentNamespaces) expectedContentSets.add(contentNamespace.downloadUrl);
        if (options != null && options.contains("--no-content")) {
            Assert.assertNull(manifestSubscription.contentSets, "The cat-manifest report does not include any Subscription Content Sets when the '--no-content' option is specified.");
        } else {
            Assert.assertTrue(actualContentSets.containsAll(expectedContentSets) && expectedContentSets.containsAll(actualContentSets), "Subscription Content Sets contains all entitlementCert.contentNamespaces=>downloadUrl: (too long to print)");
        }
    }
}
Also used : ContentNamespace(rhsm.data.ContentNamespace) EntitlementCert(rhsm.data.EntitlementCert) ManifestSubscription(rhsm.data.ManifestSubscription) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) ArrayList(java.util.ArrayList) SkipException(org.testng.SkipException) Manifest(rhsm.data.Manifest) ProductNamespace(rhsm.data.ProductNamespace)

Aggregations

SSHCommandResult (com.redhat.qe.tools.SSHCommandResult)1 ArrayList (java.util.ArrayList)1 SkipException (org.testng.SkipException)1 ContentNamespace (rhsm.data.ContentNamespace)1 EntitlementCert (rhsm.data.EntitlementCert)1 Manifest (rhsm.data.Manifest)1 ManifestSubscription (rhsm.data.ManifestSubscription)1 ProductNamespace (rhsm.data.ProductNamespace)1