-
Notifications
You must be signed in to change notification settings - Fork 156
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
Standardize mode_xxx, sudo, run, local and make it thread safe #40
Comments
I think it is better to suggest such a change to fabric instead of cuisine. See fabric#538 and fabric#98 for more discussion. |
Thinking about it, it absolutely makes sense to implement this kind of feature in fabric. But following above mentioned issues, it is not clear to me, when and if this will come. But in the meantime, we still have to live with what we have: and this is a working, but slightly confusing/inconsistent solution - that I wanted to streamline with my proposal. These are our options: And anyway, if we want to approach the fabric guys, it might be helpful to come with a proper proposal. And at the moment, we just have a brainstorming with myself. |
This is in an interesting discussion, however, the main reason why I introduced this notion of "modes" is the to avoid having to re-write functions that use a specific mode. In particular, most basic functions should only be implemented using However, you don't want to have Sames goes for So in essence:
I agree with @schacki's proposals:
The reason why I think we should keep
instead of
but I would agree with using Thoughts? |
on the one hand, you prefer "sudo("some admin-related command")" over "with mode_sudo(): run("some admin-related command")", but at the same time you prefere "mode_sudo() instead of run in cuisine's core functions". I do not bring that together in my mind, please help :-). i do not fully agree with: "but some others need to be implemented using sudo (packages, users, groups) as they are typical admin tasks". actually, this complete idea was triggered by an issue I had on webfaction: i do not have sudo rights there, but I do have read access to /etc/passwd and /etc/shadow. when i try to run check_user, i get an error, since you are using sudo: |
In that case reading the password should not use sudo, as it's not necessary. I didn't say I would like to use run() only in function core, only that I was not opposed to using with mode_sudo and run() instead ;) |
great discussion so far, so what is the bottom line? and i am not sarcarstic but really not sure :-) first of all: do we want to align/push the fabric team, as madkinder proposed, or do we just want to move forward and adapt later on, once the fabric team has come up with a better solution? if we want to move forward, what kind of API do we want to use for what I called the execution function(s)? please find my ideas here: a) run (cuisine) b) run (fabric) c) run_local(cuisine) and local (fabric) d) sudo (cuisine) and sudo (fabric) |
I have had a talk on #fabric and figured out that the devs aren't happy about the idea of having any kind of local_sudo implementation in the core. So I guess the best way to persuade them (if it is possible at all) is to implement it in cuisine, then show them some use cases that demonstrate reusability of the code and how awesome it is. To cut the long story short: I guess we should go cuisine-only way. At least for now. Here are some other random ideas.
I totally agree with sebastien that all the cuisine core functions are supposed to use the generic with mode_sudo(user='superpower'):
package_ensure('python-django')
package_ensure('postgresql-9.1') |
|
following this: http://docs.fabfile.org/en/1.3.4/usage/env.html#user, we could utilize for user argument of mode_user() could you explain the stack of modes in more detail please, and what would be the advantage? |
to be consistent with fabric approach, should the mode_xxx() not wrap the fabric settings decorator. from my understanding, this is EXACTLY what we want. |
@schacki yes indeed, and I think @madkinder made a pretty good summary of what we should do next. I've released an update today, but would love to have some contributions for you guys, esp. for the proper user_* and group_* implementation. I will take care of the mode_* rewrite using fabric's env. So who is taking what? |
regarding " proper user* and group* implementation", I would not recommend myself, my command line knowledge is limited (thats why I loave cuisine :-) ). |
Alright, then, thanks! |
I think there are a lot of good ideas in this thread, and I've been looking into possible implementations. @sebastien, does the env-based implementation seem to make sense, and is it coming along? I put together a proof-of-concept implementation today, but it involves monkey-patching fabric, which some people find unacceptable. It turns out that fabric's internal _run_command function controls almost everything you'd want to change in the modes, including specifying a user to sudo as. I've patched that function to override variables based on env settings and to run local execution through subprocess (similar to a pull request I made earlier, but cleaner, since fabric handles output, aborting during errors, etc.). Before I start working on a clean pull request, does this sound like a workable approach? I like to avoid monkey-patching whenever possible, but in this case it just seems like a much cleaner way to solve the problem. |
@davehughes I was planning to rework the Feel free to share a gist though, I'm curious to see what it's like! |
Sounds good, I'll look forward to the update. In the meantime, my stab at the implementation is summarized in this gist. |
Ha, it's interesting, we took at similar approach for modes -- well done! Here's the update 96e7300 -- I've added some test cases for modes as well. |
The update looks good - in hindsight, I guess it isn't necessary to have a stack for modes, since each context manager just has to hold on to the oldMode to be able to roll back to the previous state. There are a few possible improvements that I see, mostly having to do with the local mode. Right now, there are a few things that fabric's remote run methods do that run_local() doesn't:
I think I'm going to try and rework run_local so it works more like the _run_command function I was trying to monkey-patch. It will involve a little bit of duplication, but I think it's worth it to have behavior that is more in line with fabric's handling. |
Yes, if |
My bad, env.sudo_prefix did get documented recently; I was browsing some outdated doc. http://docs.fabfile.org/en/1.4.3/usage/env.html#sudo-prefix This seems like it could be a replacement for the SUDO_PASSWORD setting. The main question in my mind is whether cuisine.sudo_password() is intended to only set the sudo password for mode_local (this seems to be the case, but I can't tell for sure). |
I actually didn't add |
There are currently 4 mode functions(=mode_local, mode_remote, mode_sudo, mode_user) and 4 global mode variables (=MODE_USER,MODE_LOCAL, MODE_SUDO, MODE) , 3 cuisine execution functions (run, sudo, run_local) and the 3 native fabric execution functions (run, sudo, local).
Some of these have different APIs, but similar functionality. E.g. model_local and mode_sudo both influence the very basic behaviour of the run function. But mode_sudo uses/implements the "with" API and manipulates a global variable to control the behavior, while mode_local manipulates the module itself.
Some of these just overwrite and wrap the fabric native functions without changing the functionality like sudo, while others change the functionality significantly like run.
One global variable is boolean (mode_local), while others are strings(mode_sudo).
At the moment I do not get my head around it, why these complexities are necessary and why we cannot standardize all that and make it more simple. I am aware that I currently might not fully understand this complete beast and that whatever kind of changes we possibly apply here, this has a major effect.
So let me sketch some preliminary ideas here, to make my thoughts clearer, but also hopefully as a basis for further discussions around this topic:
Implement ONE cuisine run function. This run function checks fabric.api.env for certain variables. Based on the results of fabric.api.env, a certain excecution behavior will be enforced (e.g. run local with sudo, or run remote as current user, etc). And this is the only place where this complete set of behaviors is controlled.
a) 1 boolean env variable env.MODE_SUDO=True|False will determine, if sudo is used in the run function or not.
b) The current mode_sudo and mode_user classes are used to controll env.MODE_SUDO
a) 1 boolean env variable env.MODE_LOCAL=True|False will determine, if statements are executed on the local ore remote machine.
b) 2 new classes mode_local and model_remote including the enter/exit API are used to controll env.MODE_LOCAL
Looking forward to your feedback. I am happy to contribute any code along those lines.
Juergen
The text was updated successfully, but these errors were encountered: