Github user grkvlt commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/475#discussion_r90471366
--- Diff:
core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationIntegrationTest.java
---
@@ -19,53 +19,206 @@
package org.apache.brooklyn.location.ssh;
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.OutputStream;
+import java.net.InetAddress;
import java.security.KeyPair;
import java.util.Arrays;
import java.util.Map;
+import java.util.concurrent.Callable;
import org.apache.brooklyn.api.location.Location;
import org.apache.brooklyn.api.location.LocationSpec;
-import org.apache.brooklyn.api.mgmt.ManagementContext;
-import org.apache.brooklyn.core.entity.Entities;
-import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
-import org.apache.brooklyn.core.test.entity.TestApplication;
+import org.apache.brooklyn.api.location.MachineDetails;
+import org.apache.brooklyn.core.entity.AbstractEntity;
+import org.apache.brooklyn.core.internal.BrooklynProperties;
import
org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
+import org.apache.brooklyn.test.Asserts;
import org.apache.brooklyn.util.collections.MutableMap;
import org.apache.brooklyn.util.core.crypto.SecureKeys;
+import org.apache.brooklyn.util.core.file.ArchiveUtils;
+import org.apache.brooklyn.util.core.internal.ssh.SshException;
import org.apache.brooklyn.util.core.internal.ssh.SshTool;
import org.apache.brooklyn.util.core.internal.ssh.sshj.SshjTool;
import
org.apache.brooklyn.util.core.internal.ssh.sshj.SshjTool.SshjToolBuilder;
+import org.apache.brooklyn.util.core.task.BasicExecutionContext;
+import org.apache.brooklyn.util.core.task.BasicExecutionManager;
import org.apache.brooklyn.util.guava.Maybe;
+import org.apache.brooklyn.util.net.Networking;
+import org.apache.brooklyn.util.net.Urls;
+import org.apache.brooklyn.util.os.Os;
+import org.apache.brooklyn.util.stream.Streams;
+import org.apache.brooklyn.util.time.Duration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import com.google.common.base.Charsets;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import com.google.common.io.Files;
-public class SshMachineLocationIntegrationTest {
+public class SshMachineLocationIntegrationTest extends
SshMachineLocationTest {
- protected TestApplication app;
- protected ManagementContext mgmt;
+ private static final Logger LOG =
LoggerFactory.getLogger(AbstractEntity.class);
- @BeforeMethod(alwaysRun=true)
- public void setup() throws Exception {
- mgmt = LocalManagementContextForTests.builder(true)
- .useDefaultProperties()
- .build();
- app = TestApplication.Factory.newManagedInstanceForTests(mgmt);
+ @Override
+ protected BrooklynProperties getBrooklynProperties() {
+ // Requires location named "localhost-passphrase", which it
expects to find in local
+ // brooklyn.properties (or brooklyn.cfg in karaf).
+ return BrooklynProperties.Factory.newDefault();
+ }
+
+ @Override
+ protected SshMachineLocation newHost() {
+ return
mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)
+ .configure("address", Networking.getLocalHost()));
}
- @AfterMethod(alwaysRun=true)
- public void tearDown() throws Exception {
- if (mgmt != null) Entities.destroyAll(mgmt);
- mgmt = null;
+ // Overridden just to make it integration (because `newHost()` returns
a real ssh'ing host)
+ @Test(groups="Integration")
+ @Override
+ public void testSshExecScript() throws Exception {
+ super.testSshExecScript();
+ }
+
+ // Overridden just to make it integration (because `newHost()` returns
a real ssh'ing host)
+ @Test(groups="Integration")
+ @Override
+ public void testSshExecCommands() throws Exception {
+ super.testSshExecCommands();
+ }
+
+ // Overridden just to make it integration (because `newHost()` returns
a real ssh'ing host)
+ @Test(groups="Integration")
+ @Override
+ public void testIsSshableWhenTrue() throws Exception {
+ super.testIsSshableWhenTrue();
+ }
+
+ // Overridden just to make it integration (because `newHost()` returns
a real ssh'ing host)
+ @Test(groups="Integration")
+ @Override
+ public void testDoesNotLogPasswordsInEnvironmentVariables() {
+ super.testDoesNotLogPasswordsInEnvironmentVariables();
+ }
+
+ // Overrides super, because expect real machine details (rather than
asserting our stub data)
+ @Test(groups = "Integration")
+ @Override
+ public void testGetMachineDetails() throws Exception {
+ BasicExecutionManager execManager = new
BasicExecutionManager("mycontextid");
+ BasicExecutionContext execContext = new
BasicExecutionContext(execManager);
+ try {
+ MachineDetails details = execContext.submit(new
Callable<MachineDetails>() {
+ public MachineDetails call() {
+ return host.getMachineDetails();
+ }}).get();
+ LOG.info("machineDetails="+details);
+ assertNotNull(details);
+ } finally {
+ execManager.shutdownNow();
+ }
+ }
+
+ @Test(groups = "Integration")
+ public void testCopyFileTo() throws Exception {
+ File dest = Os.newTempFile(getClass(), ".dest.tmp");
+ File src = Os.newTempFile(getClass(), ".src.tmp");
+ try {
+ Files.write("abc", src, Charsets.UTF_8);
+ host.copyTo(src, dest);
+ assertEquals("abc", Files.readFirstLine(dest, Charsets.UTF_8));
+ } finally {
+ src.delete();
+ dest.delete();
+ }
+ }
+
+ // Note: requires `ssh localhost` to be setup such that no password is
required
+ @Test(groups = "Integration")
+ public void testCopyStreamTo() throws Exception {
+ String contents = "abc";
+ File dest = new File(Os.tmp(), "sshMachineLocationTest_dest.tmp");
+ try {
+ host.copyTo(Streams.newInputStreamWithContents(contents),
dest.getAbsolutePath());
+ assertEquals("abc", Files.readFirstLine(dest, Charsets.UTF_8));
+ } finally {
+ dest.delete();
+ }
}
+ // Requires internet connectivity; on guest wifi etc can fail with
things like
+ // "Welcome to Virgin Trains" etc.
+ @Test(groups = "Integration")
+ public void testInstallUrlTo() throws Exception {
+ File dest = new File(Os.tmp(), "sshMachineLocationTest_dir/");
+ dest.mkdir();
+ try {
+ int result =
host.installTo("https://raw.github.com/brooklyncentral/brooklyn/master/README.md",
Urls.mergePaths(dest.getAbsolutePath(), "README.md"));
+ assertEquals(result, 0);
+ String contents = ArchiveUtils.readFullyString(new File(dest,
"README.md"));
+
assertTrue(contents.contains("http://brooklyncentral.github.com"), "contents
missing expected phrase; contains:\n"+contents);
+ } finally {
+ dest.delete();
+ }
+ }
+
+ @Test(groups = "Integration")
+ public void testInstallClasspathCopyTo() throws Exception {
+ File dest = new File(Os.tmp(), "sshMachineLocationTest_dir/");
+ dest.mkdir();
+ try {
+ int result =
host.installTo("classpath://brooklyn/config/sample.properties",
Urls.mergePaths(dest.getAbsolutePath(), "sample.properties"));
+ assertEquals(result, 0);
+ String contents = ArchiveUtils.readFullyString(new File(dest,
"sample.properties"));
+ assertTrue(contents.contains("Property 1"), "contents missing
expected phrase; contains:\n"+contents);
+ } finally {
+ dest.delete();
+ }
+ }
+
+ // Note: on some (home/airport) networks, `ssh 123.123.123.123` hangs
seemingly forever.
+ // Make sure we fail, waiting for longer than the 70 second TCP
timeout.
+ //
+ // Times out in 2m7s on Ubuntu Vivid (syn retries set to 6)
+ @Test(groups = "Integration")
+ public void testIsSshableWhenFalse() throws Exception {
+ byte[] unreachableIp = new byte[] {123,123,123,123};
--- End diff --
From
http://superuser.com/questions/698244/ip-address-that-is-the-equivalent-of-dev-null
> There's specifically a blackhole prefix in IPV6, as described in RFC
6666, it's 100::/64. IP4 does not have an explicit black hole like that, but a
non-existent host on one of the reserved blocks would have that effect. (e.g.,
240.0.0.0/4 is "reserved for future use" and will not be routed by anything.)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---