How to use the rally.common.validation.add 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 / nova / keypairs.py View on Github external
#
#         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 validation
from rally.plugins.openstack.cleanup import manager as resource_manager
from rally.plugins.openstack import osclients
from rally.task import context


@validation.add("required_platform", platform="openstack", users=True)
@context.configure(name="keypair", platform="openstack", order=310)
class Keypair(context.Context):
    """Create Nova KeyPair for each user."""

    # NOTE(andreykurilin): "type" != "null", since we need to support backward
    #   compatibility(previously empty dict was valid) and I hope in near
    #   future, we will extend this context to accept keys.
    CONFIG_SCHEMA = {"type": "object",
                     "additionalProperties": False}

    def _generate_keypair(self, credential):
        nova_client = osclients.Clients(credential).nova()
        # NOTE(hughsaunders): If keypair exists, it should re-generate name.

        keypairs = nova_client.keypairs.list()
        keypair_names = [keypair.name for keypair in keypairs]
github openstack / rally-openstack / rally_openstack / contexts / network / networks.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 import consts
from rally_openstack import osclients
from rally_openstack.wrappers import network as network_wrapper


LOG = logging.getLogger(__name__)


# NOTE(andreykurilin): admin is used only by cleanup
@validation.add("required_platform", platform="openstack", admin=True,
                users=True)
@context.configure(name="network", platform="openstack", order=350)
class Network(context.Context):
    """Create networking resources.

    This creates networks for all tenants, and optionally creates
    another resources like subnets and routers.
    """

    CONFIG_SCHEMA = {
        "type": "object",
        "$schema": consts.JSON_SCHEMA,
        "properties": {
            "start_cidr": {
                "type": "string"
            },
github openstack / rally-openstack / rally_openstack / contexts / network / existing_network.py View on Github external
# 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 utils
from rally.common import validation
from rally.task import context

from rally_openstack import consts
from rally_openstack import osclients
from rally_openstack.wrappers import network as network_wrapper


@validation.add("required_platform", platform="openstack", users=True)
@context.configure(name="existing_network", platform="openstack", order=349)
class ExistingNetwork(context.Context):
    """This context supports using existing networks in Rally.

    This context should be used on a deployment with existing users.
    """

    CONFIG_SCHEMA = {
        "type": "object",
        "$schema": consts.JSON_SCHEMA,
        "additionalProperties": False
    }

    def setup(self):
        for user, tenant_id in utils.iterate_per_tenants(
                self.context.get("users", [])):
github openstack / rally-openstack / rally_openstack / contexts / sahara / sahara_output_data_sources.py View on Github external
# 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 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
from rally_openstack.scenarios.sahara import utils
from rally_openstack.scenarios.swift import utils as swift_utils


@validation.add("required_platform", platform="openstack", users=True)
@context.configure(name="sahara_output_data_sources", platform="openstack",
                   order=444)
class SaharaOutputDataSources(context.Context):
    """Context class for setting up Output Data Sources for an EDP job."""

    CONFIG_SCHEMA = {
        "type": "object",
        "$schema": consts.JSON_SCHEMA,
        "properties": {
            "output_type": {
                "enum": ["swift", "hdfs"],
            },
            "output_url_prefix": {
                "type": "string",
            }
        },
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,
github openstack / rally / rally / plugins / openstack / context / nova / servers.py View on Github external
# 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.plugins.openstack.cleanup import manager as resource_manager
from rally.plugins.openstack.scenarios.nova import utils as nova_utils
from rally.plugins.openstack import types
from rally.task import context


LOG = logging.getLogger(__name__)


@validation.add("required_platform", platform="openstack", users=True)
@context.configure(name="servers", platform="openstack", order=430)
class ServerGenerator(context.Context):
    """Creates specified amount of Nova Servers per each tenant."""

    CONFIG_SCHEMA = {
        "type": "object",
        "properties": {
            "image": {
                "description": "Name of image to boot server(s) from.",
                "type": "object",
                "properties": {
                    "name": {"type": "string"}
                },
                "additionalProperties": False
            },
            "flavor": {
github openstack / rally-openstack / rally_openstack / scenarios / vm / vmtasks.py View on Github external
self._file_access_ok(
                    filename=command[key], mode=os.R_OK,
                    param_name=self.param_name, required=self.required)


@types.convert(image={"type": "glance_image"},
               flavor={"type": "nova_flavor"})
@validation.add("image_valid_on_flavor", flavor_param="flavor",
                image_param="image", fail_on_404_image=False)
@validation.add("valid_command", param_name="command")
@validation.add("number", param_name="port", minval=1, maxval=65535,
                nullable=True, integer_only=True)
@validation.add("external_network_exists", param_name="floating_network")
@validation.add("required_services", services=[consts.Service.NOVA,
                                               consts.Service.CINDER])
@validation.add("required_param_or_context",
                param_name="image", ctx_name="image_command_customizer")
@validation.add("required_platform", platform="openstack", users=True)
@scenario.configure(context={"cleanup@openstack": ["nova", "cinder"],
                             "keypair@openstack": {},
                             "allow_ssh@openstack": None},
                    name="VMTasks.boot_runcommand_delete",
                    platform="openstack")
class BootRuncommandDelete(vm_utils.VMScenario, cinder_utils.CinderBasic):

    def run(self, flavor, username, password=None,
            image=None,
            command=None,
            volume_args=None, floating_network=None, port=22,
            use_floating_ip=True, force_delete=False, wait_for_ping=True,
            max_log_length=None, **kwargs):
        """Boot a server, run script specified in command and delete server.
github openstack / rally-openstack / rally_openstack / contexts / senlin / profiles.py View on Github external
#
#    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 utils as rutils
from rally.common import validation
from rally.task import context

from rally_openstack import consts
from rally_openstack.scenarios.senlin import utils as senlin_utils


@validation.add("required_platform", platform="openstack", users=True)
@context.configure(name="profiles", platform="openstack", order=190)
class ProfilesGenerator(context.Context):
    """Context creates a temporary profile for Senlin test."""

    CONFIG_SCHEMA = {
        "type": "object",
        "$schema": consts.JSON_SCHEMA,
        "properties": {
            "type": {
                "type": "string",
            },
            "version": {
                "type": "string",
            },
            "properties": {
                "type": "object",
github openstack / rally-openstack / rally_openstack / contexts / monasca / metrics.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 six import moves

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

from rally_openstack import consts
from rally_openstack.scenarios.monasca import utils as monasca_utils


@validation.add("required_platform", platform="openstack", users=True)
@context.configure(name="monasca_metrics", platform="openstack", order=510)
class MonascaMetricGenerator(context.Context):
    """Creates Monasca Metrics."""

    CONFIG_SCHEMA = {
        "type": "object",
        "$schema": consts.JSON_SCHEMA,
        "properties": {
            "name": {
                "type": "string"
            },
            "dimensions": {
                "type": "object",
                "properties": {
                    "region": {
                        "type": "string"
github openstack / rally / rally / plugins / openstack / context / nova / flavors.py View on Github external
#    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 import consts
from rally import osclients
from rally.plugins.openstack.cleanup import manager as resource_manager
from rally.task import context

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",
                },
                "ram": {
                    "type": "integer",
                    "minimum": 1