-
Notifications
You must be signed in to change notification settings - Fork 91
NodeUtils: export upcall variables to the environment #705
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -217,8 +217,11 @@ def _upcall_read(self, cmdtpl, args=dict()): | |
| """ | ||
| cmdline = Template(self.upcalls[cmdtpl]).safe_substitute(args) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we start supporting variable interpolation through real shell variables (through environment), it seems we do not need the template anymore? The shell variable supports below will handle everything, no?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope. The shell doesn't expand variables inside single quotes, and single-quoted
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, a bit weird, as now the expansion will happen sometimes under single quote, and sometimes not. User may be surprised.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That said, I agree a single mechanism (shell-only) would probably be cleaner, but that breaks single-quoted
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, so, what would be the less surprising to people over time would be for the variable to be 100% shell variables. So, let's keep the patch as-is, but, in the same time, we must change examples to use double quotes where appropriate. Let's write them as we were only supporting shell variables. We could deprecate that later.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good to me and actually that's a very good point: it would be possible to have an empty variable with this I think, so it is highly recommended to double-quote variables in upcalls. Best practice anyway (SC2086). Thus, this will start a clean migration to shell-only variables in the future. I'll update this PR (docs, examples) with this. |
||
| self.logger.debug("EXEC '%s'", cmdline) | ||
| # also export variables so shell expansions like ${GROUP:-x} work | ||
| env = dict(os.environ, GROUP='', NODE='') | ||
| env.update((var, str(value)) for var, value in args.items()) | ||
| proc = Popen(cmdline, stdin=DEVNULL, stdout=PIPE, shell=True, | ||
| cwd=self.cfgdir, universal_newlines=True) | ||
| cwd=self.cfgdir, universal_newlines=True, env=env) | ||
| output = proc.communicate()[0].strip() | ||
| self.logger.debug("READ '%s'", output) | ||
| if proc.returncode != 0: | ||
|
|
||
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 was thinking of just changing this single quotes to double quotes actually :) not adding double quotes everywhere. That may be zealous.