コード例 #1
0
  @Test
  public void hypervisorCheckInReportsFailureWhenGuestIdUpdateFails() throws Exception {
    Owner owner = new Owner("admin");

    Map<String, List<GuestId>> hostGuestMap = new HashMap<String, List<GuestId>>();
    String expectedHostVirtId = "test-host";
    hostGuestMap.put(expectedHostVirtId, Arrays.asList(new GuestId("GUEST_B")));

    Consumer existing = new Consumer();
    existing.setUuid(expectedHostVirtId);
    existing.addGuestId(new GuestId("GUEST_A"));

    // Force update
    when(consumerCurator.findByUuid(eq(expectedHostVirtId))).thenReturn(existing);

    String expectedMessage = "Forced Exception.";
    RuntimeException exception = new RuntimeException(expectedMessage);
    // Simulate failure  when checking the owner
    when(consumerCurator.getHost(any(String.class))).thenThrow(exception);

    HypervisorCheckInResult result =
        hypervisorResource.hypervisorCheckIn(hostGuestMap, principal, owner.getKey());

    Set<String> failures = result.getFailedUpdate();
    assertEquals(1, failures.size());
    assertEquals(expectedHostVirtId + ": " + expectedMessage, failures.iterator().next());
  }
コード例 #2
0
  @Test
  public void hypervisorCheckInUpdatesGuestIdsWhenHostConsumerExists() throws Exception {
    Owner owner = new Owner("admin");

    Map<String, List<GuestId>> hostGuestMap = new HashMap<String, List<GuestId>>();
    hostGuestMap.put("test-host", Arrays.asList(new GuestId("GUEST_B")));

    Owner o = new Owner();
    o.setId("owner-id");
    Consumer existing = new Consumer();
    existing.setUuid("test-host");
    existing.setOwner(o);
    existing.addGuestId(new GuestId("GUEST_A"));

    when(consumerCurator.findByUuid(eq("test-host"))).thenReturn(existing);

    HypervisorCheckInResult result =
        hypervisorResource.hypervisorCheckIn(hostGuestMap, principal, owner.getKey());
    Set<Consumer> updated = result.getUpdated();
    assertEquals(1, updated.size());

    Consumer c1 = updated.iterator().next();
    assertEquals("test-host", c1.getUuid());
    assertEquals(1, c1.getGuestIds().size());
    assertEquals("GUEST_B", c1.getGuestIds().get(0).getGuestId());
  }
コード例 #3
0
ファイル: EventBuilder.java プロジェクト: rnovacek/candlepin
 private void setEventData(AbstractHibernateObject entity) {
   // Be careful to check for null before setting so we don't overwrite anything useful
   if (entity instanceof Named && ((Named) entity).getName() != null) {
     event.setTargetName(((Named) entity).getName());
   }
   if (entity instanceof Owned) {
     Owner entityOwner = ((Owned) entity).getOwner();
     if (entityOwner != null && entityOwner.getId() != null) {
       event.setOwnerId(entityOwner.getId());
     }
   }
   if (entity instanceof Entitlement) {
     event.setReferenceType(Event.ReferenceType.POOL);
     Pool referencedPool = ((Entitlement) entity).getPool();
     if (referencedPool != null && referencedPool.getId() != null) {
       event.setReferenceId(referencedPool.getId());
     }
   }
   if ((String) entity.getId() != null) {
     event.setEntityId((String) entity.getId());
     if (entity instanceof ConsumerProperty) {
       Consumer owningConsumer = ((ConsumerProperty) entity).getConsumer();
       if (owningConsumer != null && owningConsumer.getId() != null) {
         event.setConsumerId(owningConsumer.getId());
       }
     }
   }
 }
コード例 #4
0
  @Test
  public void hypervisorCheckInCreatesNewConsumer() throws Exception {
    Owner owner = new Owner("admin");

    Map<String, List<GuestId>> hostGuestMap = new HashMap<String, List<GuestId>>();
    hostGuestMap.put("test-host", Arrays.asList(new GuestId("GUEST_A"), new GuestId("GUEST_B")));

    when(consumerCurator.findByUuid(eq("test-host"))).thenReturn(null);
    when(ownerCurator.lookupByKey(eq(owner.getKey()))).thenReturn(owner);
    when(principal.canAccess(eq(owner), eq(Access.ALL))).thenReturn(true);
    when(consumerTypeCurator.lookupByLabel(eq(ConsumerTypeEnum.HYPERVISOR.getLabel())))
        .thenReturn(hypervisorType);
    when(idCertService.generateIdentityCert(any(Consumer.class)))
        .thenReturn(new IdentityCertificate());

    HypervisorCheckInResult result =
        hypervisorResource.hypervisorCheckIn(hostGuestMap, principal, owner.getKey());

    Set<Consumer> created = result.getCreated();
    assertEquals(1, created.size());

    Consumer c1 = created.iterator().next();
    assertEquals("test-host", c1.getUuid());
    assertEquals(2, c1.getGuestIds().size());
    assertEquals("GUEST_A", c1.getGuestIds().get(0).getGuestId());
    assertEquals("GUEST_B", c1.getGuestIds().get(1).getGuestId());
    assertEquals("x86_64", c1.getFact("uname.machine"));
    assertEquals("hypervisor", c1.getType().getLabel());
  }
