Search in sources :

Example 21 with SubscriptionPool

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

the class BugzillaTests method testRefreshPoolAfterChangeInProvidedProducts.

/**
 * @author skallesh
 * @throws Exception
 * @throws JSONException
 */
@SuppressWarnings("deprecation")
@Test(description = "verify if refresh pools will not notice change in provided products", groups = { "Tier3Tests", "RefreshPoolAfterChangeInProvidedProducts", "blockedByBug-665118" }, enabled = false)
public void testRefreshPoolAfterChangeInProvidedProducts() throws Exception {
    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);
    String consumerId = clienttasks.getCurrentConsumerId();
    ownerKey = CandlepinTasks.getOwnerKeyOfConsumerId(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, consumerId);
    String name, productId;
    List<String> providedProductIds = new ArrayList<String>();
    name = "Test product to check pool refresh";
    productId = "test-product";
    Map<String, String> attributes = new HashMap<String, String>();
    attributes.clear();
    attributes.put("version", "1.0");
    attributes.put("variant", "server");
    attributes.put("arch", "ALL");
    attributes.put("warning_period", "30");
    attributes.put("type", "MKT");
    attributes.put("type", "SVC");
    providedProductIds.add("37060");
    Integer contractNumber = getRandInt();
    Integer accountNumber = getRandInt();
    Calendar endCalendar = new GregorianCalendar();
    endCalendar.set(Calendar.HOUR_OF_DAY, 0);
    endCalendar.set(Calendar.MINUTE, 0);
    // avoid times in the middle of the
    endCalendar.set(Calendar.SECOND, 0);
    // day
    // 15 days from today
    endCalendar.add(Calendar.MINUTE, 15 * 24 * 60);
    Date endDate = endCalendar.getTime();
    Calendar startCalendar = new GregorianCalendar();
    startCalendar.set(Calendar.HOUR_OF_DAY, 0);
    startCalendar.set(Calendar.MINUTE, 0);
    // avoid times in the middle of
    startCalendar.set(Calendar.SECOND, 0);
    // the day
    // 1 day ago
    startCalendar.add(Calendar.MINUTE, -1 * 24 * 60);
    Date startDate = startCalendar.getTime();
    CandlepinTasks.deleteSubscriptionsAndRefreshPoolsUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, sm_clientOrg, productId);
    String resourcePath = "/products/" + productId;
    if (SubscriptionManagerTasks.isVersion(servertasks.statusVersion, ">=", "2.0.0"))
        resourcePath = "/owners/" + sm_clientOrg + resourcePath;
    CandlepinTasks.deleteResourceUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, resourcePath);
    CandlepinTasks.createProductUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, sm_clientOrg, name, productId, 1, attributes, null);
    @SuppressWarnings("deprecation") String requestBody = CandlepinTasks.createSubscriptionRequestBody(sm_serverUrl, 20, startDate, endDate, productId, contractNumber, accountNumber, providedProductIds, null).toString();
    JSONObject jsonSubscription = new JSONObject(CandlepinTasks.postResourceUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, "/owners/" + ownerKey + "/subscriptions", requestBody));
    JSONObject jobDetail = CandlepinTasks.refreshPoolsUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, ownerKey);
    jobDetail = CandlepinTasks.waitForJobDetailStateUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, jobDetail, "FINISHED", 5 * 1000, 1);
    String poolId = null;
    for (SubscriptionPool pools : clienttasks.getCurrentlyAvailableSubscriptionPools()) {
        if (pools.productId.equals(productId)) {
            poolId = pools.poolId;
        }
    }
    providedProductIds.remove("37060");
    providedProductIds.add("100000000000002");
    List<JSONObject> pprods = new ArrayList<JSONObject>();
    if (providedProducts != null)
        for (String id : providedProductIds) {
            JSONObject jo = new JSONObject();
            jo.put("id", id);
            pprods.add(jo);
        }
    jsonSubscription.remove("derivedProvidedProducts");
    jsonSubscription.put("providedProducts", pprods);
    // String sub="{\"quantity\":\"8\"}]}";
    // JSONObject jsonData= new JSONObject(jsonSubscription);
    CandlepinTasks.putResourceUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, "/owners/admin/subscriptions/", jsonSubscription);
    jobDetail = CandlepinTasks.refreshPoolsUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, ownerKey);
    CandlepinTasks.waitForJobDetailStateUsingRESTfulAPI(sm_serverAdminUsername, sm_serverAdminPassword, sm_serverUrl, jobDetail, "FINISHED", 5 * 1000, 1);
    for (SubscriptionPool pools : clienttasks.getCurrentlyAvailableSubscriptionPools()) {
        if (pools.productId.equals(productId)) {
            poolId = pools.poolId;
        }
    }
}
Also used : HashMap(java.util.HashMap) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) BigInteger(java.math.BigInteger) JSONObject(org.json.JSONObject) SubscriptionPool(rhsm.data.SubscriptionPool) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 22 with SubscriptionPool

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

