Search in sources :

Example 66 with ProductCert

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

the class FlexibleBrandingTests method configProductCertDirBeforeClass.

@BeforeClass(groups = "setup")
public void configProductCertDirBeforeClass() {
    if (clienttasks == null)
        return;
    List<ProductCert> productCerts = clienttasks.getCurrentProductCerts();
    productCert32060 = ProductCert.findFirstInstanceWithMatchingFieldFromList("productId", "32060", productCerts);
    productCert37060 = ProductCert.findFirstInstanceWithMatchingFieldFromList("productId", "37060", productCerts);
    if (productCert32060 == null)
        throw new SkipException("Could not find expected flexible branded product cert id 32060 installed.");
    if (productCert37060 == null)
        throw new SkipException("Could not find expected flexible branded product cert id 37060 installed.");
    // TEMPORARY WORKAROUND FOR BUG: Bug 1183175 - changing to a different rhsm.productcertdir configuration throws OSError: [Errno 17] File exists
    boolean invokeWorkaroundWhileBugIsOpen = true;
    String bugId = "1183175";
    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("Cannot configure a different productCertDir while bug '" + bugId + "' is open.");
    }
    // END OF WORKAROUND
    originalProductCertDir = clienttasks.getConfFileParameter(clienttasks.rhsmConfFile, "rhsm", "productCertDir");
    Assert.assertNotNull(originalProductCertDir);
    log.info("Initializing a new product cert directory containing product 32060...");
    RemoteFileTasks.runCommandAndAssert(client, "mkdir -p " + tmpProductCertDir, Integer.valueOf(0));
    RemoteFileTasks.runCommandAndAssert(client, "rm -f " + tmpProductCertDir + "/*.pem", Integer.valueOf(0));
    clienttasks.updateConfFileParameter(clienttasks.rhsmConfFile, "productCertDir", tmpProductCertDir);
}
Also used : ProductCert(rhsm.data.ProductCert) SkipException(org.testng.SkipException) BugzillaAPIException(com.redhat.qe.auto.bugzilla.BugzillaAPIException) BeforeClass(org.testng.annotations.BeforeClass)

Example 67 with ProductCert

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

the class GuestLimitingTests method tmpProductCertDirWithInstalledProductCertsConfiguration.

@BeforeClass(groups = "setup")
protected void tmpProductCertDirWithInstalledProductCertsConfiguration() {
    if (rhsmProductCertDir == null) {
        rhsmProductCertDir = clienttasks.getConfFileParameter(clienttasks.rhsmConfFile, "rhsm", "productCertDir");
        Assert.assertNotNull(rhsmProductCertDir);
    }
    log.info("Initializing a new product cert directory with the currently installed product certs for this test...");
    ProductCert installedProductCert37060 = ProductCert.findFirstInstanceWithMatchingFieldFromList("productId", "37060", clienttasks.getCurrentProductCerts());
    RemoteFileTasks.runCommandAndAssert(client, "mkdir -p " + tmpProductCertDir, Integer.valueOf(0));
    RemoteFileTasks.runCommandAndAssert(client, "rm -f " + tmpProductCertDir + "/*.pem", Integer.valueOf(0));
    RemoteFileTasks.runCommandAndAssert(client, "cp " + installedProductCert37060.file + " " + tmpProductCertDir, Integer.valueOf(0));
    clienttasks.updateConfFileParameter(clienttasks.rhsmConfFile, "productCertDir", tmpProductCertDir);
}
Also used : ProductCert(rhsm.data.ProductCert) BeforeClass(org.testng.annotations.BeforeClass)

Example 68 with ProductCert

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

the class GuestLimitingTests method testComplianceOfHostWithFiveGuestsAndGuestLimitOfFour.

/**
 * @author skallesh
 * @throws Exception
 * @throws JSONException
 */
@// update=true	// uncomment to make TestDefinition changes update Polarion testcases through the polarize testcase importer
TestDefinition(projectID = { Project.RHEL6, Project.RedHatEnterpriseLinux7 }, testCaseID = { "RHEL6-37721", "RHEL7-51948" }, linkedWorkItems = { @LinkedItem(// RHSM-REQ : Guest-limited Subscriptions
workitemId = "RHEL6-30331", project = Project.RHEL6, role = DefTypes.Role.VERIFIES), @LinkedItem(// RHSM-REQ : Guest-limited Subscriptions
workitemId = "RHEL7-84959", project = Project.RedHatEnterpriseLinux7, role = DefTypes.Role.VERIFIES) }, 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 = "Verify the compliance status on the server when the host has more than 4 guests", groups = { "Tier2Tests" }, enabled = true)
public void testComplianceOfHostWithFiveGuestsAndGuestLimitOfFour() throws JSONException, Exception {
    String consumerId = clienttasks.getCurrentConsumerId(clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (String) null, null, null, null, true, null, null, null, null, null));
    clienttasks.autoheal(null, null, true, null, null, null, null);
    if (clienttasks.getFactValue("virt.is_guest").equals("True")) {
        Map<String, String> factsMap = new HashMap<String, String>();
        factsMap.put("virt.is_guest", "False");
        factsMap.put(" virt.uuid", "");
        clienttasks.createFactsFileWithOverridingValues(factsMap);
        clienttasks.facts(null, true, null, null, null, null);
    }
    ownerKey = CandlepinTasks.getOwnerKeyOfConsumerId(sm_clientUsername, sm_clientPassword, sm_serverUrl, consumerId);
    // call Candlepin API to PUT some guestIds onto the host consumer
    JSONObject jsonData = new JSONObject();
    Map<String, String> attributes = new HashMap<String, String>();
    attributes.clear();
    attributes.put("virtWhoType", "libvirt");
    attributes.put("active", "1");
    int guestLimit = 5;
    List<JSONObject> expectedGuestIds = new ArrayList<JSONObject>();
    for (int k = 0; k <= guestLimit; k++) {
        expectedGuestIds.add(createGuestIdRequestBody("test-guestId" + k, attributes));
    }
    jsonData.put("guestIds", expectedGuestIds);
    CandlepinTasks.putResourceUsingRESTfulAPI(sm_clientUsername, sm_clientPassword, sm_serverUrl, "/consumers/" + consumerId, jsonData);
    String pool = getGuestlimitPool(String.valueOf(guestLimit - 1));
    ProductCert installedProductCert = ProductCert.findFirstInstanceWithMatchingFieldFromList("productId", providedProductIds.get(randomGenerator.nextInt(providedProductIds.size())), clienttasks.getCurrentProductCerts());
    Assert.assertNotNull(installedProductCert, "Found installed product cert needed for this test.");
    clienttasks.subscribe(null, null, pool, null, null, "1", null, null, null, null, null, null, null);
    String compliance = clienttasks.getFactValue(factname);
    // Assert the system compliance
    Assert.assertEquals(compliance, factValueForSystemPartialCompliance);
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProductCert(rhsm.data.ProductCert) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test)

