Search in sources :

Example 26 with PoolQuantity

use of org.candlepin.model.PoolQuantity in project candlepin by candlepin.

the class AutobindRulesTest method guestLimitAutobindServerAttached.

/*
     * If the hypervisor is already installed, and at least partially
     * subscribed, autobind will be able to cover the server subscription
     */
@Test
public void guestLimitAutobindServerAttached() {
    consumer.setFact("cpu.cpu_socket(s)", "8");
    for (int i = 0; i < 5; i++) {
        consumer.addGuestId(new GuestId("" + i, consumer, activeGuestAttrs));
    }
    Product server = mockStackingProduct(productId, "some server", "stackid1", "2");
    server.setAttribute(Product.Attributes.GUEST_LIMIT, "4");
    Product hypervisor = mockStackingProduct("hypervisor", "some hypervisor", "stackid2", "2");
    hypervisor.setAttribute(Product.Attributes.GUEST_LIMIT, "-1");
    Pool serverPool = TestUtil.createPool(owner, server, 10);
    Pool hyperPool = TestUtil.createPool(owner, hypervisor, 10);
    serverPool.setId("POOL-ID1");
    hyperPool.setId("Pool-ID2");
    Entitlement entitlement = TestUtil.createEntitlement();
    entitlement.setPool(hyperPool);
    // compliant
    entitlement.setQuantity(4);
    // The hypervisor must be installed and entitled on the system for autobind
    // to pick up the unlimited guest_limit
    compliance.addCompliantProduct(hypervisor.getId(), entitlement);
    List<Pool> pools = new LinkedList<>();
    pools.add(serverPool);
    pools.add(hyperPool);
    List<PoolQuantity> bestPools = autobindRules.selectBestPools(consumer, new String[] { server.getId() }, pools, compliance, null, new HashSet<>(), false);
    assertEquals(1, bestPools.size());
    assertEquals(new Integer(4), bestPools.get(0).getQuantity());
    assertEquals("POOL-ID1", bestPools.get(0).getPool().getId());
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) GuestId(org.candlepin.model.GuestId) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 27 with PoolQuantity

use of org.candlepin.model.PoolQuantity in project candlepin by candlepin.

the class AutobindRulesTest method ensureSelectBestPoolsFiltersPoolsBySLAWhenConsumerHasSLASet.

