Esempio n. 1
0
    def fetch_logs_from_host(hostname, install_path, prefix, logs, directory,
                             pattern):
        """ Static method Copies logs from specified host on the specified install path

    :Parameter hostname the remote host from where we need to fetch the logs
    :Parameter install_path path where the app is installed
    :Parameter prefix prefix used to copy logs. Generall the unique_id of process
    :Parameter logs a list of logs given by absolute path from the remote host
    :Parameter directory the local directory to store the copied logs
    :Parameter pattern a pattern to apply to files to restrict the set of logs copied
    """
        if hostname is not None:
            with get_sftp_client(hostname,
                                 username=runtime.get_username(),
                                 password=runtime.get_password()) as ftp:
                for f in logs:
                    try:
                        mode = ftp.stat(f).st_mode
                    except IOError, e:
                        if e.errno == errno.ENOENT:
                            logger.error("Log file " + f +
                                         " does not exist on " + hostname)
                            pass
                    else:
                        copy_dir(ftp, f, directory, prefix)
                if install_path is not None:
                    copy_dir(ftp, install_path, directory, prefix, pattern)
Esempio n. 2
0
    def get_logs(self, unique_id, logs, directory, pattern='^$'):
        """ Copies logs from the remote host that the process is running on to the provided directory

    :Parameter unique_id the unique_id of the process in question
    :Parameter logs a list of logs given by absolute path from the remote host
    :Parameter directory the local directory to store the copied logs
    :Parameter pattern a pattern to apply to files to restrict the set of logs copied
    """
        hostname = self.processes[unique_id].hostname
        install_path = self.processes[unique_id].install_path
        if hostname is not None:
            with get_sftp_client(hostname,
                                 username=runtime.get_username(),
                                 password=runtime.get_password()) as ftp:
                for f in logs:
                    try:
                        mode = ftp.stat(f).st_mode
                    except IOError, e:
                        if e.errno == errno.ENOENT:
                            logger.error("Log file " + f +
                                         " does not exist on " + hostname)
                            pass
                    else:
                        copy_dir(ftp, f, directory, unique_id)
                if install_path is not None:
                    copy_dir(ftp, install_path, directory, unique_id, pattern)
Esempio n. 3
0
  def test_copy_logs(self):

    install_path = '/tmp/test_copy_dir'
    if not os.path.exists(install_path):
      os.mkdir(install_path)

    output_path = '/tmp/test_copy_dir_output'
    if not os.path.exists(output_path):
      os.mkdir(output_path)
    with open(os.path.join(install_path, 'test.log'), 'w') as f:
      f.write('this is the test log')
    with open(os.path.join(install_path, 'test.out'), 'w') as f:
      f.write('this is the test out')
    with open(os.path.join(install_path, 'test.foo'), 'w') as f:
      f.write('this is the test foo')
    with get_sftp_client('localhost') as ftp:
      copy_dir(ftp, install_path, output_path, 'prefix', '.*out')
    assert os.path.exists(os.path.join(output_path, "prefix_test_copy_dir-test.out"))
    shutil.rmtree(output_path)
    shutil.rmtree(install_path)
Esempio n. 4
0
    def test_copy_logs(self):

        install_path = "/tmp/test_copy_dir"
        if not os.path.exists(install_path):
            os.mkdir(install_path)

        output_path = "/tmp/test_copy_dir_output"
        if not os.path.exists(output_path):
            os.mkdir(output_path)
        with open(os.path.join(install_path, "test.log"), "w") as f:
            f.write("this is the test log")
        with open(os.path.join(install_path, "test.out"), "w") as f:
            f.write("this is the test out")
        with open(os.path.join(install_path, "test.foo"), "w") as f:
            f.write("this is the test foo")
        with get_sftp_client("localhost") as ftp:
            copy_dir(ftp, install_path, output_path, "prefix", ".*out")
        assert os.path.exists(os.path.join(output_path, "prefix_test_copy_dir-test.out"))
        shutil.rmtree(output_path)
        shutil.rmtree(install_path)
Esempio n. 5
0
    def test_copy_logs(self):

        install_path = '/tmp/test_copy_dir'
        if not os.path.exists(install_path):
            os.mkdir(install_path)

        output_path = '/tmp/test_copy_dir_output'
        if not os.path.exists(output_path):
            os.mkdir(output_path)
        with open(os.path.join(install_path, 'test.log'), 'w') as f:
            f.write('this is the test log')
        with open(os.path.join(install_path, 'test.out'), 'w') as f:
            f.write('this is the test out')
        with open(os.path.join(install_path, 'test.foo'), 'w') as f:
            f.write('this is the test foo')
        with get_sftp_client('localhost') as ftp:
            copy_dir(ftp, install_path, output_path, 'prefix', '.*out')
        assert os.path.exists(
            os.path.join(output_path, "prefix_test_copy_dir-test.out"))
        shutil.rmtree(output_path)
        shutil.rmtree(install_path)
Esempio n. 6
0
  def get_logs(self, unique_id, logs, directory, pattern='^$'):
    """ Copies logs from the remote host that the process is running on to the provided directory

    :Parameter unique_id the unique_id of the process in question
    :Parameter logs a list of logs given by absolute path from the remote host
    :Parameter directory the local directory to store the copied logs
    :Parameter pattern a pattern to apply to files to restrict the set of logs copied
    """
    hostname = self.processes[unique_id].hostname
    install_path = self.processes[unique_id].install_path
    if hostname is not None:
      with get_sftp_client(hostname, username=runtime.get_username(), password=runtime.get_password()) as ftp:
        for f in logs:
          try:
            mode = ftp.stat(f).st_mode
          except IOError, e:
            if e.errno == errno.ENOENT:
              logger.error("Log file " + f + " does not exist on " + hostname)
              pass
          else:
            copy_dir(ftp, f, directory, unique_id)
        if install_path is not None:
          copy_dir(ftp, install_path, directory, unique_id, pattern)
Esempio n. 7
0
  def fetch_logs_from_host(self, hostname, install_path, prefix, logs, directory, pattern):
    """ Copies logs from any host on the specified install path

    :Parameter hostname the remote host from where we need to fetch the logs
    :Parameter install_path path where the app is installed
    :Parameter prefix prefix used to copy logs. Generall the unique_id of process
    :Parameter logs a list of logs given by absolute path from the remote host
    :Parameter directory the local directory to store the copied logs
    :Parameter pattern a pattern to apply to files to restrict the set of logs copied
    """
    if hostname is not None:
      with get_sftp_client(hostname, username=runtime.get_username(), password=runtime.get_password()) as ftp:
        for f in logs:
          try:
            mode = ftp.stat(f).st_mode
          except IOError, e:
            if e.errno == errno.ENOENT:
              logger.error("Log file " + f + " does not exist on " + hostname)
              pass
          else:
            copy_dir(ftp, f, directory, prefix, pattern)
        if install_path is not None:
          copy_dir(ftp, install_path, directory, prefix, pattern)