brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [1/2] brooklyn-server git commit: Use login port for ssh
Date Mon, 06 Jun 2016 09:21:16 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master 784e18fd1 -> 9f7a7787a


Use login port for ssh

Currently we assume port 22 for ssh unless a
portforwarder has been configured.  This uses the getLoginPort
from nodemetadata to determine the ssh port.


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/f8c4c16d
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/f8c4c16d
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/f8c4c16d

Branch: refs/heads/master
Commit: f8c4c16d2af54e171ea1b1727f7ac80c0f58a5bd
Parents: 115a371
Author: Duncan Grant <duncan.grant@cloudsoftcorp.com>
Authored: Mon May 30 12:44:18 2016 +0100
Committer: Duncan Grant <duncan.grant@cloudsoftcorp.com>
Committed: Wed Jun 1 15:13:38 2016 +0100

----------------------------------------------------------------------
 .../brooklyn/location/jclouds/JcloudsLocation.java  | 11 ++++++++++-
 .../location/jclouds/JcloudsLocationTest.java       | 16 +++++++++++++++-
 2 files changed, 25 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f8c4c16d/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
index e30bc0d..2ebacc1 100644
--- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
+++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
@@ -2896,7 +2896,7 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation
im
         String user = (users.size() == 1) ? Iterables.getOnlyElement(users) : "{" + Joiner.on(",").join(users)
+ "}";
         String vmIp = hostAndPortOverride.isPresent() ? hostAndPortOverride.get().getHostText()
: getFirstReachableAddress(node, setup);
         if (vmIp==null) LOG.warn("Unable to extract IP for "+node+" ("+setup.getDescription()+"):
subsequent connection attempt will likely fail");
-        int vmPort = hostAndPortOverride.isPresent() ? hostAndPortOverride.get().getPortOrDefault(22)
: 22;
+        int vmPort = hostAndPortOverride.isPresent() ? hostAndPortOverride.get().getPortOrDefault(22)
: getLoginPortOrDefault(node, 22);
 
         String connectionDetails = user + "@" + vmIp + ":" + vmPort;
         final HostAndPort hostAndPort = hostAndPortOverride.isPresent() ? hostAndPortOverride.get()
: HostAndPort.fromParts(vmIp, vmPort);
@@ -2948,6 +2948,15 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation
im
         return credsSuccessful.get();
     }
 
+    @VisibleForTesting
+    static int getLoginPortOrDefault(NodeMetadata node, int defaultPort) {
+        int loginPort = node.getLoginPort();
+        if (loginPort > 0) {
+            return loginPort;
+        }
+        return defaultPort;
+    }
+
     protected void waitForReachable(Callable<Boolean> checker, String hostAndPort,
List<LoginCredentials> credentialsToLog, ConfigBag setup, Duration timeout) {
         if (LOG.isDebugEnabled()) {
             List<String> credsToString = Lists.newArrayList();

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f8c4c16d/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsLocationTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsLocationTest.java
b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsLocationTest.java
index 85123b1..8b04f93 100644
--- a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsLocationTest.java
+++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsLocationTest.java
@@ -47,6 +47,7 @@ import org.apache.brooklyn.util.collections.MutableMap;
 import org.apache.brooklyn.util.core.config.ConfigBag;
 import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.apache.brooklyn.util.http.HttpAsserts;
+import org.jclouds.compute.domain.NodeMetadata;
 import org.jclouds.scriptbuilder.domain.OsFamily;
 import org.jclouds.scriptbuilder.domain.StatementList;
 import org.mockito.Mockito;
@@ -613,5 +614,18 @@ public class JcloudsLocationTest implements JcloudsLocationConfig {
     public void testAwsVpcFailureDocLink() {
         HttpAsserts.assertContentContainsText(JcloudsLocation.AWS_VPC_HELP_URL, "VPC", "Classic");
     }
-    
+
+    @Test
+    public void testGetLoginPortOrDefaultReturnsDefaultWhenLoginPortNve() {
+        NodeMetadata mock = Mockito.mock(NodeMetadata.class);
+        Mockito.when(mock.getLoginPort()).thenReturn(-1);
+        Assert.assertEquals(JcloudsLocation.getLoginPortOrDefault(mock,22), 22);
+    }
+
+    @Test
+    public void testGetLoginPortOrDefaultReturnsPortWhenLoginPortPve() {
+        NodeMetadata mock = Mockito.mock(NodeMetadata.class);
+        Mockito.when(mock.getLoginPort()).thenReturn(666);
+        Assert.assertEquals(JcloudsLocation.getLoginPortOrDefault(mock,22), 666);
+    }
 }


Mime
View raw message