mirror of
https://github.com/apache/jclouds.git
synced 2025-02-16 15:08:28 +00:00
commit
5bad701876
@ -18,7 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.live;
|
package org.jclouds.openstack.nova.live;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -37,30 +36,23 @@ public class PropertyHelper {
|
|||||||
|
|
||||||
private static String provider = "nova";
|
private static String provider = "nova";
|
||||||
|
|
||||||
public static void overridePropertyFromSystemProperty(final Properties properties, String propertyName) {
|
public static Map<String, String> setupKeyPair(Properties properties) throws IOException {
|
||||||
if ((System.getProperty(propertyName) != null) && !System.getProperty(propertyName).equals("${" + propertyName + "}"))
|
return ImmutableMap.of(
|
||||||
properties.setProperty(propertyName, System.getProperty(propertyName));
|
"private", Resources.toString(Resources.getResource(PropertyHelper.class, properties.getProperty("test.ssh.keyfile.private")), Charsets.UTF_8),
|
||||||
}
|
"public", Resources.toString(Resources.getResource(PropertyHelper.class, properties.getProperty("test.ssh.keyfile.public")), Charsets.UTF_8));
|
||||||
|
|
||||||
public static Map<String, String> setupKeyPair(Properties properties) throws FileNotFoundException, IOException {
|
|
||||||
return ImmutableMap.<String, String>of(
|
|
||||||
"private", Resources.toString(Resources.getResource(properties.getProperty("test.ssh.keyfile.private")), Charsets.UTF_8),
|
|
||||||
"public", Resources.toString(Resources.getResource(properties.getProperty("test.ssh.keyfile.public")), Charsets.UTF_8));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Properties setupProperties(Class<?> clazz) throws IOException {
|
public static Properties setupProperties(Class<?> clazz) throws IOException {
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
|
|
||||||
InputStream propertiesStream = clazz.getResourceAsStream("/test.properties");
|
String propertiesPath = System.getProperty("test.properties");
|
||||||
if (propertiesStream != null)
|
if (propertiesPath != null) {
|
||||||
|
InputStream propertiesStream = clazz.getResourceAsStream(propertiesPath);
|
||||||
properties.load(propertiesStream);
|
properties.load(propertiesStream);
|
||||||
overridePropertyFromSystemProperty(properties, "test." + provider + ".endpoint");
|
}
|
||||||
overridePropertyFromSystemProperty(properties, "test." + provider + ".apiversion");
|
|
||||||
overridePropertyFromSystemProperty(properties, "test." + provider + ".identity");
|
properties.putAll(System.getProperties());
|
||||||
overridePropertyFromSystemProperty(properties, "test." + provider + ".credential");
|
|
||||||
overridePropertyFromSystemProperty(properties, "test.ssh.keyfile.private");
|
|
||||||
overridePropertyFromSystemProperty(properties, "test.ssh.keyfile.public");
|
|
||||||
overridePropertyFromSystemProperty(properties, "test.initializer");
|
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ import java.util.concurrent.ExecutionException;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
import org.jclouds.compute.ComputeService;
|
import org.jclouds.compute.ComputeService;
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||||
@ -75,6 +76,7 @@ public class ComputeBase {
|
|||||||
|
|
||||||
protected Map<String, String> keyPair;
|
protected Map<String, String> keyPair;
|
||||||
protected Properties overrides;
|
protected Properties overrides;
|
||||||
|
protected String testImageId;
|
||||||
|
|
||||||
@BeforeTest
|
@BeforeTest
|
||||||
public void before() throws InterruptedException, ExecutionException, TimeoutException, IOException {
|
public void before() throws InterruptedException, ExecutionException, TimeoutException, IOException {
|
||||||
@ -82,6 +84,7 @@ public class ComputeBase {
|
|||||||
setupOverrides(properties);
|
setupOverrides(properties);
|
||||||
overrides = properties;
|
overrides = properties;
|
||||||
keyPair = setupKeyPair(properties);
|
keyPair = setupKeyPair(properties);
|
||||||
|
testImageId = properties.getProperty("test.nova.image.id");
|
||||||
initializeContextAndComputeService(properties);
|
initializeContextAndComputeService(properties);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -97,7 +100,7 @@ public class ComputeBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected TemplateBuilder getDefaultTemplateBuilder() {
|
protected TemplateBuilder getDefaultTemplateBuilder() {
|
||||||
return computeService.templateBuilder().imageId("95").options(getDefaultTemplateOptions());
|
return computeService.templateBuilder().imageId(testImageId).options(getDefaultTemplateOptions());
|
||||||
}
|
}
|
||||||
|
|
||||||
private TemplateOptions getDefaultTemplateOptions() {
|
private TemplateOptions getDefaultTemplateOptions() {
|
||||||
@ -133,13 +136,14 @@ public class ComputeBase {
|
|||||||
computeService = context.getComputeService();
|
computeService = context.getComputeService();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String awaitForPublicAddressAssigned(String nodeId) throws InterruptedException {
|
protected String awaitForStartup(String nodeId) throws InterruptedException {
|
||||||
while (true) {
|
while (true) {
|
||||||
Set<String> addresses = computeService.getNodeMetadata(nodeId).getPublicAddresses();
|
NodeMetadata metadata = computeService.getNodeMetadata(nodeId);
|
||||||
|
Set<String> addresses = metadata.getPublicAddresses();
|
||||||
System.out.println(addresses);
|
System.out.println(addresses);
|
||||||
System.out.println(computeService.getNodeMetadata(nodeId).getState());
|
System.out.println(metadata.getState());
|
||||||
if (addresses != null)
|
if (metadata.getState() == NodeState.RUNNING && addresses != null && !addresses.isEmpty())
|
||||||
if (!addresses.isEmpty()) return addresses.iterator().next();
|
return addresses.iterator().next();
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,7 @@ import com.google.common.collect.ImmutableSet;
|
|||||||
public class ComputeServiceCheck {
|
public class ComputeServiceCheck {
|
||||||
private ComputeServiceContextFactory contextFactory;
|
private ComputeServiceContextFactory contextFactory;
|
||||||
private ComputeServiceContext context;
|
private ComputeServiceContext context;
|
||||||
|
private String testImageId;
|
||||||
|
|
||||||
@BeforeTest
|
@BeforeTest
|
||||||
public void setupClient() throws IOException {
|
public void setupClient() throws IOException {
|
||||||
@ -56,6 +57,7 @@ public class ComputeServiceCheck {
|
|||||||
Properties properties = setupOverrides(setupProperties(this.getClass()));
|
Properties properties = setupOverrides(setupProperties(this.getClass()));
|
||||||
context = contextFactory.createContext("nova",
|
context = contextFactory.createContext("nova",
|
||||||
ImmutableSet.of(new SshjSshClientModule(), new SLF4JLoggingModule()), properties);
|
ImmutableSet.of(new SshjSshClientModule(), new SLF4JLoggingModule()), properties);
|
||||||
|
testImageId = properties.getProperty("test.nova.image.id");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -73,7 +75,7 @@ public class ComputeServiceCheck {
|
|||||||
ComputeService cs = context.getComputeService();
|
ComputeService cs = context.getComputeService();
|
||||||
|
|
||||||
TemplateOptions options = new TemplateOptions().blockUntilRunning(false);
|
TemplateOptions options = new TemplateOptions().blockUntilRunning(false);
|
||||||
Template template = cs.templateBuilder().imageId("95").hardwareId("2").options(options).build();
|
Template template = cs.templateBuilder().imageId(testImageId).hardwareId("2").options(options).build();
|
||||||
Set<? extends NodeMetadata> metedata = cs.createNodesInGroup("test", 1, template);
|
Set<? extends NodeMetadata> metedata = cs.createNodesInGroup("test", 1, template);
|
||||||
System.out.println(metedata);
|
System.out.println(metedata);
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,7 @@ import java.util.SortedSet;
|
|||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
|
import net.schmizz.sshj.userauth.UserAuthException;
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||||
import org.jclouds.compute.RunNodesException;
|
import org.jclouds.compute.RunNodesException;
|
||||||
@ -150,10 +151,10 @@ public class NovaComputeServiceLiveTest extends ComputeBase {
|
|||||||
.family(OsFamily.UBUNTU).description("ffoo").build()));
|
.family(OsFamily.UBUNTU).description("ffoo").build()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = AuthorizationException.class, expectedExceptionsMessageRegExp = "Auth fail", timeOut = 120000)
|
@Test(expectedExceptions = UserAuthException.class, timeOut = 240000)
|
||||||
void testScriptExecutionWithWrongCredentials() throws Throwable, RunScriptOnNodesException, URISyntaxException, InterruptedException {
|
void testScriptExecutionWithWrongCredentials() throws Throwable {
|
||||||
NodeMetadata node = getDefaultNodeImmediately(group);
|
NodeMetadata node = getDefaultNodeImmediately(group);
|
||||||
String address = awaitForPublicAddressAssigned(node.getId());
|
String address = awaitForStartup(node.getId());
|
||||||
awaitForSshPort(address, new Credentials("root", keyPair.get("private")));
|
awaitForSshPort(address, new Credentials("root", keyPair.get("private")));
|
||||||
OperatingSystem os = node.getOperatingSystem();
|
OperatingSystem os = node.getOperatingSystem();
|
||||||
try {
|
try {
|
||||||
@ -165,11 +166,11 @@ public class NovaComputeServiceLiveTest extends ComputeBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeOut = 120000)
|
@Test(timeOut = 240000)
|
||||||
public void testScriptExecutionAfterBootWithBasicTemplate() throws InterruptedException, RunNodesException, RunScriptOnNodesException, URISyntaxException, IOException {
|
public void testScriptExecutionAfterBootWithBasicTemplate() throws InterruptedException, RunNodesException, RunScriptOnNodesException, URISyntaxException, IOException {
|
||||||
|
|
||||||
NodeMetadata node = getDefaultNodeImmediately(group);
|
NodeMetadata node = getDefaultNodeImmediately(group);
|
||||||
String address = awaitForPublicAddressAssigned(node.getId());
|
String address = awaitForStartup(node.getId());
|
||||||
awaitForSshPort(address, new Credentials("root", keyPair.get("private")));
|
awaitForSshPort(address, new Credentials("root", keyPair.get("private")));
|
||||||
for (Map.Entry<? extends NodeMetadata, ExecResponse> response : computeService.runScriptOnNodesMatching(
|
for (Map.Entry<? extends NodeMetadata, ExecResponse> response : computeService.runScriptOnNodesMatching(
|
||||||
runningInGroup(group), Statements.exec("echo hello"),
|
runningInGroup(group), Statements.exec("echo hello"),
|
||||||
@ -267,7 +268,6 @@ public class NovaComputeServiceLiveTest extends ComputeBase {
|
|||||||
@Test(timeOut = 120000)
|
@Test(timeOut = 120000)
|
||||||
public void testGetNodeMetadata() throws Exception {
|
public void testGetNodeMetadata() throws Exception {
|
||||||
Set<NodeMetadata> nodes = Sets.newHashSet(getDefaultNodeImmediately(group));
|
Set<NodeMetadata> nodes = Sets.newHashSet(getDefaultNodeImmediately(group));
|
||||||
awaitForPublicAddressAssigned(nodes.iterator().next().getId());
|
|
||||||
Map<String, ? extends NodeMetadata> metadataMap = newLinkedHashMap(uniqueIndex(filter(computeService
|
Map<String, ? extends NodeMetadata> metadataMap = newLinkedHashMap(uniqueIndex(filter(computeService
|
||||||
.listNodesDetailsMatching(all()), and(inGroup(group), not(TERMINATED))),
|
.listNodesDetailsMatching(all()), and(inGroup(group), not(TERMINATED))),
|
||||||
new Function<NodeMetadata, String>() {
|
new Function<NodeMetadata, String>() {
|
||||||
@ -279,6 +279,7 @@ public class NovaComputeServiceLiveTest extends ComputeBase {
|
|||||||
|
|
||||||
}));
|
}));
|
||||||
for (NodeMetadata node : nodes) {
|
for (NodeMetadata node : nodes) {
|
||||||
|
awaitForStartup(node.getId());
|
||||||
metadataMap.remove(node.getId());
|
metadataMap.remove(node.getId());
|
||||||
NodeMetadata nodeMetadata = computeService.getNodeMetadata(node.getId());
|
NodeMetadata nodeMetadata = computeService.getNodeMetadata(node.getId());
|
||||||
assertEquals(parseGroupFromName(nodeMetadata.getName()), group);
|
assertEquals(parseGroupFromName(nodeMetadata.getName()), group);
|
||||||
|
@ -50,7 +50,7 @@ import com.google.inject.Module;
|
|||||||
* @author Victor Galkin
|
* @author Victor Galkin
|
||||||
*/
|
*/
|
||||||
public class ClientBase {
|
public class ClientBase {
|
||||||
protected int testImageId = 95;
|
protected int testImageId;
|
||||||
protected NovaClient client;
|
protected NovaClient client;
|
||||||
protected SshClient.Factory sshFactory;
|
protected SshClient.Factory sshFactory;
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@ -76,6 +76,8 @@ public class ClientBase {
|
|||||||
injector.injectMembers(socketOpen); // add logger
|
injector.injectMembers(socketOpen); // add logger
|
||||||
|
|
||||||
keyPair = setupKeyPair(properties);
|
keyPair = setupKeyPair(properties);
|
||||||
|
|
||||||
|
testImageId = Integer.valueOf(properties.getProperty("test.nova.image.id"));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Server getDefaultServerImmediately() {
|
protected Server getDefaultServerImmediately() {
|
||||||
|
1
apis/nova/src/test/resources/.gitignore
vendored
1
apis/nova/src/test/resources/.gitignore
vendored
@ -1 +0,0 @@
|
|||||||
/test.properties
|
|
@ -2,6 +2,6 @@ test.nova.endpoint=http://dragon004.hw.griddynamics.net:8774
|
|||||||
test.nova.apiversion=1.1
|
test.nova.apiversion=1.1
|
||||||
test.nova.identity=admin
|
test.nova.identity=admin
|
||||||
test.nova.credential=d744752f-20d3-4d75-979f-f62f16033b07
|
test.nova.credential=d744752f-20d3-4d75-979f-f62f16033b07
|
||||||
test.initializer=
|
test.nova.image.id=17
|
||||||
test.ssh.keyfile.private=f:/gigaspace/distr/gigaspaces.pem
|
test.ssh.keyfile.private=/keys/rhelimg.pem
|
||||||
test.ssh.keyfile.public=f:/gigaspace/distr/gigaspaces.pem
|
test.ssh.keyfile.public=/keys/rhelimg.pub
|
Loading…
x
Reference in New Issue
Block a user