Search in sources :

Example 91 with Entitlement

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

the class ComplianceRulesTest method virtualSingleEntOnlyUsesVcpuAndRam.

@Test
public void virtualSingleEntOnlyUsesVcpuAndRam() {
    Consumer c = mockConsumer(PRODUCT_1);
    c.setFact("virt.is_guest", "true");
    c.setFact("cpu.core(s)_per_socket", "8");
    c.setFact("cpu.cpu_socket(s)", "10");
    // 8GB RAM
    c.setFact("memory.memtotal", "8000000");
    List<Entitlement> ents = new LinkedList<>();
    Entitlement ent = mockEntitlement(c, TestUtil.createProduct("Awesome Product"), PRODUCT_1);
    ent.getPool().getProduct().setAttribute(Product.Attributes.CORES, "1");
    ent.getPool().getProduct().setAttribute(Product.Attributes.RAM, "1");
    ent.getPool().getProduct().setAttribute(Product.Attributes.SOCKETS, "1");
    ent.getPool().getProduct().setAttribute(Product.Attributes.VCPU, "1");
    ents.add(ent);
    ents.get(0).setQuantity(1);
    mockEntCurator(c, ents);
    ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30));
    assertEquals(ComplianceStatus.YELLOW, status.getStatus());
    assertEquals(0, status.getNonCompliantProducts().size());
    assertEquals(1, status.getPartiallyCompliantProducts().size());
    assertEquals(0, status.getCompliantProducts().size());
    assertTrue(status.getPartiallyCompliantProducts().keySet().contains(PRODUCT_1.getId()));
    // We should be partial because of ram and vcpus, nothing else
    assertEquals(2, status.getReasons().size());
    List<String> reasonKeys = new LinkedList<>();
    for (ComplianceReason r : status.getReasons()) {
        reasonKeys.add(r.getKey());
    }
    assertTrue(reasonKeys.contains("RAM"));
    assertTrue(reasonKeys.contains("VCPU"));
}
Also used : Consumer(org.candlepin.model.Consumer) Entitlement(org.candlepin.model.Entitlement) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 92 with Entitlement

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

the class ComplianceRulesTest method fullyCompliantVirtLimitStackWithInactiveGuests.

@Test
public void fullyCompliantVirtLimitStackWithInactiveGuests() {
    Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2);
    for (int i = 0; i < 5; i++) {
        c.addGuestId(new GuestId("" + i, c));
    }
    List<Entitlement> ents = new LinkedList<>();
    ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    for (Entitlement ent : ents) {
        ent.getPool().getProduct().setAttribute(Product.Attributes.GUEST_LIMIT, "4");
    }
    mockEntCurator(c, ents);
    ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30));
    assertEquals(0, status.getNonCompliantProducts().size());
    assertEquals(0, status.getPartiallyCompliantProducts().size());
    assertEquals(2, status.getCompliantProducts().size());
    assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId()));
    assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_2.getId()));
    assertEquals(4, status.getCompliantProducts().get(PRODUCT_1.getId()).size());
    assertEquals(4, status.getCompliantProducts().get(PRODUCT_2.getId()).size());
}
Also used : Consumer(org.candlepin.model.Consumer) GuestId(org.candlepin.model.GuestId) Entitlement(org.candlepin.model.Entitlement) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 93 with Entitlement

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

the class ComplianceRulesTest method regularEntsBothLackingSocketCoverage.

/*
     * Test an installed product with two normal non-stacked entitlements, both of which
     * do not provide enough sockets for the system. Note that these entitlements
     * are not stacked together.
     */
