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

feat: read Salt-Cloud Maps from the Pillar #47742

Merged
merged 2 commits into from
May 29, 2018
Merged

feat: read Salt-Cloud Maps from the Pillar #47742

merged 2 commits into from
May 29, 2018

Conversation

nickgarber
Copy link
Contributor

@nickgarber nickgarber commented May 20, 2018

What does this PR do?

Enable use of cloud map data sourced from the Pillar.
Uses the map data found in the pillar at cloud:maps: + the key-name provided with map_pillar argument.

Example

salt-call cloud.map_run map_pillar=my-prd-map

Where

cloud:
  maps:
    my-prd-map:
      named-profile-01:
        - named-instance-01
        - named-instance-02

To preserve backwards compatibility the map_pillar option is ignored in the presence of either map_data or path arguments.

The implementation is in two parts: (1) add maps data from the pillar at CloudClient.__init__() (alongside the existing similarly loaded profiles and providers info), and (2) allow for selecting and reading from this data in Map.read(), which is the function that map data is sourced from.

What issues does this PR fix or reference?

#40975

Previous Behavior

Allow loading map data from a file or from a JSON data structure via CLI.

New Behavior

Add a pillar-based option to the existing map data.

Tests written?

No so far, but what sort of tests should this have?

Commits signed with GPG?

No

@ghost ghost self-requested a review May 20, 2018 23:38
Copy link
Contributor

@gtmanfred gtmanfred left a comment

Choose a reason for hiding this comment

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

This looks great!

Just a couple docs issue that need to be cleaned up.

@@ -210,6 +210,8 @@ def map_run(path=None, **kwargs):

salt minionname cloud.map_run /path/to/cloud.map
salt minionname cloud.map_run map_data='<actual map data>'
# to use map data in pillar under salt:cloud:maps:<map_pillar>'
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this should be cloud:maps not salt:cloud:maps

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Heya @gtmanfred, you're absolutely right! I was referencing it's location in the salt-formula pillar by accident. I have the correction for this on my laptop already - will push ASAP.

@@ -210,6 +210,8 @@ def map_run(path=None, **kwargs):

salt minionname cloud.map_run /path/to/cloud.map
salt minionname cloud.map_run map_data='<actual map data>'
# to use map data in pillar under salt:cloud:maps:<map_pillar>'
salt minionname cloud.map_run map_pillar='<map_pillar>'
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 a section above this for map_pillar and really describe what it is and how to use it?

Copy link
Contributor

@cachedout cachedout left a comment

Choose a reason for hiding this comment

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

Once we get docs pushed that will be reflected here, I think this looks good:

https://docs.saltstack.com/en/latest/topics/cloud/config.html#pillar-configuration

@nickgarber
Copy link
Contributor Author

I've added docs and am just watching for tests. Does this change need to include tests? Any other feedback to consider?

@gtmanfred
Copy link
Contributor

Tests would be great.

You can put them in unit tests, or if you want to write an integration test, we put them in salt/integration/cloud, and add the @expensiveTest decorator to them.

Thanks!
Daniel

@nickgarber nickgarber changed the title [WIP] #40975 Feat: read Salt-Cloud Maps from the Pillar #40975 Feat: read Salt-Cloud Maps from the Pillar May 22, 2018
@nickgarber nickgarber changed the title #40975 Feat: read Salt-Cloud Maps from the Pillar feat: read Salt-Cloud Maps from the Pillar May 22, 2018
 - The function signature `def map_run(path=None, **kwargs):`, so
   doesn't need to change.
 - Adding support for Cloud Maps in Pillar builds on the strength of the
   dynamic pillar-centric data organizing scheme.
 - in `Map.__init__`, a file path is read in as the class's
   `self.rendered_map` by the `Map.read` function, (which locates the file
   using the file path that the CloudClient is where most of the
   functionality is collected and it gets a copy of pillar values
   here (https://github.com/saltstack/salt/blob/develop/salt/cloud/init.py#L194-L206).

(doc)
 - added usage and precedence info to `map_run()` at modules/cloud.py
 - added example pillar to topics/cloud/config.rst
 - corrected YAML indentation of example 7 in topics/cloud/map.rst
@nickgarber nickgarber changed the title feat: read Salt-Cloud Maps from the Pillar [WIP] feat: read Salt-Cloud Maps from the Pillar May 25, 2018
@nickgarber
Copy link
Contributor Author

After looking into the cloud tests I'd prefer to come back to adding tests in a separate PR.

@gtmanfred gtmanfred merged commit cf1e5d4 into saltstack:develop May 29, 2018
@nickgarber nickgarber deleted the develop__wip-issue-40975-read-salt-cloud-maps-from-the-pillar branch May 29, 2018 17:47
@nickgarber nickgarber changed the title [WIP] feat: read Salt-Cloud Maps from the Pillar feat: read Salt-Cloud Maps from the Pillar May 29, 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