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 import/export modules around AWX Kit features #7799

Conversation

john-westcott-iv
Copy link
Member

SUMMARY

This PR adds a tower_import and tower_export modules to wrap the awxkit features.
It includes changes to the module_utils library structure:

  • Original TowerModule becomes TowerLegacyModule
  • TowerModule from tower_api becomes TowerAPIModule (and has some base stuff split out)
  • A new TowerAWXKitModule is created in tower_awxkit.py
  • A real base TowerModule is created in tower_module.py
    • TowerModule is responsible for loading config files and having the base connection argument spec, dealing with exit/warning, etc
    • TowerAWXKit and TowerAPI are responsible for interfacing with Tower
    • TowerAWXKitModule and TowerAPIModule are child classes of TowerModule
ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME
  • Collection
AWX VERSION
awx: 13.0.0
ADDITIONAL INFORMATION

@softwarefactory-project-zuul
Copy link
Contributor

Build failed.

@softwarefactory-project-zuul
Copy link
Contributor

Build failed.

# Here we are going to setup a dict of values to export
export_args = {}
for resource in EXPORTABLE_RESOURCES:
if module.params.get('all') or module.params.get(resource) == 'all':
Copy link
Member

Choose a reason for hiding this comment

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

Seems like we should add some really simple validation for the case that

module.params.get('all') and module.params.get(resource) not in (None, 'all')

In that case, you're getting conflicting instructions from the user. The "all" parameter dictates that you should export all credentials, but the credential param says to export just "my-cred", for example.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we consider moving away from the use of 'all' flags? The actual semantics of the import/export code that I wrote is unambiguous, the case that @AlanCoding is talking about here cannot arise.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm open to input but I think I am partial to the explicit all parameter and keywords. We could make it do something like:

- name: Export all resources
   tower_export:
   register: all_exported_data

And then have something like your code:

        # If no resource parameters are explicitly used, export everything.
        all_resources = all(module.params.get(resource) is None for resource in EXPORTABLE_RESOURCES)

But then we are back to our existing loop, just changing module.params.get('all') to all_resources.

I think I am also partial to the explicit:

- name: Export all credentials
  tower_export:
    credentials: 'all'

as opposed to :

- name: Export all credentials
  tower_export:
    credentials: ''

The second syntax looks like it could be confused with "nothing" vs an all. Anyone else have thoughts on this?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, as a gut reaction I personally like the aesthetics of this

- name: Export all resources
   tower_export:
   register: all_exported_data

But the behavior is "jumpy". If you have credentials: "foo" then it exports 1 thing, but take it away and it exports 1,000 things. If this syntax returned nothing that would give a better impression of behavioral stability. I'm just saying it's arguable so I don't want to take a position.

I don't have a problem with the current "all" param. The validation statement I'm talking about would just be 1 conditional.

I also don't want to care about giving blank values. Ansible has an omit syntax. You could throw an error for blank values for clarity, but it doesn't bother me either way, it shouldn't be your problem to deal with.

@@ -89,7 +89,7 @@ def main():
)

# Create a module for ourselves
module = TowerModule(argument_spec=argument_spec)
module = TowerAPIModule(argument_spec=argument_spec)
Copy link
Contributor

Choose a reason for hiding this comment

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

The new import/export code does not support hosts or groups, though there is an open issue to add them in.

@softwarefactory-project-zuul
Copy link
Contributor

Build failed.

@softwarefactory-project-zuul
Copy link
Contributor

Build failed.

@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

@AlanCoding
Copy link
Member

👍 looking so far. I'm kicking off some tests, once those are passing, then I'm going to be pushing to get this ready for merge.

log_contents = log_capture_string.getvalue()
log_capture_string.close()
if log_contents != '':
module.fail_json(msg=log_contents)
Copy link
Member

Choose a reason for hiding this comment

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

this seems a little extreme... wouldn't you just want to warn with the log contents? Wouldn't the CLI code raise an exception if something was actually a problem? Asking @jbradberry here too

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I agree, this seems a bit much.

@john-westcott-iv john-westcott-iv force-pushed the import-export-collecion-modules branch from fcf9974 to 1fb0e86 Compare August 6, 2020 14:32
@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

@john-westcott-iv john-westcott-iv force-pushed the import-export-collecion-modules branch from d510d8b to a5afe02 Compare August 19, 2020 18:31
@softwarefactory-project-zuul
Copy link
Contributor

Build failed.

@AlanCoding
Copy link
Member

recheck

@softwarefactory-project-zuul
Copy link
Contributor

Build failed.

@beeankha
Copy link
Contributor

recheck

@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded (gate pipeline).

@softwarefactory-project-zuul softwarefactory-project-zuul bot merged commit cf116d1 into ansible:devel Aug 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants