Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support composable template without top-level template #1489

Merged
merged 4 commits into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions esrally/track/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,15 @@ def __init__(self, track, params, templates, **kwargs):
elif templates:
filter_template = params.get("template")
settings = params.get("settings")
template_definitions = []
for template in templates:
if not filter_template or template.name == filter_template:
body = template.content
if body and "template" in body:
body = CreateComposableTemplateParamSource._create_or_merge(template.content, ["template", "settings"], settings)
self.template_definitions.append((template.name, body))
body = self._create_or_merge(template.content, ["template", "settings"], settings)
template_definitions.append((template.name, body))
if filter_template and not template_definitions:
template_names = ", ".join([template.name for template in templates])
raise exceptions.InvalidSyntax(f"Unknown template: {filter_template}. Available templates: {template_names}.")
self.template_definitions.extend(template_definitions)
else:
raise exceptions.InvalidSyntax(
"Please set the properties 'template' and 'body' for the "
Expand Down
69 changes: 69 additions & 0 deletions tests/track/params_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2138,6 +2138,56 @@ def test_create_composable_index_template_from_track(self):
"composed_of": ["ct1", "ct2"],
}

def test_create_composable_index_template_from_track_wrong_filter(self):
t1 = track.IndexTemplate(
name="t1",
content={},
pattern="",
)
t2 = track.IndexTemplate(
name="t2",
content={},
pattern="",
)

with pytest.raises(exceptions.InvalidSyntax) as exc:
params.CreateComposableTemplateParamSource(
track=track.Track(name="unit-test", composable_templates=[t1, t2]),
params={
"template": "t3",
},
)
assert exc.value.args[0] == ("Unknown template: t3. Available templates: t1, t2.")

def test_create_composable_index_template_from_track_no_template(self):
tpl = track.IndexTemplate(
name="default",
pattern="*",
content={
"index_patterns": ["my*"],
"composed_of": ["ct1", "ct2"],
},
)

source = params.CreateComposableTemplateParamSource(
track=track.Track(name="unit-test", composable_templates=[tpl]),
params={
"settings": {"index.number_of_replicas": 1},
},
)

p = source.params()

assert len(p["templates"]) == 1
assert p["request-params"] == {}
template, body = p["templates"][0]
assert template == "default"
assert body == {
"index_patterns": ["my*"],
"template": {"settings": {"index.number_of_replicas": 1}},
"composed_of": ["ct1", "ct2"],
}

def test_create_or_merge(self):
content = params.CreateComposableTemplateParamSource._create_or_merge(
{"parent": {}},
Expand Down Expand Up @@ -2270,6 +2320,25 @@ def test_create_component_index_template_from_track(self):
}
}

def test_create_component_index_template_from_track_wrong_filter(self):
t1 = track.ComponentTemplate(
name="t1",
content={},
)
t2 = track.ComponentTemplate(
name="t2",
content={},
)

with pytest.raises(exceptions.InvalidSyntax) as exc:
params.CreateComponentTemplateParamSource(
track=track.Track(name="unit-test", component_templates=[t1, t2]),
params={
"template": "t3",
},
)
assert exc.value.args[0] == ("Unknown template: t3. Available templates: t1, t2.")


class TestDeleteComponentTemplateParamSource:
def test_delete_component_template_by_name(self):
Expand Down