Skip to content

Commit

Permalink
Add tests for sftp_read
Browse files Browse the repository at this point in the history
  • Loading branch information
ogajduse authored and JacobCallahan committed Feb 28, 2023
1 parent 21554c1 commit 33c4c87
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 14 deletions.
43 changes: 35 additions & 8 deletions tests/functional/test_containers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path
from tempfile import NamedTemporaryFile
import pytest
from click.testing import CliRunner
from broker import Broker
Expand Down Expand Up @@ -71,10 +72,23 @@ def test_container_e2e():
assert c_host._cont_inst.top()['Processes']
res = c_host.execute("hostname")
assert res.stdout.strip() == c_host.hostname
# Test that a file can be uploaded to the container
c_host.session.sftp_write("broker_settings.yaml", "/root")
res = c_host.execute("ls")
assert "broker_settings.yaml" in res.stdout
loc_settings_path = Path("broker_settings.yaml")
remote_dir = "/tmp/fake"
c_host.session.sftp_write(loc_settings_path.name, f"{remote_dir}/")
res = c_host.execute(f"ls {remote_dir}")
assert str(loc_settings_path) in res.stdout
with NamedTemporaryFile() as tmp:
c_host.session.sftp_read(f"{remote_dir}/{loc_settings_path.name}", tmp.file.name)
data = c_host.session.sftp_read(
f"{remote_dir}/{loc_settings_path.name}", return_data=True
)
assert (
loc_settings_path.read_bytes() == Path(tmp.file.name).read_bytes()
), "Local file is different from the received one"
assert (
loc_settings_path.read_bytes() == data
), "Local file is different from the received one (return_data=True)"
assert data == Path(tmp.file.name).read_bytes(), "Received files do not match"


def test_container_e2e_mp():
Expand All @@ -83,7 +97,20 @@ def test_container_e2e_mp():
assert c_host._cont_inst.top()['Processes']
res = c_host.execute("hostname")
assert res.stdout.strip() == c_host.hostname
# Test that a file can be uploaded to the container
c_host.session.sftp_write("broker_settings.yaml", "/tmp/fake/")
res = c_host.execute("ls /tmp/fake")
assert "broker_settings.yaml" in res.stdout
loc_settings_path = Path("broker_settings.yaml")
remote_dir = "/tmp/fake"
c_host.session.sftp_write(loc_settings_path.name, f"{remote_dir}/")
res = c_host.execute(f"ls {remote_dir}")
assert str(loc_settings_path) in res.stdout
with NamedTemporaryFile() as tmp:
c_host.session.sftp_read(f"{remote_dir}/{loc_settings_path.name}", tmp.file.name)
data = c_host.session.sftp_read(
f"{remote_dir}/{loc_settings_path.name}", return_data=True
)
assert (
loc_settings_path.read_bytes() == Path(tmp.file.name).read_bytes()
), "Local file is different from the received one"
assert (
loc_settings_path.read_bytes() == data
), "Local file is different from the received one (return_data=True)"
assert data == Path(tmp.file.name).read_bytes(), "Received files do not match"
41 changes: 35 additions & 6 deletions tests/functional/test_satlab.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path
from tempfile import NamedTemporaryFile
import pytest
from click.testing import CliRunner
from broker import Broker
Expand Down Expand Up @@ -68,16 +69,44 @@ def test_tower_host():
with Broker(workflow="deploy-base-rhel") as r_host:
res = r_host.execute("hostname")
assert res.stdout.strip() == r_host.hostname
r_host.session.sftp_write("broker_settings.yaml", "/tmp/fake/")
res = r_host.execute("ls /tmp/fake")
assert "broker_settings.yaml" in res.stdout
loc_settings_path = Path("broker_settings.yaml")
remote_dir = "/tmp/fake"
r_host.session.sftp_write(loc_settings_path.name, f"{remote_dir}/")
res = r_host.execute(f"ls {remote_dir}")
assert str(loc_settings_path) in res.stdout
with NamedTemporaryFile() as tmp:
r_host.session.sftp_read(f"{remote_dir}/{loc_settings_path.name}", tmp.file.name)
data = r_host.session.sftp_read(
f"{remote_dir}/{loc_settings_path.name}", return_data=True
)
assert (
loc_settings_path.read_bytes() == Path(tmp.file.name).read_bytes()
), "Local file is different from the received one"
assert (
loc_settings_path.read_bytes() == data
), "Local file is different from the received one (return_data=True)"
assert data == Path(tmp.file.name).read_bytes(), "Received files do not match"


def test_tower_host_mp():
with Broker(workflow="deploy-base-rhel", _count=3) as r_hosts:
for r_host in r_hosts:
res = r_host.execute("hostname")
assert res.stdout.strip() == r_host.hostname
r_host.session.sftp_write("broker_settings.yaml", "/tmp/fake/")
res = r_host.execute("ls /tmp/fake")
assert "broker_settings.yaml" in res.stdout
loc_settings_path = Path("broker_settings.yaml")
remote_dir = "/tmp/fake"
r_host.session.sftp_write(loc_settings_path.name, f"{remote_dir}/")
res = r_host.execute(f"ls {remote_dir}")
assert str(loc_settings_path) in res.stdout
with NamedTemporaryFile() as tmp:
r_host.session.sftp_read(f"{remote_dir}/{loc_settings_path.name}", tmp.file.name)
data = r_host.session.sftp_read(
f"{remote_dir}/{loc_settings_path.name}", return_data=True
)
assert (
loc_settings_path.read_bytes() == Path(tmp.file.name).read_bytes()
), "Local file is different from the received one"
assert (
loc_settings_path.read_bytes() == data
), "Local file is different from the received one (return_data=True)"
assert data == Path(tmp.file.name).read_bytes(), "Received files do not match"

0 comments on commit 33c4c87

Please sign in to comment.