Skip to content

Fix for elasticsearch.index_template_present fails on ES <6.x #48442#48445

Merged
rallytime merged 2 commits intosaltstack:developfrom
babs:fix-issue-48442-elasticsearch
Jul 16, 2018
Merged

Fix for elasticsearch.index_template_present fails on ES <6.x #48442#48445
rallytime merged 2 commits intosaltstack:developfrom
babs:fix-issue-48442-elasticsearch

Conversation

@babs
Copy link
Copy Markdown
Contributor

@babs babs commented Jul 5, 2018

What does this PR do?

It resolv a bug related to index template for Elasticsearch before 6.x

What issues does this PR fix or reference?

It fixes issue #48442.

Tests written?

No

Commits signed with GPG?

No

Copy link
Copy Markdown
Contributor

@rallytime rallytime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR @babs

I have a couple of suggestions. In additon there is a very small lint error that needs to be fixed:

https://jenkins.saltstack.com/job/PR/job/salt-pr-lint-n/23133/violations/file/salt/states/elasticsearch.py/

Comment thread salt/states/elasticsearch.py Outdated
if check_definition:
definition_to_diff = {'aliases': {}, 'mappings': {}, 'settings': {}}
definition_to_diff.update(definition)
if type(definition) == str:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using an isinstance check here is more clear.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take care of that

diff = __utils__['dictdiffer.deep_diff'](current_template, definition_to_diff)
# Prune empty keys (avoid false positive diff)
for key in ("mappings", "aliases", "settings"):
if current_template[key] == {}:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here. :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check here it not th know if it's a dict but and empty dict.
I find isinstance(current_template[key], dict) and len(current_template[key].key() == 0) a little bit too wordy for that purpose, any suggestion ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about if not current_template[key]:?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not current_template[key]: would also match non dict typed values, I'll check if it might have any border effect as if an empty string was an expected value

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right and this is fine. It just felt that an awkward check to me.

@babs
Copy link
Copy Markdown
Contributor Author

babs commented Jul 9, 2018

Hi @rallytime, should I squash the commits ?

@cachedout
Copy link
Copy Markdown
Contributor

Have we tested this change on EL 6 and above as well?

@babs
Copy link
Copy Markdown
Contributor Author

babs commented Jul 15, 2018

@cachedout yes I did, I've both in prod using it (5.x and 6+).
The definition is slightly different at the state level but this is due to ES representation of data and a type change.

@rallytime rallytime merged commit 53d16ec into saltstack:develop Jul 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants