use of org.candlepin.model.ConsumerCapability in project candlepin by candlepin.
the class ManifestEntitlementRulesTest method preEntitlementNoCoreCapableBindError.
@Test
public void preEntitlementNoCoreCapableBindError() {
// Test with sockets to make sure that they are skipped.
Consumer c = this.createMockConsumer(true);
c.setFact("cpu.core(s)_per_socket", "2");
Set<ConsumerCapability> caps = new HashSet<>();
c.setCapabilities(caps);
Product prod = TestUtil.createProduct();
prod.setAttribute(Product.Attributes.CORES, "2");
Pool p = TestUtil.createPool(prod);
p.setId("poolId");
ValidationResult results = enforcer.preEntitlement(c, p, 1, CallerType.BIND);
assertNotNull(results);
assertEquals(0, results.getWarnings().size());
ValidationError error = results.getErrors().get(0);
assertEquals("rulefailed.cores.unsupported.by.consumer", error.getResourceKey());
}
use of org.candlepin.model.ConsumerCapability in project candlepin by candlepin.
the class ManifestEntitlementRulesTest method preEntitlementNoRamCapableListWarn.
@Test
public void preEntitlementNoRamCapableListWarn() {
// Test with sockets to make sure that they are skipped.
Consumer c = this.createMockConsumer(true);
c.setFact("memory.memtotal", "2000000");
Set<ConsumerCapability> caps = new HashSet<>();
c.setCapabilities(caps);
Product prod = TestUtil.createProduct();
prod.setAttribute(Product.Attributes.RAM, "2");
Pool p = TestUtil.createPool(prod);
p.setId("poolId");
ValidationResult results = enforcer.preEntitlement(c, p, 1, CallerType.LIST_POOLS);
assertNotNull(results);
assertEquals(0, results.getErrors().size());
ValidationWarning warning = results.getWarnings().get(0);
assertEquals("rulewarning.ram.unsupported.by.consumer", warning.getResourceKey());
}
use of org.candlepin.model.ConsumerCapability in project candlepin by candlepin.
the class ConsumerTranslatorTest method initSourceObject.
@Override
protected Consumer initSourceObject() {
ConsumerType ctype = this.consumerTypeTranslatorTest.initSourceObject();
Environment environment = this.environmentTranslatorTest.initSourceObject();
Owner owner = this.ownerTranslatorTest.initSourceObject();
when(mockOwnerCurator.findOwnerById(eq(owner.getId()))).thenReturn(owner);
Consumer consumer = new Consumer();
consumer.setId("consumer_id");
consumer.setUuid("consumer_uuid");
consumer.setName("consumer_name");
consumer.setUsername("consumer_user_name");
consumer.setEntitlementStatus("consumer_ent_status");
consumer.setServiceLevel("consumer_service_level");
consumer.setReleaseVer(new Release("releaseVer"));
consumer.setOwner(owner);
consumer.setEnvironment(environment);
consumer.setEntitlementCount(0L);
consumer.setLastCheckin(new Date());
consumer.setCanActivate(Boolean.TRUE);
consumer.setHypervisorId(hypervisorIdTranslatorTest.initSourceObject());
consumer.setAutoheal(Boolean.TRUE);
consumer.setRecipientOwnerKey("test_recipient_owner_key");
consumer.setAnnotations("test_annotations");
consumer.setContentAccessMode("test_content_access_mode");
consumer.setIdCert((IdentityCertificate) this.certificateTranslatorTest.initSourceObject());
consumer.setType(ctype);
Map<String, String> facts = new HashMap<>();
for (int i = 0; i < 5; ++i) {
facts.put("fact-" + i, "value-" + i);
}
consumer.setFacts(facts);
Set<ConsumerInstalledProduct> installedProducts = new HashSet<>();
for (int i = 0; i < 5; ++i) {
ConsumerInstalledProduct installedProduct = cipTranslatorTest.initSourceObject();
installedProduct.setId("installedProduct-" + i);
installedProducts.add(installedProduct);
}
consumer.setInstalledProducts(installedProducts);
Set<ConsumerCapability> capabilities = new HashSet<>();
for (int i = 0; i < 5; ++i) {
ConsumerCapability capability = capabilityTranslatorTest.initSourceObject();
capability.setName("capability-" + i);
capabilities.add(capability);
}
consumer.setCapabilities(capabilities);
Set<String> contentTags = new HashSet<>();
for (int i = 0; i < 5; ++i) {
contentTags.add("contentTag-" + i);
}
consumer.setContentTags(contentTags);
List<GuestId> guestIds = new LinkedList<>();
for (int i = 0; i < 5; ++i) {
GuestId guestId = guestIdTranslatorTest.initSourceObject();
guestId.setId("guestId-" + i);
guestIds.add(guestId);
}
consumer.setGuestIds(guestIds);
when(mockConsumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
when(mockConsumerTypeCurator.getConsumerType(eq(consumer))).thenReturn(ctype);
when(mockEnvironmentCurator.find(eq(environment.getId()))).thenReturn(environment);
when(mockEnvironmentCurator.getConsumerEnvironment(eq(consumer))).thenReturn(environment);
return consumer;
}
use of org.candlepin.model.ConsumerCapability in project candlepin by candlepin.
the class DefaultEntitlementCertServiceAdapter method shouldGenerateV3.
/**
* Checks if the specified consumer is capable of using v3 certificates
*
* @param consumer
* The consumer to check
*
* @return
* true if the consumer should use v3 certificates; false otherwise
*/
private boolean shouldGenerateV3(Consumer consumer) {
if (consumer != null) {
ConsumerType type = this.consumerTypeCurator.getConsumerType(consumer);
if (type.isManifest()) {
for (ConsumerCapability capability : consumer.getCapabilities()) {
if ("cert_v3".equals(capability.getName())) {
return true;
}
}
return false;
} else if (type.isType(ConsumerTypeEnum.HYPERVISOR)) {
// Hypervisors in this context don't use content, so V3 is allowed
return true;
}
// Consumer isn't a special type, check their certificate_version fact
String entitlementVersion = consumer.getFact("system.certificate_version");
return entitlementVersion != null && entitlementVersion.startsWith("3.");
}
return false;
}
use of org.candlepin.model.ConsumerCapability in project candlepin by candlepin.
the class ConsumerResource method updateCapabilities.
/**
* @param existing
* @param update
* @return a String object
*/
private boolean updateCapabilities(Consumer existing, ConsumerDTO update) {
boolean change = false;
if (update == null) {
// create
if ((existing.getCapabilities() == null || existing.getCapabilities().isEmpty()) && existing.getFact("distributor_version") != null) {
Set<DistributorVersionCapability> capabilities = distributorVersionCurator.findCapabilitiesByDistVersion(existing.getFact("distributor_version"));
if (capabilities != null) {
Set<ConsumerCapability> ccaps = new HashSet<>();
for (DistributorVersionCapability dvc : capabilities) {
ConsumerCapability cc = new ConsumerCapability(existing, dvc.getName());
ccaps.add(cc);
}
existing.setCapabilities(ccaps);
}
change = true;
}
} else {
// update
if (update.getCapabilities() != null) {
Set<ConsumerCapability> entityCapabilities = populateCapabilities(existing, update);
if (!entityCapabilities.equals(existing.getCapabilities())) {
existing.setCapabilities(entityCapabilities);
change = true;
}
} else if (update.getFact("distributor_version") != null) {
DistributorVersion dv = distributorVersionCurator.findByName(update.getFact("distributor_version"));
if (dv != null) {
Set<ConsumerCapability> ccaps = new HashSet<>();
for (DistributorVersionCapability dvc : dv.getCapabilities()) {
ConsumerCapability cc = new ConsumerCapability(existing, dvc.getName());
ccaps.add(cc);
}
existing.setCapabilities(ccaps);
}
change = true;
}
}
if (change) {
log.debug("Capabilities changed.");
} else {
log.debug("Capability list either null or does not contain changes.");
}
return change;
}
Aggregations