Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow remote_copy to copy to a different path #221

Merged
merged 1 commit into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion broker/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ def setup_logzero(
path="logs/broker.log",
):
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
patch_awx_for_verbosity(awxkit.api)
if isinstance(level, str) and level.lower() == "trace":
patch_awx_for_verbosity(awxkit.api)
set_log_level(level)
set_file_logging(file_level, path)
if formatter:
Expand Down
7 changes: 4 additions & 3 deletions broker/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,17 @@ def sftp_write(self, source, destination=None, ensure_dir=True):
with sftp.open(destination, FILE_FLAGS, SFTP_MODE) as remote:
remote.write(data)

def remote_copy(self, source, dest_host, ensure_dir=True):
def remote_copy(self, source, dest_host, dest_path=None, ensure_dir=True):
"""Copy a file from this host to another"""
dest_path = dest_path or source
sftp_down = self.session.sftp_init()
sftp_up = dest_host.session.session.sftp_init()
if ensure_dir:
dest_host.run(f"mkdir -p {Path(source).absolute().parent}")
dest_host.session.run(f"mkdir -p {Path(dest_path).absolute().parent}")
with sftp_down.open(
source, ssh2_sftp.LIBSSH2_FXF_READ, ssh2_sftp.LIBSSH2_SFTP_S_IRUSR
) as download:
with sftp_up.open(source, FILE_FLAGS, SFTP_MODE) as upload:
with sftp_up.open(dest_path, FILE_FLAGS, SFTP_MODE) as upload:
for size, data in download:
upload.write(data)

Expand Down
9 changes: 9 additions & 0 deletions tests/functional/test_satlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,12 @@ def test_tower_host_mp():
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"
# test remote copy from one host to another
r_hosts[0].session.remote_copy(
source=f"{remote_dir}/{loc_settings_path.name}",
dest_host=r_hosts[1],
dest_path=f"/root/{loc_settings_path.name}"
)
res = r_hosts[1].execute(f"ls /root")
assert loc_settings_path.name in res.stdout