Пример #1
0
        public async Task EnableSshOptimisticCheckFailSshCommandAsync()
        {
            sshKeyLoader.LoadOrCreateAsync().Returns(fakeKey);
            remoteCommand.RunWithSuccessAsync(null, null).ReturnsForAnyArgs(
                Task.FromException(new YetiCommon.ProcessException("SSH exception")));

            await sshManager.EnableSshAsync(fakeGamelet, fakeAction);

            await gameletClient.Received(1).EnableSshAsync(fakeGamelet.Id, fakeKey.PublicKey);
        }
Пример #2
0
        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);
        }
Пример #3
0
        /// <summary>
        /// Clear stdout/stderr so that we don't start to tail before guest_orc clears.
        /// </summary>
        bool ClearLogs(Gamelet gamelet)
        {
            ICancelableTask clearLogsTask =
                _cancelableTaskFactory.Create(TaskMessages.ClearingInstanceLogs,
                                              async _ => await _remoteCommand.RunWithSuccessAsync(
                                                  new SshTarget(gamelet), ClearLogsCmd));

            try
            {
                return(clearLogsTask.RunAndRecord(_actionRecorder, ActionType.GameletClearLogs));
            }
            catch (ProcessException e)
            {
                Trace.WriteLine($"Error clearing instance logs: {e.Message}");
                _dialogUtil.ShowError(ErrorStrings.FailedToStartRequiredProcess(e.Message),
                                      e.ToString());
                return(false);
            }
        }