use of org.candlepin.resource.dto.AutobindData in project candlepin by candlepin.
the class PoolManagerFunctionalTest method testRegenerateEntitlementCertificatesWithSingleEntitlement.
@Test
public void testRegenerateEntitlementCertificatesWithSingleEntitlement() throws Exception {
AutobindData data = AutobindData.create(childVirtSystem, o).on(new Date()).forProducts(new String[] { provisioning.getId() });
this.entitlementCurator.refresh(poolManager.entitleByProducts(data).get(0));
regenerateECAndAssertNotSameCertificates();
}
use of org.candlepin.resource.dto.AutobindData in project candlepin by candlepin.
the class ConsumerResource method revokeOnGuestMigration.
/*
* Check if this consumer is a guest, and if it appears to have migrated.
* We only check for existing entitlements, restricted to a host that does not match
* the guest's current host, as determined by the most recent guest ID report in the
* db. If autobind has been disabled for the guest's owner, the host_restricted entitlements
* from the old host are still removed, but no auto-bind occurs.
*/
protected void revokeOnGuestMigration(Consumer guest) {
if (guest == null || !guest.isGuest() || !guest.hasFact("virt.uuid")) {
// No consumer provided, it's not a guest or it doesn't have a virt UUID
return;
}
Consumer host = consumerCurator.getHost(guest);
// we need to create a list of entitlements to delete before actually
// deleting, otherwise we are tampering with the loop iterator (BZ #786730)
Set<Entitlement> deletableGuestEntitlements = new HashSet<>();
log.debug("Revoking {} entitlements not matching host: {}", guest, host);
for (Entitlement entitlement : guest.getEntitlements()) {
Pool pool = entitlement.getPool();
// virt-only then the host-guest dynamic doesn't apply, so skip it.
if (!pool.hasAttribute(Pool.Attributes.REQUIRES_HOST) && !pool.isUnmappedGuestPool() && !isVirtOnly(pool)) {
continue;
}
if (pool.hasAttribute(Pool.Attributes.REQUIRES_HOST)) {
String requiredHost = getRequiredHost(pool);
if (host != null && !requiredHost.equals(host.getUuid())) {
log.debug("Removing entitlement {} from guest {} due to host mismatch.", entitlement.getId(), guest.getUuid());
deletableGuestEntitlements.add(entitlement);
}
} else if (pool.isUnmappedGuestPool() && host != null) {
log.debug("Removing unmapped guest pool from {} now that it is mapped", guest.getUuid());
deletableGuestEntitlements.add(entitlement);
}
}
// perform the entitlement revocation
for (Entitlement entitlement : deletableGuestEntitlements) {
poolManager.revokeEntitlement(entitlement);
}
if (deletableGuestEntitlements.size() > 0) {
// auto heal guests after revocations
boolean hasInstalledProducts = guest.getInstalledProducts() != null && !guest.getInstalledProducts().isEmpty();
if (guest.isAutoheal() && !deletableGuestEntitlements.isEmpty() && hasInstalledProducts) {
Owner owner = ownerCurator.findOwnerById(guest.getOwnerId());
AutobindData autobindData = AutobindData.create(guest, owner).on(new Date());
// perform the autobind for the guest.
try {
List<Entitlement> ents = entitler.bindByProducts(autobindData);
entitler.sendEvents(ents);
} catch (AutobindDisabledForOwnerException e) {
log.warn("Guest auto-attach skipped. {}", e.getMessage());
}
}
}
}
use of org.candlepin.resource.dto.AutobindData in project candlepin by candlepin.
the class Entitler method bindByProducts.
public List<Entitlement> bindByProducts(String[] productIds, String consumeruuid, Date entitleDate, Collection<String> fromPools) throws AutobindDisabledForOwnerException {
Consumer c = consumerCurator.findByUuid(consumeruuid);
Owner o = ownerCurator.findOwnerById(c.getOwnerId());
AutobindData data = AutobindData.create(c, o).on(entitleDate).forProducts(productIds).withPools(fromPools);
return bindByProducts(data);
}
use of org.candlepin.resource.dto.AutobindData in project candlepin by candlepin.
the class ConsumerResourceTest method futureHealing.
@Test
public void futureHealing() throws Exception {
Owner o = createOwner();
o.setId(TestUtil.randomString());
Consumer c = createConsumer(o);
SubscriptionServiceAdapter sa = mock(SubscriptionServiceAdapter.class);
Entitler e = mock(Entitler.class);
ConsumerCurator cc = mock(ConsumerCurator.class);
ConsumerInstalledProduct cip = mock(ConsumerInstalledProduct.class);
Set<ConsumerInstalledProduct> products = new HashSet<>();
products.add(cip);
when(mockOwnerCurator.findOwnerById(eq(o.getId()))).thenReturn(o);
when(cip.getProductId()).thenReturn("product-foo");
when(sa.hasUnacceptedSubscriptionTerms(eq(o))).thenReturn(false);
when(cc.verifyAndLookupConsumerWithEntitlements(eq(c.getUuid()))).thenReturn(c);
ConsumerResource cr = new ConsumerResource(cc, mockConsumerTypeCurator, null, sa, this.mockOwnerServiceAdapter, null, null, null, null, null, null, null, null, null, null, null, mockOwnerCurator, null, e, null, null, null, null, this.config, null, null, null, consumerBindUtil, null, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
String dtStr = "2011-09-26T18:10:50.184081+00:00";
Date dt = ResourceDateParser.parseDateString(dtStr);
cr.bind(c.getUuid(), null, null, null, null, null, false, dtStr, null);
AutobindData data = AutobindData.create(c, o).on(dt);
verify(e).bindByProducts(eq(data));
}
use of org.candlepin.resource.dto.AutobindData in project candlepin by candlepin.
the class ConsumerBindUtilTest method registerWithKeyWithPoolAndInstalledProductsAutoAttach.
@Test
public void registerWithKeyWithPoolAndInstalledProductsAutoAttach() throws Exception {
Product prod = TestUtil.createProduct();
String[] prodIds = new String[] { prod.getId() };
Pool pool = TestUtil.createPool(owner, prod);
pool.setId("id-string");
List<String> poolIds = new ArrayList<>();
poolIds.add(pool.getId());
List<ActivationKey> keys = new ArrayList<>();
ActivationKey key1 = new ActivationKey("key1", owner);
keys.add(key1);
key1.addPool(pool, 0L);
key1.setAutoAttach(true);
Consumer consumer = new Consumer("sys.example.com", null, null, system);
Set<ConsumerInstalledProduct> cips = new HashSet<>();
ConsumerInstalledProduct cip = new ConsumerInstalledProduct(consumer, prod);
cips.add(cip);
consumer.setInstalledProducts(cips);
AutobindData ad = new AutobindData(consumer, owner).withPools(poolIds).forProducts(prodIds);
consumerBindUtil.handleActivationKeys(consumer, keys, false);
verify(entitler).bindByProducts(eq(ad));
}
Aggregations