コード例 #1
0
  // 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));
    }
  }
コード例 #2
0
 @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();
 }
コード例 #3
0
  @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());
  }
コード例 #4
0
  @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));
    }
  }
コード例 #5
0
 @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);
 }
コード例 #6
0
 @Test(enabled = true, dependsOnMethods = "testGet")
 public void testReboot() throws Exception {
   client.rebootNodesMatching(NodePredicates.withTag(tag)); // TODO test
   // validation
   testGet();
 }