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());
}
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());
}
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));
}
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));
}
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());
}
Aggregations