How to use the rally.exceptions.RallyException 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_api.py View on Github external
def test__request_fail(self, mock_find_exception, mock_request):
        api_inst = api.API(skip_db_check=True)
        method = "test"
        path = "path"
        response = mock_request.return_value
        mock_find_exception.return_value = exceptions.RallyException()
        response.status_code = 201
        response.json.return_value = {"result": "test"}
        self.assertRaises(exceptions.RallyException,
                          api_inst._request, path=path, method=method)
github openstack / rally / tests / unit / plugins / openstack / verification / tempest / test_manager.py View on Github external
plugins_list = [
            {"name": "some", "entry_point": "foo.bar", "location": "/tmp"},
            {"name": "another", "entry_point": "bar.foo", "location": "/tmp"}
        ]
        mock_list_extensions.return_value = plugins_list

        tempest = manager.TempestManager(mock.MagicMock(uuid="uuuiiiddd"))

        tempest.uninstall_extension("some")
        mock_rmtree.assert_called_once_with(plugins_list[0]["location"])
        mock_list_extensions.assert_called_once_with()

        mock_rmtree.reset_mock()
        mock_list_extensions.reset_mock()

        self.assertRaises(exceptions.RallyException,
                          tempest.uninstall_extension, "unexist")

        mock_list_extensions.assert_called_once_with()
        self.assertFalse(mock_rmtree.called)
github openstack / rally / rally / plugins / openstack / scenarios / tempest / utils.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.

import functools
import os
import subprocess
import tempfile

from rally.common.i18n import _
from rally import exceptions


class TempestBenchmarkFailure(exceptions.RallyException):
    msg_fmt = _("Failed tempest test(s): '%(message)s'")


def tempest_log_wrapper(func):
    @functools.wraps(func)
    def inner_func(scenario_obj, *args, **kwargs):
        if "log_file" not in kwargs:
            # set temporary log file
            kwargs["log_file"] = os.path.join(
                scenario_obj.context["tmp_results_dir"],
                os.path.basename(tempfile.NamedTemporaryFile().name))

        # run target scenario
        try:
            func(scenario_obj, *args, **kwargs)
        except subprocess.CalledProcessError:
github openstack / rally / rally / task / scenario.py View on Github external
def wrapper(cls):
        # TODO(boris-42): Drop this check as soon as we refactor rally report
        if "." not in name.strip("."):
            raise exceptions.RallyException(
                "Scenario name must include a dot: '%s'" % name)

        for c in context:
            if "@" not in c:
                msg = ("Old fashion plugin configuration detected in "
                       " `%(scenario)s' scenario. Use full name for "
                       " `%(context)s' context like %(context)s@platform "
                       "where 'platform' is a name of context platform ("
                       "openstack, k8s, etc).")
                LOG.warning(msg % {"scenario": "%s@%s" % (name, platform),
                                   "context": c})

        cls = plugin.configure(name=name, platform=platform)(cls)
        cls._meta_setdefault("default_context", {})

        cls._meta_get("default_context").update(context)
github openstack / rally / rally / exceptions.py View on Github external
if isinstance(exc, RallyException):
        return exc
    return RallyException(str(exc))


class ValidationError(RallyException):
    error_code = 110
    msg_fmt = "Validation error: %(message)s"


class InvalidArgumentsException(RallyException):
    error_code = 111
    msg_fmt = "Invalid arguments: '%(message)s'"


class InvalidConfigException(RallyException):
    error_code = 112
    msg_fmt = "This config has invalid schema: `%(message)s`"


class InvalidTaskException(InvalidConfigException):
    error_code = 113
    msg_fmt = "Task config is invalid: `%(message)s`"


class InvalidTaskConfig(InvalidTaskException):
    error_code = 114
    msg_fmt = ("Input task is invalid!\n\n"
               "Subtask %(name)s[%(pos)s] has wrong configuration"
               "\nSubtask configuration:\n%(config)s\n"
               "\nReason(s):\n %(reason)s")
