Skip to content

Commit

Permalink
Massage the tests into passing
Browse files Browse the repository at this point in the history
  • Loading branch information
twizmwazin committed Jan 30, 2024
1 parent bee8eb1 commit 53d46d6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
19 changes: 10 additions & 9 deletions python/binharness/bootstrap/ssh.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""binharness.bootstrap.ssh - SSH bootstrap module for binharness."""
from __future__ import annotations

import time

import paramiko

from binharness.agentenvironment import AgentConnection
Expand All @@ -29,11 +27,13 @@ def stop(self: SSHAgent) -> None:
self._ssh_client.exec_command("kill $(cat /tmp/bh_agent_server.pid)")


def bootstrap_ssh_environment_with_client(
def bootstrap_ssh_environment_with_client( # noqa: PLR0913
agent_binary: str,
ssh_client: paramiko.SSHClient,
ip: str,
port: int = 60162,
connect_ip: str,
listen_ip: str = "0.0.0.0", # noqa: S104
listen_port: int = 60162,
connect_port: int = 60162,
install_path: str = "bh_agent_server",
) -> SSHAgent:
"""Bootstraps an agent running on a box over ssh.
Expand All @@ -51,11 +51,10 @@ def bootstrap_ssh_environment_with_client(
ssh_client.exec_command(f"chmod +x {install_path}")

# Start the agent
_, stdout, _ = ssh_client.exec_command(f"{install_path} -d {ip} {port}")
time.sleep(1) # TODO: This is a hack to wait for the agent to start
_, stdout, _ = ssh_client.exec_command(f"{install_path} {listen_ip} {listen_port}")

# Create the agent connection
return SSHAgent(ssh_client, ip, port)
return SSHAgent(ssh_client, connect_ip, connect_port)


def bootstrap_ssh_environment(
Expand All @@ -79,4 +78,6 @@ def bootstrap_ssh_environment(
ssh_client.connect(ip, username=username)

# Bootstrap the environment
return bootstrap_ssh_environment_with_client(agent_binary, ssh_client, ip, port)
return bootstrap_ssh_environment_with_client(
agent_binary, ssh_client, ip, listen_port=port, connect_port=port
)
2 changes: 1 addition & 1 deletion python/tests/bootstrap/test_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ def test_bootstrap_env_from_image(
assert proc.returncode == 0
assert proc.stdout.read() == b"hello world\n"
finally:
agent.container.stop()
agent.container.kill()
4 changes: 1 addition & 3 deletions python/tests/bootstrap/test_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import mockssh
import pytest

from binharness.agentenvironment import AgentConnection
from binharness.bootstrap.ssh import bootstrap_ssh_environment_with_client
from binharness.types.executor import NullExecutor
from binharness.types.target import Target
Expand Down Expand Up @@ -40,11 +39,10 @@ def test_bootstrap_ssh_environment_with_client(
)

try:
assert isinstance(agent, AgentConnection)
assert agent.get_environment_ids() == [0]

env = agent.get_environment(0)
target = Target(env, Path("/usr/bin/echo"), args=["hello world"])
target = Target(env, Path("/bin/echo"), args=["hello world"])
proc = NullExecutor().run_target(target)

proc.wait()
Expand Down

0 comments on commit 53d46d6

Please sign in to comment.