How to use the rally.task.context 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 / rally / plugins / openstack / context / cleanup / context.py View on Github external
CONFIG_SCHEMA = {
        "type": "array",
        "$schema": consts.JSON_SCHEMA,
        "items": {
            "type": "string",
        },
        "additionalProperties": False
    }

    def setup(self):
        pass


# NOTE(amaretskiy): Set order to run this just before UserCleanup
@context.configure(name="admin_cleanup", order=(sys.maxsize - 1), hidden=True)
class AdminCleanup(CleanupMixin, context.Context):
    """Context class for admin resources cleanup."""

    @classmethod
    def validate(cls, config, non_hidden=False):
        super(AdminCleanup, cls).validate(config, non_hidden)

        missing = set(config)
        missing -= manager.list_resource_names(admin_required=True)
        missing = ", ".join(missing)
        if missing:
            LOG.info(_("Couldn't find cleanup resource managers: %s")
                     % missing)
            raise NoSuchCleanupResources(missing)

    @logging.log_task_wrapper(LOG.info, _("admin resources cleanup"))
    def cleanup(self):
github openstack / rally / rally / verification / context.py View on Github external
pattern = re.compile(regex)
            for test in load_list:
                if pattern.search(test):
                    result[test] = reason
        except re.error:
            # assume regex is a test id, eg: tempest.api.compute.admin.
            # test_flavors.FlavorsAdminTestJSON.
            # test_create_flavor_using_string_ram
            # [id-3b541a2e-2ac2-4b42-8b8d-ba6e22fcd4da]
            result[regex] = reason
            continue
    return result


@plugin.base()
class VerifierContext(context.BaseContext):
    """Verifier context that will be run before starting a verification."""

    def __init__(self, ctx):
        super(VerifierContext, self).__init__(ctx)
        self.verification = self.context.get("verification", {})
        self.verifier = self.context["verifier"]

    @classmethod
    def validate(cls, config):
        # do not validate jsonschema.
        pass

    def setup(self):
        self._process_runargs()

    def _process_runargs(self):
github openstack / rally-openstack / rally_openstack / contexts / quotas / quotas.py View on Github external
from rally.task import context

from rally_openstack import consts
from rally_openstack.contexts.quotas import cinder_quotas
from rally_openstack.contexts.quotas import designate_quotas
from rally_openstack.contexts.quotas import manila_quotas
from rally_openstack.contexts.quotas import neutron_quotas
from rally_openstack.contexts.quotas import nova_quotas
from rally_openstack import osclients


LOG = logging.getLogger(__name__)


@validation.add("required_platform", platform="openstack", admin=True)
@context.configure(name="quotas", platform="openstack", order=300)
class Quotas(context.Context):
    """Sets OpenStack Tenants quotas."""

    CONFIG_SCHEMA = {
        "type": "object",
        "$schema": consts.JSON_SCHEMA,
        "additionalProperties": False,
        "properties": {
            "nova": nova_quotas.NovaQuotas.QUOTAS_SCHEMA,
            "cinder": cinder_quotas.CinderQuotas.QUOTAS_SCHEMA,
            "manila": manila_quotas.ManilaQuotas.QUOTAS_SCHEMA,
            "designate": designate_quotas.DesignateQuotas.QUOTAS_SCHEMA,
            "neutron": neutron_quotas.NeutronQuotas.QUOTAS_SCHEMA
        }
    }
github openstack / rally-openstack / rally_openstack / contexts / sahara / sahara_job_binaries.py View on Github external
import requests

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

from rally_openstack.cleanup import manager as resource_manager
from rally_openstack import consts
from rally_openstack import osclients
from rally_openstack.scenarios.sahara import utils