Example 69 with ProductCert

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

the class SubscriptionManagerTasks method getProductCertsProvidedBySubscriptionPool.

/**
 * From amongst the given product certs, return those that are provided for by the given pool.
 * @param productCerts
 * @param pool
 * @return
 * @throws JSONException
 * @throws Exception
 */
public List<ProductCert> getProductCertsProvidedBySubscriptionPool(List<ProductCert> productCerts, SubscriptionPool pool) throws JSONException, Exception {
    List<ProductCert> productCertsProvidedBySubscriptionPool = new ArrayList<ProductCert>();
    // String hostname = getConfFileParameter(rhsmConfFile, "hostname");
    // String port = getConfFileParameter(rhsmConfFile, "port");
    // String prefix = getConfFileParameter(rhsmConfFile, "prefix");
    JSONObject jsonPool = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(this.currentlyRegisteredUsername, this.currentlyRegisteredPassword, candlepinUrl, "/pools/" + pool.poolId));
    JSONArray jsonProvidedProducts = (JSONArray) jsonPool.getJSONArray("providedProducts");
    for (int k = 0; k < jsonProvidedProducts.length(); k++) {
        JSONObject jsonProvidedProduct = (JSONObject) jsonProvidedProducts.get(k);
        String providedProductId = jsonProvidedProduct.getString("productId");
        // is this productId among the installed ProductCerts? if so, add them all to the currentProductCertsCorrespondingToSubscriptionPool
        productCertsProvidedBySubscriptionPool.addAll(ProductCert.findAllInstancesWithMatchingFieldFromList("productId", providedProductId, productCerts));
    }
    return productCertsProvidedBySubscriptionPool;
}
Also used : JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) ProductCert(rhsm.data.ProductCert)

Example 70 with ProductCert

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

the class SubscriptionManagerTasks method areAllRequiredTagsProvidedByProductCerts.

public boolean areAllRequiredTagsProvidedByProductCerts(String requiredTagsAsString, List<ProductCert> productCerts) {
    // same some time...  if requiredTagsAsString is null, then effectively the requiredTags are provided by any list of product certs
    if (requiredTagsAsString == null)
        return true;
    // get all of the provided tags from the productCerts
    List<String> providedTags = new ArrayList<String>();
    for (ProductCert productCert : productCerts) {
        if (productCert.productNamespace.providedTags != null) {
            for (String providedTag : productCert.productNamespace.providedTags.split("\\s*,\\s*")) {
                providedTags.add(providedTag);
            }
        }
    }
    // get all of the required tags from the contentNamespace
    List<String> requiredTags = new ArrayList<String>();
    if (requiredTagsAsString != null) {
        for (String requiredTag : requiredTagsAsString.split("\\s*,\\s*")) {
            if (!requiredTag.isEmpty())
                requiredTags.add(requiredTag);
        }
    }
    // are ALL of the requiredTags provided?  Note: true is returned (and should be) when requiredTags.isEmpty()
    return providedTags.containsAll(requiredTags);
}
Also used : ArrayList(java.util.ArrayList) ProductCert(rhsm.data.ProductCert)

Aggregations

ProductCert (rhsm.data.ProductCert)90 Test (org.testng.annotations.Test)60 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)54 SkipException (org.testng.SkipException)44 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)40 ArrayList (java.util.ArrayList)40 File (java.io.File)26 SubscriptionPool (rhsm.data.SubscriptionPool)24 EntitlementCert (rhsm.data.EntitlementCert)23 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)22 InstalledProduct (rhsm.data.InstalledProduct)21 JSONObject (org.json.JSONObject)19 SSHCommandResult (com.redhat.qe.tools.SSHCommandResult)17 List (java.util.List)16 ContentNamespace (rhsm.data.ContentNamespace)15 HashSet (java.util.HashSet)13 Calendar (java.util.Calendar)7 HashMap (java.util.HashMap)7 BigInteger (java.math.BigInteger)6 JSONArray (org.json.JSONArray)6