-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
added support for freebsd_update #36675 #36971
added support for freebsd_update #36675 #36971
Conversation
All my basic functions accept the same arguments. An example follows:
The basic reason I've chosen to do so, is that they are all --except for the not-yet-implemented upgrade function-- calling the same function: _wrapper(), which accepts the exact same arguments. This way, even though most of these functions in their current implementation don't use most of their arguments, if someone in the future wanted to exploit the arguments' existence, their new code would be backwards compatible. |
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.
There are a few minor things to fix up here but overall it looks great. Please have a look and let me know what you think. Thanks!
import salt | ||
import salt.utils.decorators as decorators | ||
from salt.exceptions import CommandNotFoundError | ||
|
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.
We'll need a import salt.ext.six as six
here.
cmd = _cmd(**kwargs) | ||
res = __salt__['cmd.run_all']('{0} {1} {2} {3}'.format(pre, cmd, post, orig), **run_args) | ||
if err_ is not None: # copy return values if asked to | ||
for k, v in res.items(): |
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.
Could we change this to six.iteritems(res)
?
return err_ | ||
if err_ is not None and 'stdout' in err_: | ||
stdout[name] = err_['stdout'] | ||
return '\n'.join(['{0}: {1}'.format(k, v) for (k, v) in stdout.items()]) |
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.
six.iteritems(stdout)
here as well
return '{0} {1}'.format(update_cmd, ' '.join(params)) | ||
|
||
|
||
def _wrapper(orig, pre='', post='', err_=None, run_args={}, **kwargs): |
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.
We can't have mutable types as a default. (Explanation: http://reinout.vanrees.org/weblog/2012/04/18/default-parameters.html)
return res['stdout'] | ||
|
||
|
||
def fetch(pre='', post='', err_=None, run_args={}, **kwargs): |
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.
Same issue with mutable arg here.
return res['stdout'] | ||
|
||
|
||
def fetch(pre='', post='', err_=None, run_args={}, **kwargs): |
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.
We also like to avoid **kwargs
wherever possible in execution modules.
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.
I think (as explained in the pull request) that it could be safely be kept as is, since it reduces code complexity and maintenance.
return _wrapper('fetch', pre=pre, post=post, err_=err_, run_args=run_args, **kwargs) | ||
|
||
|
||
def install(pre='', post='', err_=None, run_args={}, **kwargs): |
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.
Same issue here with mutable arg and **kwargs
There are some additional issues which require attention here: https://jenkins.saltstack.com/job/PR/job/salt-pr-lint-n/5987/violations/file/salt/modules/freebsd_update.py/ |
@cachedout, I'm sorry! I didn't see your comments and made some changes on my branch, which I'm not sure that they have been automatically updated in my pull request, and that don't contain the corrections you suggested. Moreover, I must have done something wrong, because my initial build failed (and I wasn't able to understand why). The good thing is that my new changes -accidentally- fix some of the things you suggested :). I'll try to fix the rest of them, but there's a design problem I'm facing: I'm using **kwargs because it removed lots of boilerplate (otherwise all my functions' prototypes would have to accept the same keyword arguments along with their docstrings, and if a later argument appeared in Moreover, I'll change my PS. I'll submit a pull request for making the |
Hmm...@cachedout, if you could please help me understand why my builds fail, I would be really grateful! Because when I try to see the "Details", I can see some huge logfiles, where I can't discern which part of my code causes jenkins to fail. |
Hi @mamalos. Something went wrong here. You may have pushed from the wrong branch since it seems like a number of unrelated commits are present. It might be easier to have you close this and re-open a PR against the correct branch. Let me know if I can help. |
Hey @cachedout. Yes I need some help. I'll tell you what I've been doing and please tell me when I made the mistake. The following code assumes that I've already forked salt, cloned it locally, created a new branch, committed changes, fetched upstream, rebased, pushed and started a pull request. Then, some time has passed and I want to make a new branch for a new pull request:
That's how I did it on the first pull request for update-freebsd support, which failed in many tests. Then I tried to make the changes you suggested by executing:
and after the last command (
At this point I tried to pull the specific branch and push back the merged changes (from this point onwards I have the terminal history so I'll also paste the output):
And that's the code for the last test that failed. After that I worked in a new branch (following the steps of the contributing guide), made a pull request and my pull request was merged (by you:)). But, before following the steps, I did:
And then:
So, after reading your last message I:
...and I'm clearly unsure of what to do now... |
42aabb7
to
d519fd5
Compare
I think I corrected the mistake. I'm giving it a final try and if it fails I'll just start a new PR as you suggested. |
Hmm...it failed again, I'll start a new PR. |
This actually looks close to right now. All we need is for you to fix the issues here in your local checkout: Then, just commit to your local branch and push the change to this branch |
d519fd5
to
8666b97
Compare
Ah, cool, this commit passed the tests, so I think we're done now! :) |
There is one test that complains about missing examples which should probably
|
@eradman, I agree with you (and the tests) that it would be much wiser if I wrote CLI examples of how the functions should be used (I hadn't noticed that other "public" functions did), so, next week I'll try to find some time and write examples and reissue a pull request. |
What does this PR do?
It basically adds a salt wrapper to FreeBSD's freebsd-update command.
What issues does this PR fix or reference?
#36675
New Behavior
People will be able to user salt '*' freebsd-update.xxx to mimic freebsd-update behaviour.
Tests written?
No