From e8dcfa5f526d97662b484fefbb7d03843984a6e1 Mon Sep 17 00:00:00 2001 From: Dmitri Babaev Date: Sun, 31 Jul 2011 00:46:11 +0400 Subject: [PATCH] image id property for tests, test properties load refactoring --- .../openstack/nova/live/PropertyHelper.java | 26 +++++++------------ .../nova/live/compute/ComputeBase.java | 4 ++- .../live/compute/ComputeServiceCheck.java | 4 ++- .../nova/live/novaclient/ClientBase.java | 4 ++- apis/nova/src/test/resources/.gitignore | 1 - ...operties.template => dragon004.properties} | 6 ++--- 6 files changed, 21 insertions(+), 24 deletions(-) delete mode 100644 apis/nova/src/test/resources/.gitignore rename apis/nova/src/test/resources/{test.properties.template => dragon004.properties} (54%) diff --git a/apis/nova/src/test/java/org/jclouds/openstack/nova/live/PropertyHelper.java b/apis/nova/src/test/java/org/jclouds/openstack/nova/live/PropertyHelper.java index 3f65a987e9..65141ba039 100644 --- a/apis/nova/src/test/java/org/jclouds/openstack/nova/live/PropertyHelper.java +++ b/apis/nova/src/test/java/org/jclouds/openstack/nova/live/PropertyHelper.java @@ -18,7 +18,6 @@ */ package org.jclouds.openstack.nova.live; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.Map; @@ -37,13 +36,8 @@ public class PropertyHelper { private static String provider = "nova"; - public static void overridePropertyFromSystemProperty(final Properties properties, String propertyName) { - if ((System.getProperty(propertyName) != null) && !System.getProperty(propertyName).equals("${" + propertyName + "}")) - properties.setProperty(propertyName, System.getProperty(propertyName)); - } - - public static Map setupKeyPair(Properties properties) throws FileNotFoundException, IOException { - return ImmutableMap.of( + public static Map setupKeyPair(Properties properties) throws IOException { + return ImmutableMap.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)); } @@ -51,16 +45,14 @@ public class PropertyHelper { public static Properties setupProperties(Class clazz) throws IOException { Properties properties = new Properties(); - InputStream propertiesStream = clazz.getResourceAsStream("/test.properties"); - if (propertiesStream != null) + String propertiesPath = System.getProperty("test.properties"); + if (propertiesPath != null) { + InputStream propertiesStream = clazz.getResourceAsStream(propertiesPath); properties.load(propertiesStream); - overridePropertyFromSystemProperty(properties, "test." + provider + ".endpoint"); - overridePropertyFromSystemProperty(properties, "test." + provider + ".apiversion"); - overridePropertyFromSystemProperty(properties, "test." + provider + ".identity"); - overridePropertyFromSystemProperty(properties, "test." + provider + ".credential"); - overridePropertyFromSystemProperty(properties, "test.ssh.keyfile.private"); - overridePropertyFromSystemProperty(properties, "test.ssh.keyfile.public"); - overridePropertyFromSystemProperty(properties, "test.initializer"); + } + + properties.putAll(System.getProperties()); + return properties; } diff --git a/apis/nova/src/test/java/org/jclouds/openstack/nova/live/compute/ComputeBase.java b/apis/nova/src/test/java/org/jclouds/openstack/nova/live/compute/ComputeBase.java index ee08c37008..8eb93995c6 100644 --- a/apis/nova/src/test/java/org/jclouds/openstack/nova/live/compute/ComputeBase.java +++ b/apis/nova/src/test/java/org/jclouds/openstack/nova/live/compute/ComputeBase.java @@ -75,6 +75,7 @@ public class ComputeBase { protected Map keyPair; protected Properties overrides; + protected String testImageId; @BeforeTest public void before() throws InterruptedException, ExecutionException, TimeoutException, IOException { @@ -82,6 +83,7 @@ public class ComputeBase { setupOverrides(properties); overrides = properties; keyPair = setupKeyPair(properties); + testImageId = properties.getProperty("test.nova.image.id"); initializeContextAndComputeService(properties); } @@ -97,7 +99,7 @@ public class ComputeBase { } protected TemplateBuilder getDefaultTemplateBuilder() { - return computeService.templateBuilder().imageId("95").options(getDefaultTemplateOptions()); + return computeService.templateBuilder().imageId(testImageId).options(getDefaultTemplateOptions()); } private TemplateOptions getDefaultTemplateOptions() { diff --git a/apis/nova/src/test/java/org/jclouds/openstack/nova/live/compute/ComputeServiceCheck.java b/apis/nova/src/test/java/org/jclouds/openstack/nova/live/compute/ComputeServiceCheck.java index 6bcb61b6b5..f9632d40e9 100644 --- a/apis/nova/src/test/java/org/jclouds/openstack/nova/live/compute/ComputeServiceCheck.java +++ b/apis/nova/src/test/java/org/jclouds/openstack/nova/live/compute/ComputeServiceCheck.java @@ -49,6 +49,7 @@ import com.google.common.collect.ImmutableSet; public class ComputeServiceCheck { private ComputeServiceContextFactory contextFactory; private ComputeServiceContext context; + private String testImageId; @BeforeTest public void setupClient() throws IOException { @@ -56,6 +57,7 @@ public class ComputeServiceCheck { Properties properties = setupOverrides(setupProperties(this.getClass())); context = contextFactory.createContext("nova", ImmutableSet.of(new SshjSshClientModule(), new SLF4JLoggingModule()), properties); + testImageId = properties.getProperty("test.nova.image.id"); } @Test @@ -73,7 +75,7 @@ public class ComputeServiceCheck { ComputeService cs = context.getComputeService(); 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 metedata = cs.createNodesInGroup("test", 1, template); System.out.println(metedata); } diff --git a/apis/nova/src/test/java/org/jclouds/openstack/nova/live/novaclient/ClientBase.java b/apis/nova/src/test/java/org/jclouds/openstack/nova/live/novaclient/ClientBase.java index a3e1295d1b..f7fcb9b4ed 100644 --- a/apis/nova/src/test/java/org/jclouds/openstack/nova/live/novaclient/ClientBase.java +++ b/apis/nova/src/test/java/org/jclouds/openstack/nova/live/novaclient/ClientBase.java @@ -50,7 +50,7 @@ import com.google.inject.Module; * @author Victor Galkin */ public class ClientBase { - protected int testImageId = 95; + protected int testImageId; protected NovaClient client; protected SshClient.Factory sshFactory; @SuppressWarnings("unused") @@ -76,6 +76,8 @@ public class ClientBase { injector.injectMembers(socketOpen); // add logger keyPair = setupKeyPair(properties); + + testImageId = Integer.valueOf(properties.getProperty("test.nova.image.id")); } protected Server getDefaultServerImmediately() { diff --git a/apis/nova/src/test/resources/.gitignore b/apis/nova/src/test/resources/.gitignore deleted file mode 100644 index c6e479480a..0000000000 --- a/apis/nova/src/test/resources/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/test.properties diff --git a/apis/nova/src/test/resources/test.properties.template b/apis/nova/src/test/resources/dragon004.properties similarity index 54% rename from apis/nova/src/test/resources/test.properties.template rename to apis/nova/src/test/resources/dragon004.properties index dd98c75dc9..85d7434859 100644 --- a/apis/nova/src/test/resources/test.properties.template +++ b/apis/nova/src/test/resources/dragon004.properties @@ -2,6 +2,6 @@ test.nova.endpoint=http://dragon004.hw.griddynamics.net:8774 test.nova.apiversion=1.1 test.nova.identity=admin test.nova.credential=d744752f-20d3-4d75-979f-f62f16033b07 -test.initializer= -test.ssh.keyfile.private=f:/gigaspace/distr/gigaspaces.pem -test.ssh.keyfile.public=f:/gigaspace/distr/gigaspaces.pem \ No newline at end of file +test.nova.image.id=17 +test.ssh.keyfile.private=/keys/rhelimg.pem +test.ssh.keyfile.public=/keys/rhelimg.pub \ No newline at end of file