Esempio n. 1
0
def get_real_current_usage(remote, username, r_dir):
    """this will return real space consumed currently by rsem analysis"""
    output = misc.sshexec('du -s {0}'.format(r_dir), remote, username)
    # e.g. output:
    # ['3096\t/path/to/top_outdir\n']
    usage = int(output[0].split('\t')[0]) * 1024 # in KB => byte
    return usage
Esempio n. 2
0
 def test_sshexec(self, mock_paramiko):
     mock_paramiko.Transport().open_session().makefile().readlines.return_value = ['some_output\n']
     self.assertEqual(misc.sshexec('cmd', 'host', 'username'), ['some_output\n'])
     # interestingly, Transpost is called twice while in the code, it's
     # explicitly called only once
     self.assertEqual(mock_paramiko.Transport.call_args_list,
                      [mock.call(), mock.call(('host', 22))])
Esempio n. 3
0
 def test_sshexec(self, mock_paramiko):
     mock_paramiko.Transport().open_session().makefile(
     ).readlines.return_value = ['some_output\n']
     self.assertEqual(misc.sshexec('cmd', 'host', 'username'),
                      ['some_output\n'])
     # interestingly, Transpost is called twice while in the code, it's
     # explicitly called only once
     self.assertEqual(mock_paramiko.Transport.call_args_list,
                      [mock.call(), mock.call(('host', 22))])
Esempio n. 4
0
def fetch_remote_file_list(remote, username, r_dir):
    find_cmd = 'find {0}'.format(r_dir)
    output = misc.sshexec(find_cmd, remote, username)
    if output is None:
        raise ValueError(
            'cannot estimate current usage on remote host. Please check '
            '{0} exists on {1}, or {1} may be down'.format(r_dir, remote))
    output = [_.strip() for _ in output] # remote trailing '\n'
    return output
Esempio n. 5
0
def get_remote_free_disk_space(remote, username, df_cmd):
    """
    find the free disk space on remote host.

    :param df_cmd: should be in the form of df -k -P target_dir
    """
    output = misc.sshexec(df_cmd, remote, username)
    # e.g. output:
    # ['Filesystem         1024-blocks      Used Available Capacity Mounted on\n',
    #  '/dev/analysis        16106127360 12607690752 3498436608      79% /extscratch\n']
    return int(output[1].split()[3]) * 1024
Esempio n. 6
0
 def test_sshexec_execution_failed_remotely(self, mock_paramiko):
     mock_paramiko.Transport().open_session().makefile(
     ).readlines.return_value = None
     self.assertIsNone(misc.sshexec('cmd', 'host', 'username'))
     self.assertEqual(mock_paramiko.Transport.call_args_list,
                      [mock.call(), mock.call(('host', 22))])
Esempio n. 7
0
 def test_sshexec_execution_failed_remotely(self, mock_paramiko):
     mock_paramiko.Transport().open_session().makefile().readlines.return_value = None
     self.assertIsNone(misc.sshexec('cmd', 'host', 'username'))
     self.assertEqual(mock_paramiko.Transport.call_args_list,
                      [mock.call(), mock.call(('host', 22))])