def test_download_happy_path(self, mock_mkdir, mock_os_listdir):
     mock_os_listdir.return_value = []
     mock_stat = mock.Mock()
     mock_stat.st_mode = stat.S_IFREG
     sftp = mock.Mock()
     sftp.listdir.return_value = ['match1', 'nomatch']
     sftp.stat.return_value = mock_stat
     utils.copy_logs_sftp(sftp, ['source/match*'], 'target', 'host', 'username', 'key', upload=False)
     sftp.get.assert_called_with('source/match1', 'target/match1')
 def test_upload_happy_path(self, mock_mkdir, mock_get_ssh_object, mock_os_stat, mock_os_listdir):
     mock_os_listdir.return_value = ['source_file']
     mock_stat = mock.Mock()
     mock_stat.st_mode = stat.S_IFREG
     mock_os_stat.return_value = mock_stat
     sftp = mock.Mock()
     sftp.listdir.return_value = []
     utils.copy_logs_sftp(sftp, ['source/*'], 'target', 'host', 'username', 'key', upload=True)
     sftp.put.assert_called_with('source/source_file', 'target/source_file')
 def test_source_dir_missing(self, mock_mkdir, mock_os_listdir):
     mock_os_listdir.side_effect = IOError(errno.ENOENT, 'No such file or directory')
     mock_stat = mock.Mock()
     mock_stat.st_mode = stat.S_IFREG
     sftp = mock.Mock()
     sftp.listdir.return_value = ['source_file']
     sftp.stat.return_value = mock_stat
     utils.copy_logs_sftp(sftp, ['source/*'], 'target', 'host', 'username', 'key', upload=True)
     self.assertEqual(0, len(sftp.put.mock_calls))
     self.assertEqual(1, len(mock_os_listdir.mock_calls))
 def test_download_error_continues(self, mock_mkdir, mock_os_listdir):
     mock_os_listdir.return_value = []
     mock_stat = mock.Mock()
     mock_stat.st_mode = stat.S_IFREG
     sftp = mock.Mock()
     sftp.listdir.return_value = ['match1', 'nomatch', 'match2']
     sftp.stat.return_value = mock_stat
     sftp.get.side_effect = IOError(errno.EIO, 'Unknown failure')
     utils.copy_logs_sftp(sftp, ['source/match*'], 'target', 'host', 'username', 'key', upload=False)
     sftp.get.assert_has_calls([mock.call('source/match1', 'target/match1'),
                                mock.call('source/match2', 'target/match2')])
Exemplo n.º 5
0
 def test_download_happy_path(self, mock_mkdir, mock_os_listdir):
     mock_os_listdir.return_value = []
     mock_stat = mock.Mock()
     mock_stat.st_mode = stat.S_IFREG
     sftp = mock.Mock()
     sftp.listdir.return_value = ['match1', 'nomatch']
     sftp.stat.return_value = mock_stat
     utils.copy_logs_sftp(sftp, ['source/match*'],
                          'target',
                          'host',
                          'username',
                          'key',
                          upload=False)
     sftp.get.assert_called_with('source/match1', 'target/match1')
Exemplo n.º 6
0
 def test_upload_happy_path(self, mock_mkdir, mock_get_ssh_object,
                            mock_os_stat, mock_os_listdir):
     mock_os_listdir.return_value = ['source_file']
     mock_stat = mock.Mock()
     mock_stat.st_mode = stat.S_IFREG
     mock_os_stat.return_value = mock_stat
     sftp = mock.Mock()
     sftp.listdir.return_value = []
     utils.copy_logs_sftp(sftp, ['source/*'],
                          'target',
                          'host',
                          'username',
                          'key',
                          upload=True)
     sftp.put.assert_called_with('source/source_file', 'target/source_file')
Exemplo n.º 7
0
 def test_source_dir_missing(self, mock_mkdir, mock_os_listdir):
     mock_os_listdir.side_effect = IOError(errno.ENOENT,
                                           'No such file or directory')
     mock_stat = mock.Mock()
     mock_stat.st_mode = stat.S_IFREG
     sftp = mock.Mock()
     sftp.listdir.return_value = ['source_file']
     sftp.stat.return_value = mock_stat
     utils.copy_logs_sftp(sftp, ['source/*'],
                          'target',
                          'host',
                          'username',
                          'key',
                          upload=True)
     self.assertEqual(0, len(sftp.put.mock_calls))
     self.assertEqual(1, len(mock_os_listdir.mock_calls))
Exemplo n.º 8
0
 def test_download_error_continues(self, mock_mkdir, mock_os_listdir):
     mock_os_listdir.return_value = []
     mock_stat = mock.Mock()
     mock_stat.st_mode = stat.S_IFREG
     sftp = mock.Mock()
     sftp.listdir.return_value = ['match1', 'nomatch', 'match2']
     sftp.stat.return_value = mock_stat
     sftp.get.side_effect = IOError(errno.EIO, 'Unknown failure')
     utils.copy_logs_sftp(sftp, ['source/match*'],
                          'target',
                          'host',
                          'username',
                          'key',
                          upload=False)
     sftp.get.assert_has_calls([
         mock.call('source/match1', 'target/match1'),
         mock.call('source/match2', 'target/match2')
     ])