re-enabled most tests and corrected some minor bugs, only destoyPoolNodes is missing

This commit is contained in:
David Ribeiro Alves 2012-07-18 01:58:18 +01:00
parent 01f121a654
commit cdde419b24
13 changed files with 146 additions and 210 deletions

View File

@ -26,6 +26,7 @@ import static org.jclouds.nodepool.config.NodePoolProperties.MIN_SIZE;
import static org.jclouds.nodepool.config.NodePoolProperties.POOL_ADMIN_ACCESS; import static org.jclouds.nodepool.config.NodePoolProperties.POOL_ADMIN_ACCESS;
import static org.jclouds.nodepool.config.NodePoolProperties.REMOVE_DESTROYED; import static org.jclouds.nodepool.config.NodePoolProperties.REMOVE_DESTROYED;
import java.io.File;
import java.net.URI; import java.net.URI;
import java.util.Properties; import java.util.Properties;
@ -62,7 +63,6 @@ public class NodePoolApiMetadata extends BaseApiMetadata {
public static Properties defaultProperties() { public static Properties defaultProperties() {
Properties properties = BaseRestApiMetadata.defaultProperties(); Properties properties = BaseRestApiMetadata.defaultProperties();
properties.setProperty("nodepool.identity", "nodepool-user");
properties.setProperty(BACKEND_GROUP, "nodepool"); properties.setProperty(BACKEND_GROUP, "nodepool");
properties.setProperty(METADATA_CONTAINER, "nodes"); properties.setProperty(METADATA_CONTAINER, "nodes");
properties.setProperty(BACKEND_MODULES, properties.setProperty(BACKEND_MODULES,
@ -70,9 +70,12 @@ public class NodePoolApiMetadata extends BaseApiMetadata {
properties.setProperty(MAX_SIZE, 10 + ""); properties.setProperty(MAX_SIZE, 10 + "");
properties.setProperty(MIN_SIZE, 5 + ""); properties.setProperty(MIN_SIZE, 5 + "");
properties.setProperty(REMOVE_DESTROYED, "true"); properties.setProperty(REMOVE_DESTROYED, "true");
// by default use the current user's user and private key // by default use the current user's user and private key if one exists, if not the properties
properties.setProperty(POOL_ADMIN_ACCESS, "adminUsername=" + System.getProperty("user.name") // will need to be set (no default passwords)
+ ",adminPrivateKeyFile=" + System.getProperty("user.home") + "/.ssh/id_rsa"); if (new File(System.getProperty("user.home") + "/.ssh/id_rsa").exists()) {
properties.setProperty(POOL_ADMIN_ACCESS, "adminUsername=" + System.getProperty("user.name")
+ ",adminPrivateKeyFile=" + System.getProperty("user.home") + "/.ssh/id_rsa");
}
return properties; return properties;
} }

View File

@ -1,3 +1,22 @@
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.nodepool.config; package org.jclouds.nodepool.config;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -44,6 +63,7 @@ public class NodePoolComputeServiceContextModule extends JCloudsNativeComputeSer
bind(ComputeServiceContext.class).to(NodePoolComputeServiceContext.class); bind(ComputeServiceContext.class).to(NodePoolComputeServiceContext.class);
install(new LocationsFromComputeServiceAdapterModule<NodeMetadata, Hardware, Image, Location>() { install(new LocationsFromComputeServiceAdapterModule<NodeMetadata, Hardware, Image, Location>() {
}); });
} }
@Override @Override

View File

@ -61,8 +61,10 @@ public abstract class BaseNodePoolComputeServiceAdapter implements NodePoolCompu
protected final AdminAccess.Builder initialCredentialsBuilder; protected final AdminAccess.Builder initialCredentialsBuilder;
public BaseNodePoolComputeServiceAdapter(@Backend Supplier<ComputeService> backendComputeService, public BaseNodePoolComputeServiceAdapter(@Backend Supplier<ComputeService> backendComputeService,
@Backend Supplier<Template> backendTemplate, @Named(BACKEND_GROUP) String poolGroupName,
NodeMetadataStore metadataStore, @Named(POOL_ADMIN_ACCESS) String poolNodeAdminAccess, @Backend Supplier<Template> backendTemplate, @Named(BACKEND_GROUP) String poolGroupName,
NodeMetadataStore metadataStore, @Named(POOL_ADMIN_ACCESS) String poolNodeAdminAccess,
AdminAccess.Configuration configuration) { AdminAccess.Configuration configuration) {
this.backendComputeService = backendComputeService; this.backendComputeService = backendComputeService;
this.poolGroupName = poolGroupName; this.poolGroupName = poolGroupName;

View File

@ -1,3 +1,21 @@
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.nodepool.internal; package org.jclouds.nodepool.internal;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;

View File

@ -1,3 +1,21 @@
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.nodepool.internal; package org.jclouds.nodepool.internal;
import java.util.HashMap; import java.util.HashMap;

View File

@ -23,6 +23,7 @@ import static org.jclouds.nodepool.config.NodePoolProperties.BACKEND_PROVIDER;
import static org.jclouds.nodepool.config.NodePoolProperties.BASEDIR; import static org.jclouds.nodepool.config.NodePoolProperties.BASEDIR;
import static org.jclouds.nodepool.config.NodePoolProperties.MAX_SIZE; import static org.jclouds.nodepool.config.NodePoolProperties.MAX_SIZE;
import static org.jclouds.nodepool.config.NodePoolProperties.MIN_SIZE; import static org.jclouds.nodepool.config.NodePoolProperties.MIN_SIZE;
import static org.jclouds.nodepool.config.NodePoolProperties.REMOVE_DESTROYED;
import static org.jclouds.scriptbuilder.domain.Statements.exec; import static org.jclouds.scriptbuilder.domain.Statements.exec;
import java.io.File; import java.io.File;
@ -41,7 +42,7 @@ import com.google.inject.Module;
/** /**
* *
* @author Adrian Cole * @author Adrian Cole, David Alves
*/ */
@Test(groups = "live", testName = "BYONBackendLiveTest") @Test(groups = "live", testName = "BYONBackendLiveTest")
public class BYONBackendLiveTest extends BaseComputeServiceContextLiveTest { public class BYONBackendLiveTest extends BaseComputeServiceContextLiveTest {
@ -61,6 +62,7 @@ public class BYONBackendLiveTest extends BaseComputeServiceContextLiveTest {
contextProperties.setProperty(BASEDIR, basedir); contextProperties.setProperty(BASEDIR, basedir);
contextProperties.setProperty(MAX_SIZE, 1 + ""); contextProperties.setProperty(MAX_SIZE, 1 + "");
contextProperties.setProperty(MIN_SIZE, 1 + ""); contextProperties.setProperty(MIN_SIZE, 1 + "");
contextProperties.setProperty(REMOVE_DESTROYED, false + "");
contextProperties.setProperty("nodepool.identity", System.getProperty("user.name")); contextProperties.setProperty("nodepool.identity", System.getProperty("user.name"));
StringBuilder nodes = new StringBuilder(); StringBuilder nodes = new StringBuilder();

View File

@ -1,151 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.nodepool;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertSame;
import static org.testng.Assert.assertTrue;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import java.util.Set;
import javax.inject.Inject;
import org.jclouds.Context;
import org.jclouds.ContextBuilder;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeMetadata.Status;
import org.jclouds.compute.domain.NodeMetadataBuilder;
import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.compute.strategy.PrioritizeCredentialsFromTemplate;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.nodepool.config.NodePoolProperties;
import org.jclouds.nodepool.internal.NodeMetadataStore;
import org.jclouds.util.Strings2;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Injector;
/**
* @author Adrian Cole, David Alves
*/
@Test(groups = "unit")
public class NodeMetadataStoreTestDisabled {
// unit tests should have no dependencies, yet this one is failing on cloudbees:
// Guice creation errors: 1) Error injecting constructor, java.lang.IllegalArgumentException: key adminPrivateKeyFile value set to /home/hudson/.ssh/id_rsa, must be an existing file at org.jclouds.nodepool.internal.EagerNodePoolComputeServiceAdapter.<init>(EagerNodePoolComputeServiceAdapter.java:77) at
@Inject
NodeMetadataStore store;
private String baseDir;
private NodeMetadata nodeMeta1;
private NodeMetadata nodeMeta2;
private TemplateOptions templateOptions;
@BeforeMethod
public void setUp() {
Injector injector = createInjector();
injector.injectMembers(this);
this.nodeMeta1 = new NodeMetadataBuilder().id("testmeta1").status(Status.ERROR).build();
this.nodeMeta2 = new NodeMetadataBuilder().id("testmeta2").status(Status.ERROR).build();
this.templateOptions = new TemplateOptions().overrideLoginUser("testuser").overrideLoginPassword("testpass")
.overrideAuthenticateSudo(true).userMetadata("testmetakey", "testmetavalue")
.overrideLoginPrivateKey("pk").userMetadata("testmetakey2", "testmetavalue2")
.tags(ImmutableList.of("tag1", "tag2"));
}
protected Injector createInjector() {
this.baseDir = "target/nodemetadatastoretest";
Properties overrides = new Properties();
overrides.setProperty(NodePoolProperties.BACKEND_PROVIDER, "stub");
overrides.setProperty(NodePoolProperties.MIN_SIZE, "0");
overrides.setProperty(NodePoolProperties.BASEDIR, baseDir);
// note no ssh module since we are stub and not trying ssh, yet
overrides.setProperty(NodePoolProperties.BACKEND_MODULES, SLF4JLoggingModule.class.getName());
Context nodePoolCtx = ContextBuilder.newBuilder("nodepool").credentials("foo", "bar").overrides(overrides)
.build();
return nodePoolCtx.utils().getInjector();
}
@Test(groups = "unit")
public void testStore() throws FileNotFoundException, IOException {
store.store(nodeMeta1, templateOptions, "testgroup");
store.store(nodeMeta2, templateOptions, "testgroup");
String readJSon = Strings2.toStringAndClose(new FileInputStream(baseDir + File.separator + "nodes"
+ File.separator + nodeMeta1.getId()));
assertEquals(readJSon, "{\"group\":\"testgroup\",\"tags\":[\"tag1\",\"tag2\"],"
+ "\"userMetadata\":{\"testmetakey\":\"testmetavalue\",\"testmetakey2\":\"testmetavalue2\"},"
+ "\"user\":\"testuser\",\"password\":\"testpass\",\"privateKey\":\"pk\",\"authenticateSudo\":true}");
}
@Test(groups = "unit", dependsOnMethods = "testStore")
public void testCredentialsFromStoreOverrideBackendCredentials() {
// test that node store credentials are not overriden from somewhere else
assertNull(createInjector().getBinding(PrioritizeCredentialsFromTemplate.class).getProvider().get()
.apply(null, null));
}
@Test(groups = "unit", dependsOnMethods = "testStore")
public void testLoad() {
NodeMetadata loaded = store.load(nodeMeta1);
assertEquals(loaded.getId(), nodeMeta1.getId());
assertTrue(loaded.getTags().contains("tag1"));
assertTrue(loaded.getTags().contains("tag2"));
assertTrue(loaded.getUserMetadata().containsKey("testmetakey")
&& loaded.getUserMetadata().get("testmetakey").equals("testmetavalue"));
assertTrue(loaded.getUserMetadata().containsKey("testmetakey2")
&& loaded.getUserMetadata().get("testmetakey2").equals("testmetavalue2"));
assertEquals(loaded.getCredentials().getUser(), "testuser");
assertEquals(loaded.getCredentials().getPassword(), "testpass");
assertEquals(loaded.getCredentials().getPrivateKey(), "pk");
assertEquals(loaded.getCredentials().shouldAuthenticateSudo(), true);
assertEquals(loaded.getGroup(), "testgroup");
}
@Test(groups = "unit", dependsOnMethods = "testLoad")
public void testLoadAll() {
Set<NodeMetadata> loaded = store.loadAll(ImmutableSet.of(nodeMeta1, nodeMeta2));
assertSame(loaded.size(), 2);
}
@Test(groups = "unit", dependsOnMethods = "testLoadAll")
public void testDeleteMapping() {
store.deleteMapping(nodeMeta1.getId());
// make sure the other node is still there and this one isn't
assertNull(store.load(nodeMeta1));
assertEquals(nodeMeta2.getId(), store.load(nodeMeta2).getId());
}
@Test(groups = "unit", dependsOnMethods = "testDeleteMapping")
public void testDeleteAllMappings() {
store.deleteAllMappings();
assertNull(store.load(nodeMeta1));
assertNull(store.load(nodeMeta2));
assertSame(new File(baseDir + File.separator + "nodes").listFiles().length, 0);
}
}

View File

@ -41,27 +41,21 @@ import com.google.inject.TypeLiteral;
@Test(groups = "unit", testName = "NodePoolComputeServiceContextTest") @Test(groups = "unit", testName = "NodePoolComputeServiceContextTest")
public class NodePoolComputeServiceContextTest { public class NodePoolComputeServiceContextTest {
//TODO: identity became nodepool-user
@Test(enabled = false)
public void testBinds() { public void testBinds() {
final String basedir = "target/" + this.getClass().getSimpleName(); final String basedir = "target/" + this.getClass().getSimpleName();
new File(basedir).delete(); new File(basedir).delete();
Properties overrides = new Properties(); Properties overrides = new Properties();
overrides.setProperty(NodePoolProperties.BACKEND_PROVIDER, "stub"); overrides.setProperty(NodePoolProperties.BACKEND_PROVIDER, "stub");
overrides.setProperty(NodePoolProperties.BASEDIR, basedir); overrides.setProperty(NodePoolProperties.BASEDIR, basedir);
// note no ssh module since we are stub and not trying ssh, yet // note no ssh module since we are stub and not trying ssh, yet
overrides.setProperty(NodePoolProperties.BACKEND_MODULES, SLF4JLoggingModule.class.getName()); overrides.setProperty(NodePoolProperties.BACKEND_MODULES, SLF4JLoggingModule.class.getName());
ComputeService stub = ContextBuilder.newBuilder("nodepool") ComputeService stub = ContextBuilder.newBuilder("nodepool").credentials("foo", "bar").endpoint("gooend")
.credentials("foo", "bar") .apiVersion("1.1").buildVersion("1.1-2").overrides(overrides).buildInjector()
.endpoint("gooend") .getInstance(Key.get(new TypeLiteral<Supplier<ComputeService>>() {
.apiVersion("1.1") }, Backend.class)).get();
.buildVersion("1.1-2")
.overrides(overrides)
.buildInjector().getInstance(Key.get(new TypeLiteral<Supplier<ComputeService>>(){}, Backend.class)).get();
assertEquals(stub.getContext().unwrap().getIdentity(), "foo"); assertEquals(stub.getContext().unwrap().getIdentity(), "foo");
assertEquals(stub.getContext().utils().injector().getInstance(Key.get(String.class, Credential.class)), "bar"); assertEquals(stub.getContext().utils().injector().getInstance(Key.get(String.class, Credential.class)), "bar");
assertEquals(stub.getContext().unwrap().getProviderMetadata().getEndpoint(), "gooend"); assertEquals(stub.getContext().unwrap().getProviderMetadata().getEndpoint(), "gooend");
@ -73,5 +67,4 @@ public class NodePoolComputeServiceContextTest {
} }
} }

View File

@ -67,7 +67,8 @@ import com.google.common.io.Closeables;
import com.google.inject.Module; import com.google.inject.Module;
public class NodePoolComputeServiceLiveTest extends BaseComputeServiceLiveTest { public class NodePoolComputeServiceLiveTest extends BaseComputeServiceLiveTest {
final String basedir = "target/" + this.getClass().getSimpleName().toLowerCase();
private final String basedir = "target/" + this.getClass().getSimpleName().toLowerCase();
public NodePoolComputeServiceLiveTest() { public NodePoolComputeServiceLiveTest() {
provider = "nodepool"; provider = "nodepool";
@ -76,6 +77,9 @@ public class NodePoolComputeServiceLiveTest extends BaseComputeServiceLiveTest {
@Override @Override
protected Properties setupProperties() { protected Properties setupProperties() {
Properties contextProperties = super.setupProperties(); Properties contextProperties = super.setupProperties();
contextProperties.setProperty(BASEDIR, basedir);
contextProperties.setProperty("nodepool.identity", "pooluser");
contextProperties.setProperty(POOL_ADMIN_ACCESS, "adminUsername=pooluser,adminPassword=poolpassword");
contextProperties.setProperty(TIMEOUT_SCRIPT_COMPLETE, (1200 * 1000) + ""); contextProperties.setProperty(TIMEOUT_SCRIPT_COMPLETE, (1200 * 1000) + "");
contextProperties.setProperty(TIMEOUT_PORT_OPEN, (1200 * 1000) + ""); contextProperties.setProperty(TIMEOUT_PORT_OPEN, (1200 * 1000) + "");
contextProperties.setProperty(BASEDIR, basedir); contextProperties.setProperty(BASEDIR, basedir);
@ -102,7 +106,7 @@ public class NodePoolComputeServiceLiveTest extends BaseComputeServiceLiveTest {
} }
@Override @Override
@Test(enabled = true) @Test(enabled = true, groups = "live")
public void testCreateAndRunAService() throws Exception { public void testCreateAndRunAService() throws Exception {
this.group = this.group + "s"; this.group = this.group + "s";
final String configuration = Strings2.toStringAndClose(RunScriptData.class final String configuration = Strings2.toStringAndClose(RunScriptData.class
@ -125,6 +129,11 @@ public class NodePoolComputeServiceLiveTest extends BaseComputeServiceLiveTest {
watch.reset().start(); watch.reset().start();
// note this is a dependency on the template resolution so we have the
// right process per
// operating system. moreover, we wish this to run as root, so that it
// can change ip
// tables rules and setup our admin user
client.runScriptOnNode(nodeId, installAdminUserJBossAndOpenPorts(node.getOperatingSystem()), client.runScriptOnNode(nodeId, installAdminUserJBossAndOpenPorts(node.getOperatingSystem()),
nameTask("configure-jboss")); nameTask("configure-jboss"));
@ -170,7 +179,7 @@ public class NodePoolComputeServiceLiveTest extends BaseComputeServiceLiveTest {
}), "jboss", node, JBOSS_PATTERN); }), "jboss", node, JBOSS_PATTERN);
} }
@Test(enabled = true, dependsOnMethods = "testCreateAndRunAService") @Test(enabled = true, groups = "live", dependsOnMethods = "testCreateAndRunAService")
public void testRebuildPoolStateFromStore() { public void testRebuildPoolStateFromStore() {
tearDownContext(); tearDownContext();
setupContext(); setupContext();
@ -178,13 +187,13 @@ public class NodePoolComputeServiceLiveTest extends BaseComputeServiceLiveTest {
assertEquals(((NodeMetadata) Iterables.get(client.listNodes(), 0)).getGroup(), this.group); assertEquals(((NodeMetadata) Iterables.get(client.listNodes(), 0)).getGroup(), this.group);
} }
@Test(enabled = false, dependsOnMethods = "testRebuildPoolStateFromStore") @Test(enabled = true, groups = "live", dependsOnMethods = "testRebuildPoolStateFromStore")
public void testIncreasePoolAllowed() throws RunNodesException { public void testIncreasePoolAllowed() throws RunNodesException {
client.createNodesInGroup(this.group, 1); client.createNodesInGroup(this.group, 1);
assertSame(client.listNodes().size(), 2); assertSame(client.listNodes().size(), 2);
} }
@Test(enabled = false, dependsOnMethods = "testIncreasePoolAllowed") @Test(enabled = true, groups = "live", dependsOnMethods = "testIncreasePoolAllowed")
public void testIncreasePoolNotAllowed() throws RunNodesException { public void testIncreasePoolNotAllowed() throws RunNodesException {
boolean caughtException = false; boolean caughtException = false;
try { try {
@ -195,7 +204,7 @@ public class NodePoolComputeServiceLiveTest extends BaseComputeServiceLiveTest {
assertTrue(caughtException, "expected an exception to be thrown"); assertTrue(caughtException, "expected an exception to be thrown");
} }
@Test(enabled = true, dependsOnMethods = "testRebuildPoolStateFromStore") @Test(enabled = true, groups = "live", dependsOnMethods = "testRebuildPoolStateFromStore")
public void testGetBackendComputeServiceContext() { public void testGetBackendComputeServiceContext() {
NodePoolComputeServiceContext ctx = context.utils().injector().getInstance(NodePoolComputeServiceContext.class); NodePoolComputeServiceContext ctx = context.utils().injector().getInstance(NodePoolComputeServiceContext.class);
assertNotNull(ctx.getBackendContext()); assertNotNull(ctx.getBackendContext());
@ -204,7 +213,7 @@ public class NodePoolComputeServiceLiveTest extends BaseComputeServiceLiveTest {
NodePredicates.inGroup(ctx.getPoolGroupName())).size(), 2); NodePredicates.inGroup(ctx.getPoolGroupName())).size(), 2);
} }
@Test(enabled = false, dependsOnMethods = "testGetBackendComputeServiceContext") @Test(enabled = false, groups = "live", dependsOnMethods = "testGetBackendComputeServiceContext")
public void testDestroyPoolNodes() { public void testDestroyPoolNodes() {
client.destroyNodesMatching(NodePredicates.inGroup(this.group)); client.destroyNodesMatching(NodePredicates.inGroup(this.group));
// after we destroy all nodes we should still have minsize nodes in the pool // after we destroy all nodes we should still have minsize nodes in the pool
@ -212,7 +221,7 @@ public class NodePoolComputeServiceLiveTest extends BaseComputeServiceLiveTest {
assertSame(ctx.getPoolStats().currentSize(), 1); assertSame(ctx.getPoolStats().currentSize(), 1);
} }
@Test(enabled = true, dependsOnMethods = "testGetBackendComputeServiceContext") @Test(enabled = true, groups = "live", dependsOnMethods = "testGetBackendComputeServiceContext")
public void testDestroyPool() { public void testDestroyPool() {
// TODO get the ctx without the injector // TODO get the ctx without the injector
NodePoolComputeServiceContext ctx = context.utils().injector().getInstance(NodePoolComputeServiceContext.class); NodePoolComputeServiceContext ctx = context.utils().injector().getInstance(NodePoolComputeServiceContext.class);
@ -223,7 +232,7 @@ public class NodePoolComputeServiceLiveTest extends BaseComputeServiceLiveTest {
} }
@Override @Override
@Test(enabled = false, dependsOnMethods = "testCompareSizes") @Test(enabled = false)
public void testAScriptExecutionAfterBootWithBasicTemplate() throws Exception { public void testAScriptExecutionAfterBootWithBasicTemplate() throws Exception {
} }
@ -233,7 +242,7 @@ public class NodePoolComputeServiceLiveTest extends BaseComputeServiceLiveTest {
} }
@Override @Override
@Test(enabled = false, dependsOnMethods = "testCompareSizes") @Test(enabled = false)
public void testConcurrentUseOfComputeServiceToCreateNodes() throws Exception { public void testConcurrentUseOfComputeServiceToCreateNodes() throws Exception {
} }

View File

@ -18,6 +18,7 @@
*/ */
package org.jclouds.nodepool.config; package org.jclouds.nodepool.config;
import static org.easymock.EasyMock.createNiceMock;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.File; import java.io.File;
@ -25,13 +26,19 @@ import java.util.Properties;
import org.jclouds.ContextBuilder; import org.jclouds.ContextBuilder;
import org.jclouds.compute.ComputeService; import org.jclouds.compute.ComputeService;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.LoginCredentials;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.nodepool.Backend; import org.jclouds.nodepool.Backend;
import org.jclouds.rest.annotations.Credential; import org.jclouds.rest.annotations.Credential;
import org.jclouds.ssh.SshClient;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.net.HostAndPort;
import com.google.inject.AbstractModule;
import com.google.inject.Key; import com.google.inject.Key;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
/** /**
@ -40,26 +47,22 @@ import com.google.inject.TypeLiteral;
@Test(groups = "unit", testName = "BindBackendComputeServiceTest") @Test(groups = "unit", testName = "BindBackendComputeServiceTest")
public class BindBackendComputeServiceTest { public class BindBackendComputeServiceTest {
//TODO: identity became nodepool-user
@Test(enabled = false)
public void testBinds() { public void testBinds() {
final String basedir = "target/" + this.getClass().getSimpleName(); final String basedir = "target/" + this.getClass().getSimpleName();
new File(basedir).delete(); new File(basedir).delete();
Properties overrides = new Properties(); Properties overrides = new Properties();
overrides.setProperty(NodePoolProperties.BACKEND_PROVIDER, "stub"); overrides.setProperty(NodePoolProperties.BACKEND_PROVIDER, "stub");
overrides.setProperty(NodePoolProperties.BASEDIR, basedir); overrides.setProperty(NodePoolProperties.BASEDIR, basedir);
// note no ssh module since we are stub and not trying ssh, yet // note no ssh module since we are stub and not trying ssh, yet
overrides.setProperty(NodePoolProperties.BACKEND_MODULES, SLF4JLoggingModule.class.getName()); overrides.setProperty(NodePoolProperties.BACKEND_MODULES, SLF4JLoggingModule.class.getName() + ","
+ StubSshClientModule.class.getName());
ComputeService stub = ContextBuilder.newBuilder("nodepool").credentials("foo", "bar").endpoint("gooend")
.apiVersion("1.1").buildVersion("1.1-2").overrides(overrides).buildInjector()
.getInstance(Key.get(new TypeLiteral<Supplier<ComputeService>>() {
}, Backend.class)).get();
ComputeService stub = ContextBuilder.newBuilder("nodepool")
.credentials("foo", "bar")
.endpoint("gooend")
.apiVersion("1.1")
.buildVersion("1.1-2")
.overrides(overrides)
.buildInjector().getInstance(Key.get(new TypeLiteral<Supplier<ComputeService>>(){}, Backend.class)).get();
assertEquals(stub.getContext().unwrap().getIdentity(), "foo"); assertEquals(stub.getContext().unwrap().getIdentity(), "foo");
assertEquals(stub.getContext().utils().injector().getInstance(Key.get(String.class, Credential.class)), "bar"); assertEquals(stub.getContext().utils().injector().getInstance(Key.get(String.class, Credential.class)), "bar");
assertEquals(stub.getContext().unwrap().getProviderMetadata().getEndpoint(), "gooend"); assertEquals(stub.getContext().unwrap().getProviderMetadata().getEndpoint(), "gooend");
@ -71,5 +74,23 @@ public class BindBackendComputeServiceTest {
} }
public static class StubSshClientModule extends AbstractModule {
protected void configure() {
bind(SshClient.Factory.class).to(Factory.class).in(Scopes.SINGLETON);
}
private static class Factory implements SshClient.Factory {
@Override
public SshClient create(HostAndPort socket, LoginCredentials credentials) {
return createNiceMock(SshClient.class);
}
@Override
public SshClient create(HostAndPort socket, Credentials credentials) {
return createNiceMock(SshClient.class);
}
}
}
} }

View File

@ -41,24 +41,21 @@ import com.google.inject.name.Names;
@Test(groups = "unit", testName = "BindInputStreamToFilesystemBlobStoreTest") @Test(groups = "unit", testName = "BindInputStreamToFilesystemBlobStoreTest")
public class BindInputStreamToFilesystemBlobStoreTest { public class BindInputStreamToFilesystemBlobStoreTest {
//TODO: binding error
@Test(enabled = false)
public void testCreatesDir() { public void testCreatesDir() {
final String basedir = "target/" + this.getClass().getSimpleName(); final String basedir = "target/" + this.getClass().getSimpleName();
new File(basedir).delete(); new File(basedir).delete();
Map<String, InputStream> file = Guice.createInjector(new AbstractModule() { Map<String, InputStream> file = Guice
.createInjector(new AbstractModule() {
@Override @Override
protected void configure() { protected void configure() {
bindConstant().annotatedWith(Names.named(NodePoolProperties.BASEDIR)).to(basedir); bindConstant().annotatedWith(Names.named(NodePoolProperties.BASEDIR)).to(basedir);
bindConstant().annotatedWith(Names.named(NodePoolProperties.METADATA_CONTAINER)).to("barr"); bindConstant().annotatedWith(Names.named(NodePoolProperties.METADATA_CONTAINER)).to("barr");
bindConstant().annotatedWith(Names.named(NodePoolProperties.BACKEND_MODULES)).to( bindConstant().annotatedWith(Names.named(NodePoolProperties.BACKEND_MODULES)).to(
SLF4JLoggingModule.class.getName()); SLF4JLoggingModule.class.getName());
} }
}, new BindInputStreamToFilesystemBlobStore())
}, new BindInputStreamToFilesystemBlobStore()).getInstance( .getInstance(Key.get(new TypeLiteral<Supplier<Map<String, InputStream>>>() {
Key.get(new TypeLiteral<Supplier<Map<String, InputStream>>>() { }, Names.named("METADATA"))).get();
})).get();
assert (new File(basedir + "/barr").exists()); assert (new File(basedir + "/barr").exists());
assertEquals(file.keySet(), ImmutableSet.of()); assertEquals(file.keySet(), ImmutableSet.of());

View File

@ -1,5 +1,5 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<configuration scan="false"> <configuration scan="false">
<appender name="FILE" class="ch.qos.logback.core.FileAppender"> <appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>target/test-data/jclouds.log</file> <file>target/test-data/jclouds.log</file>

View File

@ -10,6 +10,8 @@ import java.util.List;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import clojure.main;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
@ -64,6 +66,8 @@ import com.google.common.collect.ImmutableMap;
public class AdminAccessBuilderSpec { public class AdminAccessBuilderSpec {
private static final long serialVersionUID = -379469670373111569L;
/** Parses a single value. */ /** Parses a single value. */
protected static interface ValueParser { protected static interface ValueParser {
void parse(AdminAccessBuilderSpec spec, String key, @Nullable String value); void parse(AdminAccessBuilderSpec spec, String key, @Nullable String value);