@Test
public void ensureSelectBestPoolsFiltersPoolsBySLAWhenConsumerHasSLASet() {
    // Create Premium SLA prod
    String slaPremiumProdId = "premium-sla-product";
    Product slaPremiumProduct = TestUtil.createProduct(slaPremiumProdId, "Product with SLA Premium");
    slaPremiumProduct.setAttribute(Product.Attributes.SUPPORT_LEVEL, "Premium");
    Pool slaPremiumPool = TestUtil.createPool(owner, slaPremiumProduct);
    slaPremiumPool.setId("pool-with-premium-sla");
    slaPremiumPool.getProduct().setAttribute(Product.Attributes.SUPPORT_LEVEL, "Premium");
    // Create Standard SLA Product
    String slaStandardProdId = "standard-sla-product";
    Product slaStandardProduct = TestUtil.createProduct(slaStandardProdId, "Product with SLA Standard");
    slaStandardProduct.setAttribute(Product.Attributes.SUPPORT_LEVEL, "Standard");
    Pool slaStandardPool = TestUtil.createPool(owner, slaStandardProduct);
    slaStandardPool.setId("pool-with-standard-sla");
    slaStandardPool.getProduct().setAttribute(Product.Attributes.SUPPORT_LEVEL, "Standard");
    // Create a product with no SLA.
    Product noSLAProduct = TestUtil.createProduct(productId, "A test product");
    Pool noSLAPool = TestUtil.createPool(owner, noSLAProduct);
    noSLAPool.setId("pool-1");
    List<Pool> pools = new LinkedList<>();
    pools.add(noSLAPool);
    pools.add(slaPremiumPool);
    pools.add(slaStandardPool);
    // SLA filtering only occurs when consumer has SLA set.
    consumer.setServiceLevel("Premium");
    List<PoolQuantity> bestPools = autobindRules.selectBestPools(consumer, new String[] { productId, slaPremiumProdId, slaStandardProdId }, pools, compliance, null, new HashSet<>(), false);
    assertEquals(2, bestPools.size());
    assertTrue(bestPools.contains(new PoolQuantity(slaPremiumPool, 1)));
    assertTrue(bestPools.contains(new PoolQuantity(noSLAPool, 1)));
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 28 with PoolQuantity

use of org.candlepin.model.PoolQuantity in project candlepin by candlepin.

the class AutobindRulesTest method unlimitedStackedPoolIsPickedUp.

@Test
public void unlimitedStackedPoolIsPickedUp() {
    consumer.setFact("cpu.cpu_socket(s)", "8");
    Product product = mockStackingProduct(productId, "my-prod", "stackid", "2");
    Pool pool = TestUtil.createPool(owner, product, -1);
    pool.setId("POOL-ID");
    List<Pool> pools = new LinkedList<>();
    pools.add(pool);
    List<PoolQuantity> bestPools = autobindRules.selectBestPools(consumer, new String[] { product.getId() }, pools, compliance, null, new HashSet<>(), false);
    assertEquals(1, bestPools.size());
    assertEquals(new Integer(4), bestPools.get(0).getQuantity());
    assertEquals("POOL-ID", bestPools.get(0).getPool().getId());
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 29 with PoolQuantity

use of org.candlepin.model.PoolQuantity in project candlepin by candlepin.

the class AutobindRulesTest method testFindBestWithConsumerSockets.

@Test
public void testFindBestWithConsumerSockets() {
    consumer.setFact("cpu.cpu_socket(s)", "4");
    Product product = TestUtil.createProduct(productId, "A test product");
    product.setAttribute(Product.Attributes.SOCKETS, "4");
    Pool pool = TestUtil.createPool(owner, product);
    pool.setId("DEAD-BEEF");
    List<Pool> pools = new LinkedList<>();
    pools.add(pool);
    List<PoolQuantity> bestPools = autobindRules.selectBestPools(consumer, new String[] { productId }, pools, compliance, null, new HashSet<>(), false);
    assertEquals(1, bestPools.size());
    assertTrue(bestPools.contains(new PoolQuantity(pool, 1)));
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 30 with PoolQuantity

use of org.candlepin.model.PoolQuantity in project candlepin by candlepin.

the class AutobindRulesTest method testFindBestWithMultiAttrsStackedVirt.

/*
     * Make sure the attribute with the minimum number of pools is chosen
     */
@Test
public void testFindBestWithMultiAttrsStackedVirt() {
    consumer.setFact("cpu.cpu_socket(s)", "4");
    consumer.setFact("memory.memtotal", "16000000");
    consumer.setFact("cpu.core(s)_per_socket", "4");
    consumer.setFact("virt.is_guest", "true");
    // Will be common to both SKUs and what we autobind for:
    Product provided = mockProduct("5000", "Eng Product");
    Product sku1 = mockStackingProduct(productId, "Test Stack product", "1", "1");
    sku1.setAttribute(Product.Attributes.CORES, "6");
    sku1.setAttribute(Product.Attributes.RAM, "2");
    sku1.setAttribute(Product.Attributes.SOCKETS, "2");
    Pool pool1 = createPool("DEAD-BEEF1", owner, sku1, provided);
    pool1.setAttribute(Product.Attributes.VIRT_ONLY, "true");
    // only enforce cores on pool 2:
    Product sku2 = mockStackingProduct("prod2", "Test Stack product", "1", "1");
    sku2.setAttribute(Product.Attributes.CORES, "6");
    Pool pool2 = createPool("DEAD-BEEF2", owner, sku2, provided);
    Pool pool3 = createPool("DEAD-BEEF3", owner, sku1, provided);
    List<Pool> pools = new LinkedList<>();
    pools.add(pool1);
    pools.add(pool2);
    pools.add(pool3);
    List<PoolQuantity> bestPools = autobindRules.selectBestPools(consumer, new String[] { provided.getId() }, pools, compliance, null, new HashSet<>(), false);
    assertEquals(2, bestPools.size());
    // higher quantity from this pool, as it is virt_only
    assertTrue(bestPools.contains(new PoolQuantity(pool1, 5)));
    assertTrue(bestPools.contains(new PoolQuantity(pool3, 3)));
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

PoolQuantity (org.candlepin.model.PoolQuantity)75 Pool (org.candlepin.model.Pool)65 Test (org.junit.Test)52 Entitlement (org.candlepin.model.Entitlement)34 LinkedList (java.util.LinkedList)30 Product (org.candlepin.model.Product)28 HashMap (java.util.HashMap)27 ArrayList (java.util.ArrayList)21 Consumer (org.candlepin.model.Consumer)12 List (java.util.List)11 ConsumerType (org.candlepin.model.ConsumerType)11 Matchers.anyString (org.mockito.Matchers.anyString)11 Date (java.util.Date)8 Set (java.util.Set)8 HashSet (java.util.HashSet)7 EntitlementRefusedException (org.candlepin.policy.EntitlementRefusedException)7 ValidationResult (org.candlepin.policy.ValidationResult)7 Subscription (org.candlepin.model.dto.Subscription)6 Matchers.anyLong (org.mockito.Matchers.anyLong)6 PoolFilterBuilder (org.candlepin.model.PoolFilterBuilder)5