Ejemplo n.º 1
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());
  }
  private boolean shouldGenerateV3(Entitlement entitlement) {
    Consumer consumer = entitlement.getConsumer();

    if (consumer.getType().isManifest()) {
      for (ConsumerCapability capability : consumer.getCapabilities()) {
        if ("cert_v3".equals(capability.getName())) {
          return true;
        }
      }
      return false;
    } else if (consumer.getType().getLabel().equals(ConsumerTypeEnum.HYPERVISOR.getLabel())) {
      // Hypervisors in this context don't use content, so allow v3
      return true;
    } else {
      String entitlementVersion = consumer.getFact("system.certificate_version");
      return entitlementVersion != null && entitlementVersion.startsWith("3.");
    }
  }