Skip to content

Commit

Permalink
Allow remote_copy to copy to a different path
Browse files Browse the repository at this point in the history
This change allows a user to supply a different destination path for
remote_copy.

I also ensured that awxkit logs won't be modified unless Broker is in
trace level logging mode.

Fixes SatelliteQE#165
  • Loading branch information
JacobCallahan committed Jul 3, 2023
1 parent 636ed1d commit 31a3b87
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
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

0 comments on commit 31a3b87

Please sign in to comment.