Remove redunant BenchmarkEngine.bind() method

At some point of Rally this method was important but at this moment
it is something strange that should be just removed and simplified

Change-Id: I13896329c7a1cf687e307a32fcb0b8a943f9d80d
This commit is contained in:
Boris Pavlovic 2014-11-25 05:24:37 +04:00
parent 152890afbf
commit 34fd003f8e
4 changed files with 54 additions and 92 deletions

View File

@ -74,29 +74,42 @@ CONFIG_SCHEMA = {
class BenchmarkEngine(object): class BenchmarkEngine(object):
"""The Benchmark engine class is used to execute benchmark scenarios. """The Benchmark engine class is used to execute benchmark scenarios.
An instance of class is initialized by the Orchestrator with the benchmarks An instance of this class is initialized by the API with the benchmarks
configuration and then is used to execute all specified scenarios. configuration and then is used to validate and execute all specified
in config benchmarks.
.. note:: .. note::
Typical usage: Typical usage:
... ...
benchmark_engine = BenchmarkEngine(config, task) admin = .... # contains dict representations of objects.Endpoint
# Deploying the cloud... # with OpenStack admin credentials
# admin - is an objects.Endpoint that actually presents admin user
# users - is a list of objects.Endpoint that actually presents list users = .... # contains a list of dicts of representations of
of users. # objects.Endpoint with OpenStack users credentials.
with benchmark_engine.bind(admin=admin, users=users):
benchmark_engine.run() engine = BenchmarkEngine(config, task, admin=admin, users=users)
engine.validate() # to test config
engine.run() # to run config
""" """
def __init__(self, config, task): def __init__(self, config, task, admin=None, users=None):
"""BenchmarkEngine constructor. """BenchmarkEngine constructor.
:param config: The configuration with specified benchmark scenarios :param config: The configuration with specified benchmark scenarios
:param task: The current task which is being performed :param task: The current task which is being performed
:param admin: Dict with admin credentials
:param users: List of dicts with user credentials
""" """
self.config = config self.config = config
self.task = task self.task = task
self.admin = admin and endpoint.Endpoint(**admin) or None
self.users = map(lambda u: endpoint.Endpoint(**u), users or [])
@rutils.log_task_wrapper(LOG.info, _("Task validation check cloud."))
def _check_cloud(self):
clients = osclients.Clients(self.admin)
clients.verified_keystone()
@rutils.log_task_wrapper(LOG.info, @rutils.log_task_wrapper(LOG.info,
_("Task validation of scenarios names.")) _("Task validation of scenarios names."))
@ -141,15 +154,14 @@ class BenchmarkEngine(object):
@rutils.log_task_wrapper(LOG.info, _("Task validation of semantic.")) @rutils.log_task_wrapper(LOG.info, _("Task validation of semantic."))
def _validate_config_semantic(self, config): def _validate_config_semantic(self, config):
self._check_cloud()
# NOTE(boris-42): In future we will have more complex context, because # NOTE(boris-42): In future we will have more complex context, because
# we will have pre-created users mode as well. # we will have pre-created users mode as well.
context = { context = {"task": self.task, "admin": {"endpoint": self.admin}}
"task": self.task,
"admin": {"endpoint": self.admin_endpoint}
}
with users_ctx.UserGenerator(context) as ctx: with users_ctx.UserGenerator(context) as ctx:
ctx.setup() ctx.setup()
admin = osclients.Clients(self.admin_endpoint) admin = osclients.Clients(self.admin)
user = osclients.Clients(context["users"][0]["endpoint"]) user = osclients.Clients(context["users"][0]["endpoint"])
for name, values in config.iteritems(): for name, values in config.iteritems():
@ -214,7 +226,11 @@ class BenchmarkEngine(object):
consumer.start() consumer.start()
context_obj = self._prepare_context(kw.get("context", {}), context_obj = self._prepare_context(kw.get("context", {}),
name, self.admin_endpoint) name, self.admin)
# NOTE(boris-42): reset duration, in case of failures during
# context creation
self.duration = 0
try: try:
with base_ctx.ContextManager(context_obj): with base_ctx.ContextManager(context_obj):
self.duration = runner.run(name, context_obj, self.duration = runner.run(name, context_obj,
@ -224,22 +240,6 @@ class BenchmarkEngine(object):
consumer.join() consumer.join()
self.task.update_status(consts.TaskStatus.FINISHED) self.task.update_status(consts.TaskStatus.FINISHED)
@rutils.log_task_wrapper(LOG.info, _("Check cloud."))
def bind(self, admin=None, users=None):
"""Bind benchmark engine to OpenStack cloud.
This method will set self.admin_endpoint with passed values,
as well it will check that admin user is actually admin.
:param admin: admin credentials
:param users: List of users credentials
:returns: self
"""
self.admin_endpoint = endpoint.Endpoint(**admin)
clients = osclients.Clients(self.admin_endpoint)
clients.verified_keystone()
return self
def consume_results(self, key, task, result_queue, is_done): def consume_results(self, key, task, result_queue, is_done):
"""Consume scenario runner results from queue and send them to db. """Consume scenario runner results from queue and send them to db.

View File

@ -71,12 +71,12 @@ def destroy_deploy(deployment):
deployment = objects.Deployment.get(deployment) deployment = objects.Deployment.get(deployment)
deployer = deploy.EngineFactory.get_engine(deployment['config']['type'], deployer = deploy.EngineFactory.get_engine(deployment['config']['type'],
deployment) deployment)
tempest.Tempest(deployment['uuid']).uninstall()
with deployer: with deployer:
deployer.make_cleanup() deployer.make_cleanup()
deployment.delete() deployment.delete()
tempest.Tempest(deployment['uuid']).uninstall()
def recreate_deploy(deployment): def recreate_deploy(deployment):
"""Performs a clean up and then start to deploy. """Performs a clean up and then start to deploy.
@ -114,9 +114,8 @@ def task_validate(deployment, config):
""" """
deployment = objects.Deployment.get(deployment) deployment = objects.Deployment.get(deployment)
task = objects.Task(deployment_uuid=deployment['uuid']) task = objects.Task(deployment_uuid=deployment['uuid'])
benchmark_engine = engine.BenchmarkEngine(config, task) benchmark_engine = engine.BenchmarkEngine(
benchmark_engine.bind(admin=deployment["admin"], config, task, admin=deployment["admin"], users=deployment["users"])
users=deployment["users"])
benchmark_engine.validate() benchmark_engine.validate()
@ -133,12 +132,10 @@ def start_task(deployment, config, task=None):
task = task or objects.Task(deployment_uuid=deployment['uuid']) task = task or objects.Task(deployment_uuid=deployment['uuid'])
LOG.info("Benchmark Task %s on Deployment %s" % (task['uuid'], LOG.info("Benchmark Task %s on Deployment %s" % (task['uuid'],
deployment['uuid'])) deployment['uuid']))
benchmark_engine = engine.BenchmarkEngine(config, task) benchmark_engine = engine.BenchmarkEngine(
admin = deployment["admin"] config, task, admin=deployment["admin"], users=deployment["users"])
users = deployment["users"]
try: try:
benchmark_engine.bind(admin=admin, users=users)
benchmark_engine.validate() benchmark_engine.validate()
benchmark_engine.run() benchmark_engine.run()
except exceptions.InvalidTaskException: except exceptions.InvalidTaskException:

View File

@ -206,7 +206,7 @@ class BenchmarkEngineTestCase(test.TestCase):
fake_task = mock.MagicMock() fake_task = mock.MagicMock()
eng = engine.BenchmarkEngine(config, fake_task) eng = engine.BenchmarkEngine(config, fake_task)
eng.admin_endpoint = "admin" eng.admin = "admin"
eng._validate_config_semantic(config) eng._validate_config_semantic(config)
@ -229,10 +229,7 @@ class BenchmarkEngineTestCase(test.TestCase):
@mock.patch("rally.benchmark.engine.base_ctx.ContextManager.setup") @mock.patch("rally.benchmark.engine.base_ctx.ContextManager.setup")
@mock.patch("rally.benchmark.engine.base_scenario.Scenario") @mock.patch("rally.benchmark.engine.base_scenario.Scenario")
@mock.patch("rally.benchmark.engine.base_runner.ScenarioRunner") @mock.patch("rally.benchmark.engine.base_runner.ScenarioRunner")
@mock.patch("rally.benchmark.engine.osclients") def test_run__update_status(self, mock_runner, mock_scenario,
@mock.patch("rally.benchmark.engine.endpoint.Endpoint")
def test_run__update_status(self, mock_endpoint, mock_osclients,
mock_runner, mock_scenario,
mock_setup, mock_cleanup, mock_consume): mock_setup, mock_cleanup, mock_consume):
task = mock.MagicMock() task = mock.MagicMock()
eng = engine.BenchmarkEngine([], task) eng = engine.BenchmarkEngine([], task)
@ -247,17 +244,14 @@ class BenchmarkEngineTestCase(test.TestCase):
@mock.patch("rally.benchmark.engine.base_runner.ScenarioRunner") @mock.patch("rally.benchmark.engine.base_runner.ScenarioRunner")
@mock.patch("rally.benchmark.engine.base_ctx.ContextManager.cleanup") @mock.patch("rally.benchmark.engine.base_ctx.ContextManager.cleanup")
@mock.patch("rally.benchmark.engine.base_ctx.ContextManager.setup") @mock.patch("rally.benchmark.engine.base_ctx.ContextManager.setup")
@mock.patch("rally.benchmark.engine.osclients") def test_run__config_has_args(self, mock_setup, mock_cleanup,
@mock.patch("rally.benchmark.engine.endpoint.Endpoint")
def test_run__config_has_args(self, mock_endpoint, mock_osclients,
mock_setup, mock_cleanup,
mock_runner, mock_scenario, mock_consume): mock_runner, mock_scenario, mock_consume):
config = { config = {
"a.benchmark": [{"args": {"a": "a", "b": 1}}], "a.benchmark": [{"args": {"a": "a", "b": 1}}],
"b.benchmark": [{"args": {"a": 1}}] "b.benchmark": [{"args": {"a": 1}}]
} }
task = mock.MagicMock() task = mock.MagicMock()
eng = engine.BenchmarkEngine(config, task).bind({}) eng = engine.BenchmarkEngine(config, task)
eng.run() eng.run()
@mock.patch("rally.benchmark.engine.BenchmarkEngine.consume_results") @mock.patch("rally.benchmark.engine.BenchmarkEngine.consume_results")
@ -265,17 +259,14 @@ class BenchmarkEngineTestCase(test.TestCase):
@mock.patch("rally.benchmark.engine.base_runner.ScenarioRunner") @mock.patch("rally.benchmark.engine.base_runner.ScenarioRunner")
@mock.patch("rally.benchmark.engine.base_ctx.ContextManager.cleanup") @mock.patch("rally.benchmark.engine.base_ctx.ContextManager.cleanup")
@mock.patch("rally.benchmark.engine.base_ctx.ContextManager.setup") @mock.patch("rally.benchmark.engine.base_ctx.ContextManager.setup")
@mock.patch("rally.benchmark.engine.osclients") def test_run__config_has_runner(self, mock_setup, mock_cleanup,
@mock.patch("rally.benchmark.engine.endpoint.Endpoint")
def test_run__config_has_runner(self, mock_endpoint, mock_osclients,
mock_setup, mock_cleanup,
mock_runner, mock_scenario, mock_consume): mock_runner, mock_scenario, mock_consume):
config = { config = {
"a.benchmark": [{"runner": {"type": "a", "b": 1}}], "a.benchmark": [{"runner": {"type": "a", "b": 1}}],
"b.benchmark": [{"runner": {"a": 1}}] "b.benchmark": [{"runner": {"a": 1}}]
} }
task = mock.MagicMock() task = mock.MagicMock()
eng = engine.BenchmarkEngine(config, task).bind({}) eng = engine.BenchmarkEngine(config, task)
eng.run() eng.run()
@mock.patch("rally.benchmark.engine.BenchmarkEngine.consume_results") @mock.patch("rally.benchmark.engine.BenchmarkEngine.consume_results")
@ -283,42 +274,16 @@ class BenchmarkEngineTestCase(test.TestCase):
@mock.patch("rally.benchmark.engine.base_runner.ScenarioRunner") @mock.patch("rally.benchmark.engine.base_runner.ScenarioRunner")
@mock.patch("rally.benchmark.engine.base_ctx.ContextManager.cleanup") @mock.patch("rally.benchmark.engine.base_ctx.ContextManager.cleanup")
@mock.patch("rally.benchmark.engine.base_ctx.ContextManager.setup") @mock.patch("rally.benchmark.engine.base_ctx.ContextManager.setup")
@mock.patch("rally.benchmark.engine.osclients") def test_run__config_has_context(self, mock_ctx_setup, mock_ctx_cleanup,
@mock.patch("rally.benchmark.engine.endpoint.Endpoint")
def test_run__config_has_context(self, mock_endpoint, mock_osclients,
mock_ctx_setup, mock_ctx_cleanup,
mock_runner, mock_scenario, mock_consume): mock_runner, mock_scenario, mock_consume):
config = { config = {
"a.benchmark": [{"context": {"context_a": {"a": 1}}}], "a.benchmark": [{"context": {"context_a": {"a": 1}}}],
"b.benchmark": [{"context": {"context_b": {"b": 2}}}] "b.benchmark": [{"context": {"context_b": {"b": 2}}}]
} }
task = mock.MagicMock() task = mock.MagicMock()
eng = engine.BenchmarkEngine(config, task).bind({}) eng = engine.BenchmarkEngine(config, task)
eng.run() eng.run()
@mock.patch("rally.benchmark.engine.osclients")
@mock.patch("rally.benchmark.engine.endpoint.Endpoint")
def test_bind(self, mock_endpoint, mock_osclients):
mock_endpoint.return_value = mock.MagicMock()
benchmark_engine = engine.BenchmarkEngine(mock.MagicMock(),
mock.MagicMock())
admin = {
"auth_url": "http://valid.com",
"username": "user",
"password": "pwd",
"tenant_name": "tenant"
}
binded_benchmark_engine = benchmark_engine.bind(admin)
self.assertEqual(mock_endpoint.return_value,
benchmark_engine.admin_endpoint)
self.assertEqual(benchmark_engine, binded_benchmark_engine)
expected_calls = [
mock.call.Clients(mock_endpoint.return_value),
mock.call.Clients().verified_keystone()
]
mock_osclients.assert_has_calls(expected_calls)
@mock.patch("rally.benchmark.engine.base_scenario.Scenario.meta") @mock.patch("rally.benchmark.engine.base_scenario.Scenario.meta")
def test__prepare_context(self, mock_meta): def test__prepare_context(self, mock_meta):
default_context = {"a": 1, "b": 2} default_context = {"a": 1, "b": 2}

View File

@ -76,13 +76,13 @@ class APITestCase(test.TestCase):
users=[])) users=[]))
@mock.patch("rally.orchestrator.api.engine.BenchmarkEngine") @mock.patch("rally.orchestrator.api.engine.BenchmarkEngine")
def test_task_validate(self, mock_engine, mock_deployment_get, mock_task): def test_task_validate(self, mock_engine, mock_deployment_get, mock_task):
api.task_validate(mock_deployment_get.return_value['uuid'], "config") api.task_validate(mock_deployment_get.return_value["uuid"], "config")
mock_engine.assert_has_calls([ mock_engine.assert_has_calls([
mock.call("config", mock_task.return_value), mock.call("config", mock_task.return_value,
mock.call().bind(admin=mock_deployment_get.return_value["admin"], admin=mock_deployment_get.return_value["admin"],
users=[]), users=[]),
mock.call().validate(), mock.call().validate()
]) ])
mock_task.assert_called_once_with( mock_task.assert_called_once_with(
@ -110,9 +110,9 @@ class APITestCase(test.TestCase):
api.start_task(mock_deployment_get.return_value["uuid"], "config") api.start_task(mock_deployment_get.return_value["uuid"], "config")
mock_engine.assert_has_calls([ mock_engine.assert_has_calls([
mock.call("config", mock_task.return_value), mock.call("config", mock_task.return_value,
mock.call().bind(admin=mock_deployment_get.return_value["admin"], admin=mock_deployment_get.return_value["admin"],
users=[]), users=[]),
mock.call().validate(), mock.call().validate(),
mock.call().run(), mock.call().run(),
]) ])