コード例 #5
0
  @Test(expected = NotFoundException.class)
  public void certificateRetrievalRaisesExceptionIfNoCertificateWasGenerated() throws Exception {
    // generate certificate for one owner
    or.createUeberCertificate(principal, owner.getKey());

    // verify that owner under test doesn't have a certificate
    Owner anotherOwner = ownerCurator.create(new Owner(OWNER_NAME + "1"));
    or.getUeberCertificate(principal, anotherOwner.getKey());
  }
コード例 #6
0
  @Test(expected = BadRequestException.class)
  public void testCreatePersonConsumerWithActivationKey() {
    Consumer c = mock(Consumer.class);
    Owner o = mock(Owner.class);
    ActivationKey ak = mock(ActivationKey.class);
    NoAuthPrincipal nap = mock(NoAuthPrincipal.class);
    ActivationKeyCurator akc = mock(ActivationKeyCurator.class);
    OwnerCurator oc = mock(OwnerCurator.class);
    ConsumerTypeCurator ctc = mock(ConsumerTypeCurator.class);
    ConsumerContentOverrideCurator ccoc = mock(ConsumerContentOverrideCurator.class);

    ConsumerType cType = new ConsumerType(ConsumerTypeEnum.PERSON);
    when(ak.getId()).thenReturn("testKey");
    when(o.getKey()).thenReturn("testOwner");
    when(akc.lookupForOwner(eq("testKey"), eq(o))).thenReturn(ak);
    when(oc.lookupByKey(eq("testOwner"))).thenReturn(o);
    when(c.getType()).thenReturn(cType);
    when(c.getName()).thenReturn("testConsumer");
    when(ctc.lookupByLabel(eq("person"))).thenReturn(cType);

    ConsumerResource cr =
        new ConsumerResource(
            null,
            ctc,
            null,
            null,
            null,
            null,
            null,
            i18n,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            oc,
            akc,
            null,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            consumerBindUtil,
            productCurator,
            null);
    cr.create(c, nap, null, "testOwner", "testKey", true);
  }
コード例 #7
0
  @Test
  public void testUeberCertIsRegeneratedOnNextInvocation() throws Exception {
    EntitlementCertificate firstCert = or.createUeberCertificate(principal, owner.getKey());
    Product firstProduct = productCurator.lookupByName(owner, owner.getKey() + UEBER_PRODUCT);

    EntitlementCertificate secondCert = or.createUeberCertificate(principal, owner.getKey());
    Product secondProduct = productCurator.lookupByName(owner, owner.getKey() + UEBER_PRODUCT);

    // make sure we didn't regenerate the whole thing
    assertTrue(firstProduct.getUuid() == secondProduct.getUuid());
    // only the ueber cert
    assertFalse(firstCert.getId() == secondCert.getId());
  }
コード例 #8
0
  @Test(expected = NotFoundException.class)
  public void testNullPerson() {
    Consumer c = mock(Consumer.class);
    Owner o = mock(Owner.class);
    UserServiceAdapter usa = mock(UserServiceAdapter.class);
    UserPrincipal up = mock(UserPrincipal.class);
    OwnerCurator oc = mock(OwnerCurator.class);
    ConsumerTypeCurator ctc = mock(ConsumerTypeCurator.class);
    ConsumerType cType = new ConsumerType(ConsumerTypeEnum.PERSON);

    when(o.getKey()).thenReturn("testOwner");
    when(oc.lookupByKey(eq("testOwner"))).thenReturn(o);
    when(c.getType()).thenReturn(cType);
    when(c.getName()).thenReturn("testConsumer");
    when(ctc.lookupByLabel(eq("person"))).thenReturn(cType);
    when(up.canAccess(eq(o), eq(SubResource.CONSUMERS), eq(Access.CREATE))).thenReturn(true);
    // usa.findByLogin() will return null by default no need for a when

    ConsumerResource cr =
        new ConsumerResource(
            null,
            ctc,
            null,
            null,
            null,
            null,
            null,
            i18n,
            null,
            null,
            null,
            null,
            usa,
            null,
            null,
            oc,
            null,
            null,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            consumerBindUtil,
            productCurator,
            null);
    cr.create(c, up, null, "testOwner", null, true);
  }
