whirr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomwh...@apache.org
Subject svn commit: r1004117 - in /incubator/whirr/trunk: ./ core/src/main/java/org/apache/whirr/service/ core/src/test/java/org/apache/whirr/ssh/ services/cassandra/ services/cassandra/src/test/java/org/apache/whirr/service/cassandra/integration/ services/had...
Date Mon, 04 Oct 2010 05:09:03 GMT
Author: tomwhite
Date: Mon Oct  4 05:09:02 2010
New Revision: 1004117

URL: http://svn.apache.org/viewvc?rev=1004117&view=rev
Log:
WHIRR-109. Unit tests fail if there is no private key found at ~/.ssh/id_rsa. Contributed
by Adrian Cole.

Added:
    incubator/whirr/trunk/core/src/test/java/org/apache/whirr/ssh/
    incubator/whirr/trunk/core/src/test/java/org/apache/whirr/ssh/KeyPair.java   (with props)
    incubator/whirr/trunk/core/src/test/java/org/apache/whirr/ssh/KeyPairTest.java   (with
props)
Modified:
    incubator/whirr/trunk/CHANGES.txt
    incubator/whirr/trunk/core/src/main/java/org/apache/whirr/service/ClusterSpec.java
    incubator/whirr/trunk/pom.xml
    incubator/whirr/trunk/services/cassandra/pom.xml
    incubator/whirr/trunk/services/cassandra/src/test/java/org/apache/whirr/service/cassandra/integration/CassandraServiceTest.java
    incubator/whirr/trunk/services/hadoop/pom.xml
    incubator/whirr/trunk/services/hadoop/src/test/java/org/apache/whirr/service/hadoop/integration/HadoopServiceTest.java
    incubator/whirr/trunk/services/zookeeper/pom.xml
    incubator/whirr/trunk/services/zookeeper/src/test/java/org/apache/whirr/service/zookeeper/integration/ZooKeeperServiceTest.java

Modified: incubator/whirr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/CHANGES.txt?rev=1004117&r1=1004116&r2=1004117&view=diff
==============================================================================
--- incubator/whirr/trunk/CHANGES.txt (original)
+++ incubator/whirr/trunk/CHANGES.txt Mon Oct  4 05:09:02 2010
@@ -20,6 +20,9 @@ Trunk (unreleased changes)
 
     WHIRR-105. Add version command to the CLI. (tomwhite)
 
+    WHIRR-109. Unit tests fail if there is no private key found at
+    ~/.ssh/id_rsa. (Adrian Cole via tomwhite)
+
   BUG FIXES
 
     WHIRR-93. Fail on checkstyle violation. (tomwhite)

