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
File refactor #39345
File refactor #39345
Conversation
The test
|
91ed5fd
to
e65beb1
Compare
Some file_common_args are not common to all file modules. Divide the args into categories for a future refator of this into a separate file_argspec.
* Remove use of six.b as Python-2.6+ have byte literals. * Make AnsibleModule a global object so we'll have access to it in all the functions we're going to break this up into. * Rework the parameters so things that are in file_common_args are used from file_common_args or the reason for deviation is documented. * Remove validate as a parameter: this should be taken care of by removing it from params before the copy and template action plugin invoke file. * Rename diff_peek to _diff_peek as it is an internal parameter. * add module_name execute_module call to assemble so that it is more greppable
cc17bac
to
1d8cb9d
Compare
This is ready for review from @mattclay (as the 2.6 RM). This mostly moves the logic around without changing too much. A few refactors get their start here but will be completed in future PRs. |
lib/ansible/modules/files/file.py
Outdated
raise ParameterError(results={"path": params["path"], | ||
"msg": "recurse option requires state to be 'directory'"}) | ||
|
||
return params |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this function mutates the input params
why return it? Did you intend to copy it before modifying it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conceptually this is additions to the argspec so it should be mutating the params and not returning the params. I added the return since it didn't hurt anything and the calling code immediately does the equivalent of params = module.params
I can remove the return and change the caller if you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please remove the return and update the caller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside from the aforementioned change request, everything else looks OK.
* Separate the logic for each state into separate functions * Start the process of separating out initialization (pre-processing of parameters that cannot be done via arg spec) from the logic to implement each state. * Start the process of raising exceptions for errors and returning result values from each state implementing function Goal is for all fail_json's to be consolidated into exception handlers at the toplevel and for there to be only one exit_json() at the toplevel.
argument_spec=dict( | ||
state=dict(choices=['file', 'directory', 'link', 'hard', 'touch', 'absent'], default=None), | ||
path=dict(aliases=['dest', 'name'], required=True, type='path'), | ||
original_basename=dict(required=False), # Internal use only, for recursive ops |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be _original_basename
to match _diff_peek
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
original_basename is used for more than one module in several action_plugins. I'll have to look at each place to see if they should all be made private or if certain ones call file while others are calling (for instance) copy.
@@ -216,25 +216,32 @@ | |||
_ANSIBLE_ARGS = None | |||
|
|||
FILE_COMMON_ARGUMENTS = dict( | |||
src=dict(), | |||
# These are things we want. About setting metadata (mode, ownership, permissions in general) on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonder if it's worth giving some details of how to know if something should be in here or not, ie what is "common"?
May help reduce confusion in the future and things like backup
, force
being added back in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. I can do that when we actually break basic.py apart.
|
||
# not taken by the file module, but other action plugins call the file module so this ignores | ||
# them for now. In the future, the caller should take care of removing these from the module | ||
# arugments before calling the file module. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arugments -> arguments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k. I'll fix that in a followup PR
SUMMARY
Refactoring file so that it is easier to:
A few changes may also spill over to other file handling modules like copy which depend on the file module to perform their work sometimes.
ISSUE TYPE
COMPONENT NAME
primarily, lib/ansible/modules/files/file.py
ANSIBLE VERSION
ADDITIONAL INFORMATION
This has been okayed for inclusion in Ansible-2.6 as it is required to sanely bugfix the file module.