Merge lp:~axwalk/juju-core/lp1212148-cloudinit-printf into lp:~go-bot/juju-core/trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Andrew Wilkins | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | 1686 | ||||
Proposed branch: | lp:~axwalk/juju-core/lp1212148-cloudinit-printf | ||||
Merge into: | lp:~go-bot/juju-core/trunk | ||||
Diff against target: |
145 lines (+23/-16) 5 files modified
agent/agent.go (+1/-1) cloudinit/cloudinit_test.go (+1/-1) cloudinit/options.go (+8/-1) container/lxc/lxc_test.go (+1/-1) environs/cloudinit/cloudinit_test.go (+12/-12) |
||||
To merge this branch: | bzr merge lp:~axwalk/juju-core/lp1212148-cloudinit-printf | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+181045@code.launchpad.net |
Commit message
Use printf instead of echo shell builtin
When writing cloud-init config files, use
printf to write files rather than shell's
echo builtin. There are differences between
bash and dash's echo when it comes to
interpreting escape sequences (e.g. \n).
Thus, depending on the guest being spun up,
we could get different results for files
being created via the cloud-init runcmds.
We could potentially use /bin/echo, but
it's safer just to use printf(1).
Description of the change
Use printf instead of echo shell builtin
When writing cloud-init config files, use
printf to write files rather than shell's
echo builtin. There are differences between
bash and dash's echo when it comes to
interpreting escape sequences (e.g. \n).
Thus, depending on the guest being spun up,
we could get different results for files
being created via the cloud-init runcmds.
We could potentially use /bin/echo, but
it's safer just to use printf(1).
Reviewers: mp+181045_ code.launchpad. net,
Message:
Please take a look.
Description:
Use printf instead of echo shell builtin
When writing cloud-init config files, use
printf to write files rather than shell's
echo builtin. There are differences between
bash and dash's echo when it comes to
interpreting escape sequences (e.g. \n).
Thus, depending on the guest being spun up,
we could get different results for files
being created via the cloud-init runcmds.
We could potentially use /bin/echo, but
it's safer just to use printf(1).
https:/ /code.launchpad .net/~axwalk/ juju-core/ lp1212148- cloudinit- printf/ +merge/ 181045
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/13123043/
Affected files: cloudinit_ test.go options. go lxc/lxc_ test.go cloudinit/ cloudinit_ test.go
A [revision details]
M agent/agent.go
M cloudinit/
M cloudinit/
M container/
M environs/
Index: [revision details] 20130820022554- t4r3stekgq56x0i h
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-
+New revision: <email address hidden>
Index: agent/agent.go c.confFile( )) c.Dir() )) string( data)), f) string( data)), f)
=== modified file 'agent/agent.go'
--- agent/agent.go 2013-08-02 15:50:58 +0000
+++ agent/agent.go 2013-08-20 13:32:26 +0000
@@ -201,7 +201,7 @@
f := utils.ShQuote(
addCmd("mkdir -p %s", utils.ShQuote(
addCmd("install -m %o /dev/null %s", 0600, f)
- addCmd("echo %s > %s", utils.ShQuote(
+ addCmd(`printf "%%s\n" %s > %s`, utils.ShQuote(
return cmds, nil
}
Index: cloudinit/ cloudinit_ test.go cloudinit_ test.go' cloudinit_ test.go 2013-08-19 11:17:19 +0000 cloudinit_ test.go 2013-08-20 13:32:26 +0000 apt.conf. d/99proxy' :http:: Proxy "http:// 10.0.3. 1:3142";' apt.conf. d/99proxy' :http:: Proxy "http:// 10.0.3. 1:3142";' apt.conf. d/99proxy'
=== modified file 'cloudinit/
--- cloudinit/
+++ cloudinit/
@@ -242,7 +242,7 @@
header = "#cloud-config\n"
addFileExpected = `runcmd:
- install -m 644 /dev/null '/etc/apt/
-- echo '"Acquire:
> '/etc/apt/
+- printf "%s\n" '"Acquire:
> '/etc/apt/
`
)
Index: cloudinit/ options. go options. go' options. go 2013-08-05 11:01:08 +0000 options. go 2013-08-20 13:32:26 +0000 Sprintf( "install -m %o /dev/null %s", mode, p),
=== modified file 'cloudinit/
--- cloudinit/
+++ cloudinit/
@@ -235,10 +235,17 @@
// AddFile will add multiple run_cmd entries to safely set the contents of
a
// specific file to the requested contents.
func (cfg *Config) AddFile(filename, data string, mode uint) {
+ // Note: recent versions of cloud-init have the "write_files"
+ // module, which can write arbitrary files. We currently support
+ // 12.04 LTS, which uses an older version of cloud-init without
+ // this module.
p := shquote(filename)
+ // Don't use the shell's echo builtin here; the interpretation
+ // of escape sequences differs between shells, namely bash and
+ // dash. Instead, we use printf (or we could use /bin/echo).
cfg.AddScripts(
fmt.
- fmt.Sprintf("echo %s > %s", shquote(data), p),
+ fmt.Sprintf(`pr...