コード例 #9
0
ファイル: PoolTest.java プロジェクト: bcrochet/candlepin
 @Test
 public void testCreate() {
   Pool lookedUp = entityManager().find(Pool.class, pool.getId());
   assertNotNull(lookedUp);
   assertEquals(owner.getId(), lookedUp.getOwner().getId());
   assertEquals(prod1.getId(), lookedUp.getProductId());
   assertTrue(lookedUp.provides(prod1.getId()));
 }
コード例 #10
0
ファイル: ConsumerImporter.java プロジェクト: beav/candlepin
  public void store(Owner owner, ConsumerDto consumer, ConflictOverrides forcedConflicts)
      throws SyncDataFormatException {

    if (consumer.getUuid() == null) {
      throw new SyncDataFormatException(i18n.tr("No ID for upstream distributor"));
    }

    // Make sure no other owner is already using this upstream UUID:
    Owner alreadyUsing = curator.lookupWithUpstreamUuid(consumer.getUuid());
    if (alreadyUsing != null && !alreadyUsing.getKey().equals(owner.getKey())) {
      log.error("Cannot import manifest for org: " + owner.getKey());
      log.error(
          "Upstream distributor "
              + consumer.getUuid()
              + " already in use by org: "
              + alreadyUsing.getKey());

      // NOTE: this is not a conflict that can be overridden because we simply don't
      // allow two orgs to use the same manifest at once. The other org would have to
      // delete their manifest after which it could be used elsewhere.
      throw new SyncDataFormatException(
          i18n.tr("This distributor has already been imported by another owner"));
    }

    if (owner.getUpstreamUuid() != null && !owner.getUpstreamUuid().equals(consumer.getUuid())) {
      if (!forcedConflicts.isForced(Importer.Conflict.DISTRIBUTOR_CONFLICT)) {
        throw new ImportConflictException(
            i18n.tr("Owner has already imported from another distributor"),
            Importer.Conflict.DISTRIBUTOR_CONFLICT);
      } else {
        log.warn("Forcing import from a new distributor for org: " + owner.getKey());
        log.warn("Old distributor UUID: " + owner.getUpstreamUuid());
        log.warn("New distributor UUID: " + consumer.getUuid());
      }
    }

    owner.setUpstreamUuid(consumer.getUuid());
    curator.merge(owner);
  }
コード例 #11
0
  @Test
  public void hypervisorCheckInReportsFailuresOnCreateFailure() {
    Owner owner = new Owner("admin");

    Map<String, List<GuestId>> hostGuestMap = new HashMap<String, List<GuestId>>();
    String expectedHostVirtId = "test-host-id";
    hostGuestMap.put(
        expectedHostVirtId, Arrays.asList(new GuestId("GUEST_A"), new GuestId("GUEST_B")));

    // Force create.
    when(consumerCurator.findByUuid(eq(expectedHostVirtId))).thenReturn(null);

    String expectedMessage = "Forced Exception.";
    RuntimeException exception = new RuntimeException(expectedMessage);
    // Simulate failure  when checking the owner
    when(ownerCurator.lookupByKey(eq(owner.getKey()))).thenThrow(exception);

    HypervisorCheckInResult result =
        hypervisorResource.hypervisorCheckIn(hostGuestMap, principal, owner.getKey());

    Set<String> failures = result.getFailedUpdate();
    assertEquals(1, failures.size());
    assertEquals(expectedHostVirtId + ": " + expectedMessage, failures.iterator().next());
  }
コード例 #12
0
 @Test
 public void certificateRetrievalReturnsCert() {
   EntitlementCertificate cert = or.createUeberCertificate(principal, owner.getKey());
   assertNotNull(cert);
 }
コード例 #13
0
 @Test
 public void testUeberEntitlementIsGenerated() throws Exception {
   or.createUeberCertificate(principal, owner.getKey());
   assertNotNull(poolCurator.findUeberPool(owner));
 }
コード例 #14
0
 @Test
 public void testUeberConsumerIsCreated() throws Exception {
   or.createUeberCertificate(principal, owner.getKey());
   assertNotNull(consumerCurator.findByName(owner, "ueber_cert_consumer"));
 }
コード例 #15
0
 @Test
 public void testUeberProductIsCreated() throws Exception {
   or.createUeberCertificate(principal, owner.getKey());
   assertNotNull(productCurator.lookupByName(owner, owner.getKey() + UEBER_PRODUCT));
 }