diff --git a/rally/benchmark/context/base.py b/rally/benchmark/context/base.py index 54520ddad0..8d4134cd5d 100644 --- a/rally/benchmark/context/base.py +++ b/rally/benchmark/context/base.py @@ -67,6 +67,9 @@ class Context(object): def __init__(self, context): self.config = context.get("config", {}).get(self.get_name(), {}) + if hasattr(self, "DEFAULT_CONFIG"): + for key, value in self.DEFAULT_CONFIG.items(): + self.config.setdefault(key, value) self.context = context self.task = context["task"] diff --git a/rally/benchmark/context/network.py b/rally/benchmark/context/network.py index b525389f6f..550ebef119 100644 --- a/rally/benchmark/context/network.py +++ b/rally/benchmark/context/network.py @@ -43,12 +43,14 @@ class Network(base.Context): }, "additionalProperties": False } - START_CIDR_DFLT = "10.2.0.0/24" + + DEFAULT_CONFIG = { + "start_cidr": "10.2.0.0/24", + "networks_per_tenant": 1 + } def __init__(self, context): super(Network, self).__init__(context) - self.config.setdefault("start_cidr", self.START_CIDR_DFLT) - self.config.setdefault("networks_per_tenant", 1) self.net_wrapper = network_wrapper.wrap( osclients.Clients(context["admin"]["endpoint"]), self.config) diff --git a/rally/benchmark/context/servers.py b/rally/benchmark/context/servers.py index af4dff9789..2471fafc0b 100755 --- a/rally/benchmark/context/servers.py +++ b/rally/benchmark/context/servers.py @@ -62,9 +62,9 @@ class ServerGenerator(base.Context): "additionalProperties": False } - def __init__(self, context): - super(ServerGenerator, self).__init__(context) - self.config.setdefault("servers_per_tenant", 5) + DEFAULT_CONFIG = { + "servers_per_tenant": 5 + } @rutils.log_task_wrapper(LOG.info, _("Enter context: `Servers`")) def setup(self): diff --git a/rally/benchmark/context/stacks.py b/rally/benchmark/context/stacks.py index 1342e4b961..25b9a1c3c7 100644 --- a/rally/benchmark/context/stacks.py +++ b/rally/benchmark/context/stacks.py @@ -54,10 +54,10 @@ class StackGenerator(base.Context): "additionalProperties": False } - def __init__(self, context): - super(StackGenerator, self).__init__(context) - self.config.setdefault("stacks_per_tenant", 2) - self.config.setdefault("resources_per_stack", 10) + DEFAULT_CONFIG = { + "stacks_per_tenant": 2, + "resources_per_stack": 10 + } @staticmethod def _prepare_stack_template(res_num): @@ -87,4 +87,4 @@ class StackGenerator(base.Context): @rutils.log_task_wrapper(LOG.info, _("Exit context: `Stacks`")) def cleanup(self): resource_manager.cleanup(names=["heat.stacks"], - users=self.context.get("users", [])) \ No newline at end of file + users=self.context.get("users", [])) diff --git a/rally/benchmark/context/users.py b/rally/benchmark/context/users.py index 166dc26bc1..a0823fba14 100644 --- a/rally/benchmark/context/users.py +++ b/rally/benchmark/context/users.py @@ -84,17 +84,17 @@ class UserGenerator(base.Context): PATTERN_TENANT = "ctx_rally_%(task_id)s_tenant_%(iter)i" PATTERN_USER = "ctx_rally_%(tenant_id)s_user_%(uid)d" + DEFAULT_CONFIG = { + "tenants": 1, + "users_per_tenant": 1, + "resource_management_workers": + cfg.CONF.users_context.resource_management_workers, + "project_domain": cfg.CONF.users_context.project_domain, + "user_domain": cfg.CONF.users_context.user_domain + } + def __init__(self, context): super(UserGenerator, self).__init__(context) - self.config.setdefault("tenants", 1) - self.config.setdefault("users_per_tenant", 1) - self.config.setdefault( - "resource_management_workers", - cfg.CONF.users_context.resource_management_workers) - self.config.setdefault("project_domain", - cfg.CONF.users_context.project_domain) - self.config.setdefault("user_domain", - cfg.CONF.users_context.user_domain) self.context["users"] = [] self.context["tenants"] = dict() self.endpoint = self.context["admin"]["endpoint"] diff --git a/rally/benchmark/context/volumes.py b/rally/benchmark/context/volumes.py index 67840e295c..14af7a16d3 100644 --- a/rally/benchmark/context/volumes.py +++ b/rally/benchmark/context/volumes.py @@ -47,9 +47,9 @@ class VolumeGenerator(base.Context): "additionalProperties": False } - def __init__(self, context): - super(VolumeGenerator, self).__init__(context) - self.config.setdefault("volumes_per_tenant", 1) + DEFAULT_CONFIG = { + "volumes_per_tenant": 1 + } @rutils.log_task_wrapper(LOG.info, _("Enter context: `Volumes`")) def setup(self): diff --git a/tests/unit/benchmark/context/test_network.py b/tests/unit/benchmark/context/test_network.py index d4bb802118..579fb6c093 100644 --- a/tests/unit/benchmark/context/test_network.py +++ b/tests/unit/benchmark/context/test_network.py @@ -31,7 +31,7 @@ class NetworkTestCase(test.TestCase): "bar_tenant": {"networks": [{"id": "bar_net"}]}}} def test_START_CIDR_DFLT(self): - netaddr.IPNetwork(network_context.Network.START_CIDR_DFLT) + netaddr.IPNetwork(network_context.Network.DEFAULT_CONFIG["start_cidr"]) @mock.patch("rally.osclients.Clients") @mock.patch(NET + "wrap", return_value="foo_service") @@ -40,7 +40,7 @@ class NetworkTestCase(test.TestCase): self.assertEqual(context.net_wrapper, "foo_service") self.assertEqual(context.config["networks_per_tenant"], 1) self.assertEqual(context.config["start_cidr"], - network_context.Network.START_CIDR_DFLT) + network_context.Network.DEFAULT_CONFIG["start_cidr"]) context = network_context.Network( self.get_context(start_cidr="foo_cidr", networks_per_tenant=42))