Runner Type as consts

This patch adds new consts class for runner type and also fixs some
missing place of old runner type

Change-Id: I3dc75b31bae1a053ed705049c4c40d98c5e79679
This commit is contained in:
Kun Huang 2014-04-22 11:02:41 +08:00
parent 7e771f1e6f
commit ee2618db99
9 changed files with 32 additions and 15 deletions

View File

@ -155,7 +155,7 @@ class BenchmarkEngine(object):
def _get_runner(self, config):
runner = config.get("runner", {})
runner.setdefault("type", "continuous")
runner.setdefault("type", consts.RunnerType.SERIAL)
return base_runner.ScenarioRunner.get_runner(self.task, self.endpoints,
runner)

View File

@ -23,6 +23,7 @@ from oslo.config import cfg
from rally.benchmark.context import base as base_ctx
from rally.benchmark.scenarios import base
from rally.benchmark import utils
from rally import consts
from rally import exceptions
from rally.openstack.common import log as logging
from rally import osclients
@ -169,7 +170,8 @@ class ScenarioRunner(object):
@staticmethod
def validate(config):
"""Validates runner's part of task config."""
runner = ScenarioRunner._get_cls(config.get("type", "constant"))
runner = ScenarioRunner._get_cls(config.get("type",
consts.RunnerType.SERIAL))
jsonschema.validate(config, runner.CONFIG_SCHEMA)
@abc.abstractmethod

View File

@ -20,9 +20,10 @@ import time
from rally.benchmark.runners import base
from rally.benchmark import utils
from rally import consts
from rally.openstack.common import log as logging
from rally import utils as rutils
from rally.openstack.common import log as logging
LOG = logging.getLogger(__name__)
@ -40,7 +41,7 @@ class ConstantScenarioRunner(base.ScenarioRunner):
placing load on the cloud under test.
"""
__execution_type__ = "constant"
__execution_type__ = consts.RunnerType.CONSTANT
CONFIG_SCHEMA = {
"type": "object",
@ -112,7 +113,7 @@ class ConstantForDurationScenarioRunner(base.ScenarioRunner):
placing load on the cloud under test.
"""
__execution_type__ = "constant_for_duration"
__execution_type__ = consts.RunnerType.CONSTANT_FOR_DURATION
CONFIG_SCHEMA = {
"type": "object",

View File

@ -19,6 +19,7 @@ import time
from rally.benchmark.runners import base
from rally.benchmark import utils
from rally import consts
from rally import utils as rutils
@ -37,7 +38,7 @@ class PeriodicScenarioRunner(base.ScenarioRunner):
a certain cloud can handle.
"""
__execution_type__ = "periodic"
__execution_type__ = consts.RunnerType.PERIODIC
CONFIG_SCHEMA = {
"type": "object",

View File

@ -14,6 +14,7 @@
# under the License.
from rally.benchmark.runners import base
from rally import consts
from rally import utils
@ -27,7 +28,7 @@ class SerialScenarioRunner(base.ScenarioRunner):
from the same command that you use to start Rally.
"""
__execution_type__ = "serial"
__execution_type__ = consts.RunnerType.SERIAL
# NOTE(mmorais): additionalProperties is set True to allow switching
# between parallel and serial runners by modifying only *type* property

View File

@ -53,6 +53,14 @@ class _EndpointPermission(utils.ImmutableMixin, utils.EnumMixin):
USER = "user"
class _RunnerType(utils.ImmutableMixin, utils.EnumMixin):
SERIAL = "serial"
CONSTANT = "constant"
CONSTANT_FOR_DURATION = "constant_for_duration"
PERIODIC = "periodic"
TaskStatus = _TaskStatus()
DeployStatus = _DeployStatus()
EndpointPermission = _EndpointPermission()
RunnerType = _RunnerType()

View File

@ -18,6 +18,7 @@ import mock
from rally.benchmark.runners import base
from rally.benchmark.runners import constant
from rally.benchmark.runners import serial
from rally.benchmark.scenarios import base as base_scenario
from rally import consts
from rally import exceptions
@ -201,7 +202,7 @@ class ScenarioRunnerTestCase(test.TestCase):
base.ScenarioRunner.validate(config)
mock_validate.assert_called_once_with(
config,
constant.ConstantScenarioRunner.CONFIG_SCHEMA)
serial.SerialScenarioRunner.CONFIG_SCHEMA)
@mock.patch("rally.benchmark.runners.base.base_ctx.ContextManager")
def test_run(self, mock_ctx_manager):

View File

@ -17,6 +17,7 @@ import jsonschema
from rally.benchmark.runners import base
from rally.benchmark.runners import constant
from rally import consts
from tests import fakes
from tests import test
@ -28,7 +29,7 @@ class ConstantScenarioRunnerTestCase(test.TestCase):
times = 4
concurrency = 2
timeout = 2
type = "constant"
type = consts.RunnerType.CONSTANT
self.config = {"times": times, "concurrency": concurrency,
"timeout": timeout, "type": type}
self.context = fakes.FakeUserContext({"task":
@ -39,7 +40,7 @@ class ConstantScenarioRunnerTestCase(test.TestCase):
constant.ConstantScenarioRunner.validate(self.config)
def test_validate_failed(self):
self.config["type"] = "constant_for_duration"
self.config["type"] = consts.RunnerType.CONSTANT_FOR_DURATION
self.assertRaises(jsonschema.ValidationError,
constant.ConstantScenarioRunner.validate,
self.config)
@ -82,7 +83,7 @@ class ConstantForDurationScenarioRunnerTeestCase(test.TestCase):
duration = 0
concurrency = 2
timeout = 2
type = "constant_for_duration"
type = consts.RunnerType.CONSTANT_FOR_DURATION
self.config = {"duration": duration, "concurrency": concurrency,
"timeout": timeout, "type": type}
self.context = fakes.FakeUserContext({"task":
@ -93,7 +94,7 @@ class ConstantForDurationScenarioRunnerTeestCase(test.TestCase):
constant.ConstantForDurationScenarioRunner.validate(self.config)
def test_validate_failed(self):
self.config["type"] = "constant"
self.config["type"] = consts.RunnerType.CONSTANT
self.assertRaises(jsonschema.ValidationError, constant.
ConstantForDurationScenarioRunner.validate,
self.config)

View File

@ -34,7 +34,7 @@ class PeriodicScenarioRunnerTestCase(test.TestCase):
def test_validate(self):
config = {
"type": "periodic",
"type": consts.RunnerType.PERIODIC,
"times": 1,
"period": 0.000001,
"timeout": 1
@ -42,7 +42,8 @@ class PeriodicScenarioRunnerTestCase(test.TestCase):
periodic.PeriodicScenarioRunner.validate(config)
def test_validate_failed(self):
config = {"type": "periodic", "a": 10}
config = {"type": consts.RunnerType.PERIODIC,
"a": 10}
self.assertRaises(jsonschema.ValidationError,
periodic.PeriodicScenarioRunner.validate, config)
@ -110,5 +111,6 @@ class PeriodicScenarioRunnerTestCase(test.TestCase):
runner = base.ScenarioRunner.get_runner(mock.MagicMock(),
self.fake_endpoints,
{"type": "periodic"})
{"type":
consts.RunnerType.PERIODIC})
self.assertTrue(runner is not None)