Beispiel #1
0
    def configure(self, settings_path=None):
        """Read the settings file and parse the configuration.

        :param str settings_path: path to settings file to read. If None, looks in the project
            root for a file named 'robottelo.properties'.

        :raises: ImproperlyConfigured if any issue is found during the parsing
            or validation of the configuration.
        """

        if not settings_path:
            # Expect the settings file to be on the robottelo project root.
            settings_path = os.path.join(get_project_root(),
                                         SETTINGS_FILE_NAME)

        if not os.path.isfile(settings_path):
            raise ImproperlyConfigured(
                f'Not able to find settings file at {settings_path}')

        self.reader = INIReader(settings_path)
        attrs = map(lambda attr_name: (attr_name, getattr(self, attr_name)),
                    dir(self))
        feature_settings = filter(
            lambda tpl: isinstance(tpl[1], FeatureSettings), attrs)
        for name, settings in feature_settings:
            settings.read(self.reader)
            # Only has section will extend the error
            if self.reader.has_section(name):
                self._validation_errors.extend(settings.validate())
        if self._validation_errors:
            raise ImproperlyConfigured(
                'Failed to validate the configuration, check the message(s):\n'
                '{}'.format('\n'.join(self._validation_errors)))
Beispiel #2
0
 def __server_get_hostname(self, key="hostname"):
     try:
         return self._get_from_configs(f"server.{key}")
     except AttributeError:
         default = self._get_from_configs("server.hostname")
         reader = INIReader(
             os.path.join(get_project_root(), SETTINGS_FILE_NAME))
         return reader.get('server', key, default)
Beispiel #3
0
    def configure_logging(self):
        """Configure logging for the entire framework.

        If a config named ``logging.conf`` exists in Robottelo's root
        directory, the logger is configured using the options in that file.
        Otherwise, a custom logging output format is set, and default values
        are used for all other logging options.
        """
        # All output should be made by the logging module, including warnings
        logging.captureWarnings(True)

        # Set the logging level based on the Robottelo's verbosity
        for name in ('nailgun', 'robottelo'):
            logging.getLogger(name).setLevel(self.verbosity)

        # Allow overriding logging config based on the presence of logging.conf
        # file on Robottelo's project root
        logging_conf_path = os.path.join(get_project_root(), 'logging.conf')
        if os.path.isfile(logging_conf_path):
            logging.config.fileConfig(logging_conf_path)
        else:
            logging.basicConfig(
                format='%(levelname)s %(module)s:%(lineno)d: %(message)s')
Beispiel #4
0
"""Utilities to help work with log files"""
import os
import re

from robottelo import ssh
from robottelo.config.base import get_project_root

LOGS_DATA_DIR = os.path.join(get_project_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
Beispiel #5
0
# coding: utf-8
import logging
import os
from collections import defaultdict

from robottelo.config import settings
from robottelo.config.base import get_project_root
from robottelo.decorators import setting_is_set
from robozilla.filters import BZDecorator
from robozilla.parser import Parser

BASE_PATH = os.path.join(get_project_root(), 'tests', 'foreman')
VFLAGS = ['sat-{0}.{1}.{2}'.format(6, m, p) for m in '01234' for p in '0z']

LOGGER = logging.getLogger(__name__)


def log_debug(message):
    LOGGER.debug(message)


def get_decorated_bugs():  # pragma: no cover
    """Using Robozilla parser, get all IDs from skip_if_bug_open decorator
    and return the dictionary containing fetched data.

    Important information is stored on `bug_data` key::
        bugs[BUG_ID]['bug_data']['resolution|status|flags|whiteboard']
    """

    if not settings.configured:
        settings.configure()
Beispiel #6
0
 def patched_gpgkey_init(self, server_config=None, **kwargs):
     """Set a default value on the ``content`` field."""
     gpgkey_init(self, server_config, **kwargs)
     self._fields['content'].default = os.path.join(
         get_project_root(), 'tests', 'foreman', 'data',
         'valid_gpg_key.txt')
Beispiel #7
0
# coding: utf-8
import logging
import os
from collections import defaultdict

from robottelo.config import settings
from robottelo.config.base import get_project_root
from robottelo.decorators import setting_is_set
from robozilla.filters import BZDecorator
from robozilla.parser import Parser

BASE_PATH = os.path.join(get_project_root(), 'tests', 'foreman')


LOGGER = logging.getLogger(__name__)


def log_debug(message):
    LOGGER.debug(message)


def get_decorated_bugs():  # pragma: no cover
    """Using Robozilla parser, get all IDs from skip_if_bug_open decorator
    and return the dictionary containing fetched data.

    Important information is stored on `bug_data` key::
        bugs[BUG_ID]['bug_data']['resolution|status|flags|whiteboard']
    """

    if not settings.configured:
        settings.configure()
Beispiel #8
0
"""Utilities to help work with log files"""
import os
import re

from robottelo import ssh
from robottelo.config.base import get_project_root

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


class LogFile:
    """
    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
        """
import os
import tempfile
from robottelo.config import settings
from robottelo.cli.base import CLIReturnCodeError
from robottelo.cli import virt_who_config
from robottelo.api.utils import wait_for_tasks

from robottelo import ssh
from robottelo.config.base import get_project_root
from six.moves.configparser import ConfigParser

VIRTWHO_CONFIG_FILE_PATTERN = 'virt-who-config-{}.conf'
VIRTWHO_CONFIGD = "/etc/virt-who.d/"
VIRTWHO_CONFIG_FILE_PATH_PATTERN = VIRTWHO_CONFIGD + VIRTWHO_CONFIG_FILE_PATTERN
VIRTWHO_SYSCONFIG = "/etc/sysconfig/virt-who"
VIRTWHO_CONFIGD_LOCAL = os.path.join(get_project_root(), 'data', 'virtwho-configs')


def wait_for_virtwho_report_task(config_id, poll_timeout=600, poll_rate=30):
    search = 'label=Actions::Katello::Host::Hypervisors '\
             'and user=virt_who_reporter_{}'.format(config_id)
    return wait_for_tasks(search, poll_timeout=poll_timeout, poll_rate=poll_rate)


class VirtWhoHypervisorConfig(object):

    def __init__(self, config_id, server=None):
        self.server = server if server else settings.server.hostname
        self.config_id = config_id
        self.config_file_name = VIRTWHO_CONFIG_FILE_PATTERN.format(self.config_id)
        self.remote_path = os.path.join(VIRTWHO_CONFIGD, self.config_file_name)