@validation.add("required_platform", platform="openstack", users=True)
@context.configure(name="sahara_job_binaries", platform="openstack", order=442)
class SaharaJobBinaries(context.Context):
    """Context class for setting up Job Binaries for an EDP job."""

    CONFIG_SCHEMA = {
        "type": "object",
        "$schema": consts.JSON_SCHEMA,
        "properties": {
            "mains": {
                "type": "array",
                "items": {
                    "type": "object",
                    "properties": {
                        "name": {
                            "type": "string"
                        },
                        "download_url": {
                            "type": "string"
github openstack / rally-openstack / rally_openstack / contexts / glance / images.py View on Github external
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
from rally_openstack.services.image import image


CONF = cfg.CONF

LOG = logging.getLogger(__name__)


@validation.add("required_platform", platform="openstack", users=True)
@context.configure(name="images", platform="openstack", order=410)
class ImageGenerator(context.Context):
    """Uploads specified Glance images to every tenant."""

    CONFIG_SCHEMA = {
        "type": "object",
        "$schema": consts.JSON_SCHEMA,
        "properties": {
            "image_url": {
                "type": "string",
                "description": "Location of the source to create image from."
            },
            "disk_format": {
                "description": "The format of the disk.",
                "enum": ["qcow2", "raw", "vhd", "vmdk", "vdi", "iso", "aki",
                         "ari", "ami"]
            },
github openstack / rally-openstack / rally_openstack / contexts / cinder / volume_types.py View on Github external
from rally.common import logging
from rally.common import utils
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
from rally_openstack.services.storage import block


LOG = logging.getLogger(__name__)


@validation.add("required_platform", platform="openstack", admin=True)
@context.configure(name="volume_types", platform="openstack", order=410)
class VolumeTypeGenerator(context.Context):
    """Adds cinder volumes types."""

    CONFIG_SCHEMA = {
        "type": "array",
        "$schema": consts.JSON_SCHEMA,
        "items": {"type": "string"}
    }

    def setup(self):
        admin_clients = osclients.Clients(
            self.context.get("admin", {}).get("credential"))
        cinder_service = block.BlockStorage(
            admin_clients,
            name_generator=self.generate_random_name,
            atomic_inst=self.atomic_actions())
github openstack / rally / rally / plugins / openstack / context / cleanup / __init__.py View on Github external
% missing)
            raise NoSuchCleanupResources(missing)

    @logging.log_task_wrapper(LOG.info, _("admin resources cleanup"))
    def cleanup(self):
        manager.cleanup(
            names=self.config,
            admin_required=True,
            admin=self.context["admin"],
            users=self.context.get("users", []),
            api_versions=self.context["config"].get("api_versions"))


# NOTE(amaretskiy): Set maximum order to run this last
@context.configure(name="cleanup", order=sys.maxsize, hidden=True)
class UserCleanup(CleanupMixin, context.Context):
    """Context class for user resources cleanup."""

    @classmethod
    def validate(cls, config, non_hidden=False):
        super(UserCleanup, cls).validate(config, non_hidden)

        missing = set(config)
        missing -= manager.list_resource_names(admin_required=False)
        missing = ", ".join(missing)
        if missing:
            LOG.info(_("Couldn't find cleanup resource managers: %s")
                     % missing)
            raise NoSuchCleanupResources(missing)

    @logging.log_task_wrapper(LOG.info, _("user resources cleanup"))
    def cleanup(self):
github openstack / rally-openstack / rally_openstack / contexts / network / allow_ssh.py View on Github external
"security_group_id": rally_open["id"]
        }
    ]

    existing_rules = set(
        _rule_to_key(r) for r in rally_open.get("security_group_rules", []))
    for new_rule in rules_to_add:
        if _rule_to_key(new_rule) not in existing_rules:
            neutron.create_security_group_rule(
                {"security_group_rule": new_rule})

    return rally_open


@validation.add("required_platform", platform="openstack", users=True)
@context.configure(name="allow_ssh", platform="openstack", order=320)
class AllowSSH(context.Context):
    """Sets up security groups for all users to access VM via SSH."""

    def setup(self):
        admin_or_user = (self.context.get("admin") or
                         self.context.get("users")[0])

        net_wrapper = network.wrap(
            osclients.Clients(admin_or_user["credential"]),
            self, config=self.config)
        use_sg, msg = net_wrapper.supports_extension("security-group")
        if not use_sg:
            LOG.info("Security group context is disabled: %s" % msg)
            return

        secgroup_name = self.generate_random_name()
github openstack / rally / rally / plugins / openstack / context / magnum / cluster_templates.py View on Github external
from rally.common.i18n import _
from rally.common import logging
from rally.common import utils as rutils
from rally import consts
from rally.plugins.openstack.cleanup import manager as resource_manager
from rally.plugins.openstack.scenarios.magnum import utils as magnum_utils
from rally.plugins.openstack.scenarios.nova import utils as nova_utils
from rally.task import context


LOG = logging.getLogger(__name__)


@context.configure(name="cluster_templates", order=470)
class ClusterTemplateGenerator(context.Context):
    """Context class for generating temporary cluster model for benchmarks."""

    CONFIG_SCHEMA = {
        "type": "object",
        "$schema": consts.JSON_SCHEMA,
        "properties": {
            "image_id": {
                "type": "string"
            },
            "flavor_id": {
                "type": "string"
            },
            "master_flavor_id": {
                "type": "string"
            },
            "external_network_id": {
github openstack / rally-openstack / rally_openstack / contexts / manila / manila_share_networks.py View on Github external
"share_networks": {
             "tenant_1_name_or_id": ["share_network_1_name_or_id",
                                     "share_network_2_name_or_id"],
             "tenant_2_name_or_id": ["share_network_3_name_or_id"]}
         }
     }

Also, make sure that all 'existing users' in appropriate registered deployment
have share networks if its usage is enabled, else Rally will randomly take
users that does not satisfy criteria.
"""


@validation.add("required_platform", platform="openstack", users=True)
@context.configure(name=CONTEXT_NAME, platform="openstack", order=450)
class ShareNetworks(context.Context):
    """This context creates share networks for Manila project."""
    CONFIG_SCHEMA = {
        "type": "object",
        "$schema": rally_consts.JSON_SCHEMA,
        "properties": {
            "use_share_networks": {
                "type": "boolean",
                "description": "Specifies whether manila should use share "
                               "networks for share creation or not."},

            "share_networks": {
                "type": "object",
                "description": SHARE_NETWORKS_ARG_DESCR,
                "additionalProperties": True
            },
        },