github openstack / rally / rally / plugins / openstack / verification / tempest / config.py View on Github external
# get the most recent version
                target_version = sorted(versions.keys())[-1]
                if target_version == 2:
                    uri = versions[2]
                    uri_v3 = os.path.join(cropped_auth_url, "v3")
                else:
                    # keystone v2 is disabled. let's do it explicitly
                    self.conf.set("identity-feature-enabled", "api_v2",
                                  "False")
                    uri_v3 = versions[3]
                    uri = os.path.join(cropped_auth_url, "v2.0")
            else:
                # Does Keystone released new version of API ?!
                LOG.debug("Discovered keystone versions: %s" % versions)
                raise exceptions.RallyException("Failed to discover keystone "
                                                "auth urls.")

        else:
            if self.credential.auth_url.rstrip("/").endswith("v2.0"):
                uri = self.credential.auth_url
                uri_v3 = uri.replace("/v2.0", "/v3")
                target_version = 2
            else:
                uri_v3 = self.credential.auth_url
                uri = uri_v3.replace("/v3", "/v2.0")
                target_version = 3

        self.conf.set(section_name, "auth_version", "v%s" % target_version)
        self.conf.set(section_name, "uri", uri)
        self.conf.set(section_name, "uri_v3", uri_v3)
github openstack / rally-openstack / rally_openstack / services / storage / cinder_common.py View on Github external
def delete_encryption_type(self, volume_type):
        """Delete the encryption type information for the specified volume type.

        :param volume_type: the volume type whose encryption type information
                            must be deleted
        """
        aname = "cinder_v%s.delete_encryption_type" % self.version
        with atomic.ActionTimer(self, aname):
            resp = self._get_client().volume_encryption_types.delete(
                volume_type)
            if (resp[0].status_code != 202):
                raise exceptions.RallyException(
                    "EncryptionType Deletion Failed")
github openstack / rally / rally / common / validation.py View on Github external
def wrapper(plugin):
        if issubclass(plugin, RequiredPlatformValidator):
            raise exceptions.RallyException(
                "Cannot add a validator to RequiredPlatformValidator")
        elif issubclass(plugin, Validator) and name != "required_platform":
            raise exceptions.RallyException(
                "Only RequiredPlatformValidator can be added "
                "to other validators as a validator")

        plugin._meta_setdefault("validators", [])
        plugin._meta_get("validators").append((name, (), kwargs,))
        return plugin
github openstack / rally / rally / plugins / common / exporters / elastic / client.py View on Github external
# it is an error. let's try to find the reason
        reason = None
        try:
            data = resp.json()
        except ValueError:
            # it is ok
            pass
        else:
            if "error" in data:
                if isinstance(data["error"], dict):
                    reason = data["error"].get("reason", "")
                else:
                    reason = data["error"]
        reason = reason or resp.text or "n/a"
        action = action or "connect to"
        raise exceptions.RallyException(
            "[HTTP %s] Failed to %s ElasticSearch cluster: %s" %
            (resp.status_code, action, reason))
github openstack / rally / rally / plugins / openstack / wrappers / network.py View on Github external
This is process and thread safe, because `cidr_incr' points to
    value stored directly in RAM. This guarantees that CIDRs will be
    serial and unique even under hard multiprocessing/threading load.

    :param start_cidr: start CIDR str
    :returns: next available CIDR str
    """
    if netaddr.IPNetwork(start_cidr).version == 4:
        cidr = str(netaddr.IPNetwork(start_cidr).next(next(cidr_incr)))
    else:
        cidr = str(netaddr.IPNetwork(start_cidr).next(next(ipv6_cidr_incr)))
    LOG.debug("CIDR generated: %s" % cidr)
    return cidr


class NetworkWrapperException(exceptions.RallyException):
    error_code = 217
    msg_fmt = "%(message)s"


@six.add_metaclass(abc.ABCMeta)
class NetworkWrapper(object):
    """Base class for network service implementations.

    We actually have two network services implementations, with different API:
    NovaNetwork and Neutron. The idea is (at least to try) to use unified
    service, which hides most differences and routines behind the scenes.
    This allows to significantly re-use and simplify code.
    """
    START_CIDR = "10.2.0.0/24"
    START_IPV6_CIDR = "dead:beaf::/64"
    SERVICE_IMPL = None