[Bug-Fix]: Remove ability to put incorrect kwargs for an exception

Also, this patch simplify `format_message` method of base
Rally exception class

Change-Id: Ia6ccd68bb7740ea43402e633017684d4df8c07fe
Closes-Bug: #1491388
This commit is contained in:
Andrey Kurilin 2015-09-02 16:02:32 +03:00
parent 7041971c41
commit aa191d6b66
10 changed files with 18 additions and 55 deletions

View File

@ -47,8 +47,9 @@
# (Optional) Enables or disables syslog rfc5424 format for logging. If
# enabled, prefixes the MSG part of the syslog message with APP-NAME
# (RFC5424). The format without the APP-NAME is deprecated in K, and
# will be removed in M, along with this option. (boolean value)
# (RFC5424). The format without the APP-NAME is deprecated in Kilo,
# and will be removed in Mitaka, along with this option. (boolean
# value)
# This option is deprecated for removal.
# Its value may be silently ignored in the future.
#use_syslog_rfc_format = true
@ -98,9 +99,6 @@
# quiet. (boolean value)
#rally_debug = false
# make exception message format errors fatal (boolean value)
#fatal_exception_format_errors = false
# HTTP timeout for any of OpenStack service in seconds (floating point
# value)
#openstack_client_http_timeout = 180.0

View File

@ -205,7 +205,7 @@ class Connection(object):
count = (self.model_query(models.Deployment, session=session).
filter_by(uuid=uuid).delete(synchronize_session=False))
if not count:
raise exceptions.DeploymentNotFound(uuid=uuid)
raise exceptions.DeploymentNotFound(deployment=uuid)
def deployment_get(self, deployment):
return self._deployment_get(deployment)

View File

@ -15,7 +15,6 @@
import itertools
from rally.common import log
from rally import exceptions
from rally import osclients
from rally.plugins.openstack.context.cleanup import base as cleanup_base
from rally.plugins.openstack.context.keystone import users
@ -33,7 +32,6 @@ def list_opts():
return [
("DEFAULT",
itertools.chain(log.DEBUG_OPTS,
exceptions.EXC_LOG_OPTS,
osclients.OSCLIENTS_OPTS)),
("benchmark",
itertools.chain(cinder_utils.CINDER_BENCHMARK_OPTS,

View File

@ -96,12 +96,13 @@ class Engine(plugin.Plugin):
try:
engine_cls = Engine.get(name)
return engine_cls(deployment)
except exceptions.PluginNotFound:
except exceptions.PluginNotFound as e:
LOG.error(_("Deployment %(uuid)s: Deploy engine for %(name)s "
"does not exist.") %
{"uuid": deployment["uuid"], "name": name})
deployment.update_status(consts.DeployStatus.DEPLOY_FAILED)
raise exceptions.PluginNotFound(name=name)
raise exceptions.PluginNotFound(
namespace=e.kwargs.get("namespace"), name=name)
@abc.abstractmethod
def deploy(self):

View File

@ -13,10 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import sys
from oslo_config import cfg
import six
from rally.common.i18n import _
@ -24,15 +20,6 @@ from rally.common import log as logging
LOG = logging.getLogger(__name__)
EXC_LOG_OPTS = [
cfg.BoolOpt("fatal_exception_format_errors",
default=False,
help="make exception message format errors fatal"),
]
CONF = cfg.CONF
CONF.register_opts(EXC_LOG_OPTS)
class RallyException(Exception):
"""Base Rally Exception
@ -47,37 +34,13 @@ class RallyException(Exception):
def __init__(self, message=None, **kwargs):
self.kwargs = kwargs
if "code" not in self.kwargs:
try:
self.kwargs["code"] = self.code
except AttributeError:
pass
if "%(message)s" in self.msg_fmt:
kwargs.update({"message": message})
try:
message = self.msg_fmt % kwargs
except KeyError:
exc_info = sys.exc_info()
# kwargs doesn't match a variable in the message
# log the issue and the kwargs
msg = "kwargs don't match in string format operation: %s"
LOG.debug(msg % kwargs, exc_info=exc_info)
if CONF.fatal_exception_format_errors:
raise exc_info[0].with_traceback(exc_info[2])
else:
# at least get the core message out if something happened
message = message or self.msg_fmt
super(RallyException, self).__init__(message)
super(RallyException, self).__init__(self.msg_fmt % kwargs)
def format_message(self):
if self.__class__.__name__.endswith("_Remote"):
return self.args[0]
else:
return six.text_type(self)
return six.text_type(self)
class ImmutableException(RallyException):

View File

@ -319,7 +319,7 @@ class DeploymentCommandsTestCase(test.TestCase):
def test_deployment_not_found(self, mock_deployment_get):
deployment_id = "e87e4dca-b515-4477-888d-5f6103f13b42"
mock_deployment_get.side_effect = exceptions.DeploymentNotFound(
uuid=deployment_id)
deployment=deployment_id)
self.assertEqual(1, self.deployment.use(deployment_id))
@mock.patch("rally.osclients.Clients.verified_keystone")
@ -354,7 +354,8 @@ class DeploymentCommandsTestCase(test.TestCase):
def test_deployment_check_not_exist(self, mock_deployment_get,
mock_clients_verified_keystone):
deployment_id = "e87e4dca-b515-4477-888d-5f6103f13b42"
mock_deployment_get.side_effect = exceptions.DeploymentNotFound()
mock_deployment_get.side_effect = exceptions.DeploymentNotFound(
deployment=deployment_id)
mock_clients_verified_keystone.services.list.return_value = []
self.assertEqual(self.deployment.check(deployment_id), 1)

View File

@ -46,8 +46,10 @@ class InfoCommandsTestCase(test.TestCase):
mock_scenario_get.assert_called_once_with(query)
self.assertIsNone(status)
@mock.patch(SCENARIO + ".get", side_effect=exceptions.PluginNotFound)
@mock.patch(SCENARIO + ".get")
def test_find_failure_status(self, mock_scenario_get):
mock_scenario_get.side_effect = exceptions.PluginNotFound(
namespace="any", name="any")
query = "Dummy.non_existing"
status = self.info.find(query)
mock_scenario_get.assert_called_once_with(query)

View File

@ -201,7 +201,7 @@ class CliUtilsTestCase(test.TestCase):
self.assertEqual(ret, 1)
@mock.patch("rally.common.db.task_get",
side_effect=exceptions.TaskNotFound(FAKE_TASK_UUID))
side_effect=exceptions.TaskNotFound(uuid=FAKE_TASK_UUID))
def test_run_task_not_found(self, mock_task_get):
ret = cliutils.run(["rally", "task", "status", "%s" % FAKE_TASK_UUID],
self.categories)

View File

@ -141,7 +141,7 @@ class NovaNetworkWrapperTestCase(test.TestCase):
def get_fip(*args, **kwargs):
for i in fip_found:
return "fip_id"
raise exceptions.GetResourceNotFound
raise exceptions.GetResourceNotFound(resource="")
wrap._get_floating_ip = mock.Mock(side_effect=get_fip)
wrap.delete_floating_ip("fip_id")

View File

@ -28,7 +28,7 @@ class BenchmarkUtilsTestCase(test.TestCase):
def test_wait_for_delete(self):
def update_resource(self):
raise exceptions.GetResourceNotFound()
raise exceptions.GetResourceNotFound(resource=None)
resource = mock.MagicMock()
utils.wait_for_delete(resource, update_resource=update_resource)