Skip to content

Commit

Permalink
[PLAT-4483] Don’t use SFTP for copying files from YBA to YBDB (non no…
Browse files Browse the repository at this point in the history
…de-agent case)

Summary: Node agent takes care of it. But, if it is disabled, we can still have a fallback as the fix is trivial.

Test Plan: Created a universe successfully and verified the health check upload works.

Reviewers: amalyshev, nbhatia, svarshney

Reviewed By: amalyshev

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D26320
  • Loading branch information
nkhogen committed Jun 23, 2023
1 parent 039399c commit 36a4ccf
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
20 changes: 10 additions & 10 deletions managed/devops/opscli/ybops/utils/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from Crypto.PublicKey import RSA

from scp import SCPClient
from ybops.common.exceptions import YBOpsRuntimeError, YBOpsRecoverableError

SSH2 = 'ssh2'
Expand Down Expand Up @@ -372,7 +373,6 @@ def __init__(self, ssh2_enabled=False):
self.key = None
self.port = ''
self.client = None
self.sftp_client = None
self.ssh_type = SSH2 if ssh2_enabled and check_ssh2_bin_present() else SSH

@retry_ssh_errors(retry_delay=CONNECTION_RETRY_DELAY_SEC)
Expand Down Expand Up @@ -497,11 +497,14 @@ def download_file_from_remote_server(self, remote_file_name, local_file_name):
remote_file_name: Path to the shell script on remote machine
'''
if self.ssh_type == SSH:
self.sftp_client = self.client.open_sftp()
scp_client = SCPClient(self.client.get_transport())
try:
self.sftp_client.get(remote_file_name, local_file_name)
scp_client.get(remote_file_name, local_file_name)
except Exception as e:
logging.warning('Caught exception on file transfer', e)
raise e
finally:
self.sftp_client.close()
scp_client.close()
else:
cmd = self.__generate_shell_command(self.hostname, self.port,
self.username, self.key,
Expand All @@ -519,17 +522,14 @@ def upload_file_to_remote_server(self, local_file_name, remote_file_name, **kwar
remote_file_name: Path to the shell script on remote machine
'''
if self.ssh_type == SSH:
self.sftp_client = self.client.open_sftp()
scp_client = SCPClient(self.client.get_transport())
try:
self.sftp_client.put(local_file_name, remote_file_name)
chmod = kwargs.get('chmod', 0)
if chmod != 0:
self.sftp_client.chmod(remote_file_name, chmod)
scp_client.put(local_file_name, remote_file_name)
except Exception as e:
logging.warning('Caught exception on file transfer', e)
raise e
finally:
self.sftp_client.close()
scp_client.close()
else:
cmd = self.__generate_shell_command(self.hostname, self.port,
self.username, self.key,
Expand Down
1 change: 1 addition & 0 deletions managed/devops/python3_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ python-ldap
PyYAML
requests-oauthlib==1.3.0
requests==2.25.1
scp==0.14.5
setuptools>=11.333
six
yb-cassandra-driver
1 change: 1 addition & 0 deletions managed/devops/python3_requirements_frozen.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ requests-oauthlib==1.3.0
requests==2.25.1
rsa==4.7.2
s3transfer==0.4.2
scp==0.14.5
six==1.16.0
typing_extensions==4.1.1
uritemplate==3.0.1
Expand Down
1 change: 1 addition & 0 deletions managed/devops/python_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ python-dateutil==2.5.3
PyYAML==5.1
requests-oauthlib==1.3.0
requests==2.24.0
scp==0.14.5
setuptools>=11.333
six==1.15.0
1 change: 1 addition & 0 deletions managed/devops/python_requirements_frozen.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ requests==2.25.1
requests-oauthlib==1.3.0
rsa==4.7.2
s3transfer==0.4.2
scp==0.14.5
six==1.10.0
uritemplate==3.0.1
urllib3==1.26.6
Expand Down

0 comments on commit 36a4ccf

Please sign in to comment.