Modified: incubator/whirr/trunk/core/src/main/java/org/apache/whirr/service/ClusterSpec.java
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/core/src/main/java/org/apache/whirr/service/ClusterSpec.java?rev=1004117&r1=1004116&r2=1004117&view=diff
==============================================================================
--- incubator/whirr/trunk/core/src/main/java/org/apache/whirr/service/ClusterSpec.java (original)
+++ incubator/whirr/trunk/core/src/main/java/org/apache/whirr/service/ClusterSpec.java Mon
Oct  4 05:09:02 2010
@@ -181,13 +181,13 @@ public class ClusterSpec {
     try {
       String privateKeyPath = c.getString(
           Property.PRIVATE_KEY_FILE.getConfigName());
-      if (privateKeyPath != null)
+      if (privateKeyPath != null && new File(privateKeyPath).exists())
         setPrivateKey(new File(privateKeyPath));
       String publicKeyPath = c.getString(Property.PUBLIC_KEY_FILE.
                getConfigName());
       publicKeyPath = publicKeyPath == null && privateKeyPath != null ?
                 privateKeyPath + ".pub" : publicKeyPath;
-      if (publicKeyPath != null)
+      if (publicKeyPath != null && new File(publicKeyPath).exists())
         setPublicKey(new File(publicKeyPath));
     } catch (IOException e) {
       throw new ConfigurationException("error reading key from file", e);

Added: incubator/whirr/trunk/core/src/test/java/org/apache/whirr/ssh/KeyPair.java
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/core/src/test/java/org/apache/whirr/ssh/KeyPair.java?rev=1004117&view=auto
==============================================================================
--- incubator/whirr/trunk/core/src/test/java/org/apache/whirr/ssh/KeyPair.java (added)
+++ incubator/whirr/trunk/core/src/test/java/org/apache/whirr/ssh/KeyPair.java Mon Oct  4
05:09:02 2010
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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.apache.whirr.ssh;
+
+import java.io.ByteArrayOutputStream;
+import java.util.Map;
+
+import com.google.common.collect.ImmutableMap;
+import com.jcraft.jsch.JSch;
+import com.jcraft.jsch.JSchException;
+
+/**
+ * A convenience class for generating an RSA key pair.
+ */
+public class KeyPair {
+
+  /**
+   * return a "public" -> rsa public key, "private" -> its corresponding
+   *   private key
+   */
+  public static Map<String,String> generate() throws JSchException {
+    com.jcraft.jsch.KeyPair pair = com.jcraft.jsch.KeyPair.genKeyPair(
+        new JSch(),  com.jcraft.jsch.KeyPair.RSA);
+    ByteArrayOutputStream publicKeyOut = new ByteArrayOutputStream();
+    ByteArrayOutputStream privateKeyOut = new ByteArrayOutputStream();
+    pair.writePublicKey(publicKeyOut, "whirr");
+    pair.writePrivateKey(privateKeyOut);
+    String publicKey = new String(publicKeyOut.toByteArray());
+    String privateKey = new String(privateKeyOut.toByteArray());
+    return ImmutableMap.<String, String> of("public", publicKey,
+        "private", privateKey);
+  }
+}

Propchange: incubator/whirr/trunk/core/src/test/java/org/apache/whirr/ssh/KeyPair.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/whirr/trunk/core/src/test/java/org/apache/whirr/ssh/KeyPairTest.java
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/core/src/test/java/org/apache/whirr/ssh/KeyPairTest.java?rev=1004117&view=auto
==============================================================================
--- incubator/whirr/trunk/core/src/test/java/org/apache/whirr/ssh/KeyPairTest.java (added)
+++ incubator/whirr/trunk/core/src/test/java/org/apache/whirr/ssh/KeyPairTest.java Mon Oct
 4 05:09:02 2010
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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.apache.whirr.ssh;
+
+import static org.hamcrest.Matchers.containsString;
+import static org.junit.Assert.assertThat;
+
+import java.util.Map;
+
+import org.junit.Test;
+
+import com.jcraft.jsch.JSchException;
+
+public class KeyPairTest {
+
+  @Test
+  public void testGenerate() throws JSchException {
+    Map<String, String> pair = KeyPair.generate();
+    assertThat(pair.get("public"),
+        containsString("ssh-rsa "));
+    assertThat(pair.get("private"),
+          containsString("-----BEGIN RSA PRIVATE KEY-----\n"));
+  }
+  
+}

Propchange: incubator/whirr/trunk/core/src/test/java/org/apache/whirr/ssh/KeyPairTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/whirr/trunk/pom.xml
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/pom.xml?rev=1004117&r1=1004116&r2=1004117&view=diff
==============================================================================
--- incubator/whirr/trunk/pom.xml (original)
+++ incubator/whirr/trunk/pom.xml Mon Oct  4 05:09:02 2010
@@ -213,6 +213,13 @@
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-jar-plugin</artifactId>
         <version>2.3.1</version>
+        <executions>
+          <execution>
+            <goals>
+              <goal>test-jar</goal>
+            </goals>
+          </execution>
+        </executions>
         <configuration>
           <archive>
             <manifest>

Modified: incubator/whirr/trunk/services/cassandra/pom.xml
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/services/cassandra/pom.xml?rev=1004117&r1=1004116&r2=1004117&view=diff
==============================================================================
--- incubator/whirr/trunk/services/cassandra/pom.xml (original)
+++ incubator/whirr/trunk/services/cassandra/pom.xml Mon Oct  4 05:09:02 2010
@@ -35,6 +35,13 @@
       <version>${project.version}</version>
     </dependency>
     <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>whirr-core</artifactId>
+      <version>${project.version}</version>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>org.jclouds</groupId>
       <artifactId>jclouds-aws</artifactId>
     </dependency>

Modified: incubator/whirr/trunk/services/cassandra/src/test/java/org/apache/whirr/service/cassandra/integration/CassandraServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/services/cassandra/src/test/java/org/apache/whirr/service/cassandra/integration/CassandraServiceTest.java?rev=1004117&r1=1004116&r2=1004117&view=diff
==============================================================================
--- incubator/whirr/trunk/services/cassandra/src/test/java/org/apache/whirr/service/cassandra/integration/CassandraServiceTest.java
(original)
+++ incubator/whirr/trunk/services/cassandra/src/test/java/org/apache/whirr/service/cassandra/integration/CassandraServiceTest.java
Mon Oct  4 05:09:02 2010
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertTru
 import java.io.IOException;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import org.apache.cassandra.thrift.Cassandra;
@@ -41,10 +42,13 @@ import org.apache.whirr.service.Service;
 import org.apache.whirr.service.ServiceFactory;
 import org.apache.whirr.service.Cluster.Instance;
 import org.apache.whirr.service.cassandra.CassandraService;
+import org.apache.whirr.ssh.KeyPair;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
+import com.jcraft.jsch.JSchException;
+
 public class CassandraServiceTest {
 
   private static final String KEYSPACE = "Keyspace1";
@@ -54,13 +58,19 @@ public class CassandraServiceTest {
   private Cluster cluster;
 
   @Before
-  public void setUp() throws ConfigurationException, IOException {
+  public void setUp() throws ConfigurationException, IOException,
+      JSchException {
     CompositeConfiguration config = new CompositeConfiguration();
     if (System.getProperty("config") != null) {
       config.addConfiguration(new PropertiesConfiguration(System.getProperty("config")));
     }
     config.addConfiguration(new PropertiesConfiguration("whirr-cassandra-test.properties"));
     clusterSpec = new ClusterSpec(config);
+    if (clusterSpec.getPrivateKey() == null) {
+      Map<String, String> pair = KeyPair.generate();
+      clusterSpec.setPublicKey(pair.get("public"));
+      clusterSpec.setPrivateKey(pair.get("private"));
+    }
     Service s = new ServiceFactory().create(clusterSpec.getServiceName());
     assertThat(s, instanceOf(CassandraService.class));
     service = (CassandraService) s;

Modified: incubator/whirr/trunk/services/hadoop/pom.xml
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/services/hadoop/pom.xml?rev=1004117&r1=1004116&r2=1004117&view=diff
==============================================================================
--- incubator/whirr/trunk/services/hadoop/pom.xml (original)
+++ incubator/whirr/trunk/services/hadoop/pom.xml Mon Oct  4 05:09:02 2010
@@ -35,6 +35,13 @@
       <version>${project.version}</version>
     </dependency>
     <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>whirr-core</artifactId>
+      <version>${project.version}</version>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>org.jclouds</groupId>
       <artifactId>jclouds-aws</artifactId>
     </dependency>

Modified: incubator/whirr/trunk/services/hadoop/src/test/java/org/apache/whirr/service/hadoop/integration/HadoopServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/services/hadoop/src/test/java/org/apache/whirr/service/hadoop/integration/HadoopServiceTest.java?rev=1004117&r1=1004116&r2=1004117&view=diff
==============================================================================
--- incubator/whirr/trunk/services/hadoop/src/test/java/org/apache/whirr/service/hadoop/integration/HadoopServiceTest.java
(original)
+++ incubator/whirr/trunk/services/hadoop/src/test/java/org/apache/whirr/service/hadoop/integration/HadoopServiceTest.java
Mon Oct  4 05:09:02 2010
@@ -29,6 +29,7 @@ import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.Writer;
+import java.util.Map;
 import java.util.Map.Entry;
 
 import org.apache.commons.configuration.CompositeConfiguration;
@@ -53,10 +54,13 @@ import org.apache.whirr.service.ServiceF
 import org.apache.whirr.service.hadoop.HadoopCluster;
 import org.apache.whirr.service.hadoop.HadoopProxy;
 import org.apache.whirr.service.hadoop.HadoopService;
+import org.apache.whirr.ssh.KeyPair;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
+import com.jcraft.jsch.JSchException;
+
 public class HadoopServiceTest {
   
   private ClusterSpec clusterSpec;
@@ -65,13 +69,19 @@ public class HadoopServiceTest {
   private HadoopCluster cluster;
   
   @Before
-  public void setUp() throws ConfigurationException, IOException {
+  public void setUp() throws ConfigurationException, IOException, 
+      JSchException {
     CompositeConfiguration config = new CompositeConfiguration();
     if (System.getProperty("config") != null) {
       config.addConfiguration(new PropertiesConfiguration(System.getProperty("config")));
     }
     config.addConfiguration(new PropertiesConfiguration("whirr-hadoop-test.properties"));
     clusterSpec = new ClusterSpec(config);
+    if (clusterSpec.getPrivateKey() == null) {
+      Map<String, String> pair = KeyPair.generate();
+      clusterSpec.setPublicKey(pair.get("public"));
+      clusterSpec.setPrivateKey(pair.get("private"));
+    }
     Service s = new ServiceFactory().create(clusterSpec.getServiceName());
     assertThat(s, instanceOf(HadoopService.class));
     service = (HadoopService) s;

Modified: incubator/whirr/trunk/services/zookeeper/pom.xml
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/services/zookeeper/pom.xml?rev=1004117&r1=1004116&r2=1004117&view=diff
==============================================================================
--- incubator/whirr/trunk/services/zookeeper/pom.xml (original)
+++ incubator/whirr/trunk/services/zookeeper/pom.xml Mon Oct  4 05:09:02 2010
@@ -35,6 +35,13 @@
       <version>${project.version}</version>
     </dependency>
     <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>whirr-core</artifactId>
+      <version>${project.version}</version>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>org.jclouds</groupId>
       <artifactId>jclouds-aws</artifactId>
     </dependency>

Modified: incubator/whirr/trunk/services/zookeeper/src/test/java/org/apache/whirr/service/zookeeper/integration/ZooKeeperServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/services/zookeeper/src/test/java/org/apache/whirr/service/zookeeper/integration/ZooKeeperServiceTest.java?rev=1004117&r1=1004116&r2=1004117&view=diff
==============================================================================
--- incubator/whirr/trunk/services/zookeeper/src/test/java/org/apache/whirr/service/zookeeper/integration/ZooKeeperServiceTest.java
(original)
+++ incubator/whirr/trunk/services/zookeeper/src/test/java/org/apache/whirr/service/zookeeper/integration/ZooKeeperServiceTest.java
Mon Oct  4 05:09:02 2010
@@ -23,6 +23,7 @@ import static org.hamcrest.Matchers.inst
 import static org.junit.Assert.assertThat;
 
 import java.io.IOException;
+import java.util.Map;
 import java.util.concurrent.CountDownLatch;
 
 import org.apache.commons.configuration.CompositeConfiguration;
@@ -33,6 +34,7 @@ import org.apache.whirr.service.Service;
 import org.apache.whirr.service.ServiceFactory;
 import org.apache.whirr.service.zookeeper.ZooKeeperCluster;
 import org.apache.whirr.service.zookeeper.ZooKeeperService;
+import org.apache.whirr.ssh.KeyPair;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.WatchedEvent;
 import org.apache.zookeeper.Watcher;
@@ -43,6 +45,8 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
+import com.jcraft.jsch.JSchException;
+
 public class ZooKeeperServiceTest {
   
   private ClusterSpec clusterSpec;
@@ -50,13 +54,19 @@ public class ZooKeeperServiceTest {
   private ZooKeeperCluster cluster;
   
   @Before
-  public void setUp() throws ConfigurationException, IOException {
+  public void setUp() throws ConfigurationException, IOException, 
+      JSchException {
     CompositeConfiguration config = new CompositeConfiguration();
     if (System.getProperty("config") != null) {
       config.addConfiguration(new PropertiesConfiguration(System.getProperty("config")));
     }
     config.addConfiguration(new PropertiesConfiguration("whirr-zookeeper-test.properties"));
     clusterSpec = new ClusterSpec(config);
+    if (clusterSpec.getPrivateKey() == null) {
+      Map<String, String> pair = KeyPair.generate();
+      clusterSpec.setPublicKey(pair.get("public"));
+      clusterSpec.setPrivateKey(pair.get("private"));
+    }
     Service s = new ServiceFactory().create(clusterSpec.getServiceName());
     assertThat(s, instanceOf(ZooKeeperService.class));
     service = (ZooKeeperService) s;



Mime
View raw message