How to use the rally.common.logging function in rally

To help you get started, we’ve selected a few rally examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstack / rally / tests / unit / test_logging.py View on Github external
def test_logcatcher(self):
        LOG = log.getLogger("testlogger")
        LOG.logger.setLevel(log.INFO)

        with log.LogCatcher(LOG) as catcher:
            LOG.warning("Warning")
            LOG.info("Info")
            LOG.debug("Debug")

        catcher.assertInLogs("Warning")
        self.assertRaises(AssertionError, catcher.assertInLogs, "Error")

        self.assertEqual(["Warning", "Info"], catcher.fetchLogs())
        self.assertEqual(2, len(catcher.fetchLogRecords()))
github openstack / rally / tests / unit / common / test_logging.py View on Github external
def test_setup(self, mock_oslogging, mock_handlers, mock_conf):

        proj = "fakep"
        version = "fakev"
        mock_handlers.ColorHandler.LEVEL_COLORS = {
            logging.DEBUG: "debug_color"}
        mock_conf.rally_debug = True

        rally_logging.setup(proj, version)

        self.assertIn(logging.RDEBUG, mock_handlers.ColorHandler.LEVEL_COLORS)
        self.assertEqual(
            mock_handlers.ColorHandler.LEVEL_COLORS[logging.DEBUG],
            mock_handlers.ColorHandler.LEVEL_COLORS[logging.RDEBUG])

        mock_oslogging.setup.assert_called_once_with(mock_conf, proj, version)
        mock_oslogging.getLogger(None).logger.setLevel.assert_called_once_with(
            logging.RDEBUG)
github openstack / rally-openstack / rally_openstack / contexts / nova / flavors.py View on Github external
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from rally.common import logging
from rally.common import utils as rutils
from rally.common import validation
from rally.task import context

from rally_openstack.cleanup import manager as resource_manager
from rally_openstack import consts
from rally_openstack import osclients


LOG = logging.getLogger(__name__)


@validation.add("required_platform", platform="openstack", admin=True)
@context.configure(name="flavors", platform="openstack", order=340)
class FlavorsGenerator(context.Context):
    """Context creates a list of flavors."""

    CONFIG_SCHEMA = {
        "type": "array",
        "$schema": consts.JSON_SCHEMA,
        "items": {
            "type": "object",
            "properties": {
                "name": {
                    "type": "string",
                },
github openstack / rally-openstack / rally_openstack / scenarios / neutron / utils.py View on Github external
import random

from rally.common import cfg
from rally.common import logging
from rally import exceptions
from rally.task import atomic
from rally.task import utils

from rally_openstack import scenario
from rally_openstack.wrappers import network as network_wrapper


CONF = cfg.CONF


LOG = logging.getLogger(__name__)


class NeutronScenario(scenario.OpenStackScenario):
    """Base class for Neutron scenarios with basic atomic actions."""

    # TODO(rkiran): modify in case LBaaS-v2 requires
    LB_METHOD = "ROUND_ROBIN"
    LB_PROTOCOL = "HTTP"
    LB_PROTOCOL_PORT = 80
    HM_TYPE = "PING"
    HM_MAX_RETRIES = 3
    HM_DELAY = 20
    HM_TIMEOUT = 10

    def _get_network_id(self, network, **kwargs):
        """Get Neutron network ID for the network name.
github openstack / rally / rally / common / broker.py View on Github external
"""
    cache = {}
    while True:
        if not queue:
            break
        else:
            try:
                args = queue.popleft()
            except IndexError:
                # consumed by other thread
                continue
        try:
            consume(cache, args)
        except Exception as e:
            msg = "Failed to consume a task from the queue"
            if logging.is_debug():
                LOG.exception(msg)
            else:
                LOG.warning("%s: %s" % (msg, e))
github openstack / rally / samples / plugins / context / context_plugin.py View on Github external
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from rally.common import logging
from rally import consts
from rally.plugins.openstack import osclients
from rally.task import context

LOG = logging.getLogger(__name__)


@context.configure(name="create_flavor", platform="openstack", order=1000)
class CreateFlavorContext(context.Context):
    """Create sample flavor

    This sample create flavor with specified options before task starts and
    delete it after task completion.
    To create your own context plugin, inherit it from
    rally.task.context.Context
    """

    CONFIG_SCHEMA = {
        "type": "object",
        "$schema": consts.JSON_SCHEMA,
        "additionalProperties": False,
github openstack / ec2-api / rally-scenarios / plugins / context_plugin_images.py View on Github external
    @logging.log_task_wrapper(LOG.info, _("Enter context: `Images`"))
    def setup(self):
        disk_format = self.config["disk_format"]
        container_format = self.config["container_format"]
        images_per_tenant = self.config["images_per_tenant"]

        for user, tenant_id in rutils.iterate_per_tenants(
                self.context["users"]):
            glance = osclients.Clients(user["credential"]).glance().images
            current_images = []
            for i in range(images_per_tenant):
                kw = {
                    "name": "image-" + tenant_id[0:8] + "-" + str(i),
                    "container_format": container_format,
                    "disk_format": disk_format,
                }
                image = glance.create(**kw)
github openstack / rally / rally / common / utils.py View on Github external
import random
import re
import shutil
import string
import sys
import tempfile
import time
import uuid

from six import moves

from rally.common import logging
from rally import exceptions
from rally.utils import strutils

LOG = logging.getLogger(__name__)


class ImmutableMixin(object):
    _inited = False

    def __init__(self):
        self._inited = True

    def __setattr__(self, key, value):
        if self._inited:
            raise AttributeError("This object is immutable.")
        super(ImmutableMixin, self).__setattr__(key, value)


class EnumMixin(object):
    def __iter__(self):
github openstack / rally / rally / plugins / common / exporter / file_system.py View on Github external
#    under the License.


import json
import os
import sys

from six.moves.urllib import parse as urlparse

from rally import api
from rally.common import logging
from rally import exceptions
from rally.task import exporter


LOG = logging.getLogger(__name__)


@exporter.configure(name="file")
class FileExporter(exporter.Exporter):
    """Export task results in the file."""

    def validate(self):
        """Validate connection string.

        The format of connection string in file plugin is
            file:///
github openstack / kuryr-libnetwork / rally-jobs / plugins / context / docker_networks.py View on Github external
}
                    ]
                }
                res = docker_client.create_network(name="kuryr_network",
                                                   driver="kuryr",
                                                   ipam=ipam)
                self.context["netid"] = res.get("Id")
                self.context["netname"] = "kuryr_network"
            else:
                res = docker_client.create_network(name="docker_network")
                self.context["netid"] = res.get("Id")
                self.context["netname"] = "docker_network"
            LOG.debug("Container network id is '%s'" % self.context["netid"])
        except Exception as e:
            msg = "Can't create docker network: %s" % e.message
            if logging.is_debug():
                LOG.exception(msg)
            else:
                LOG.warning(msg)