Exemplo n.º 1
0
  @Test(enabled = true)
  public void testCreateTemplate() throws Exception {
    Zone zone = Iterables.getFirst(client.getZoneClient().listZones(), null);
    assertNotNull(zone);
    Iterable<Network> networks =
        client
            .getNetworkClient()
            .listNetworks(ListNetworksOptions.Builder.zoneId(zone.getId()).isDefault(true));
    networks =
        Iterables.filter(
            networks,
            new Predicate<Network>() {
              @Override
              public boolean apply(@Nullable Network network) {
                return network != null && network.getState().equals("Implemented");
              }
            });
    assertEquals(Iterables.size(networks), 1);
    Network network = Iterables.getOnlyElement(networks, null);
    assertNotNull(network);

    // Create a VM and stop it
    Long templateId = (imageId != null && !"".equals(imageId)) ? new Long(imageId) : null;
    vmForCreation =
        VirtualMachineClientLiveTest.createVirtualMachineInNetwork(
            network, templateId, client, jobComplete, virtualMachineRunning);
    assertTrue(
        jobComplete.apply(
            client.getVirtualMachineClient().stopVirtualMachine(vmForCreation.getId())),
        vmForCreation.toString());

    // Work out the VM's volume
    Set<Volume> volumes =
        client
            .getVolumeClient()
            .listVolumes(ListVolumesOptions.Builder.virtualMachineId(vmForCreation.getId()));
    assertEquals(volumes.size(), 1);
    Volume volume = Iterables.getOnlyElement(volumes);

    // Create a template
    CreateTemplateOptions options = CreateTemplateOptions.Builder.volumeId(volume.getId());
    AsyncCreateResponse response =
        client
            .getTemplateClient()
            .createTemplate(
                TemplateMetadata.builder()
                    .name(prefix + "-createTemplate")
                    .osTypeId(vmForCreation.getGuestOSId())
                    .displayText("jclouds live testCreateTemplate")
                    .build(),
                options);
    assertTrue(jobComplete.apply(response.getJobId()), vmForCreation.toString());
    createdTemplate =
        client.getTemplateClient().getTemplateInZone(response.getId(), vmForCreation.getZoneId());

    // Assertions
    assertNotNull(createdTemplate);
  }
Exemplo n.º 2
0
 @AfterGroups(groups = "live")
 protected void tearDown() {
   if (vmForCreation != null) {
     assertTrue(
         jobComplete.apply(
             client.getVirtualMachineClient().stopVirtualMachine(vmForCreation.getId())),
         vmForCreation.toString());
     assertTrue(
         jobComplete.apply(
             client.getVirtualMachineClient().destroyVirtualMachine(vmForCreation.getId())),
         vmForCreation.toString());
     assertTrue(virtualMachineDestroyed.apply(vmForCreation));
   }
   if (vmForRegistration != null) {
     assertTrue(
         jobComplete.apply(
             client.getVirtualMachineClient().stopVirtualMachine(vmForRegistration.getId())),
         vmForRegistration.toString());
     assertTrue(
         jobComplete.apply(
             client.getVirtualMachineClient().destroyVirtualMachine(vmForRegistration.getId())),
         vmForRegistration.toString());
     assert virtualMachineDestroyed.apply(vmForRegistration);
   }
   if (createdTemplate != null) {
     AsyncCreateResponse deleteJob =
         client.getTemplateClient().deleteTemplate(createdTemplate.getId());
     assertTrue(jobComplete.apply(deleteJob.getJobId()));
   }
   if (registeredTemplate != null) {
     AsyncCreateResponse deleteJob =
         client.getTemplateClient().deleteTemplate(registeredTemplate.getId());
     assertTrue(jobComplete.apply(deleteJob.getJobId()));
   }
   super.tearDown();
 }
Exemplo n.º 3
0
  @Test(enabled = true, dependsOnMethods = "testRegisterTemplate")
  public void testExtractTemplate() throws Exception {
    // Initiate the extraction and wait for it to complete
    AsyncCreateResponse response =
        client
            .getTemplateClient()
            .extractTemplate(
                registeredTemplate.getId(),
                ExtractMode.HTTP_DOWNLOAD,
                registeredTemplate.getZoneId());
    assertTrue(jobComplete.apply(response.getJobId()), registeredTemplate.toString());

    // Get the result
    AsyncJob<TemplateExtraction> asyncJob =
        client.getAsyncJobClient().getAsyncJob(response.getJobId());
    TemplateExtraction extract = asyncJob.getResult();
    assertNotNull(extract);

    // Check that the URL can be retrieved
    String extractUrl = extract.getUrl();
    assertNotNull(extractUrl);
    URI uri = new URI(URLDecoder.decode(extractUrl, "utf-8"));
    assertTrue(context.utils().http().exists(uri), "does not exist: " + uri);
  }