コード例 #1
0
  @AfterTest
  void cleanup() {
    if (ebsInstance != null) {
      try {
        client
            .getInstanceServices()
            .terminateInstancesInRegion(ebsInstance.getRegion(), ebsInstance.getId());
        terminatedTester.apply(ebsInstance);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    if (ebsImage != null) {
      try {
        client.getAMIServices().deregisterImageInRegion(ebsImage.getRegion(), ebsImage.getId());
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    if (snapshot != null) {
      try {
        client
            .getElasticBlockStoreServices()
            .deleteSnapshotInRegion(snapshot.getRegion(), snapshot.getId());
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    if (attachment != null) {
      try {
        client
            .getElasticBlockStoreServices()
            .detachVolumeInRegion(volume.getRegion(), volume.getId(), true);
        assert volumeTester.apply(volume);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    if (instance != null) {
      try {
        client
            .getInstanceServices()
            .terminateInstancesInRegion(instance.getRegion(), instance.getId());
        terminatedTester.apply(instance);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    if (volume != null) {
      try {
        client
            .getElasticBlockStoreServices()
            .deleteVolumeInRegion(volume.getRegion(), volume.getId());
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    if (keyPair != null) {
      try {
        client
            .getKeyPairServices()
            .deleteKeyPairInRegion(keyPair.getRegion(), keyPair.getKeyName());
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    if (securityGroupName != null) {
      try {
        client.getSecurityGroupServices().deleteSecurityGroupInRegion(null, securityGroupName);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
コード例 #2
0
  @Test(enabled = false, dependsOnMethods = "testBundleInstance")
  void testAMIFromBundle() {
    volume =
        Iterables.getOnlyElement(
            client
                .getElasticBlockStoreServices()
                .describeVolumesInRegion(volume.getRegion(), volume.getId()));
    if (volume.getAttachments().size() > 0) {
      // should be cleanly unmounted, so force is not necessary.
      client
          .getElasticBlockStoreServices()
          .detachVolumeInRegion(instance.getRegion(), volume.getId(), false);
      System.out.printf(
          "%d: %s awaiting detachment to complete%n", System.currentTimeMillis(), volume.getId());
      assert volumeTester.apply(volume);
    } else {
      attachment = null; // protect test closer so that it doesn't try to
      // detach
    }
    snapshot =
        client
            .getElasticBlockStoreServices()
            .createSnapshotInRegion(
                volume.getRegion(), volume.getId(), withDescription("EBS Ubuntu Hardy"));

    System.out.printf(
        "%d: %s awaiting snapshot to complete%n", System.currentTimeMillis(), snapshot.getId());

    assert snapshotTester.apply(snapshot);
    Image image =
        Iterables.getOnlyElement(
            client
                .getAMIServices()
                .describeImagesInRegion(snapshot.getRegion(), imageIds(IMAGE_ID)));
    String description = image.getDescription() == null ? "jclouds" : image.getDescription();

    System.out.printf(
        "%d: %s creating ami from snapshot%n", System.currentTimeMillis(), snapshot.getId());

    String amiId =
        client
            .getAMIServices()
            .registerUnixImageBackedByEbsInRegion(
                snapshot.getRegion(),
                "ebsboot-" + image.getId(),
                snapshot.getId(),
                withKernelId(image.getKernelId())
                    .withRamdisk(image.getRamdiskId())
                    .withDescription(description)
                    .asArchitecture(Architecture.I386));
    try {
      ebsImage =
          Iterables.getOnlyElement(
              client
                  .getAMIServices()
                  .describeImagesInRegion(snapshot.getRegion(), imageIds(amiId)));
    } catch (AWSResponseException e) {
      // TODO add a retry handler for this HTTP code 400 and the below error
      if (e.getError().getClass().equals("InvalidAMIID.NotFound"))
        ebsImage =
            Iterables.getOnlyElement(
                client
                    .getAMIServices()
                    .describeImagesInRegion(snapshot.getRegion(), imageIds(amiId)));
      else throw e;
    }
    verifyImage();
  }