[Core] Make task engine more abstract
This patch removes a lot of openstack staff from task engines and makes it more abstract. * Added proper validation of tasks that use both users and existing users. * Moved all openstack scenarios to openstack namespace. Change-Id: I1ee65f831c12d2e1168f3701680b6985e06c10c6
This commit is contained in:
parent
51e093f92b
commit
4cf64300b2
@ -55,7 +55,7 @@ CONF.register_opts(USER_CONTEXT_OPTS,
|
|||||||
title="benchmark context options"))
|
title="benchmark context options"))
|
||||||
|
|
||||||
|
|
||||||
@context.configure(name="users", order=100)
|
@context.configure(name="users", namespace="openstack", order=100)
|
||||||
class UserGenerator(context.Context):
|
class UserGenerator(context.Context):
|
||||||
"""Context class for generating temporary users/tenants for benchmarks."""
|
"""Context class for generating temporary users/tenants for benchmarks."""
|
||||||
|
|
||||||
|
@ -13,14 +13,13 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import functools
|
||||||
import random
|
import random
|
||||||
|
|
||||||
from rally import osclients
|
from rally import osclients
|
||||||
from rally.task import scenario
|
from rally.task import scenario
|
||||||
|
|
||||||
# NOTE(boris-42): Shortcut to remove import of both rally.task.scenario and
|
configure = functools.partial(scenario.configure, namespace="openstack")
|
||||||
# rally.plugins.openstack.scenario
|
|
||||||
configure = scenario.configure
|
|
||||||
|
|
||||||
|
|
||||||
class OpenStackScenario(scenario.Scenario):
|
class OpenStackScenario(scenario.Scenario):
|
||||||
@ -105,3 +104,13 @@ class OpenStackScenario(scenario.Scenario):
|
|||||||
client = getattr(self._admin_clients, client_type)
|
client = getattr(self._admin_clients, client_type)
|
||||||
|
|
||||||
return client(version) if version is not None else client()
|
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)
|
||||||
|
@ -58,7 +58,7 @@ class TaskSampleTestCase(test.TestCase):
|
|||||||
task_config = yaml.safe_load(api._Task.render_template
|
task_config = yaml.safe_load(api._Task.render_template
|
||||||
(task_file.read()))
|
(task_file.read()))
|
||||||
eng = engine.TaskEngine(task_config,
|
eng = engine.TaskEngine(task_config,
|
||||||
mock.MagicMock())
|
mock.MagicMock(), mock.Mock())
|
||||||
eng.validate()
|
eng.validate()
|
||||||
except Exception:
|
except Exception:
|
||||||
print(traceback.format_exc())
|
print(traceback.format_exc())
|
||||||
|
@ -127,3 +127,30 @@ class OpenStackScenarioTestCase(test.TestCase):
|
|||||||
self.assertEqual(self.context["tenants"][tenant_id],
|
self.assertEqual(self.context["tenants"][tenant_id],
|
||||||
self.context["tenant"])
|
self.context["tenant"])
|
||||||
self.assertEqual(expected_tenant_id, tenant_id)
|
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"),
|
||||||
|
])
|
||||||
|
@ -62,7 +62,8 @@ class RallyJobsTestCase(test.TestCase):
|
|||||||
task = api._Task.render_template(task_file.read(), **args)
|
task = api._Task.render_template(task_file.read(), **args)
|
||||||
task = yaml.safe_load(task)
|
task = yaml.safe_load(task)
|
||||||
|
|
||||||
eng = engine.TaskEngine(task, mock.MagicMock())
|
eng = engine.TaskEngine(task, mock.MagicMock(),
|
||||||
|
mock.Mock())
|
||||||
eng.validate()
|
eng.validate()
|
||||||
except Exception:
|
except Exception:
|
||||||
print(traceback.format_exc())
|
print(traceback.format_exc())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user