Merge lp:~thumper/juju-core/ubuntu-profile-upgrade-step into lp:~go-bot/juju-core/trunk

Proposed by Tim Penhey
Status: Merged
Approved by: Tim Penhey
Approved revision: no longer in the source branch.
Merged at revision: 2462
Proposed branch: lp:~thumper/juju-core/ubuntu-profile-upgrade-step
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 186 lines (+133/-7)
5 files modified
upgrades/dotprofile.go (+37/-0)
upgrades/dotprofile_test.go (+82/-0)
upgrades/export_test.go (+7/-6)
upgrades/steps118.go (+6/-1)
upgrades/steps118_test.go (+1/-0)
To merge this branch: bzr merge lp:~thumper/juju-core/ubuntu-profile-upgrade-step
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+212083@code.launchpad.net

Commit message

Add upgrade job for ~ubuntu/.profile

The ubuntu user's .profile is updated to source the
~ubuntu/.juju-profile to get the proxy information.

The .juju-profile is written out by the machine agent
as it starts up if it is missing, but the .profile
needs to happen for any machines that were created by
older agents.

https://codereview.appspot.com/78660043/

Description of the change

Add upgrade job for ~ubuntu/.profile

The ubuntu user's .profile is updated to source the
~ubuntu/.juju-profile to get the proxy information.

The .juju-profile is written out by the machine agent
as it starts up if it is missing, but the .profile
needs to happen for any machines that were created by
older agents.

https://codereview.appspot.com/78660043/

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

Reviewers: mp+212083_code.launchpad.net,

Message:
Please take a look.

Description:
Add upgrade job for ~ubuntu/.profile

The ubuntu user's .profile is updated to source the
~ubuntu/.juju-profile to get the proxy information.

The .juju-profile is written out by the machine agent
as it starts up if it is missing, but the .profile
needs to happen for any machines that were created by
older agents.

https://code.launchpad.net/~thumper/juju-core/ubuntu-profile-upgrade-step/+merge/212083

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/78660043/

Affected files (+134, -7 lines):
   A [revision details]
   A upgrades/dotprofile.go
   A upgrades/dotprofile_test.go
   M upgrades/export_test.go
   M upgrades/steps118.go

Revision history for this message
Tim Penhey (thumper) wrote :
Revision history for this message
Ian Booth (wallyworld) wrote :

LGTM. I wonder if we should to grep for more than just ".juju-profile",
but I guess that is all we need.

https://codereview.appspot.com/78660043/

Revision history for this message
Tim Penhey (thumper) wrote :

On 2014/03/21 04:56:00, wallyworld wrote:
> LGTM. I wonder if we should to grep for more than just
".juju-profile", but I
> guess that is all we need.

Thanks. The only thing that should have put .juju-profile into the
/home/ubuntu/.profile should have been us.

This is exactly what the cloud-init script does too.

