Example #1
0
  /** @see VmApi#remove(String) */
  @Test(description = "DELETE /vApp/{id}")
  public void testRemoveVm() {
    // Create a temporary VApp to remove
    VApp remove = instantiateVApp();
    DeployVAppParams params =
        DeployVAppParams.builder()
            .deploymentLeaseSeconds((int) TimeUnit.SECONDS.convert(1L, TimeUnit.HOURS))
            .notForceCustomization()
            .powerOn()
            .build();
    Task deployVApp = vAppApi.deploy(remove.getId(), params);
    assertTaskSucceedsLong(deployVApp);

    // Get the edited VApp and the Vm
    remove = vAppApi.get(remove.getId());
    List<Vm> vms = remove.getChildren().getVms();
    Vm temp = Iterables.get(vms, 0);

    // otherwise it's impossible to stop a running vApp with no vms
    if (vms.size() == 1) {
      UndeployVAppParams undeployParams = UndeployVAppParams.builder().build();
      Task shutdownVapp = vAppApi.undeploy(remove.getId(), undeployParams);
      assertTaskSucceedsLong(shutdownVapp);
    } else {
      powerOffVm(temp.getId());
    }
    // The method under test
    Task removeVm = vmApi.remove(temp.getId());
    assertTrue(retryTaskSuccess.apply(removeVm), String.format(TASK_COMPLETE_TIMELY, "removeVm"));

    Vm removed = vmApi.get(temp.getId());
    assertNull(removed, "The Vm " + temp.getName() + " should have been removed");
  }
Example #2
0
  /** @see VmApi#edit(String, Vm) */
  @Test(
      description = "PUT /vApp/{id}",
      dependsOnMethods = {"testGetVm"})
  public void testEditVm() {
    Vm newVm = Vm.builder().name(name("new-name-")).description("New Description").build();

    // The method under test
    Task editVm = vmApi.edit(vmUrn, newVm);
    assertTrue(retryTaskSuccess.apply(editVm), String.format(TASK_COMPLETE_TIMELY, "editVm"));

    // Get the edited Vm
    vm = vmApi.get(vmUrn);

    // Check the required fields are set
    assertEquals(
        vm.getName(),
        newVm.getName(),
        String.format(OBJ_FIELD_EQ, VM, "Name", newVm.getName(), vm.getName()));
    assertEquals(
        vm.getDescription(),
        newVm.getDescription(),
        String.format(
            OBJ_FIELD_EQ, VM, "Description", newVm.getDescription(), vm.getDescription()));
  }