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

Projects
None yet
4 participants
@onlyanegg
Copy link
Contributor

commented May 16, 2018

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

This comment has been minimized.

Copy link
@rallytime

rallytime May 17, 2018

Contributor

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 saltstack/team-core May 17, 2018

onlyanegg added some commits May 10, 2018

Adding a merge_all function to slsutil
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 onlyanegg:slsutil-merge_all branch from 2c42d23 to fc5ff22 May 18, 2018

@onlyanegg

This comment has been minimized.

Copy link
Contributor Author

commented May 18, 2018

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

@rallytime rallytime merged commit 44e9e53 into saltstack:develop May 21, 2018

5 of 10 checks passed

jenkins/PR/salt-pr-linode-cent7-py3 Pull Requests » Salt PR - Linode CentOS 7 - PY3 #5050 — ABORTED
Details
jenkins/PR/salt-pr-linode-ubuntu16-py3 Pull Requests » Salt PR - Linode Ubuntu16.04 - PY3 #10020 — ABORTED
Details
jenkins/PR/salt-pr-rs-cent7-n Pull Requests » Salt PR - RS CentOS 7 #19107 — ABORTED
Details
default Build finished.
Details
jenkins/PR/salt-pr-linode-ubuntu14-n Pull Requests » Salt PR - Linode Ubuntu14.04 #22984 — FAILURE
Details
WIP ready for review
Details
codeclimate All good!
Details
jenkins/PR/salt-pr-clone Pull Requests » Salt PR - Clone #25240 — SUCCESS
Details
jenkins/PR/salt-pr-docs-n Pull Requests » Salt PR - Docs #17337 — SUCCESS
Details
jenkins/PR/salt-pr-lint-n Pull Requests » Salt PR - Code Lint #21967 — SUCCESS
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.