public ShellAbstractTool(File localTempDir) { if (localTempDir == null) { localTempDir = new File(Os.tmp(), "tmpssh-"+Os.user()); if (!localTempDir.exists()) localTempDir.mkdir(); Os.deleteOnExitEmptyParentsUpTo(localTempDir, new File(Os.tmp())); } this.localTempDir = localTempDir; }
@Test public void testSshExecCommands() throws Exception { String expectedName = Os.user(); RecordingSshTool.setCustomResponse(".*whoami.*", new CustomResponse(0, expectedName, "")); OutputStream outStream = new ByteArrayOutputStream(); host.execCommands(MutableMap.of("out", outStream), "mysummary", ImmutableList.of("whoami; exit")); String outString = outStream.toString(); assertTrue(outString.contains(expectedName), outString); }
@Test public void testSshExecScript() throws Exception { String expectedName = Os.user(); RecordingSshTool.setCustomResponse(".*whoami.*", new CustomResponse(0, expectedName, "")); OutputStream outStream = new ByteArrayOutputStream(); host.execScript(MutableMap.of("out", outStream), "mysummary", ImmutableList.of("whoami; exit")); String outString = outStream.toString(); assertTrue(outString.contains(expectedName), outString); }
@Test(groups = "Integration") public void testOverridingPropertyOnExec() throws Exception { SshMachineLocation host = new SshMachineLocation(MutableMap.of("address", Networking.getReachableLocalHost(), "sshPrivateKeyData", "wrongdata")); OutputStream outStream = new ByteArrayOutputStream(); String expectedName = Os.user(); host.execCommands(MutableMap.of("sshPrivateKeyData", null, "out", outStream), "my summary", ImmutableList.of("whoami")); String outString = outStream.toString(); assertTrue(outString.contains(expectedName), "outString="+outString); }
@Test(groups="Integration") public void testLocalhostInTmp() throws Exception { MyService entity = app.createAndManageChild(EntitySpec.create(MyService.class)); app.start(ImmutableList.of(localhost)); String installDir = entity.getAttribute(SoftwareProcess.INSTALL_DIR); assertTrue(installDir.startsWith("/tmp/brooklyn-"+Os.user()+"/installs/"), "installed in "+installDir); }
@Override public LocalhostMachineProvisioningLocation configure(Map<?,?> flags) { super.configure(flags); if (!groovyTruth(getDisplayName())) { setDisplayName("localhost"); } if (!groovyTruth(address)) address = getLocalhostInetAddress(); // TODO should try to confirm this machine is accessible on the given address ... but there's no // immediate convenience in java so early-trapping of that particular error is deferred if (canProvisionMore==null) { if (initialCount>0) canProvisionMore = false; else canProvisionMore = true; } if (getHostGeoInfo()==null) { if (cachedHostGeoInfo==null) cachedHostGeoInfo = HostGeoInfo.fromLocation(this); setHostGeoInfo(cachedHostGeoInfo); } if (initialCount > getMachines().size()) { provisionMore(initialCount - getMachines().size()); } if (getConfig(BrooklynConfigKeys.ONBOX_BASE_DIR)==null && (getManagementContext()==null || getManagementContext().getConfig().getConfig(BrooklynConfigKeys.ONBOX_BASE_DIR)==null)) { setConfig(BrooklynConfigKeys.ONBOX_BASE_DIR, "/tmp/brooklyn-"+Os.user()); } return this; }