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
=== added file 'upgrades/dotprofile.go'
--- upgrades/dotprofile.go 1970-01-01 00:00:00 +0000
+++ upgrades/dotprofile.go 2014-03-21 04:47:53 +0000
@@ -0,0 +1,37 @@
1// Copyright 2014 Canonical Ltd.
2// Licensed under the AGPLv3, see LICENCE file for details.
3
4package upgrades
5
6import (
7 "fmt"
8
9 "launchpad.net/juju-core/utils/exec"
10)
11
12// As of the middle of the 1.17 cycle, the proxy settings are written out to
13// /home/ubuntu/.juju-proxy both by cloud-init and the machine environ worker.
14// An older version of juju that has been upgraded will get the proxy settings
15// written out to the .juju-proxy file, but the .profile for the ubuntu user
16// wouldn't have been updated to source this file.
17//
18// This upgrade step is to add the line to source the file if it is missing
19// from the file.
20func ensureUbuntuDotProfileSourcesProxyFile(context Context) error {
21 // We look to see if the proxy line is there already as the manual
22 // provider may have had it aleady. The ubuntu user may not exist
23 // (local provider only).
24 command := fmt.Sprintf(""+
25 `([ ! -e %s/.profile ] || grep -q '.juju-proxy' %s/.profile) || `+
26 `printf '\n# Added by juju\n[ -f "$HOME/.juju-proxy" ] && . "$HOME/.juju-proxy"\n' >> %s/.profile`,
27 ubuntuHome, ubuntuHome, ubuntuHome)
28 logger.Tracef("command: %s", command)
29 result, err := exec.RunCommands(exec.RunParams{
30 Commands: command,
31 })
32 if err != nil {
33 return err
34 }
35 logger.Tracef("stdout: %s", result.Stdout)
36 return nil
37}
038
=== added file 'upgrades/dotprofile_test.go'
--- upgrades/dotprofile_test.go 1970-01-01 00:00:00 +0000
+++ upgrades/dotprofile_test.go 2014-03-21 04:47:53 +0000
@@ -0,0 +1,82 @@
1// Copyright 2014 Canonical Ltd.
2// Licensed under the AGPLv3, see LICENCE file for details.
3
4package upgrades_test
5
6import (
7 "io/ioutil"
8 "path"
9
10 "github.com/juju/loggo"
11 jc "github.com/juju/testing/checkers"
12 gc "launchpad.net/gocheck"
13
14 "launchpad.net/juju-core/testing"
15 "launchpad.net/juju-core/upgrades"
16)
17
18type ensureDotProfileSuite struct {
19 testing.FakeHomeSuite
20 home string
21 ctx upgrades.Context
22}
23
24var _ = gc.Suite(&ensureDotProfileSuite{})
25
26func (s *ensureDotProfileSuite) SetUpTest(c *gc.C) {
27 s.FakeHomeSuite.SetUpTest(c)
28
29 loggo.GetLogger("juju.upgrade").SetLogLevel(loggo.TRACE)
30
31 s.home = c.MkDir()
32 s.PatchValue(upgrades.UbuntuHome, s.home)
33 s.ctx = &mockContext{}
34}
35
36const expectedLine = `
37# Added by juju
38[ -f "$HOME/.juju-proxy" ] && . "$HOME/.juju-proxy"
39`
40
41func (s *ensureDotProfileSuite) writeDotProfile(c *gc.C, content string) {
42 dotProfile := path.Join(s.home, ".profile")
43 err := ioutil.WriteFile(dotProfile, []byte(content), 0644)
44 c.Assert(err, gc.IsNil)
45}
46
47func (s *ensureDotProfileSuite) assertProfile(c *gc.C, content string) {
48 dotProfile := path.Join(s.home, ".profile")
49 data, err := ioutil.ReadFile(dotProfile)
50 c.Assert(err, gc.IsNil)
51 c.Assert(string(data), gc.Equals, content)
52}
53
54func (s *ensureDotProfileSuite) TestSourceAdded(c *gc.C) {
55 s.writeDotProfile(c, "")
56 err := upgrades.EnsureUbuntuDotProfileSourcesProxyFile(s.ctx)
57 c.Assert(err, gc.IsNil)
58 s.assertProfile(c, expectedLine)
59}
60
61func (s *ensureDotProfileSuite) TestIdempotent(c *gc.C) {
62 s.writeDotProfile(c, "")
63 err := upgrades.EnsureUbuntuDotProfileSourcesProxyFile(s.ctx)
64 c.Assert(err, gc.IsNil)
65 err = upgrades.EnsureUbuntuDotProfileSourcesProxyFile(s.ctx)
66 c.Assert(err, gc.IsNil)
67 s.assertProfile(c, expectedLine)
68}
69
70func (s *ensureDotProfileSuite) TestProfileUntouchedIfJujuProxyInSource(c *gc.C) {
71 content := "source .juju-proxy\n"
72 s.writeDotProfile(c, content)
73 err := upgrades.EnsureUbuntuDotProfileSourcesProxyFile(s.ctx)
74 c.Assert(err, gc.IsNil)
75 s.assertProfile(c, content)
76}
77
78func (s *ensureDotProfileSuite) TestSkippedIfDotProfileDoesntExist(c *gc.C) {
79 err := upgrades.EnsureUbuntuDotProfileSourcesProxyFile(s.ctx)
80 c.Assert(err, gc.IsNil)
81 c.Assert(path.Join(s.home, ".profile"), jc.DoesNotExist)
82}
083
=== modified file 'upgrades/export_test.go'
--- upgrades/export_test.go 2014-03-18 14:50:47 +0000
+++ upgrades/export_test.go 2014-03-21 04:47:53 +0000
@@ -13,10 +13,11 @@
13 IsLocalEnviron = &isLocalEnviron13 IsLocalEnviron = &isLocalEnviron
1414
15 // 118 upgrade functions15 // 118 upgrade functions
16 StepsFor118 = stepsFor11816 StepsFor118 = stepsFor118
17 EnsureLockDirExistsAndUbuntuWritable = ensureLockDirExistsAndUbuntuWritable17 EnsureLockDirExistsAndUbuntuWritable = ensureLockDirExistsAndUbuntuWritable
18 EnsureSystemSSHKey = ensureSystemSSHKey18 EnsureSystemSSHKey = ensureSystemSSHKey
19 UpdateRsyslogPort = updateRsyslogPort19 EnsureUbuntuDotProfileSourcesProxyFile = ensureUbuntuDotProfileSourcesProxyFile
20 ProcessDeprecatedEnvSettings = processDeprecatedEnvSettings20 UpdateRsyslogPort = updateRsyslogPort
21 MigrateLocalProviderAgentConfig = migrateLocalProviderAgentConfig21 ProcessDeprecatedEnvSettings = processDeprecatedEnvSettings
22 MigrateLocalProviderAgentConfig = migrateLocalProviderAgentConfig
22)23)
2324
=== modified file 'upgrades/steps118.go'
--- upgrades/steps118.go 2014-03-18 09:21:53 +0000
+++ upgrades/steps118.go 2014-03-21 04:47:53 +0000
@@ -8,7 +8,7 @@
8 return []Step{8 return []Step{
9 &upgradeStep{9 &upgradeStep{
10 description: "make $DATADIR/locks owned by ubuntu:ubuntu",10 description: "make $DATADIR/locks owned by ubuntu:ubuntu",
11 targets: []Target{HostMachine},11 targets: []Target{AllMachines},
12 run: ensureLockDirExistsAndUbuntuWritable,12 run: ensureLockDirExistsAndUbuntuWritable,
13 },13 },
14 &upgradeStep{14 &upgradeStep{
@@ -36,5 +36,10 @@
36 targets: []Target{StateServer},36 targets: []Target{StateServer},
37 run: migrateLocalProviderAgentConfig,37 run: migrateLocalProviderAgentConfig,
38 },38 },
39 &upgradeStep{
40 description: "make /home/ubuntu/.profile source .juju-proxy file",
41 targets: []Target{AllMachines},
42 run: ensureUbuntuDotProfileSourcesProxyFile,
43 },
39 }44 }
40}45}
4146
=== modified file 'upgrades/steps118_test.go'
--- upgrades/steps118_test.go 2014-03-13 21:58:22 +0000
+++ upgrades/steps118_test.go 2014-03-21 04:47:53 +0000
@@ -23,6 +23,7 @@
23 "install rsyslog-gnutls",23 "install rsyslog-gnutls",
24 "remove deprecated environment config settings",24 "remove deprecated environment config settings",
25 "migrate local provider agent config",25 "migrate local provider agent config",
26 "make /home/ubuntu/.profile source .juju-proxy file",
26}27}
2728
28func (s *steps118Suite) TestUpgradeOperationsContent(c *gc.C) {29func (s *steps118Suite) TestUpgradeOperationsContent(c *gc.C) {

Subscribers

People subscribed via source and target branches

to status/vote changes: