Search in sources :

Example 11 with ContentNamespace

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

the class ContentTests method getPackageFromEnabledRepoAndSubscriptionPoolDataAsListOfLists.

protected List<List<Object>> getPackageFromEnabledRepoAndSubscriptionPoolDataAsListOfLists() 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()) {
        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;
                // find an available package that is uniquely provided by repo
                String pkg = clienttasks.findUniqueAvailablePackageFromRepo(repoLabel);
                if (pkg == null) {
                    log.warning("Could NOT find a unique available package from repo '" + repoLabel + "' after subscribing to SubscriptionPool: " + pool);
                }
                // String availableGroup, String installedGroup, String repoLabel, SubscriptionPool pool, String quantity
                ll.add(Arrays.asList(new Object[] { pkg, repoLabel, pool, quantity }));
            }
        }
        clienttasks.unsubscribeFromSerialNumber(clienttasks.getSerialNumberFromEntitlementCertFile(entitlementCertFile));
        // minimize the number of dataProvided rows (useful during automated testcase development)
        if (Boolean.valueOf(getProperty("sm.debug.dataProviders.minimize", "false")))
            break;
    }
    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 12 with ContentNamespace

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

the class ContentTests method testGpgCheckValuesInYumRepos.

@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-20082", "RHEL7-51098" }, level = DefTypes.Level.COMPONENT, component = "subscription-manager", testtype = @TestType(testtype = DefTypes.TestTypes.FUNCTIONAL, subtype1 = DefTypes.Subtypes.RELIABILITY, subtype2 = DefTypes.Subtypes.EMPTY), posneg = PosNeg.POSITIVE, importance = DefTypes.Importance.HIGH, automation = DefTypes.Automation.AUTOMATED, tags = "Tier1")
@Test(description = "subscription-manager content flag : gpgcheck value in redhat.repo should be disabled when gpg_url is empty or null", groups = { "Tier1Tests", "blockedByBug-741293", "blockedByBug-805690", "blockedByBug-962520" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testGpgCheckValuesInYumRepos() throws JSONException, Exception {
    // [root@jsefler-r63-server ~]# cat /etc/yum.repos.d/redhat.repo
    // #
    // # Certificate-Based Repositories
    // # Managed by (rhsm) subscription-manager
    // #
    // # If this file is empty and this system is subscribed consider
    // # a "yum repolist" to refresh available repos
    // #
    // 
    // [content-label]
    // name = content
    // baseurl = https://cdn.redhat.com/foo/path
    // enabled = 1
    // gpgcheck = 1
    // gpgkey = https://cdn.redhat.com/foo/path/gpg/
    // sslverify = 1
    // sslcacert = /etc/rhsm/ca/redhat-uep.pem
    // sslclientkey = /etc/pki/entitlement/5488047145460852736-key.pem
    // sslclientcert = /etc/pki/entitlement/5488047145460852736.pem
    // metadata_expire = 0
    // 1.3.6.1.4.1.2312.9.2 (Content Namespace)
    // 1.3.6.1.4.1.2312.9.2.<content_hash> (Red Hat Enterprise Linux (core server))
    // 1.3.6.1.4.1.2312.9.2.<content_hash>.1 (Yum repo type))
    // 1.3.6.1.4.1.2312.9.2.<content_hash>.1.1 (Name) : Red Hat Enterprise Linux (core server)
    // 1.3.6.1.4.1.2312.9.2.<content_hash>.1.2 (Label) : rhel-server
    // 1.3.6.1.4.1.2312.9.2.<content_hash>.1.5 (Vendor ID): %Red_Hat_Id% or %Red_Hat_Label%
    // 1.3.6.1.4.1.2312.9.2.<content_hash>.1.6 (Download URL): content/rhel-server/$releasever/$basearch
    // 1.3.6.1.4.1.2312.9.2.<content_hash>.1.7 (GPG Key URL): file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
    // 1.3.6.1.4.1.2312.9.2.<content_hash>.1.8 (Enabled): 1
    // 1.3.6.1.4.1.2312.9.2.<content_hash>.1.9 (Metadata Expire Seconds): 604800
    // 1.3.6.1.4.1.2312.9.2.<content_hash>.1.10 (Required Tags): TAG1,TAG2,TAG3
    List<ProductCert> currentProductCerts = clienttasks.getCurrentProductCerts();
    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);
    if (clienttasks.subscribeToTheCurrentlyAvailableSubscriptionPoolsCollectively().size() <= 0)
        throw new SkipException("No available subscriptions were found.  Therefore we cannot perform this test.");
    List<EntitlementCert> entitlementCerts = clienttasks.getCurrentEntitlementCerts();
    // or maybe we should skip when nothing is consumed
    Assert.assertTrue(!entitlementCerts.isEmpty(), "After subscribing to all available subscription pools, there must be some entitlements.");
    ArrayList<String> repolist = clienttasks.getYumRepolist("enabled");
    List<YumRepo> yumRepos = clienttasks.getCurrentlySubscribedYumRepos();
    for (EntitlementCert entitlementCert : entitlementCerts) {
        for (ContentNamespace contentNamespace : entitlementCert.contentNamespaces) {
            if (!contentNamespace.type.equalsIgnoreCase("yum"))
                continue;
            if (contentNamespace.enabled) {
                if (!clienttasks.areAllRequiredTagsInContentNamespaceProvidedByProductCerts(contentNamespace, currentProductCerts))
                    continue;
                YumRepo yumRepo = YumRepo.findFirstInstanceWithMatchingFieldFromList("id", /*label*/
                contentNamespace.label, yumRepos);
                Assert.assertNotNull(yumRepo, "Found the yum repo within '" + clienttasks.redhatRepoFile + "' corresponding to the entitled content namespace label '" + contentNamespace.label + "'.");
                // case 1: contentNamespace.gpgKeyUrl==null
                if (contentNamespace.gpgKeyUrl == null) {
                    Assert.assertFalse(yumRepo.gpgcheck, "gpgcheck is False for Yum repo '" + yumRepo.id + "' when corresponding entitlement contentNamespace has a null gpgKeyUrl: contentNamespace: " + contentNamespace);
                    Assert.assertNull(yumRepo.gpgkey, "gpgkey is not set for Yum repo '" + yumRepo.id + "' when corresponding entitlement contentNamespace has a null gpgKeyUrl: contentNamespace: " + contentNamespace);
                // case 2: contentNamespace.gpgKeyUrl==""
                } else if (contentNamespace.gpgKeyUrl.equals("")) {
                    Assert.assertFalse(yumRepo.gpgcheck, "gpgcheck is False for Yum repo '" + yumRepo.id + "' when corresponding entitlement contentNamespace has an empty gpgKeyUrl: contentNamespace: " + contentNamespace);
                    Assert.assertNull(yumRepo.gpgkey, "gpgkey is not set for Yum repo '" + yumRepo.id + "' when corresponding entitlement contentNamespace has an empty gpgKeyUrl: contentNamespace: " + contentNamespace);
                // case 3: contentNamespace.gpgKeyUrl.startsWith("http")
                } else if (contentNamespace.gpgKeyUrl.startsWith("http:") || contentNamespace.gpgKeyUrl.startsWith("https:")) {
                    Assert.assertTrue(yumRepo.gpgcheck, "gpgcheck is True for Yum repo '" + yumRepo.id + "' when corresponding entitlement contentNamespace has a non-null/empty gpgKeyUrl: contentNamespace: " + contentNamespace);
                    Assert.assertEquals(yumRepo.gpgkey, contentNamespace.gpgKeyUrl, "gpgkey is set for Yum repo '" + yumRepo.id + "' when corresponding entitlement contentNamespace has a non-null/empty gpgKeyUrl: contentNamespace: " + contentNamespace);
                // case 4: contentNamespace.gpgKeyUrl.startsWith("file:")
                } else if (contentNamespace.gpgKeyUrl.startsWith("file:")) {
                    Assert.assertTrue(yumRepo.gpgcheck, "gpgcheck is True for Yum repo '" + yumRepo.id + "' when corresponding entitlement contentNamespace has a non-null/empty gpgKeyUrl: contentNamespace: " + contentNamespace);
                    Assert.assertEquals(yumRepo.gpgkey, contentNamespace.gpgKeyUrl, "gpgkey is set for Yum repo '" + yumRepo.id + "' when corresponding entitlement contentNamespace has a non-null/empty gpgKeyUrl: contentNamespace: " + contentNamespace);
                // case 5: contentNamespace.gpgKeyUrl is a relative path
                } else {
                    Assert.assertTrue(yumRepo.gpgcheck, "gpgcheck is True for Yum repo '" + yumRepo.id + "' when corresponding entitlement contentNamespace has a non-null/empty gpgKeyUrl: contentNamespace: " + contentNamespace);
                    Assert.assertEquals(yumRepo.gpgkey, clienttasks.baseurl + contentNamespace.gpgKeyUrl, "gpgkey is set for Yum repo '" + yumRepo.id + "' when corresponding entitlement contentNamespace has a non-null/empty gpgKeyUrl: contentNamespace: " + contentNamespace);
                }
            }
        }
    }
    if (yumRepos.isEmpty())
        throw new SkipException("Since no Red Hat repos were found in '" + clienttasks.redhatRepoFile + "', there are no gpgcheck values to verify.");
}
Also used : ContentNamespace(rhsm.data.ContentNamespace) EntitlementCert(rhsm.data.EntitlementCert) ProductCert(rhsm.data.ProductCert) SkipException(org.testng.SkipException) YumRepo(rhsm.data.YumRepo) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 13 with ContentNamespace

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

the class DockerTests method verifyEntitlementsProvidingContainerImageContentAreCopiedToRegistryHostnames.

protected boolean verifyEntitlementsProvidingContainerImageContentAreCopiedToRegistryHostnames(List<EntitlementCert> entitlementCerts, List<String> registryHostnames) {
    // get a list of the currently installed product Certs
    List<ProductCert> currentProductCerts = clienttasks.getCurrentProductCerts();
    // verify that the entitlements which provide containerimage content are copied to registry_hostnames...
    // [root@jsefler-os7 ~]# ls /etc/docker/certs.d/registry.access.redhat.com/
    // 5109020365795659852.cert  5109020365795659852.key
    // [root@jsefler-os7 ~]# ls /etc/docker/certs.d/cdn.redhat.com
    // 5109020365795659852.cert  5109020365795659852.key  redhat-uep.crt
    boolean foundContainerImageContent = false;
    for (EntitlementCert entitlementCert : entitlementCerts) {
        List<ContentNamespace> containerImageContentNamespaces = ContentNamespace.findAllInstancesWithCaseInsensitiveMatchingFieldFromList("type", "containerimage", entitlementCert.contentNamespaces);
        if (containerImageContentNamespaces.isEmpty()) {
            // assert that the entitlementCert was NOT copied to the directory of registry_hostnames because it does not contain content of type 'containerimage' (case insensitive).
            for (String registryHostname : registryHostnames) {
                File certFile = getRegistryHostnameCertFileFromEntitlementCert(registryHostname, entitlementCert);
                File keyFile = getRegistryHostnameCertKeyFileFromEntitlementCert(registryHostname, entitlementCert);
                Assert.assertTrue(!RemoteFileTasks.testExists(client, certFile.getPath()), "Entitlement cert '" + entitlementCert.file + "' '" + entitlementCert.orderNamespace.productName + "' was NOT copied to '" + certFile + "' because it does not contain content of type 'containerimage' (case insensitive).");
                Assert.assertTrue(!RemoteFileTasks.testExists(client, keyFile.getPath()), "Corresponding entitlement key '" + clienttasks.getEntitlementCertKeyFileFromEntitlementCert(entitlementCert) + "' was NOT copied to '" + keyFile + "' because it does not contain content of type 'containerimage' (case insensitive).");
            }
        } else {
            foundContainerImageContent = true;
            // assert that the entitlementCert was copied to the directory of registry_hostnames (but only if all of its required_tags are installed)
            for (String registryHostname : registryHostnames) {
                File certFile = getRegistryHostnameCertFileFromEntitlementCert(registryHostname, entitlementCert);
                File keyFile = getRegistryHostnameCertKeyFileFromEntitlementCert(registryHostname, entitlementCert);
                // determine if this entitlement contains at least one container image with required tags that are provided by the installed product certs
                boolean entitlementContainsAtLeastOneContainerImageContentNamespaceWithRequiredTagsThatAreProvidedByInstalledProducts = false;
                for (ContentNamespace containerImageContentNamespace : containerImageContentNamespaces) {
                    if (clienttasks.areAllRequiredTagsInContentNamespaceProvidedByProductCerts(containerImageContentNamespace, currentProductCerts)) {
                        entitlementContainsAtLeastOneContainerImageContentNamespaceWithRequiredTagsThatAreProvidedByInstalledProducts = true;
                        log.info("containerImageContentNamespace '" + containerImageContentNamespace.name + "' has requiredTags '" + containerImageContentNamespace.requiredTags + "' that ARE provided by the currently installed products.");
                    } else {
                        log.info("containerImageContentNamespace '" + containerImageContentNamespace.name + "' has requiredTags '" + containerImageContentNamespace.requiredTags + "' that are NOT provided by the currently installed products.");
                    }
                }
                if (entitlementContainsAtLeastOneContainerImageContentNamespaceWithRequiredTagsThatAreProvidedByInstalledProducts) {
                    Assert.assertTrue(RemoteFileTasks.testExists(client, certFile.getPath()), "Entitlement cert '" + entitlementCert.file + "' '" + entitlementCert.orderNamespace.productName + "' providing a 'containerimage' (case insensitive) was copied to '" + certFile + "' because at least one contentNamespace of type containerimage from the entitlement has required_tags that are provided by the currently installed product certs.  Entitled content of type containeriamge: " + containerImageContentNamespaces);
                    Assert.assertTrue(RemoteFileTasks.testExists(client, keyFile.getPath()), "Corresponding entitlement key '" + clienttasks.getEntitlementCertKeyFileFromEntitlementCert(entitlementCert) + "' providing a 'containerimage' (case insensitive) was copied to '" + keyFile + "' because at least one contentNamespace of type containerimage from the entitlement has required_tags that are provided by the currently installed product certs.  Entitled content of type containeriamge: " + containerImageContentNamespaces);
                    // also assert that the ca cert corresponding to registry hostname is copied to the directory as a ca.crt, but only if it appears to be a redhat.com CDN
                    verifyCaCertInEtcDockerCertsRegistryHostnameDir(registryHostname);
                } else {
                    Assert.assertTrue(!RemoteFileTasks.testExists(client, certFile.getPath()), "Entitlement cert '" + entitlementCert.file + "' '" + entitlementCert.orderNamespace.productName + "' providing a 'containerimage' (case insensitive) was NOT copied to '" + certFile + "' because no contentNamespace of type containerimage from the entitlement has required_tags that are provided by the currently installed product certs.  Entitled content of type containeriamge: " + containerImageContentNamespaces);
                    Assert.assertTrue(!RemoteFileTasks.testExists(client, keyFile.getPath()), "Corresponding entitlement key '" + clienttasks.getEntitlementCertKeyFileFromEntitlementCert(entitlementCert) + "' providing a 'containerimage' (case insensitive) was NOT copied to '" + keyFile + "' because no contentNamespace of type containerimage from the entitlement has required_tags that are provided by the currently installed product certs.  Entitled content of type containeriamge: " + containerImageContentNamespaces);
                }
            }
        }
    }
    return foundContainerImageContent;
}
Also used : ContentNamespace(rhsm.data.ContentNamespace) EntitlementCert(rhsm.data.EntitlementCert) ProductCert(rhsm.data.ProductCert) File(java.io.File)

Example 14 with ContentNamespace

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

the class DockerTests method testYumRepolistOnRunningDockerImageConsumedFromHostEntitlements.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL7-55539" }, 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 a running container has yum repolist access to appropriate content from the host's entitlement", groups = { "Tier1Tests" }, dependsOnMethods = { "testYumRepolistIsEmptyOnRunningDockerImageWhenHostIsUnregistered" }, dataProvider = "getDockerImageData", enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testYumRepolistOnRunningDockerImageConsumedFromHostEntitlements(Object bugzilla, String dockerImage) {
    // register the host and autosubscribe
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, true, null, null, (String) null, null, null, null, true, false, null, null, null, null);
    // get a list of the entitled yum repos on the host
    List<String> enabledYumReposOnHost = clienttasks.getYumRepolist("enabled");
    List<EntitlementCert> entitlementCertsOnHost = clienttasks.getCurrentEntitlementCerts();
    Assert.assertTrue(!entitlementCertsOnHost.isEmpty(), "When the host has registered with autosubscribe, we expect to have been granted at least one entitlement.");
    // determine what products are installed on the running docker image
    // [root@bkr-hv03-guest07 ~]# docker run --rm registry.access.redhat.com/rhel7:latest find /etc/pki/product* -name *.pem
    // /etc/pki/product/69.pem
    // /etc/pki/product-default/69.pem
    // SSHCommandResult lsResultOnRunningDockerImage = client.runCommandAndWait("docker run --rm "+dockerImage+" find /etc/pki/product* -name *.pem");	// assumes the productCertDir config within the image is /etc/pki/product
    // assumes the productCertDir config within the image is /etc/pki/product	//  "find /etc/pki/product* -regex .+\.pem"  IS MORE RELIABLE THAN "find /etc/pki/product* -name *.pem"
    SSHCommandResult lsResultOnRunningDockerImage = client.runCommandAndWait("docker run --rm " + dockerImage + " find /etc/pki/product* -regex .+\\.pem");
    List<ProductCert> productCertsOnRunningDockerImage = new ArrayList<ProductCert>();
    for (String productCertFileOnRunningDockerImage : lsResultOnRunningDockerImage.getStdout().trim().split("\n")) {
        SSHCommandResult rctCatCertResultOnRunningDockerImage = RemoteFileTasks.runCommandAndAssert(client, "docker run --rm " + dockerImage + " rct cat-cert " + productCertFileOnRunningDockerImage, 0);
        // 201407071250:40.755 - FINE: ssh root@jsefler-7.usersys.redhat.com docker run --rm docker-registry.usersys.redhat.com/brew/rhel7:latest rct cat-cert /etc/pki/product/69.pem
        // 201407071250:43.954 - FINE: Stdout:
        // 
        // +-------------------------------------------+
        // Product Certificate
        // +-------------------------------------------+
        // 
        // Certificate:
        // Path: /etc/pki/product/69.pem
        // Version: 1.0
        // Serial: 12750047592154746969
        // Start Date: 2014-01-28 18:37:08+00:00
        // End Date: 2034-01-23 18:37:08+00:00
        // 
        // Subject:
        // CN: Red Hat Product ID [eb3b72ca-acb1-4092-9e67-f2915f6444f4]
        // 
        // Issuer:
        // C: US
        // CN: Red Hat Entitlement Product Authority
        // O: Red Hat, Inc.
        // OU: Red Hat Network
        // ST: North Carolina
        // emailAddress: ca-support@redhat.com
        // 
        // Product:
        // ID: 69
        // Name: Red Hat Enterprise Linux Server
        // Version: 7.0
        // Arch: x86_64
        // Tags: rhel-7,rhel-7-server
        // Brand Type:
        // Brand Name:
        productCertsOnRunningDockerImage.add(ProductCert.parse(rctCatCertResultOnRunningDockerImage.getStdout()).get(0));
    }
    // get the product tags installed on the running docker image
    Set<String> providedTagsOnRunningDockerImage = new HashSet<String>();
    for (ProductCert productCertOnRunningDockerImage : productCertsOnRunningDockerImage) {
        if (productCertOnRunningDockerImage.productNamespace.providedTags != null) {
            for (String providedTag : productCertOnRunningDockerImage.productNamespace.providedTags.split("\\s*,\\s*")) {
                providedTagsOnRunningDockerImage.add(providedTag);
            }
        }
    }
    // get the arch on the running docker image
    String archOnRunningDockerImage = RemoteFileTasks.runCommandAndAssert(client, "docker run --rm " + dockerImage + " uname --machine", 0).getStdout().trim();
    // get the yum repolist of enabled repos on the running docker image
    SSHCommandResult enabledYumRepolistResultOnRunningDockerImage = RemoteFileTasks.runCommandAndAssert(client, "docker run --rm " + dockerImage + " yum repolist enabled", 0, "repolist:", null);
    List<String> enabledYumReposOnRunningDockerImage = clienttasks.getYumRepolistFromSSHCommandResult(enabledYumRepolistResultOnRunningDockerImage);
    // TEMPORARY WORKAROUND FOR BUG
    if (clienttasks.redhatReleaseX.equals("7") && clienttasks.variant.equals("Workstation") && enabledYumReposOnRunningDockerImage.isEmpty()) {
        boolean invokeWorkaroundWhileBugIsOpen = true;
        // Bug 1551129 - entitlements from a RHEL7.5 Workstation host fail to flow through to a docker container with docker from latest-EXTRAS-7-RHEL-7
        String bugId = "1551129";
        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("Skipping this test on variant '" + clienttasks.variant + "' while docker bug '" + bugId + "' is open");
        }
    }
    // assert that only the appropriate entitled content sets appear in the yum repolist on the running docker image
    for (EntitlementCert entitlementCertOnHost : entitlementCertsOnHost) {
        for (ContentNamespace contentNamespaceOnHost : entitlementCertOnHost.contentNamespaces) {
            // get the content namespace requiredTags
            Set<String> contentNamespaceRequiredTags = new HashSet<String>();
            if (contentNamespaceOnHost.requiredTags != null) {
                for (String requiredTag : contentNamespaceOnHost.requiredTags.split("\\s*,\\s*")) {
                    if (requiredTag.isEmpty())
                        continue;
                    contentNamespaceRequiredTags.add(requiredTag);
                }
            }
            // get the content namespace arches
            Set<String> contentNamespaceArches = new HashSet<String>();
            if (contentNamespaceOnHost.arches != null) {
                for (String arch : contentNamespaceOnHost.arches.split("\\s*,\\s*")) {
                    if (arch.isEmpty())
                        continue;
                    contentNamespaceArches.add(arch);
                }
            }
            // Note: x86 is a general arch to cover all 32-bit intel microprocessors
            if (contentNamespaceArches.contains("x86")) {
                contentNamespaceArches.addAll(Arrays.asList("i386", "i486", "i586", "i686"));
            }
            // when the content namespace is not of type "yum", it will not appear in either the yum repolist of the host or the running docker image
            if (!contentNamespaceOnHost.type.equals("yum")) {
                Assert.assertTrue(!enabledYumReposOnHost.contains(contentNamespaceOnHost.label), "Entitled content namespace '" + contentNamespaceOnHost.label + "' of type '" + contentNamespaceOnHost.type + "' should never appear on the yum repolist of the host.");
                Assert.assertTrue(!enabledYumReposOnRunningDockerImage.contains(contentNamespaceOnHost.label), "Entitled content namespace '" + contentNamespaceOnHost.label + "' of type '" + contentNamespaceOnHost.type + "' should never appear on the yum repolist of the running docker container.");
                // go to the next content namespace
                continue;
            }
            // when the content namespace is not enabled, it will not appear in either the yum repolist of the host or the running docker image
            if (!contentNamespaceOnHost.enabled) {
                Assert.assertTrue(!enabledYumReposOnHost.contains(contentNamespaceOnHost.label), "Entitled content namespace '" + contentNamespaceOnHost.label + "' is disabled and should NOT appear on the yum repolist of the host because it is disabled by default.");
                Assert.assertTrue(!enabledYumReposOnRunningDockerImage.contains(contentNamespaceOnHost.label), "Entitled content namespace '" + contentNamespaceOnHost.label + "' is disabled and should NOT appear on the yum repolist of the running docker container because it is disabled by default.");
                // go to the next content namespace
                continue;
            }
            // when the content namespace is enabled, it's appearance on the yum repolist of the running docker image depends on the installed product certs on the image.
            if ((contentNamespaceArches.isEmpty() || contentNamespaceArches.contains(archOnRunningDockerImage)) && (contentNamespaceRequiredTags.isEmpty() || providedTagsOnRunningDockerImage.containsAll(contentNamespaceRequiredTags))) {
                Assert.assertTrue(enabledYumReposOnRunningDockerImage.contains(contentNamespaceOnHost.label), "Entitled content namespace '" + contentNamespaceOnHost.label + "' on the host should be enabled in the running docker container because both the docker container arch '" + archOnRunningDockerImage + "' is among the supported content set arches " + contentNamespaceArches + " and the docker container providedTags " + providedTagsOnRunningDockerImage + " provides all the content set required tags " + contentNamespaceRequiredTags + ".");
            } else {
                Assert.assertTrue(!enabledYumReposOnRunningDockerImage.contains(contentNamespaceOnHost.label), "Entitled content namespace '" + contentNamespaceOnHost.label + "' on the host should NOT be enabled in the running docker container because either the docker container arch '" + archOnRunningDockerImage + "' is not among the supported content set arches " + contentNamespaceArches + " or the docker container providedTags " + providedTagsOnRunningDockerImage + " does not provide all the content set required tags " + contentNamespaceRequiredTags + ".");
            }
        }
    }
    // let's test installing a simple package (zsh)
    boolean installedPackage = false;
    if (enabledYumReposOnRunningDockerImage.contains("rhel-6-server-rpms") || enabledYumReposOnRunningDockerImage.contains("rhel-7-server-rpms")) {
        RemoteFileTasks.runCommandAndAssert(client, "docker run --rm " + dockerImage + " yum -y install zsh", 0, "Complete!", null);
        // [root@jsefler-7 ~]# docker run --rm docker-registry.usersys.redhat.com/brew/rhel7:latest yum -y install zsh
        // Loaded plugins: product-id, subscription-manager
        // Resolving Dependencies
        // --> Running transaction check
        // ---> Package zsh.x86_64 0:5.0.2-7.el7 will be installed
        // --> Finished Dependency Resolution
        // 
        // Dependencies Resolved
        // 
        // ================================================================================
        // Package    Arch          Version               Repository                 Size
        // ================================================================================
        // Installing:
        // zsh        x86_64        5.0.2-7.el7           rhel-7-server-rpms        2.4 M
        // 
        // Transaction Summary
        // ================================================================================
        // Install  1 Package
        // 
        // Total download size: 2.4 M
        // Installed size: 5.6 M
        // Downloading packages:
        // warning: /var/cache/yum/x86_64/7Server/rhel-7-server-rpms/packages/zsh-5.0.2-7.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
        // Public key for zsh-5.0.2-7.el7.x86_64.rpm is not installed
        // Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
        // Importing GPG key 0xFD431D51:
        // Userid     : "Red Hat, Inc. (release key 2) <security@redhat.com>"
        // Fingerprint: 567e 347a d004 4ade 55ba 8a5f 199e 2f91 fd43 1d51
        // Package    : redhat-release-server-7.0-1.el7.x86_64 (@koji-override-0/7.0)
        // From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
        // Importing GPG key 0x2FA658E0:
        // Userid     : "Red Hat, Inc. (auxiliary key) <security@redhat.com>"
        // Fingerprint: 43a6 e49c 4a38 f4be 9abf 2a53 4568 9c88 2fa6 58e0
        // Package    : redhat-release-server-7.0-1.el7.x86_64 (@koji-override-0/7.0)
        // From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
        // Running transaction check
        // Running transaction test
        // Transaction test succeeded
        // Running transaction
        // Installing : zsh-5.0.2-7.el7.x86_64                                       1/1
        // Verifying  : zsh-5.0.2-7.el7.x86_64                                       1/1
        // 
        // Installed:
        // zsh.x86_64 0:5.0.2-7.el7
        // 
        // Complete!
        installedPackage = true;
    }
    if (!installedPackage)
        log.warning("Skipped attempts to install a package since the rhel-(6|7)-server-rpms repo was not entitled.");
}
Also used : EntitlementCert(rhsm.data.EntitlementCert) ArrayList(java.util.ArrayList) ProductCert(rhsm.data.ProductCert) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) ContentNamespace(rhsm.data.ContentNamespace) SSHCommandResult(com.redhat.qe.tools.SSHCommandResult) SkipException(org.testng.SkipException) HashSet(java.util.HashSet) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 15 with ContentNamespace

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

