Search in sources :

Example 66 with PoolQuantity

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

the class AutobindRulesTest method testFindBestWithMultiAttrsStacked.

/*
     * Make sure the attribute with the minimum number of pools is chosen
     */
@Test
public void testFindBestWithMultiAttrsStacked() {
    consumer.setFact("cpu.cpu_socket(s)", "4");
    consumer.setFact("memory.memtotal", "16000000");
    consumer.setFact("cpu.core(s)_per_socket", "4");
    // 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);
    // only enforce cores on pool 2:
    Product sku2 = mockStackingProduct("prod2", "Test Stack product", "1", "1");
    sku2.setAttribute(Product.Attributes.CORES, "6");
    sku2.setAttribute(Product.Attributes.RAM, null);
    sku2.setAttribute(Product.Attributes.SOCKETS, null);
    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(1, bestPools.size());
    assertEquals(pool2, bestPools.get(0).getPool());
    assertEquals(new Integer(3), bestPools.get(0).getQuantity());
}
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 67 with PoolQuantity

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

the class AutobindRulesTest method autobindForPhysicalSocketPicksBestFitBalanceStack.

@Test
public void autobindForPhysicalSocketPicksBestFitBalanceStack() {
    List<Pool> pools = createSocketPool(3, 100, "1");
    pools.addAll(createSocketPool(5, 100, "1"));
    setupConsumer("8", false);
    List<PoolQuantity> bestPools = autobindRules.selectBestPools(consumer, new String[] { productId }, pools, compliance, null, new HashSet<>(), false);
    // Should always pick the 3 socket subscription, becuase 3*3 gives 1 socket over-coverage,
    // and 2*5 provides 2 extra sockets.  using 1 quantity is worth .5 sockets
    assertEquals(1, bestPools.size());
    PoolQuantity q = bestPools.get(0);
    assertEquals(new Integer(3), q.getQuantity());
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Pool(org.candlepin.model.Pool) Test(org.junit.Test)

Example 68 with PoolQuantity

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

the class HostedVirtLimitEntitlementRulesTest method hostedVirtLimitAltersBonusPoolQuantity.

@Test
@SuppressWarnings("unchecked")
public void hostedVirtLimitAltersBonusPoolQuantity() {
    when(config.getBoolean(ConfigProperties.STANDALONE)).thenReturn(false);
    Subscription s = createVirtLimitSub("virtLimitProduct", 10, "10");
    ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.CANDLEPIN));
    consumer.setType(ctype);
    Pool p = TestUtil.copyFromSub(s);
    when(poolManagerMock.isManaged(eq(p))).thenReturn(true);
    List<Pool> pools = poolRules.createAndEnrichPools(p, new LinkedList<>());
    assertEquals(2, pools.size());
    Pool physicalPool = pools.get(0);
    physicalPool.setId("physical");
    Pool virtBonusPool = pools.get(1);
    virtBonusPool.setId("virt");
    assertEquals(new Long(10), physicalPool.getQuantity());
    assertEquals(0, physicalPool.getAttributes().size());
    // Quantity on bonus pool should be virt limit * sub quantity:
    assertEquals(new Long(100), virtBonusPool.getQuantity());
    assertEquals("true", virtBonusPool.getAttributeValue(Product.Attributes.VIRT_ONLY));
    assertEquals("10", virtBonusPool.getProduct().getAttributeValue(Product.Attributes.VIRT_LIMIT));
    Entitlement e = new Entitlement(physicalPool, consumer, owner, 1);
    List<Pool> poolList = new ArrayList<>();
    poolList.add(virtBonusPool);
    ArgumentCaptor<Set> captor = ArgumentCaptor.forClass(Set.class);
    when(poolManagerMock.lookupBySubscriptionIds(anyString(), captor.capture())).thenReturn(poolList);
    when(poolManagerMock.lookupBySubscriptionId(eq(physicalPool.getOwner()), eq(physicalPool.getSubscriptionId()))).thenReturn(poolList);
    Map<String, Entitlement> entitlements = new HashMap<>();
    entitlements.put(physicalPool.getId(), e);
    Map<String, PoolQuantity> poolQuantityMap = new HashMap<>();
    poolQuantityMap.put(physicalPool.getId(), new PoolQuantity(physicalPool, 1));
    List<Pool> physicalPools = new ArrayList<>();
    physicalPools.add(physicalPool);
    enforcer.postEntitlement(poolManagerMock, consumer, owner, entitlements, null, false, poolQuantityMap);
    Set<String> subscriptionIds = captor.getValue();
    assertEquals(1, subscriptionIds.size());
    assertEquals("subId", subscriptionIds.iterator().next());
    verify(poolManagerMock).updatePoolQuantity(eq(virtBonusPool), eq(-10L));
    enforcer.postUnbind(consumer, poolManagerMock, e);
    verify(poolManagerMock).updatePoolQuantity(eq(virtBonusPool), eq(10L));
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Matchers.anyLong(org.mockito.Matchers.anyLong) Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) ConsumerType(org.candlepin.model.ConsumerType) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 69 with PoolQuantity

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

