public void GloballyVisibleTunnel() { using (var t = new SSHConnectionTunnel(File.ReadLines("testmachineOne.txt").First())) { Assert.IsTrue(t.GloballyVisible); Assert.AreEqual(0, t.TunnelCount); } }
/// <summary> /// Move a file to the remote machine /// </summary> /// <param name="rootFile"></param> /// <returns></returns> private Uri MoveToBash(Uri rootFile, string remoteInfo, string remoteDirectory) { using (var t = new SSHConnectionTunnel(remoteInfo)) { var f = new FileInfo(rootFile.LocalPath); t.CopyLocalFileRemotely(f, $"{remoteDirectory}/{f.Name}"); return(new Uri($"remotebash://tev.machines/{remoteDirectory}/{f.Name}")); } }
private async Task BuildAndRunTunnel(string configFile) { using (var t = new SSHConnectionTunnel(File.ReadLines(configFile).First())) { var pid = await GetPID(t); Assert.IsTrue(pid != ""); } }
public async Task SSHTunnelSingleLink() { using (var t = new SSHConnectionTunnel(File.ReadLines("testmachineOne.txt").First())) { var pid = await GetPID(t); Assert.IsTrue(pid != ""); Assert.AreEqual(0, t.TunnelCount); } }
public void SSHTunnelMachineUserName() { var text = File.ReadLines("testmachineOne.txt").First(); using (var t = new SSHConnectionTunnel(text)) { Assert.AreEqual(text.Substring(0, text.IndexOf('@')), t.UserName); Assert.AreEqual(text.Substring(text.IndexOf('@') + 1), t.MachineName); } }
/// <summary> /// Create an SSH connection to a remote machine. /// </summary> /// <param name="remoteSSHConnectionString"></param> /// <returns></returns> /// <remarks>Should only get called by the _connection initalizer</remarks> private async Task <SSHRecoveringConnection> CreateSSHConnectionTo(string remoteSSHConnectionString = null, Action <string> dumpLine = null) { // Use the default remoteSSHConnectionString = remoteSSHConnectionString ?? _machine.RemoteSSHConnectionString; Interlocked.Increment(ref NumberOfRecoveringConnections); if (_connectionLock != null) { throw new InvalidOperationException("Connection lock has already been aquired. Interal error"); } _connectionLock = await _gConnectionInterlockLimiter.LockAsync(); TraceHelpers.TraceInfo(25, $"CreateSSHConnectionTo: Aquired RemoteSSH Lock (free: {_gConnectionInterlockLimiter.CurrentCount})", opt: TraceEventType.Start); // Create a recovering connection return(new SSHRecoveringConnection(async() => { return await Policy .Handle <SSHConnectFailureException>() .WaitAndRetryAsync(new[] { TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(60) }) .ExecuteAsync(async() => { var c = new SSHConnectionTunnel(remoteSSHConnectionString); Interlocked.Increment(ref NumberOfSSHTunnels); if (_machine.ConfigureLines != null) { var logForError = new StringBuilder(); try { // Don't dump setup unless the user really wants to see it! var localdumper = Environment.Verbose | Environment.CompileDebug ? dumpLine : (Action <string>)null; foreach (var line in _machine.ConfigureLines) { var rep = line.Replace("ROOTVersionNumber", ROOTVersionNumber); await c.ExecuteLinuxCommandAsync(rep, processLine: s => RecordLine(logForError, s, localdumper)); } } catch (Exception e) { c.Dispose(); string errMsg = ReformatLog(logForError); Trace.WriteLine($"Error making a SSH connection: {errMsg}"); throw new RemoteBashCommandFailureException($"Error making a SSH connection: {errMsg}", e); } } return c; }); })); }
public async Task SSHTunnelAddTwo() { using (var t = new SSHConnectionTunnel(File.ReadLines("testMachineTwo.txt").First())) { var pid2 = await GetPID(t); Assert.IsTrue(pid2 != ""); Assert.AreEqual(1, t.TunnelCount); Console.WriteLine(pid2); await t.ExecuteLinuxCommandAsync("export", l => Console.WriteLine(l)); } }
public void SSHTunnelTwoMachineUserName() { var text = File.ReadLines("testMachineTwo.txt").First(); var machineTwo = text.Split(new [] { "->" }, StringSplitOptions.None) .Select(i => i.Trim()) .Last(); using (var t = new SSHConnectionTunnel(text)) { Assert.AreEqual(machineTwo.Substring(0, machineTwo.IndexOf('@')), t.UserName); Assert.AreEqual(machineTwo.Substring(machineTwo.IndexOf('@') + 1), t.MachineName); } }
public async Task SSHTunnelFailWithNoInitalization() { try { using (var t = new SSHConnectionTunnel()) { var pid = await GetPID(t); } } catch (Exception e) { throw e.UnrollAggregateExceptions(); } }
public async Task SSHTunnelAddLater() { using (var t = new SSHConnectionTunnel(File.ReadLines("testmachineOne.txt").First())) { var pid1 = await GetPID(t); t.Add(File.ReadLines("testmachineone.txt").First()); var pid2 = await GetPID(t); Assert.AreNotEqual(pid1, pid2); Assert.AreEqual(1, t.TunnelCount); } }