Merge "Use `DEFAULT_CONFIG' to specify context's config"
This commit is contained in:
commit
0475a9a06b
@ -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"]
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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"]
|
||||
|
@ -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):
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user