the class DockerTests method testContainerConfigurationsAreSetAfterAutoSubscribingAndUnsubscribing.

@// update=true,	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-26770", "RHEL7-51758" }, 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 entitlements providing containerimage content are copied to relevant directories when attached via auto-subscribe (as governed by the subscription-manager-plugin-container package)", groups = { "Tier1Tests" }, enabled = true)
public // @ImplementsNitrateTest(caseId=)
void testContainerConfigurationsAreSetAfterAutoSubscribingAndUnsubscribing() {
    // get the list of registry_hostnames from /etc/rhsm/pluginconf.d/container_content.ContainerContentPlugin.conf
    String registry_hostnames = clienttasks.getConfFileParameter(containerContentPluginFile.getPath(), "registry_hostnames");
    List<String> registryHostnames = Arrays.asList(registry_hostnames.split(" *, *"));
    // rhsm-test.redhat.com does NOT appear to come from a redhat.com CDN
    if (!registryHostnames.contains("rhsm-test.redhat.com"))
        clienttasks.updateConfFileParameter(containerContentPluginFile.getPath(), "registry_hostnames", registry_hostnames + "," + "rhsm-test.redhat.com");
    // cdn.rhsm-test.redhat.com DOES appear to come from a redhat.com CDN because it matches regex ^cdn\.(?:.*\.)?redhat\.com$
    if (!registryHostnames.contains("cdn.rhsm-test.redhat.com"))
        clienttasks.updateConfFileParameter(containerContentPluginFile.getPath(), "registry_hostnames", registry_hostnames + "," + "cdn.rhsm-test.redhat.com");
    registry_hostnames = clienttasks.getConfFileParameter(containerContentPluginFile.getPath(), "registry_hostnames");
    registryHostnames = Arrays.asList(registry_hostnames.split(" *, *"));
    // register the host, autosubscribe, and get the granted entitlements
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, true, null, null, (String) null, null, null, null, true, false, null, null, null, null);
    List<EntitlementCert> entitlementCerts = clienttasks.getCurrentEntitlementCerts();
    // 5109020365795659852.cert  5109020365795659852.key  redhat-uep.crt
    if (!verifyEntitlementsProvidingContainerImageContentAreCopiedToRegistryHostnames(entitlementCerts, registryHostnames))
        throw new SkipException("None of the auto-attached subscriptions for this system provide content of type \"containerimage\".");
    // individually unsubscribe from entitlements and assert the entitlement bearing a containerimage is also removed from registry_hostnames
    for (EntitlementCert entitlementCert : entitlementCerts) {
        List<ContentNamespace> containerImageContentNamespaces = ContentNamespace.findAllInstancesWithCaseInsensitiveMatchingFieldFromList("type", "containerimage", entitlementCert.contentNamespaces);
        BigInteger serialNumber = clienttasks.getSerialNumberFromEntitlementCertFile(entitlementCert.file);
        clienttasks.unsubscribeFromSerialNumber(serialNumber);
        if (!containerImageContentNamespaces.isEmpty()) {
            // after unsubscribing, assert that the entitlementCert was removed from the directory of registry_hostnames
            for (String registryHostname : registryHostnames) {
                File certFile = getRegistryHostnameCertFileFromEntitlementCert(registryHostname, entitlementCert);
                File keyFile = getRegistryHostnameCertKeyFileFromEntitlementCert(registryHostname, entitlementCert);
                Assert.assertTrue(!RemoteFileTasks.testExists(client, certFile.getPath()), "Entitlement cert '" + entitlementCert.orderNamespace.productName + "' providing a 'containerimage' (case insensitive) was removed from '" + certFile.getPath() + "' after unsubscribing.");
                Assert.assertTrue(!RemoteFileTasks.testExists(client, keyFile.getPath()), "Corresponding entitlement key providing a 'containerimage' (case insensitive) was removed from '" + keyFile.getPath() + "' after unsubscribing.");
            }
        }
    }
}
Also used : ContentNamespace(rhsm.data.ContentNamespace) EntitlementCert(rhsm.data.EntitlementCert) BigInteger(java.math.BigInteger) SkipException(org.testng.SkipException) File(java.io.File) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

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