def put_file(self, client, source_file):
     """
     Put file on instance in default SSH directory.
     """
     try:
         file_name = os.path.basename(source_file)
         ipa_utils.put_file(client, source_file, file_name)
     except Exception as error:
         raise IpaCloudException('Failed copying file, "{0}"; {1}.'.format(
             source_file, error))
     else:
         return file_name
Exemple #2
0
def test_utils_put_file():
    client = MagicMock()
    sftp_client = MagicMock()
    client.open_sftp.return_value = sftp_client

    source_file = '/home/user/temp.file'
    destination_file = 'temp.file'

    ipa_utils.put_file(client, source_file, destination_file)

    sftp_client.put.assert_called_once_with(source_file, destination_file)
    sftp_client.close.assert_called_once_with()