the class BugzillaTests method testConsumeVirtOnlyPool.

/**
 * @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-21986", "RHEL7-51848" }, 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 = "Tier3")
@Test(description = "verify if able to entitle consumer to the pool virt_only,pool_derived,bonus pool ", groups = { "Tier3Tests", "consumeVirtOnlyPool", "blockedByBug-756628" }, enabled = true)
public void testConsumeVirtOnlyPool() throws JSONException, Exception {
    String isPool_derived = null;
    Boolean virtonly = false;
    clienttasks.register(sm_clientUsername, sm_clientPassword, sm_clientOrg, null, null, null, null, null, null, null, (List<String>) null, (String) null, null, null, true, null, null, null, null, null);
    String isGuest = clienttasks.getFactValue("virt.is_guest");
    if (isGuest.equalsIgnoreCase("true")) {
        Map<String, String> factsMap = new HashMap<String, String>();
        factsMap.put("virt.is_guest", "False");
        clienttasks.facts(null, true, null, null, null, null);
        clienttasks.createFactsFileWithOverridingValues(factsMap);
        for (SubscriptionPool availList : clienttasks.getCurrentlyAvailableSubscriptionPools()) {
            isPool_derived = CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, availList.poolId, "pool_derived");
            virtonly = CandlepinTasks.isPoolVirtOnly(sm_clientUsername, sm_clientPassword, availList.poolId, sm_serverUrl);
            if (!(isPool_derived == null) || virtonly) {
                String result = clienttasks.subscribe_(null, null, availList.poolId, null, null, null, null, null, null, null, null, null, null).getStdout();
                String Expected = "Pool is restricted to virtual guests: " + availList.subscriptionName;
                Assert.assertEquals(result.trim(), Expected);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 23 with SubscriptionPool

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

the class BugzillaTests method testManualChangesToRedhatRepo.

/**
 * @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-21915", "RHEL7-51776" }, 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 = "Tier3")
@Test(description = "verify Manual Changes To Redhat.Repo is sticky", groups = { "Tier3Tests", "ManualChangesToRedhat_Repo", "blockedByBug-797243" }, enabled = true)
public void testManualChangesToRedhatRepo() throws Exception {
    List<String[]> listOfSectionNameValues = new ArrayList<String[]>();
    listOfSectionNameValues.add(new String[] { "rhsmcertd", "autoAttachInterval".toLowerCase(), "1440" });
    clienttasks.config(null, null, true, listOfSectionNameValues);
    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);
    List<SubscriptionPool> Availablepools = clienttasks.getCurrentlyAvailableSubscriptionPools();
    SubscriptionPool pool = Availablepools.get(randomGenerator.nextInt(Availablepools.size()));
    clienttasks.subscribeToSubscriptionPool(pool);
    for (Repo repo : clienttasks.getCurrentlySubscribedRepos()) {
        if (repo.repoId.equals("always-enabled-content")) {
            Assert.assertTrue(repo.enabled);
        }
    }
    client.runCommandAndWait("sed -i \"/\\[always-enabled-content]/,/\\[/s/^enabled\\s*=.*/Enabled: false/\" /etc/yum.repos.d/redhat.repo");
    for (Repo repo : clienttasks.getCurrentlySubscribedRepos()) {
        if (repo.repoId.equals("always-enabled-content")) {
            Assert.assertFalse(repo.enabled);
        }
    }
    client.runCommandAndWait(" yum repolist enabled");
    clienttasks.unsubscribeFromAllOfTheCurrentlyConsumedProductSubscriptions();
    String expected_message = "This system has no repositories available through subscriptions.";
    String reposlist = clienttasks.repos(true, null, null, (String) null, null, null, null, null, null).getStdout();
    Assert.assertEquals(reposlist.trim(), expected_message);
    clienttasks.unregister(null, null, null, null);
    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);
    reposlist = clienttasks.repos(true, null, null, (String) null, null, null, null, null, null).getStdout();
    Assert.assertEquals(reposlist.trim(), expected_message);
    clienttasks.subscribe(true, null, (String) null, null, null, null, null, null, null, null, null, null, null);
    for (Repo repo : clienttasks.getCurrentlySubscribedRepos()) {
        if (repo.repoId.equals("always-enabled-content")) {
            Assert.assertTrue(repo.enabled);
        }
    }
}
Also used : Repo(rhsm.data.Repo) YumRepo(rhsm.data.YumRepo) ArrayList(java.util.ArrayList) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 24 with SubscriptionPool

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

