Merge "Implement max_avg_duration criteria"

This commit is contained in:
Jenkins 2014-10-15 15:10:44 +00:00 committed by Gerrit Code Review
commit 7e990476b2
2 changed files with 34 additions and 0 deletions

View File

@ -24,6 +24,7 @@ import abc
import jsonschema
import six
from rally.benchmark.processing import utils as putils
from rally.openstack.common.gettextutils import _
from rally import utils
@ -116,3 +117,19 @@ class IterationTime(SLA):
msg = (_("Maximum seconds per iteration %ss, found with %ss") %
(criterion_value, duration))
return SLAResult(success, msg)
class MaxAverageDuration(SLA):
"""Maximum average duration for one iteration in seconds."""
OPTION_NAME = "max_avg_duration"
CONFIG_SCHEMA = {"type": "number", "minimum": 0.0,
"exclusiveMinimum": True}
@staticmethod
def check(criterion_value, result):
durations = [r["duration"] for r in result if not r.get("error")]
avg = putils.mean(durations)
success = avg < criterion_value
msg = (_("Maximum average duration per iteration %ss, found with %ss")
% (criterion_value, avg))
return SLAResult(success, msg)

View File

@ -90,3 +90,20 @@ class IterationTimeTestCase(test.TestCase):
]
self.assertTrue(base.IterationTime.check(42, result).success)
self.assertFalse(base.IterationTime.check(3.62, result).success)
class MaxAverageDurationTestCase(test.TestCase):
def test_config_schema(self):
properties = {
"max_avg_duration": 0
}
self.assertRaises(jsonschema.ValidationError,
base.MaxAverageDuration.validate, properties)
def test_check(self):
result = [
{"duration": 3.14},
{"duration": 6.28},
]
self.assertTrue(base.MaxAverageDuration.check(42, result).success)
self.assertFalse(base.MaxAverageDuration.check(3.62, result).success)