From ee2618db99f31e55e8cf7755c6adbb51a5564692 Mon Sep 17 00:00:00 2001 From: Kun Huang Date: Tue, 22 Apr 2014 11:02:41 +0800 Subject: [PATCH] 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 --- rally/benchmark/engine.py | 2 +- rally/benchmark/runners/base.py | 4 +++- rally/benchmark/runners/constant.py | 7 ++++--- rally/benchmark/runners/periodic.py | 3 ++- rally/benchmark/runners/serial.py | 3 ++- rally/consts.py | 8 ++++++++ tests/benchmark/runners/test_base.py | 3 ++- tests/benchmark/runners/test_constant.py | 9 +++++---- tests/benchmark/runners/test_periodic.py | 8 +++++--- 9 files changed, 32 insertions(+), 15 deletions(-) diff --git a/rally/benchmark/engine.py b/rally/benchmark/engine.py index e3b2e18897..51832bc787 100644 --- a/rally/benchmark/engine.py +++ b/rally/benchmark/engine.py @@ -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) diff --git a/rally/benchmark/runners/base.py b/rally/benchmark/runners/base.py index 37542444d7..fba52bcdf9 100644 --- a/rally/benchmark/runners/base.py +++ b/rally/benchmark/runners/base.py @@ -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 diff --git a/rally/benchmark/runners/constant.py b/rally/benchmark/runners/constant.py index 2a82185208..56dff5154b 100644 --- a/rally/benchmark/runners/constant.py +++ b/rally/benchmark/runners/constant.py @@ -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", diff --git a/rally/benchmark/runners/periodic.py b/rally/benchmark/runners/periodic.py index a502e04747..c5929fa98a 100644 --- a/rally/benchmark/runners/periodic.py +++ b/rally/benchmark/runners/periodic.py @@ -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", diff --git a/rally/benchmark/runners/serial.py b/rally/benchmark/runners/serial.py index caefb47a8c..c425123d97 100644 --- a/rally/benchmark/runners/serial.py +++ b/rally/benchmark/runners/serial.py @@ -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 diff --git a/rally/consts.py b/rally/consts.py index 50c6635772..9d6bdf7571 100644 --- a/rally/consts.py +++ b/rally/consts.py @@ -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() diff --git a/tests/benchmark/runners/test_base.py b/tests/benchmark/runners/test_base.py index 4a95cb005c..552d60f836 100644 --- a/tests/benchmark/runners/test_base.py +++ b/tests/benchmark/runners/test_base.py @@ -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): diff --git a/tests/benchmark/runners/test_constant.py b/tests/benchmark/runners/test_constant.py index 65e6bb5a4c..ec394a538f 100644 --- a/tests/benchmark/runners/test_constant.py +++ b/tests/benchmark/runners/test_constant.py @@ -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) diff --git a/tests/benchmark/runners/test_periodic.py b/tests/benchmark/runners/test_periodic.py index 0ceb42d337..519f172645 100644 --- a/tests/benchmark/runners/test_periodic.py +++ b/tests/benchmark/runners/test_periodic.py @@ -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)