Merge "[Core] Make task engine more abstract"

This commit is contained in:
Jenkins 2017-03-06 20:27:34 +00:00 committed by Gerrit Code Review
commit 8bc5af01ba
5 changed files with 43 additions and 6 deletions

View File

@ -55,7 +55,7 @@ CONF.register_opts(USER_CONTEXT_OPTS,
title="benchmark context options"))
@context.configure(name="users", order=100)
@context.configure(name="users", namespace="openstack", order=100)
class UserGenerator(context.Context):
"""Context class for generating temporary users/tenants for benchmarks."""

View File

@ -13,14 +13,13 @@
# License for the specific language governing permissions and limitations
# under the License.
import functools
import random
from rally import osclients
from rally.task import scenario
# NOTE(boris-42): Shortcut to remove import of both rally.task.scenario and
# rally.plugins.openstack.scenario
configure = scenario.configure
configure = functools.partial(scenario.configure, namespace="openstack")
class OpenStackScenario(scenario.Scenario):
@ -105,3 +104,13 @@ class OpenStackScenario(scenario.Scenario):
client = getattr(self._admin_clients, client_type)
return client(version) if version is not None else client()
@classmethod
def validate(cls, name, config, admin=None, users=None, deployment=None):
if admin:
admin = osclients.Clients(admin)
if users:
users = [osclients.Clients(user["credential"]) for user in users]
super(OpenStackScenario, cls).validate(
name=name, config=config, admin=admin, users=users,
deployment=deployment)

View File

@ -58,7 +58,7 @@ class TaskSampleTestCase(test.TestCase):
task_config = yaml.safe_load(api._Task.render_template
(task_file.read()))
eng = engine.TaskEngine(task_config,
mock.MagicMock())
mock.MagicMock(), mock.Mock())
eng.validate()
except Exception:
print(traceback.format_exc())

View File

@ -127,3 +127,30 @@ class OpenStackScenarioTestCase(test.TestCase):
self.assertEqual(self.context["tenants"][tenant_id],
self.context["tenant"])
self.assertEqual(expected_tenant_id, tenant_id)
@mock.patch("rally.task.scenario.Scenario.validate")
def test_validate(self, mock_scenario_validate):
cred1 = mock.Mock()
cred2 = mock.Mock()
cred3 = mock.Mock()
self.osclients.mock.side_effect = [cred1, cred2, cred3]
base_scenario.OpenStackScenario.validate(
name="foo_name",
config="foo_config",
admin="foo_admin",
users=[{"credential": "foo_user1"},
{"credential": "foo_user2"}],
deployment=None)
mock_scenario_validate.assert_called_once_with(
name="foo_name",
config="foo_config",
admin=cred1,
users=[cred2, cred3],
deployment=None)
self.osclients.mock.assert_has_calls([
mock.call("foo_admin"),
mock.call("foo_user1"),
mock.call("foo_user2"),
])

View File

@ -62,7 +62,8 @@ class RallyJobsTestCase(test.TestCase):
task = api._Task.render_template(task_file.read(), **args)
task = yaml.safe_load(task)
eng = engine.TaskEngine(task, mock.MagicMock())
eng = engine.TaskEngine(task, mock.MagicMock(),
mock.Mock())
eng.validate()
except Exception:
print(traceback.format_exc())