the class HostedVirtLimitEntitlementRulesTest method hostedVirtLimitWithHostLimitedCreatesBonusPoolsOnBind.

/*
     * Bonus pools in hosted mode for products with the host_limited attribute
     * are created during binding.
     */
@Test
public void hostedVirtLimitWithHostLimitedCreatesBonusPoolsOnBind() {
    when(config.getBoolean(ConfigProperties.STANDALONE)).thenReturn(false);
    Subscription s = createVirtLimitSub("virtLimitProduct", 10, "unlimited");
    s.getProduct().setAttribute(Product.Attributes.HOST_LIMITED, "true");
    Pool p = TestUtil.copyFromSub(s);
    when(poolManagerMock.isManaged(eq(p))).thenReturn(true);
    List<Pool> pools = poolRules.createAndEnrichPools(p, new LinkedList<>());
    assertEquals(2, pools.size());
    Pool physicalPool = pools.get(0);
    physicalPool.setId("physical");
    assertEquals(new Long(10), physicalPool.getQuantity());
    assertEquals(0, physicalPool.getAttributes().size());
    Entitlement e = new Entitlement(physicalPool, consumer, owner, 1);
    Map<String, Entitlement> entitlements = new HashMap<>();
    entitlements.put(physicalPool.getId(), e);
    Map<String, PoolQuantity> poolQuantityMap = new HashMap<>();
    poolQuantityMap.put(physicalPool.getId(), new PoolQuantity(physicalPool, 1));
    enforcer.postEntitlement(poolManagerMock, consumer, owner, entitlements, null, false, poolQuantityMap);
    verify(poolManagerMock).createPools(any(List.class));
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) HashMap(java.util.HashMap) Matchers.anyLong(org.mockito.Matchers.anyLong) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Matchers.anyString(org.mockito.Matchers.anyString) Subscription(org.candlepin.model.dto.Subscription) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 70 with PoolQuantity

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

the class HostedVirtLimitEntitlementRulesTest method hostedVirtLimitUnlimitedBonusPoolQuantity.

@Test
public void hostedVirtLimitUnlimitedBonusPoolQuantity() {
    when(config.getBoolean(ConfigProperties.STANDALONE)).thenReturn(false);
    Subscription s = createVirtLimitSub("virtLimitProduct", 10, "unlimited");
    Pool p = TestUtil.copyFromSub(s);
    when(poolManagerMock.isManaged(eq(p))).thenReturn(true);
    List<Pool> pools = poolRules.createAndEnrichPools(p, new LinkedList<>());
    assertEquals(2, pools.size());
    Pool physicalPool = pools.get(0);
    physicalPool.setId("physical");
    Pool virtBonusPool = pools.get(1);
    virtBonusPool.setId("virt");
    assertEquals(new Long(10), physicalPool.getQuantity());
    assertEquals(0, physicalPool.getAttributes().size());
    // Quantity on bonus pool should be -1:
    assertEquals(new Long(-1), virtBonusPool.getQuantity());
    assertEquals("true", virtBonusPool.getAttributeValue(Product.Attributes.VIRT_ONLY));
    assertEquals("unlimited", virtBonusPool.getProduct().getAttributeValue(Product.Attributes.VIRT_LIMIT));
    Entitlement e = new Entitlement(physicalPool, consumer, owner, 1);
    List<Pool> poolList = new ArrayList<>();
    poolList.add(virtBonusPool);
    when(poolManagerMock.lookupBySubscriptionId(eq(physicalPool.getOwner()), eq(physicalPool.getSubscriptionId()))).thenReturn(poolList);
    Map<String, Entitlement> entitlements = new HashMap<>();
    entitlements.put(physicalPool.getId(), e);
    Map<String, PoolQuantity> poolQuantityMap = new HashMap<>();
    poolQuantityMap.put(physicalPool.getId(), new PoolQuantity(physicalPool, 1));
    enforcer.postEntitlement(poolManagerMock, consumer, owner, entitlements, null, false, poolQuantityMap);
    verify(poolManagerMock, never()).updatePoolQuantity(any(Pool.class), anyInt());
    enforcer.postUnbind(consumer, poolManagerMock, e);
    verify(poolManagerMock, never()).updatePoolQuantity(any(Pool.class), anyInt());
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) HashMap(java.util.HashMap) Matchers.anyLong(org.mockito.Matchers.anyLong) ArrayList(java.util.ArrayList) Pool(org.candlepin.model.Pool) Matchers.anyString(org.mockito.Matchers.anyString) Subscription(org.candlepin.model.dto.Subscription) Entitlement(org.candlepin.model.Entitlement) 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