public async Task EnableSshOptimisticCheckSuccessAsync() { sshKeyLoader.LoadOrCreateAsync().Returns(fakeKey); await sshManager.EnableSshAsync(fakeGamelet, fakeAction); sshKnownHostsWriter.Received().CreateOrUpdate(fakeGamelet); await remoteCommand.Received().RunWithSuccessAsync( new SshTarget(fakeGamelet), Arg.Any <string>()); await gameletClient.DidNotReceiveWithAnyArgs().EnableSshAsync(null, null); }
public async Task EnableSshAsync(Gamelet gamelet, Metrics.IAction action) { var sshKey = await sshKeyLoader.LoadOrCreateAsync(); sshKnownHostsWriter.CreateOrUpdate(gamelet); action.UpdateEvent(new DeveloperLogEvent { GameletData = GameletData.FromGamelet(gamelet) }); // Try to optimistically connect, but only if we already have a key file. try { await remoteCommand.RunWithSuccessAsync(new SshTarget(gamelet), "/bin/true"); return; } catch (ProcessException e) { Trace.WriteLine("Optimistic SSH check failed; fallback to calling EnableSSH; " + "error: " + e.ToString()); } // Generate a new key, if necessary, and upload it to the gamelet. var gameletClient = gameletClientFactory.Create(cloudRunner.Intercept(action)); await gameletClient.EnableSshAsync(gamelet.Id, sshKey.PublicKey); }