the class BugzillaTests method testStackingFutureSubscriptionWithCurrentSubscription.

/**
 * @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-21927", "RHEL7-51788" }, 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 = "Tier3")
@Test(description = "verify Stacking of a future subscription and present subsciption make the product compliant ", groups = { "Tier3Tests", "StackingFutureSubscriptionWithCurrentSubscription", "blockedByBug-966069" }, enabled = true)
public void testStackingFutureSubscriptionWithCurrentSubscription() throws Exception {
    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);
    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);
    int sockets = 9;
    int core = 2;
    int ram = 10;
    Map<String, String> factsMap = new HashMap<String, String>();
    factsMap.put("cpu.cpu_socket(s)", String.valueOf(sockets));
    factsMap.put("cpu.core(s)_per_socket", String.valueOf(core));
    factsMap.put("memory.memtotal", String.valueOf(GBToKBConverter(ram)));
    factsMap.put("virt.is_guest", String.valueOf(Boolean.FALSE));
    clienttasks.createFactsFileWithOverridingValues(factsMap);
    clienttasks.facts(null, true, null, null, null, null);
    Boolean nosubscriptionsFound = true;
    Calendar now = new GregorianCalendar();
    DateFormat yyyy_MM_dd_DateFormat = new SimpleDateFormat("yyyy-MM-dd");
    now.add(Calendar.YEAR, 1);
    now.add(Calendar.DATE, 1);
    String onDateToTest = yyyy_MM_dd_DateFormat.format(now.getTime());
    List<String> providedProductId = new ArrayList<String>();
    List<SubscriptionPool> AvailableStackableSubscription = SubscriptionPool.findAllInstancesWithMatchingFieldFromList("subscriptionType", "Stackable", clienttasks.getAvailableSubscriptionsMatchingInstalledProducts());
    List<SubscriptionPool> futureStackableSubscription = SubscriptionPool.findAllInstancesWithMatchingFieldFromList("subscriptionType", "Stackable", clienttasks.getAvailableFutureSubscriptionsOndate(onDateToTest));
    List<SubscriptionPool> futureSubscription = FindSubscriptionsWithSuggestedQuantityGreaterThanTwo(futureStackableSubscription);
    List<SubscriptionPool> AvailableSubscriptions = FindSubscriptionsWithSuggestedQuantityGreaterThanTwo(AvailableStackableSubscription);
    for (SubscriptionPool AvailableSubscriptionPools : AvailableSubscriptions) {
        int quantity = AvailableSubscriptionPools.suggested;
        for (SubscriptionPool FutureSubscriptionPools : futureSubscription) {
            if ((AvailableSubscriptionPools.subscriptionName).equals(FutureSubscriptionPools.subscriptionName)) {
                providedProductId = AvailableSubscriptionPools.provides;
                clienttasks.subscribe(null, null, AvailableSubscriptionPools.poolId, null, null, Integer.toString(quantity - 1), null, null, null, null, null, null, null);
                nosubscriptionsFound = false;
                InstalledProduct AfterAttachingFutureSubscription = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productName", providedProductId.get(providedProductId.size() - 1), clienttasks.getCurrentlyInstalledProducts());
                Assert.assertEquals(AfterAttachingFutureSubscription.status, "Partially Subscribed", "Verified that installed product is partially subscribed before attaching a future subscription");
                clienttasks.subscribe(null, null, FutureSubscriptionPools.poolId, null, null, "1", null, null, null, null, null, null, null);
                break;
            }
        }
    }
    if (nosubscriptionsFound)
        throw new SkipException("no subscriptions found");
    InstalledProduct AfterAttaching = InstalledProduct.findFirstInstanceWithMatchingFieldFromList("productName", providedProductId.get(providedProductId.size() - 1), clienttasks.getCurrentlyInstalledProducts());
    Assert.assertEquals(AfterAttaching.status, "Partially Subscribed", "Verified that installed product is partially subscribed even after attaching a future subscription");
}
Also used : HashMap(java.util.HashMap) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) ArrayList(java.util.ArrayList) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) InstalledProduct(rhsm.data.InstalledProduct) SkipException(org.testng.SkipException) SimpleDateFormat(java.text.SimpleDateFormat) SubscriptionPool(rhsm.data.SubscriptionPool) TestDefinition(com.github.redhatqe.polarize.metadata.TestDefinition) Test(org.testng.annotations.Test) ImplementsNitrateTest(com.redhat.qe.auto.tcms.ImplementsNitrateTest)

Example 25 with SubscriptionPool

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

the class BugzillaTests method testStatusForPartialSubscription.

/**
 * @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-21972", "RHEL7-51834" }, 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 = "Tier3")
@Test(description = "Verify if Subscription manager displays incorrect status for partially subscribed subscription", groups = { "Tier3Tests", "VerifyStatusForPartialSubscription", "blockedByBug-743710" }, enabled = true)
@ImplementsNitrateTest(caseId = 119327)
public void testStatusForPartialSubscription() throws JSONException, Exception {
    String Flag = "false";
    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);
    Map<String, String> factsMap = new HashMap<String, String>();
    factsMap.put("virt.is_guest", String.valueOf(Boolean.FALSE));
    clienttasks.createFactsFileWithOverridingValues(factsMap);
    clienttasks.facts(null, true, null, null, null, null);
    for (SubscriptionPool SubscriptionPool : clienttasks.getCurrentlyAllAvailableSubscriptionPools()) {
        if (!CandlepinTasks.isPoolProductMultiEntitlement(sm_clientUsername, sm_clientPassword, sm_serverUrl, SubscriptionPool.poolId)) {
            String poolProductSocketsAttribute = CandlepinTasks.getPoolProductAttributeValue(sm_clientUsername, sm_clientPassword, sm_serverUrl, SubscriptionPool.poolId, "sockets");
            if ((!(poolProductSocketsAttribute == null)) && (poolProductSocketsAttribute.equals("2"))) {
                clienttasks.subscribeToSubscriptionPool_(SubscriptionPool);
                Flag = "true";
            }
        }
    }
    Assert.assertTrue(Boolean.valueOf(Flag), "Found and subscribed to non-multi-entitlement 2 socket subscription pool(s) for this test.");
    Integer moreSockets = 4;
    factsMap.put("cpu.cpu_socket(s)", String.valueOf(moreSockets + Integer.valueOf(clienttasks.sockets)));
    clienttasks.createFactsFileWithOverridingValues(factsMap);
    clienttasks.facts(null, true, null, null, null, null);
    Flag = "false";
    for (InstalledProduct product : clienttasks.getCurrentlyInstalledProducts()) {
        if (!product.status.equals("Not Subscribed") && !product.status.equals("Subscribed") && !product.status.equals("Unknown")) {
            Assert.assertEquals(product.status, "Partially Subscribed", "Installed product '" + product.productName + "' status is Partially Subscribed.");
            Flag = "true";
        }
    }
    Assert.assertEquals(Flag, "true", "Verified Partially Subscribed installed product(s).");
}
Also used : BigInteger(java.math.BigInteger) HashMap(java.util.HashMap) InstalledProduct(rhsm.data.InstalledProduct) SubscriptionPool(rhsm.data.SubscriptionPool) 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

SubscriptionPool (rhsm.data.SubscriptionPool)195 Test (org.testng.annotations.Test)155 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)137 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)112 SkipException (org.testng.SkipException)90 ArrayList (java.util.ArrayList)87 JSONObject (org.json.JSONObject)66 SSHCommandResult (com.redhat.qe.tools.SSHCommandResult)53 ProductSubscription (rhsm.data.ProductSubscription)38 BigInteger (java.math.BigInteger)37 File (java.io.File)34 List (java.util.List)33 EntitlementCert (rhsm.data.EntitlementCert)33 HashMap (java.util.HashMap)32 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)28 InstalledProduct (rhsm.data.InstalledProduct)25 ProductCert (rhsm.data.ProductCert)24 JSONArray (org.json.JSONArray)22 Calendar (java.util.Calendar)12 GregorianCalendar (java.util.GregorianCalendar)11