https://codereview.appspot.com/78660043/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'upgrades/dotprofile.go'
2--- upgrades/dotprofile.go 1970-01-01 00:00:00 +0000
3+++ upgrades/dotprofile.go 2014-03-21 04:47:53 +0000
4@@ -0,0 +1,37 @@
5+// Copyright 2014 Canonical Ltd.
6+// Licensed under the AGPLv3, see LICENCE file for details.
7+
8+package upgrades
9+
10+import (
11+ "fmt"
12+
13+ "launchpad.net/juju-core/utils/exec"
14+)
15+
16+// As of the middle of the 1.17 cycle, the proxy settings are written out to
17+// /home/ubuntu/.juju-proxy both by cloud-init and the machine environ worker.
18+// An older version of juju that has been upgraded will get the proxy settings
19+// written out to the .juju-proxy file, but the .profile for the ubuntu user
20+// wouldn't have been updated to source this file.
21+//
22+// This upgrade step is to add the line to source the file if it is missing
23+// from the file.
24+func ensureUbuntuDotProfileSourcesProxyFile(context Context) error {
25+ // We look to see if the proxy line is there already as the manual
26+ // provider may have had it aleady. The ubuntu user may not exist
27+ // (local provider only).
28+ command := fmt.Sprintf(""+
29+ `([ ! -e %s/.profile ] || grep -q '.juju-proxy' %s/.profile) || `+
30+ `printf '\n# Added by juju\n[ -f "$HOME/.juju-proxy" ] && . "$HOME/.juju-proxy"\n' >> %s/.profile`,
31+ ubuntuHome, ubuntuHome, ubuntuHome)
32+ logger.Tracef("command: %s", command)
33+ result, err := exec.RunCommands(exec.RunParams{
34+ Commands: command,
35+ })
36+ if err != nil {
37+ return err
38+ }
39+ logger.Tracef("stdout: %s", result.Stdout)
40+ return nil
41+}
42
43=== added file 'upgrades/dotprofile_test.go'
44--- upgrades/dotprofile_test.go 1970-01-01 00:00:00 +0000
45+++ upgrades/dotprofile_test.go 2014-03-21 04:47:53 +0000
46@@ -0,0 +1,82 @@
47+// Copyright 2014 Canonical Ltd.
48+// Licensed under the AGPLv3, see LICENCE file for details.
49+
50+package upgrades_test
51+
52+import (
53+ "io/ioutil"
54+ "path"
55+
56+ "github.com/juju/loggo"
57+ jc "github.com/juju/testing/checkers"
58+ gc "launchpad.net/gocheck"
59+
60+ "launchpad.net/juju-core/testing"
61+ "launchpad.net/juju-core/upgrades"
62+)
63+
64+type ensureDotProfileSuite struct {
65+ testing.FakeHomeSuite
66+ home string
67+ ctx upgrades.Context
68+}
69+
70+var _ = gc.Suite(&ensureDotProfileSuite{})
71+
72+func (s *ensureDotProfileSuite) SetUpTest(c *gc.C) {
73+ s.FakeHomeSuite.SetUpTest(c)
74+
75+ loggo.GetLogger("juju.upgrade").SetLogLevel(loggo.TRACE)
76+
77+ s.home = c.MkDir()
78+ s.PatchValue(upgrades.UbuntuHome, s.home)
79+ s.ctx = &mockContext{}
80+}
81+
82+const expectedLine = `
83+# Added by juju
84+[ -f "$HOME/.juju-proxy" ] && . "$HOME/.juju-proxy"
85+`
86+
87+func (s *ensureDotProfileSuite) writeDotProfile(c *gc.C, content string) {
88+ dotProfile := path.Join(s.home, ".profile")
89+ err := ioutil.WriteFile(dotProfile, []byte(content), 0644)
90+ c.Assert(err, gc.IsNil)
91+}
92+
93+func (s *ensureDotProfileSuite) assertProfile(c *gc.C, content string) {
94+ dotProfile := path.Join(s.home, ".profile")
95+ data, err := ioutil.ReadFile(dotProfile)
96+ c.Assert(err, gc.IsNil)
97+ c.Assert(string(data), gc.Equals, content)
98+}
99+
100+func (s *ensureDotProfileSuite) TestSourceAdded(c *gc.C) {
101+ s.writeDotProfile(c, "")
102+ err := upgrades.EnsureUbuntuDotProfileSourcesProxyFile(s.ctx)
103+ c.Assert(err, gc.IsNil)
104+ s.assertProfile(c, expectedLine)
105+}
106+
107+func (s *ensureDotProfileSuite) TestIdempotent(c *gc.C) {
108+ s.writeDotProfile(c, "")
109+ err := upgrades.EnsureUbuntuDotProfileSourcesProxyFile(s.ctx)
110+ c.Assert(err, gc.IsNil)
111+ err = upgrades.EnsureUbuntuDotProfileSourcesProxyFile(s.ctx)
112+ c.Assert(err, gc.IsNil)
113+ s.assertProfile(c, expectedLine)
114+}
115+
116+func (s *ensureDotProfileSuite) TestProfileUntouchedIfJujuProxyInSource(c *gc.C) {
117+ content := "source .juju-proxy\n"
118+ s.writeDotProfile(c, content)
119+ err := upgrades.EnsureUbuntuDotProfileSourcesProxyFile(s.ctx)
120+ c.Assert(err, gc.IsNil)
121+ s.assertProfile(c, content)
122+}
123+
124+func (s *ensureDotProfileSuite) TestSkippedIfDotProfileDoesntExist(c *gc.C) {
125+ err := upgrades.EnsureUbuntuDotProfileSourcesProxyFile(s.ctx)
126+ c.Assert(err, gc.IsNil)
127+ c.Assert(path.Join(s.home, ".profile"), jc.DoesNotExist)
128+}
129
130=== modified file 'upgrades/export_test.go'
131--- upgrades/export_test.go 2014-03-18 14:50:47 +0000
132+++ upgrades/export_test.go 2014-03-21 04:47:53 +0000
133@@ -13,10 +13,11 @@
134 IsLocalEnviron = &isLocalEnviron
135
136 // 118 upgrade functions
137- StepsFor118 = stepsFor118
138- EnsureLockDirExistsAndUbuntuWritable = ensureLockDirExistsAndUbuntuWritable
139- EnsureSystemSSHKey = ensureSystemSSHKey
140- UpdateRsyslogPort = updateRsyslogPort
141- ProcessDeprecatedEnvSettings = processDeprecatedEnvSettings
142- MigrateLocalProviderAgentConfig = migrateLocalProviderAgentConfig
143+ StepsFor118 = stepsFor118
144+ EnsureLockDirExistsAndUbuntuWritable = ensureLockDirExistsAndUbuntuWritable
145+ EnsureSystemSSHKey = ensureSystemSSHKey
146+ EnsureUbuntuDotProfileSourcesProxyFile = ensureUbuntuDotProfileSourcesProxyFile
147+ UpdateRsyslogPort = updateRsyslogPort
148+ ProcessDeprecatedEnvSettings = processDeprecatedEnvSettings
149+ MigrateLocalProviderAgentConfig = migrateLocalProviderAgentConfig
150 )
151
152=== modified file 'upgrades/steps118.go'
153--- upgrades/steps118.go 2014-03-18 09:21:53 +0000
154+++ upgrades/steps118.go 2014-03-21 04:47:53 +0000
155@@ -8,7 +8,7 @@
156 return []Step{
157 &upgradeStep{
158 description: "make $DATADIR/locks owned by ubuntu:ubuntu",
159- targets: []Target{HostMachine},
160+ targets: []Target{AllMachines},
161 run: ensureLockDirExistsAndUbuntuWritable,
162 },
163 &upgradeStep{
164@@ -36,5 +36,10 @@
165 targets: []Target{StateServer},
166 run: migrateLocalProviderAgentConfig,
167 },
168+ &upgradeStep{
169+ description: "make /home/ubuntu/.profile source .juju-proxy file",
170+ targets: []Target{AllMachines},
171+ run: ensureUbuntuDotProfileSourcesProxyFile,
172+ },
173 }
174 }
175
176=== modified file 'upgrades/steps118_test.go'
177--- upgrades/steps118_test.go 2014-03-13 21:58:22 +0000
178+++ upgrades/steps118_test.go 2014-03-21 04:47:53 +0000
179@@ -23,6 +23,7 @@
180 "install rsyslog-gnutls",
181 "remove deprecated environment config settings",
182 "migrate local provider agent config",
183+ "make /home/ubuntu/.profile source .juju-proxy file",
184 }
185
186 func (s *steps118Suite) TestUpgradeOperationsContent(c *gc.C) {

Subscribers

People subscribed via source and target branches

to status/vote changes: