Skip to content

Adding a merge_all function to slsutil#47679

Merged
rallytime merged 3 commits into
saltstack:developfrom
onlyanegg:slsutil-merge_all
May 21, 2018
Merged

Adding a merge_all function to slsutil#47679
rallytime merged 3 commits into
saltstack:developfrom
onlyanegg:slsutil-merge_all

Conversation

@onlyanegg

Copy link
Copy Markdown
Contributor

The merge_all function merges a list of objects in order. This will make merging multiple objects more readable. Consider the difference between merging three objects with slsutil.merge versus merging with slsutil.merge_all

With slsutil.merge:

{{ hadoop.hdfs.data_node.service.name }}_environment_file_installed:
  file.managed:
    - name: /etc/sysconfig/{{ hadoop.hdfs.data_node.service.name }}
    - source: salt://hadoop/files/environment
    - template: jinja
    - context:
        environment: {{
          salt.slsutil.merge(
            hadoop.environment, salt.slsutil.merge(
              hadoop.hdfs.environment,
              hadoop.hdfs.data_node.environment
            )
          )
        }}

With slsutil.merge_all:

{{ hadoop.hdfs.data_node.service.name }}_environment_file_installed:
  file.managed:
    - name: /etc/sysconfig/{{ hadoop.hdfs.data_node.service.name }}
    - source: salt://hadoop/files/environment
    - template: jinja
    - context:
        environment: {{
          salt.slsutil.merge_all([
            hadoop.environment,
            hadoop.hdfs.environment,
            hadoop.hdfs.data_node.environment
          ])
        }}

I'm interested to know if you all think it would be better to add this function or to overload the merge function.

What does this PR do?

This PR adds a merge_all function to the slsutil module

What issues does this PR fix or reference?

None

Tests written?

No

Commits signed with GPG?

Yes

Please review Salt's Contributing Guide for best practices.

See GitHub's page on GPG signing for more information about signing commits with GPG.

Comment thread salt/modules/slsutil.py Outdated

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.

Can you add some more documentation to this new function? Each arg/kwarg should be documented.

Can you also add a ..versionadded:: Fluorine directive?

@rallytime rallytime requested a review from a team May 17, 2018 21:32
onlyanegg added 3 commits May 18, 2018 09:57
The merge_all function merges a list of objects in order. This will make it
easier to merge more than two objects.
@onlyanegg onlyanegg force-pushed the slsutil-merge_all branch from 2c42d23 to fc5ff22 Compare May 18, 2018 16:58
@onlyanegg

Copy link
Copy Markdown
Contributor Author

Thanks @rallytime, @gtmanfred, @cachedout. I've added the versionadded tag and argument documentation.

@rallytime rallytime merged commit 44e9e53 into saltstack:develop May 21, 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.

4 participants