// since surefire and eclipse don't otherwise guarantee the order, we are
  // starting this one alphabetically before create2nodes..
  @Test(enabled = true, dependsOnMethods = "testImagesCache")
  public void testAScriptExecutionAfterBootWithBasicTemplate() throws Exception {
    String tag = this.tag + "run";
    try {
      client.destroyNodesMatching(NodePredicates.withTag(tag));
    } catch (Exception e) {

    }

    TemplateOptions options = client.templateOptions().blockOnPort(22, 120);
    try {
      Set<? extends NodeMetadata> nodes = client.runNodesWithTag(tag, 1, options);
      Credentials good = nodes.iterator().next().getCredentials();
      assert good.account != null;
      assert good.key != null;

      Image image = Iterables.get(nodes, 0).getImage();
      try {
        Map<? extends NodeMetadata, ExecResponse> responses =
            runScriptWithCreds(tag, image.getOsFamily(), new Credentials(good.account, "romeo"));
        assert false : "shouldn't pass with a bad password\n" + responses;
      } catch (RunScriptOnNodesException e) {
        assert Throwables.getRootCause(e).getMessage().contains("Auth fail") : e;
      }

      runScriptWithCreds(tag, image.getOsFamily(), good);

      checkNodes(nodes, tag);

    } finally {
      client.destroyNodesMatching(NodePredicates.withTag(tag));
    }
  }
 @AfterTest
 protected void cleanup() throws InterruptedException, ExecutionException, TimeoutException {
   if (nodes != null) {
     client.destroyNodesMatching(NodePredicates.withTag(tag));
     for (NodeMetadata node :
         Iterables.filter(
             client.listNodesDetailsMatching(NodePredicates.all()), NodePredicates.withTag(tag))) {
       assert node.getState() == NodeState.TERMINATED : node;
     }
   }
   context.close();
 }
  @Test(enabled = true, dependsOnMethods = "testTemplateMatch")
  public void testCreateTwoNodesWithRunScript() throws Exception {
    try {
      client.destroyNodesMatching(NodePredicates.withTag(tag));
    } catch (HttpResponseException e) {
      // TODO hosting.com throws 400 when we try to delete a vApp
    } catch (NoSuchElementException e) {

    }
    template = buildTemplate(client.templateBuilder());

    template
        .getOptions()
        .installPrivateKey(keyPair.get("private"))
        .authorizePublicKey(keyPair.get("public"))
        .runScript(buildScript(template.getImage().getOsFamily()).getBytes());
    try {
      nodes = Sets.newTreeSet(client.runNodesWithTag(tag, 2, template));
    } catch (RunNodesException e) {
      nodes = Sets.newTreeSet(Iterables.concat(e.getSuccessfulNodes(), e.getNodeErrors().keySet()));
      throw e;
    }
    assertEquals(nodes.size(), 2);
    checkNodes(nodes, tag);
    NodeMetadata node1 = nodes.first();
    NodeMetadata node2 = nodes.last();
    // credentials aren't always the same
    // assertEquals(node1.getCredentials(), node2.getCredentials());

    assertLocationSameOrChild(node1.getLocation(), template.getLocation());
    assertLocationSameOrChild(node2.getLocation(), template.getLocation());

    assertEquals(node1.getImage(), template.getImage());
    assertEquals(node2.getImage(), template.getImage());
  }
  public void testStartCCInstance() throws Exception {

    Template template =
        view.getComputeService()
            .templateBuilder()
            .fromHardware(EC2HardwareBuilder.cc2_8xlarge().build())
            .osFamily(OsFamily.AMZN_LINUX)
            .build();
    assert template != null : "The returned template was null, but it should have a value.";
    assertEquals(template.getHardware().getProviderId(), InstanceType.CC2_8XLARGE);
    assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "ebs");
    assertEquals(template.getImage().getUserMetadata().get("virtualizationType"), "hvm");
    assertEquals(template.getImage().getUserMetadata().get("hypervisor"), "xen");

    template
        .getOptions()
        .runScript(Statements.newStatementList(AdminAccess.standard(), InstallJDK.fromOpenJDK()));

    String group = PREFIX + "cccluster";
    view.getComputeService().destroyNodesMatching(NodePredicates.inGroup(group));
    // TODO make this not lookup an explicit region
    client
        .getPlacementGroupApi()
        .get()
        .deletePlacementGroupInRegion(null, "jclouds#" + group + "#us-east-1");

    try {
      Set<? extends NodeMetadata> nodes =
          view.getComputeService().createNodesInGroup(group, 1, template);
      NodeMetadata node = getOnlyElement(nodes);

      getOnlyElement(
          getOnlyElement(
              client.getInstanceApi().get().describeInstancesInRegion(null, node.getProviderId())));

    } catch (RunNodesException e) {
      System.err.println(e.getNodeErrors().keySet());
      Throwables.propagate(e);
    } finally {
      view.getComputeService().destroyNodesMatching(NodePredicates.inGroup(group));
    }
  }
  @Test(enabled = true, dependsOnMethods = "testGet")
  public void testOptionToNotBlock() throws Exception {
    String tag = this.tag + "block";
    try {
      client.destroyNodesMatching(NodePredicates.withTag(tag));
    } catch (Exception e) {

    }
    // no inbound ports
    TemplateOptions options = client.templateOptions().blockUntilRunning(false).inboundPorts();
    try {
      long time = System.currentTimeMillis();
      Set<? extends NodeMetadata> nodes = client.runNodesWithTag(tag, 1, options);
      NodeMetadata node = Iterables.getOnlyElement(nodes);
      assertEquals(node.getState(), NodeState.PENDING);

      long duration = System.currentTimeMillis() - time;
      assert duration < 30 * 1000 : "duration longer than 30 seconds!:  " + duration / 1000;
    } finally {
      client.destroyNodesMatching(NodePredicates.withTag(tag));
    }
  }
 @Test(
     enabled = true,
     dependsOnMethods = "testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired")
 public void testGet() throws Exception {
   Set<? extends NodeMetadata> metadataSet =
       Sets.newHashSet(
           Iterables.filter(
               client.listNodesDetailsMatching(NodePredicates.all()),
               Predicates.and(
                   NodePredicates.withTag(tag), Predicates.not(NodePredicates.TERMINATED))));
   for (NodeMetadata node : nodes) {
     metadataSet.remove(node);
     NodeMetadata metadata = client.getNodeMetadata(node.getId());
     assertEquals(metadata.getProviderId(), node.getProviderId());
     assertEquals(metadata.getTag(), node.getTag());
     assertLocationSameOrChild(metadata.getLocation(), template.getLocation());
     assertEquals(metadata.getImage(), template.getImage());
     assertEquals(metadata.getState(), NodeState.RUNNING);
     assertEquals(metadata.getPrivateAddresses(), node.getPrivateAddresses());
     assertEquals(metadata.getPublicAddresses(), node.getPublicAddresses());
   }
   assertNodeZero(metadataSet);
 }
 protected Map<? extends NodeMetadata, ExecResponse> runScriptWithCreds(
     final String tag, OsFamily osFamily, Credentials creds) throws RunScriptOnNodesException {
   try {
     return client.runScriptOnNodesMatching(
         NodePredicates.runningWithTag(tag),
         buildScript(osFamily).getBytes(),
         RunScriptOptions.Builder.overrideCredentialsWith(creds));
   } catch (SshException e) {
     if (Throwables.getRootCause(e).getMessage().contains("Auth fail")) {
       // System.err.printf("bad credentials: %s:%s for %s%n",
       // creds.account, creds.key, client
       // .listNodesDetailsMatching(tag));
     }
     throw e;
   }
 }
 public void testGetNodesWithDetails() throws Exception {
   for (NodeMetadata node : client.listNodesDetailsMatching(NodePredicates.all())) {
     assert node.getProviderId() != null : node;
     assert node.getLocation() != null : node;
     assertEquals(node.getType(), ComputeType.NODE);
     assert node instanceof NodeMetadata;
     NodeMetadata nodeMetadata = (NodeMetadata) node;
     assert nodeMetadata.getProviderId() != null : nodeMetadata;
     // nullable
     // assert nodeMetadata.getImage() != null : node;
     // user specified name is not always supported
     // assert nodeMetadata.getName() != null : nodeMetadata;
     if (nodeMetadata.getState() == NodeState.RUNNING) {
       assert nodeMetadata.getPublicAddresses() != null : nodeMetadata;
       assert nodeMetadata.getPublicAddresses().size() > 0
               || nodeMetadata.getPrivateAddresses().size() > 0
           : nodeMetadata;
       assertNotNull(nodeMetadata.getPrivateAddresses());
     }
   }
 }
  public void testCreatePreemptibleNodeWithSsd() throws Exception {
    String group = this.group + "ssd";
    try {
      TemplateOptions options = client.templateOptions();

      options.as(GoogleComputeEngineTemplateOptions.class).bootDiskType("pd-ssd").preemptible(true);

      // create a node
      Set<? extends NodeMetadata> nodes = client.createNodesInGroup(group, 1, options);
      assertEquals(nodes.size(), 1, "One node should have been created");

      // Verify the disk on the instance is an ssd.
      NodeMetadata node = Iterables.get(nodes, 0);
      GoogleComputeEngineApi api = client.getContext().unwrapApi(GoogleComputeEngineApi.class);
      Instance instance = api.instancesInZone(node.getLocation().getId()).get(node.getName());
      Disk disk =
          api.disksInZone(node.getLocation().getId()).get(toName(instance.disks().get(0).source()));
      assertTrue(disk.type().toString().endsWith("pd-ssd"));
      assertTrue(instance.scheduling().preemptible());

    } finally {
      client.destroyNodesMatching(NodePredicates.inGroup(group));
    }
  }
 @Test(enabled = true, dependsOnMethods = "testGet")
 public void testReboot() throws Exception {
   client.rebootNodesMatching(NodePredicates.withTag(tag)); // TODO test
   // validation
   testGet();
 }
Ejemplo n.º 11
0
 @Override
 public Iterable<? extends ComputeMetadata> listNodes() {
   return listDetailsOnNodesMatching(NodePredicates.all());
 }