Пример #1
0
    def test__get_connection(self):
        """Test method ``_get_connection``.

        Mock up ``paramiko.SSHClient`` (by overriding method
        ``_call_paramiko_sshclient``) before calling ``_get_connection``.
        Assert that certain parameters are passed to the (mock)
        ``paramiko.SSHClient`` object, and that certain methods on that object
        are called.

        """
        ssh._call_paramiko_sshclient = MockSSHClient  # pylint:disable=W0212
        backup = conf.properties

        key_filename = os.path.join(
            get_app_root(), 'tests', 'robottelo', 'data', 'test_dsa.key'
        )
        conf.properties['main.server.hostname'] = 'example.com'
        conf.properties['main.server.ssh.username'] = '******'
        conf.properties['main.server.ssh.key_private'] = key_filename
        with ssh._get_connection() as connection:  # pylint:disable=W0212
            self.assertEqual(connection.set_missing_host_key_policy_, 1)
            self.assertEqual(connection.connect_, 1)
            self.assertEqual(connection.close_, 0)
            self.assertEqual(connection.hostname, 'example.com')
            self.assertEqual(connection.username, 'nobody')
            self.assertEqual(connection.key_filename, key_filename)
        self.assertEqual(connection.set_missing_host_key_policy_, 1)
        self.assertEqual(connection.connect_, 1)
        self.assertEqual(connection.close_, 1)

        conf.properties = backup
Пример #2
0
"""Utilities to help work with log files"""

import os
import re

from robottelo.common import get_app_root, ssh


LOGS_DATA_DIR = os.path.join(get_app_root(), 'data', 'logs')


class LogFile(object):
    """
    References a remote log file. The log file will be downloaded to allow
    operate on it using python
    """

    def __init__(self, remote_path, pattern=None):
        self.remote_path = remote_path
        self.pattern = pattern

        if not os.path.isdir(LOGS_DATA_DIR):
            os.makedirs(LOGS_DATA_DIR)
        self.local_path = os.path.join(LOGS_DATA_DIR,
                                       os.path.basename(remote_path))
        ssh.download_file(remote_path, self.local_path)
        with open(self.local_path) as file_:
            self.data = file_.readlines()

    def filter(self, pattern=None):
        """
Пример #3
0
"""Utilities to help work with log files"""

import os
import re

from robottelo.common import get_app_root, ssh

LOGS_DATA_DIR = os.path.join(get_app_root(), 'data', 'logs')


class LogFile(object):
    """
    References a remote log file. The log file will be downloaded to allow
    operate on it using python
    """
    def __init__(self, remote_path, pattern=None):
        self.remote_path = remote_path
        self.pattern = pattern

        if not os.path.isdir(LOGS_DATA_DIR):
            os.makedirs(LOGS_DATA_DIR)
        self.local_path = os.path.join(LOGS_DATA_DIR,
                                       os.path.basename(remote_path))
        ssh.download_file(remote_path, self.local_path)
        with open(self.local_path) as file_:
            self.data = file_.readlines()

    def filter(self, pattern=None):
        """
        Filter the log file using the pattern argument or object's pattern
        """