@Test
public void regularEntsBothLackingSocketCoverage() {
    // Consumer with 8 sockets:
    Consumer c = mockConsumer(PRODUCT_1);
    List<Entitlement> ents = new LinkedList<>();
    // One entitlement that only provides four sockets:
    ents.add(mockEntitlement(c, TestUtil.createProduct("Awesome Product"), PRODUCT_1));
    ents.get(0).getPool().getProduct().setAttribute(Product.Attributes.SOCKETS, "4");
    // One entitlement that provides 6 sockets:
    ents.add(mockEntitlement(c, TestUtil.createProduct("Awesome Product"), PRODUCT_1));
    ents.get(1).getPool().getProduct().setAttribute(Product.Attributes.SOCKETS, "6");
    mockEntCurator(c, ents);
    ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30));
    assertEquals(0, status.getNonCompliantProducts().size());
    assertEquals(1, status.getPartiallyCompliantProducts().size());
    assertEquals(0, status.getCompliantProducts().size());
    assertEquals(0, status.getPartialStacks().size());
    assertTrue(status.getPartiallyCompliantProducts().keySet().contains(PRODUCT_1.getId()));
}
Also used : Consumer(org.candlepin.model.Consumer) Entitlement(org.candlepin.model.Entitlement) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 94 with Entitlement

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

the class ComplianceRulesTest method fullyCompliantVirtLimitStackAllUnlimited.

@Test
public void fullyCompliantVirtLimitStackAllUnlimited() {
    Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2);
    for (int i = 0; i < 5; i++) {
        c.addGuestId(new GuestId("" + i, c, activeGuestAttrs));
    }
    List<Entitlement> ents = new LinkedList<>();
    ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    for (Entitlement ent : ents) {
        ent.getPool().getProduct().setAttribute(Product.Attributes.GUEST_LIMIT, "-1");
    }
    mockEntCurator(c, ents);
    ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30));
    assertEquals(0, status.getNonCompliantProducts().size());
    assertEquals(2, status.getCompliantProducts().size());
    assertEquals(0, status.getPartiallyCompliantProducts().size());
    assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId()));
    assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_2.getId()));
    assertEquals(4, status.getCompliantProducts().get(PRODUCT_1.getId()).size());
    assertEquals(4, status.getCompliantProducts().get(PRODUCT_2.getId()).size());
}
Also used : Consumer(org.candlepin.model.Consumer) GuestId(org.candlepin.model.GuestId) Entitlement(org.candlepin.model.Entitlement) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 95 with Entitlement

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

the class ComplianceRulesTest method compliantStack.

// Test a fully stacked scenario:
@Test
public void compliantStack() {
    Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2);
    List<Entitlement> ents = new LinkedList<>();
    ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    ents.add(mockStackedEntitlement(c, STACK_ID_1, TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
    mockEntCurator(c, ents);
    ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30));
    assertEquals(0, status.getNonCompliantProducts().size());
    assertEquals(0, status.getPartiallyCompliantProducts().size());
    assertEquals(2, status.getCompliantProducts().size());
    assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId()));
    assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_2.getId()));
    assertEquals(4, status.getCompliantProducts().get(PRODUCT_1.getId()).size());
    assertEquals(4, status.getCompliantProducts().get(PRODUCT_2.getId()).size());
}
Also used : Consumer(org.candlepin.model.Consumer) Entitlement(org.candlepin.model.Entitlement) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

Entitlement (org.candlepin.model.Entitlement)301 Test (org.junit.Test)201 Consumer (org.candlepin.model.Consumer)164 Pool (org.candlepin.model.Pool)125 LinkedList (java.util.LinkedList)84 Product (org.candlepin.model.Product)68 Date (java.util.Date)62 ArrayList (java.util.ArrayList)61 HashSet (java.util.HashSet)59 HashMap (java.util.HashMap)55 Owner (org.candlepin.model.Owner)44 PoolQuantity (org.candlepin.model.PoolQuantity)35 ConsumerType (org.candlepin.model.ConsumerType)34 List (java.util.List)30 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)24 Matchers.anyString (org.mockito.Matchers.anyString)17 Set (java.util.Set)16 Subscription (org.candlepin.model.dto.Subscription)16 ApiOperation (io.swagger.annotations.ApiOperation)15 ApiResponses (io.swagger.annotations.ApiResponses)15