@Override protected Properties setupProperties() { Properties properties = super.setupProperties(); properties.setProperty("jclouds.ssh.max-retries", "20"); return properties; } }
@Test(enabled = true, dependsOnMethods = { "testListNodes", "testGetNodesWithDetails", "testListNodesByIds" }) @Override public void testDestroyNodes() { super.testDestroyNodes(); }
@Test(enabled = true, dependsOnMethods = "testSuspendResume") @Override public void testGetNodesWithDetails() throws Exception { super.testGetNodesWithDetails(); }
protected Template refreshTemplate() { return template = addRunScriptToTemplate(buildTemplate(templateBuilder())); }
private Template refreshTemplate() { return template = addRunScriptToTemplate(buildTemplate(client.templateBuilder())); }
@Test(enabled = true, dependsOnMethods = "testCreateTwoNodesWithRunScript", alwaysRun = true) public void testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired() throws Exception { if (this.nodes == null || this.nodes.isEmpty()) { template = buildTemplate(templateBuilder()); try { nodes = newTreeSet(client.createNodesInGroup(group, 1, template)); initializeContext(); template = buildTemplate(templateBuilder()); template = addRunScriptToTemplate(client.templateBuilder().fromTemplate(template) .locationId(existingLocation.getId()).build()); } else { refreshTemplate(); getAnonymousLogger().info( format("%s is not assignable; using template's location %s as ", existingLocation, checkNodes(nodes, group, "bootstrap"); NodeMetadata node = Iterables.getOnlyElement(nodes); if (existingLocationIsAssignable) assertEquals(node.getLocation(), existingLocation); else this.assertLocationSameOrChild(checkNotNull(node.getLocation(), "location of %s", node), template.getLocation()); checkOsMatchesTemplate(node); this.nodes = newTreeSet(concat(this.nodes, nodes));
@Test(enabled = true, expectedExceptions = AuthorizationException.class) public void testCorrectAuthException() throws Exception { ComputeServiceContext context = null; try { Properties overrides = setupProperties(); overrides.setProperty(provider + ".identity", "MOMMA"); overrides.setProperty(provider + ".credential", "MIA"); context = newBuilder() .modules(ImmutableSet.of(getLoggingModule(), credentialStoreModule)) .overrides(overrides).build(ComputeServiceContext.class); context.getComputeService().listNodes(); } catch (AuthorizationException e) { throw e; } catch (RuntimeException e) { e.printStackTrace(); throw e; } finally { if (context != null) context.close(); } }
protected void createAndRunAServiceInGroup(String group) throws RunNodesException { // note that some cloud providers do not support mixed case tag names ImmutableMap<String, String> userMetadata = ImmutableMap.<String, String> of("test", group); ImmutableSet<String> tags = ImmutableSet.of(group); Stopwatch watch = Stopwatch.createStarted(); template = buildTemplate(templateBuilder()); template.getOptions().inboundPorts(22, 8080).blockOnPort(22, 300).userMetadata(userMetadata).tags(tags); NodeMetadata node = getOnlyElement(client.createNodesInGroup(group, 1, template)); long createSeconds = watch.elapsed(TimeUnit.SECONDS); final String nodeId = node.getId(); checkUserMetadataContains(node, userMetadata); checkTagsInNodeEquals(node, tags); getAnonymousLogger().info( format("<< available node(%s) os(%s) in %ss", node.getId(), node.getOperatingSystem(), createSeconds)); watch.reset().start(); client.runScriptOnNode(nodeId, JettyStatements.install(), nameTask("configure-jetty")); long configureSeconds = watch.elapsed(TimeUnit.SECONDS); getAnonymousLogger().info( format( "<< configured node(%s) with %s and jetty %s in %ss", nodeId, exec(nodeId, "java -fullversion"), exec(nodeId, JettyStatements.version()), configureSeconds)); trackAvailabilityOfProcessOnNode(JettyStatements.start(), "start jetty", node); client.runScriptOnNode(nodeId, JettyStatements.stop(), runAsRoot(false).wrapInInitScript(false)); trackAvailabilityOfProcessOnNode(JettyStatements.start(), "start jetty", node); }
template = buildTemplate(templateBuilder()); template.getOptions().blockOnPort(22, 120); try { runningInGroup(group), "hostname -s", wrapInInitScript(false).runAsRoot(false).overrideLoginCredentials(good)).entrySet()) { checkResponseEqualsHostname(response.getValue(), response.getKey()); checkResponseEqualsHostname(response, node); OperatingSystem os = node.getOperatingSystem(); tryBadPassword(group, good); runScriptWithCreds(group, os, good); checkNodes(nodes, group, "runScriptWithCreds");
protected void createAndRunAServiceInGroup(String group) throws RunNodesException { // note that some cloud providers do not support mixed case tag names ImmutableMap<String, String> userMetadata = ImmutableMap.<String, String> of("test", group); ImmutableSet<String> tags = ImmutableSet. of(group); Stopwatch watch = new Stopwatch().start(); NodeMetadata node = getOnlyElement(client.createNodesInGroup(group, 1, inboundPorts(22, 8080).blockOnPort(22, 300).userMetadata(userMetadata).tags(tags))); long createSeconds = watch.elapsedTime(TimeUnit.SECONDS); final String nodeId = node.getId(); checkUserMetadataContains(node, userMetadata); checkTagsInNodeEquals(node, tags); getAnonymousLogger().info( format("<< available node(%s) os(%s) in %ss", node.getId(), node.getOperatingSystem(), createSeconds)); watch.reset().start(); client.runScriptOnNode(nodeId, JettyStatements.install(), nameTask("configure-jetty")); long configureSeconds = watch.elapsedTime(TimeUnit.SECONDS); getAnonymousLogger().info( format( "<< configured node(%s) with %s and jetty %s in %ss", nodeId, exec(nodeId, "java -fullversion"), exec(nodeId, JettyStatements.version()), configureSeconds)); trackAvailabilityOfProcessOnNode(JettyStatements.start(), "start jetty", node); client.runScriptOnNode(nodeId, JettyStatements.stop(), runAsRoot(false).wrapInInitScript(false)); trackAvailabilityOfProcessOnNode(JettyStatements.start(), "start jetty", node); }
@Test(enabled = true) public void testGet() throws Exception { template = buildTemplate(templateBuilder()); try { nodes = newTreeSet(client.createNodesInGroup(group, 1, template)); assertEquals(metadata.getProviderId(), node.getProviderId()); assertEquals(metadata.getGroup(), node.getGroup()); assertLocationSameOrChild(checkNotNull(metadata.getLocation(), "location of %s", metadata), template.getLocation()); checkImageIdMatchesTemplate(metadata); checkOsMatchesTemplate(metadata); assert metadata.getStatus() == Status.RUNNING : metadata;
@Test(enabled = true, dependsOnMethods = "testDestroyNodes", alwaysRun = true) public void testCreateTwoNodesWithOneSpecifiedName() throws Exception { template = buildTemplate(templateBuilder()); template.getOptions().nodeNames(ImmutableSet.of("first-node")); try { this.nodes = newTreeSet(client.createNodesInGroup(group, 2, template)); } catch (RunNodesException e) { this.nodes = newTreeSet(concat(e.getSuccessfulNodes(), e.getNodeErrors().keySet())); throw e; } assertEquals(this.nodes.size(), 2, "expected two nodes but was " + nodes); NodeMetadata node1 = Iterables.getFirst(this.nodes, null); NodeMetadata node2 = Iterables.getLast(this.nodes, null); // credentials aren't always the same // assertEquals(node1.getCredentials(), node2.getCredentials()); assertTrue(node1.getName().equals("first-node") || node2.getName().equals("first-node"), "one node should be named 'first-node'"); assertFalse(node1.getName().equals("first-node") && node2.getName().equals("first-node"), "one node should be named something other than 'first-node"); }
@Test(enabled = true, dependsOnMethods = "testReboot") public void testSuspendResume() throws Exception { super.testSuspendResume(); }
@Test(enabled = true, dependsOnMethods = "testSuspendResume") @Override public void testListNodes() throws Exception { super.testListNodes(); }
@Test(enabled = true, dependsOnMethods = "testSuspendResume") @Override public void testListNodesByIds() throws Exception { super.testListNodesByIds(); }
@Test public void testWeCanCancelTasks() throws Exception { String group = this.group + "w"; try { client.destroyNodesMatching(inGroup(group)); } catch (Exception e) { } template = buildTemplate(templateBuilder()); try { Set<? extends NodeMetadata> nodes = client.createNodesInGroup(group, 1, template); NodeMetadata node = getOnlyElement(nodes); weCanCancelTasks(node); } finally { client.destroyNodesMatching(inGroup(group)); } }
@Override protected void checkUserMetadataContains(NodeMetadata node, ImmutableMap<String, String> userMetadata) { if (view.unwrapApi(EC2Api.class).getTagApi().isPresent()) { super.checkUserMetadataContains(node, userMetadata); } else { assertTrue(node.getUserMetadata().isEmpty(), "not expecting metadata when tag extension isn't present: " + node); } }
@Override protected Template buildTemplate(TemplateBuilder templateBuilder) { Template template = super.buildTemplate(templateBuilder); template.getOptions().authorizePublicKey(keyPair.get("public")); return template; }
@Override protected void checkTagsInNodeEquals(NodeMetadata node, ImmutableSet<String> tags) { if (view.unwrapApi(EC2Api.class).getTagApi().isPresent()) { super.checkTagsInNodeEquals(node, tags); } else { assertTrue(node.getTags().isEmpty(), "not expecting tags when tag extension isn't present: " + node); } }
@Test(enabled = true, expectedExceptions = AuthorizationException.class) public void testCorrectAuthException() throws Exception { ComputeServiceContext context = null; try { Properties overrides = setupProperties(); overrides.setProperty(provider + ".identity", "MOM:MA"); overrides.setProperty(provider + ".credential", "MIA"); context = newBuilder() .modules(ImmutableSet.of(getLoggingModule(), credentialStoreModule)) .overrides(overrides).build(ComputeServiceContext.class); context.getComputeService().listNodes(); } catch (AuthorizationException e) { throw e; } catch (RuntimeException e) { e.printStackTrace(); throw e; } finally { if (context != null) context.close(); } }