Skip to content

Commit

Permalink
Fix conflict and updated logger
Browse files Browse the repository at this point in the history
  • Loading branch information
perseoGI committed Jan 30, 2025
1 parent 2c84cec commit 7d030ae
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/linux-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ jobs:
ssh-keygen -t rsa -b 4096 -N "" -f ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
ssh-keyscan localhost >> ~/.ssh/known_hosts
# ssh-keyscan localhost >> ~/.ssh/known_hosts
- name: Test SSH Connection
run: ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no localhost "echo 'SSH Connection Successful!'"
# - name: Test SSH Connection
# run: ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no localhost "echo 'SSH Connection Successful!'"

- name: Run runner tests
uses: ./.github/actions/test-coverage
Expand Down
10 changes: 6 additions & 4 deletions conan/internal/runner/output.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
from conan.api.output import Color, ConanOutput

class RunnerOutput(ConanOutput):
def __init__(self, hostname: str):
def __init__(self, runner_info: str):
super().__init__()
self.set_warnings_as_errors(True) # Make log errors blocker
self._prefix = f"{hostname} | "
self._prefix = f"{runner_info} | "

def _write_message(self, msg, fg=None, bg=None, newline=True):
super()._write_message(self._prefix, Color.BLACK, Color.BRIGHT_YELLOW, newline=False)
super()._write_message(msg, fg, bg, newline)
for line in msg.splitlines():
super()._write_message(self._prefix, Color.BLACK, Color.BRIGHT_YELLOW, newline=False)
super()._write_message(line, fg, bg, newline)

@property
def padding(self):
return len(self._prefix) + 1


28 changes: 16 additions & 12 deletions conan/internal/runner/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import tempfile

from conan.api.conan_api import ConanAPI
from conan.api.output import Color
from conan.api.output import Color, ConanOutput
from conan.errors import ConanException

import os
Expand Down Expand Up @@ -38,9 +38,11 @@ def __init__(
hostname = self._create_ssh_connection()
except Exception as e:
raise ConanException(f"Error creating SSH connection: {e}")
self.logger = RunnerOutput(hostname)
self.logger = ConanOutput()
self.logger.set_warnings_as_errors(True)
self.runner_logger = RunnerOutput(hostname)
self.logger.status(f"Connected to {hostname}", fg=Color.BRIGHT_MAGENTA)
self.remote_conn = RemoteConnection(self.client, self.logger)
self.remote_conn = RemoteConnection(self.client, self.runner_logger)

def run(self):
self._ensure_runner_environment()
Expand Down Expand Up @@ -136,7 +138,7 @@ def _ensure_runner_environment(self):
self.logger.error(f"Unable to create remote venv: {result.stderr}")
self._install_conan_remotely(python_command, requested_conan_version)
else:
version = self.remote_conn.run_command(f"{conan_cmd} --version").stdout
version = self.remote_conn.run_command(f"{conan_cmd} --version", verbose=True).stdout
remote_conan_version = Version(version[version.rfind(" ")+1:])
if requested_conan_version == "dev" and remote_conan_version.bump(1) == str(conan_version).replace("-dev", ""):
pass
Expand Down Expand Up @@ -172,8 +174,7 @@ def _create_remote_conan_wrapper(self, remote_conan_home: str, remote_folder: st
conan_wrapper_contents = f"""{env_lines}\n{conan_cmd} $@\n"""

self.remote_conan = self.remote_conn.create_remote_script(conan_wrapper_contents, remote_folder + "/conan", self.is_remote_windows)
conan_config_home = self.remote_conn.run_command(f"{self.remote_conan} config home").stdout
self.logger.verbose(f"Remote conan config home returned: {conan_config_home}")
self.remote_conn.run_command(f"{self.remote_conan} config home", verbose=True)
if not self.remote_conn.run_command(f"{self.remote_conan} profile detect --force"):
self.logger.error("Error creating default profile in remote machine")

Expand Down Expand Up @@ -319,11 +320,15 @@ def __init__(self, success, stdout, stderr):
self.stdout = stdout
self.stderr = stderr

def run_command(self, command: str) -> RunResult:
def run_command(self, command: str, verbose: bool = False) -> RunResult:
_, stdout, stderr = self.client.exec_command(command)
return RemoteConnection.RunResult(stdout.channel.recv_exit_status() == 0,
stdout.read().decode().strip(),
stderr.read().decode().strip())
log = self.logger.status if verbose else self.logger.verbose
log(f'$ {command}', fg=Color.BLUE)
result = RemoteConnection.RunResult(stdout.channel.recv_exit_status() == 0,
stdout.read().decode().strip(),
stderr.read().decode().strip())
log(f"{result.stdout}")
return result

def run_interactive_command(self, command: str, is_remote_windows: bool) -> bool:
''' Run a command in an SSH session.
Expand Down Expand Up @@ -366,6 +371,5 @@ def replace_cursor_match(match):
# sys.stdout.buffer.write(line)
# sys.stdout.buffer.flush()
line = remove_cursor_movements(line.replace(b'\r', b'').decode(errors='ignore').strip())
for l in line.splitlines():
self.logger.status(l)
self.logger.status(line)
return stdout.channel.recv_exit_status() == 0

0 comments on commit 7d030ae

Please sign in to comment.