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

Adding a merge_all function to slsutil #47679

Merged
merged 3 commits into from
May 21, 2018

Conversation

onlyanegg
Copy link
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.

def merge_all(lst, strategy='smart', renderer='yaml', merge_lists=False):
'''
Merge a list of objects into each other in order

Copy link
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
The merge_all function merges a list of objects in order. This will make it
easier to merge more than two objects.
@onlyanegg
Copy link
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