use of org.candlepin.model.GuestId in project candlepin by candlepin.
the class ConsumerResourceUpdateTest method testUpdateConsumerUpdatesGuestIds.
@Test
public void testUpdateConsumerUpdatesGuestIds() {
String uuid = "TEST_CONSUMER";
String[] existingGuests = new String[] { "Guest 1", "Guest 2", "Guest 3" };
Consumer existing = createConsumerWithGuests(createOwner(), existingGuests);
existing.setUuid(uuid);
when(this.consumerCurator.verifyAndLookupConsumer(uuid)).thenReturn(existing);
ConsumerDTO updated = new ConsumerDTO();
updated.setUuid(uuid);
GuestIdDTO expectedGuestId = TestUtil.createGuestIdDTO("Guest 2");
updated.addGuestId(expectedGuestId);
when(this.consumerCurator.getGuestConsumersMap(any(String.class), any(Set.class))).thenReturn(new VirtConsumerMap());
this.resource.updateConsumer(existing.getUuid(), updated, principal);
assertEquals(1, existing.getGuestIds().size());
GuestId actualGID = existing.getGuestIds().iterator().next();
assertNotNull(actualGID);
assertEquals(actualGID.getGuestId(), expectedGuestId.getGuestId());
assertEquals(actualGID.getAttributes(), expectedGuestId.getAttributes());
}
use of org.candlepin.model.GuestId in project candlepin by candlepin.
the class AutobindRulesTest method guestLimitAutobindNeitherAttached.
/*
* Expect nothing to happen. We cannot bind the hypervisor in order to make
* the guests compliant, but that'd be a nice feature in the future.
*/
@Test
public void guestLimitAutobindNeitherAttached() {
consumer.setFact("cpu.cpu_socket(s)", "8");
for (int i = 0; i < 5; i++) {
consumer.addGuestId(new GuestId("" + i, consumer, activeGuestAttrs));
}
Product server = mockStackingProduct(productId, "some server", "stackid1", "2");
server.setAttribute(Product.Attributes.GUEST_LIMIT, "4");
Product hypervisor = mockStackingProduct("hypervisor", "some hypervisor", "stackid2", "2");
hypervisor.setAttribute(Product.Attributes.GUEST_LIMIT, "-1");
Pool serverPool = TestUtil.createPool(owner, server, 10);
Pool hyperPool = TestUtil.createPool(owner, hypervisor, 10);
serverPool.setId("POOL-ID1");
hyperPool.setId("Pool-ID2");
List<Pool> pools = new LinkedList<>();
pools.add(serverPool);
pools.add(hyperPool);
assertEquals(0, autobindRules.selectBestPools(consumer, new String[] { server.getUuid() }, pools, compliance, null, new HashSet<>(), false).size());
}
use of org.candlepin.model.GuestId in project candlepin by candlepin.
the class GuestIdResourceTest method getGuestId.
@Test
public void getGuestId() {
when(guestIdCurator.findByConsumerAndId(eq(consumer), any(String.class))).thenReturn(new GuestId("guest"));
GuestIdDTO result = guestIdResource.getGuestId(consumer.getUuid(), "some-id");
assertEquals(TestUtil.createGuestIdDTO("guest"), result);
}
use of org.candlepin.model.GuestId in project candlepin by candlepin.
the class GuestIdResourceTest method deleteGuestAndUnregister.
@Test
public void deleteGuestAndUnregister() {
Consumer guestConsumer = new Consumer("guest_consumer", "guest_consumer", owner, ct);
GuestId guest = new GuestId("guest-id", consumer);
when(guestIdCurator.findByConsumerAndId(eq(consumer), eq(guest.getGuestId()))).thenReturn(guest);
when(consumerCurator.findByVirtUuid(guest.getGuestId(), consumer.getOwnerId())).thenReturn(guestConsumer);
guestIdResource.deleteGuest(consumer.getUuid(), guest.getGuestId(), true, null);
Mockito.verify(guestIdCurator, Mockito.times(1)).delete(eq(guest));
Mockito.verify(consumerResource, Mockito.never()).checkForMigration(eq(consumer), eq(guestConsumer));
Mockito.verify(consumerResource, Mockito.times(1)).deleteConsumer(eq(guestConsumer.getUuid()), any(Principal.class));
}
use of org.candlepin.model.GuestId in project candlepin by candlepin.
the class GuestIdResourceTest method updateGuestRevokeHostSpecific.
@Test
public void updateGuestRevokeHostSpecific() {
Consumer guestConsumer = new Consumer("guest_consumer", "guest_consumer", owner, ct);
GuestId originalGuest = new GuestId("guest-id", guestConsumer);
GuestIdDTO guest = TestUtil.createGuestIdDTO("guest-id");
when(guestIdCurator.findByGuestIdAndOrg(eq(guest.getGuestId()), eq(owner.getId()))).thenReturn(originalGuest);
when(consumerCurator.findByVirtUuid(eq(guest.getGuestId()), eq(owner.getId()))).thenReturn(guestConsumer);
guestIdResource.updateGuest(consumer.getUuid(), guest.getGuestId(), guest);
ArgumentCaptor<GuestId> captor = ArgumentCaptor.forClass(GuestId.class);
Mockito.verify(guestIdCurator, Mockito.times(1)).merge(captor.capture());
GuestId guestId = captor.getValue();
assertEquals("guest-id", guestId.getGuestId());
// We now check for migration when the system checks in, not during guest ID updates.
Mockito.verify(consumerResource, Mockito.times(0)).checkForMigration(any(Consumer.class), any(Consumer.class));
}
Aggregations