Merge lp:~axwalk/juju-core/lp1206195-mock-deployer-init-dir into lp:~go-bot/juju-core/trunk

Proposed by Andrew Wilkins
Status: Merged
Approved by: Andrew Wilkins
Approved revision: no longer in the source branch.
Merged at revision: 2337
Proposed branch: lp:~axwalk/juju-core/lp1206195-mock-deployer-init-dir
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 74 lines (+21/-2)
3 files modified
cmd/jujud/machine_test.go (+0/-1)
cmd/jujud/main_test.go (+16/-0)
worker/deployer/simple.go (+5/-1)
To merge this branch: bzr merge lp:~axwalk/juju-core/lp1206195-mock-deployer-init-dir
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+205907@code.launchpad.net

Commit message

cmd/jujud: override deployer init-dir in tests

worker/deployer is (mostly) hard coded to look for unit
jobs in /etc/init, and recall/remove those it doesn't know
about.

The worker/deployer tests specify a temporary directory
instead of the default; this CL updates cmd/jujud tests
to do the same.

Fixes lp:1206195

https://codereview.appspot.com/61610044/

Description of the change

cmd/jujud: override deployer init-dir in tests

worker/deployer is (mostly) hard coded to look for unit
jobs in /etc/init, and recall/remove those it doesn't know
about.

The worker/deployer tests specify a temporary directory
instead of the default; this CL updates cmd/jujud tests
to do the same.

Fixes lp:1206195

https://codereview.appspot.com/61610044/

To post a comment you must log in.
Revision history for this message
Andrew Wilkins (axwalk) wrote :
Download full text (3.2 KiB)

Reviewers: mp+205907_code.launchpad.net,

Message:
Please take a look.

Description:
cmd/jujud: override deployer init-dir in tests

worker/deployer is (mostly) hard coded to look for unit
jobs in /etc/init, and recall/remove those it doesn't know
about.

The worker/deployer tests specify a temporary directory
instead of the default; this CL updates cmd/jujud tests
to do the same.

Fixes lp:1206195

https://code.launchpad.net/~axwalk/juju-core/lp1206195-mock-deployer-init-dir/+merge/205907

(do not edit description out of merge proposal)

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

Affected files (+21, -2 lines):
   [revision details]
   cmd/jujud/machine_test.go
   cmd/jujud/main_test.go
   worker/deployer/simple.go

Index: [revision details]
=== 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-20140212024202-e5i2ten0rh1ph2d2
+New revision: <email address hidden>

Index: cmd/jujud/machine_test.go
=== modified file 'cmd/jujud/machine_test.go'
--- cmd/jujud/machine_test.go 2014-01-31 05:38:42 +0000
+++ cmd/jujud/machine_test.go 2014-02-12 07:24:47 +0000
@@ -181,7 +181,6 @@
  }

  func (s *MachineSuite) TestDyingMachine(c *gc.C) {
- c.Skip("Disabled as breaks test isolation somehow, see lp:1206195")
   m, _, _ := s.primeAgent(c, state.JobHostUnits)
   a := s.newAgent(c, m)
   done := make(chan error)

Index: cmd/jujud/main_test.go
=== modified file 'cmd/jujud/main_test.go'
--- cmd/jujud/main_test.go 2014-01-14 05:33:34 +0000
+++ cmd/jujud/main_test.go 2014-02-12 07:24:47 +0000
@@ -20,11 +20,20 @@
   "launchpad.net/juju-core/cmd"
   "launchpad.net/juju-core/environs"
   "launchpad.net/juju-core/testing"
+ "launchpad.net/juju-core/worker/deployer"
   "launchpad.net/juju-core/worker/uniter/jujuc"
  )

  var caCertFile string

+func mkdtemp(prefix string) string {
+ d, err := ioutil.TempDir("", prefix)
+ if err != nil {
+ panic(err)
+ }
+ return d
+}
+
  func mktemp(prefix string, content string) string {
   f, err := ioutil.TempFile("", prefix)
   if err != nil {
@@ -39,6 +48,11 @@
  }

  func TestPackage(t *stdtesting.T) {
+ // Change the default init dir in worker/deployer,
+ // so the deployer doesn't try to remove upstart
+ // jobs from tests.
+ deployer.InitDir = mkdtemp("juju-worker-deployer")
+
   // Change the path to "juju-run", so that the
   // tests don't try to write to /usr/local/bin.
   jujuRun = mktemp("juju-run", "")

Index: worker/deployer/simple.go
=== modified file 'worker/deployer/simple.go'
--- worker/deployer/simple.go 2014-01-22 22:48:54 +0000
+++ worker/deployer/simple.go 2014-02-12 07:24:47 +0000
@@ -21,6 +21,10 @@
   "launchpad.net/juju-core/version"
  )

+// InitDir is the default upstart init directory.
+// This is a var so it can be overridden by tests.
+var InitDir = "/etc/init"
+
  // APICalls defines the interface to the API that the simple context needs.
  type APICalls interface {
   ConnectionInfo() (params.DeployerConnectionValues, error)
@@ -65,7 +69,7 @@
   return &SimpleContext{
    api: api,
    agentConfig: agentConfig,...

Read more...

Revision history for this message
Dimiter Naydenov (dimitern) wrote :

Please repropose, the diff is missing.

https://codereview.appspot.com/61610044/

Revision history for this message
Andrew Wilkins (axwalk) wrote :
Revision history for this message
William Reade (fwereade) wrote :

LGTM with suggested tweak.

https://codereview.appspot.com/61610044/diff/20001/cmd/jujud/main_test.go
File cmd/jujud/main_test.go (right):

https://codereview.appspot.com/61610044/diff/20001/cmd/jujud/main_test.go#newcode54
cmd/jujud/main_test.go:54: deployer.InitDir =
mkdtemp("juju-worker-deployer")
This is a bit of a big hammer, but I guess at least it will continue to
work as the tests change. Just to guard against thoughtless future
refactorings, though, please use testbase.PatchValue and defer a
restore.

https://codereview.appspot.com/61610044/

Revision history for this message
Andrew Wilkins (axwalk) wrote :

Please take a look.

https://codereview.appspot.com/61610044/diff/20001/cmd/jujud/main_test.go
File cmd/jujud/main_test.go (right):

https://codereview.appspot.com/61610044/diff/20001/cmd/jujud/main_test.go#newcode54
cmd/jujud/main_test.go:54: deployer.InitDir =
mkdtemp("juju-worker-deployer")
On 2014/02/17 10:04:11, fwereade wrote:
> This is a bit of a big hammer, but I guess at least it will continue
to work as
> the tests change. Just to guard against thoughtless future
refactorings, though,
> please use testbase.PatchValue and defer a restore.

Done.

https://codereview.appspot.com/61610044/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cmd/jujud/machine_test.go'
2--- cmd/jujud/machine_test.go 2014-01-31 05:38:42 +0000
3+++ cmd/jujud/machine_test.go 2014-02-18 02:41:56 +0000
4@@ -181,7 +181,6 @@
5 }
6
7 func (s *MachineSuite) TestDyingMachine(c *gc.C) {
8- c.Skip("Disabled as breaks test isolation somehow, see lp:1206195")
9 m, _, _ := s.primeAgent(c, state.JobHostUnits)
10 a := s.newAgent(c, m)
11 done := make(chan error)
12
13=== modified file 'cmd/jujud/main_test.go'
14--- cmd/jujud/main_test.go 2014-01-14 05:33:34 +0000
15+++ cmd/jujud/main_test.go 2014-02-18 02:41:56 +0000
16@@ -20,11 +20,21 @@
17 "launchpad.net/juju-core/cmd"
18 "launchpad.net/juju-core/environs"
19 "launchpad.net/juju-core/testing"
20+ "launchpad.net/juju-core/testing/testbase"
21+ "launchpad.net/juju-core/worker/deployer"
22 "launchpad.net/juju-core/worker/uniter/jujuc"
23 )
24
25 var caCertFile string
26
27+func mkdtemp(prefix string) string {
28+ d, err := ioutil.TempDir("", prefix)
29+ if err != nil {
30+ panic(err)
31+ }
32+ return d
33+}
34+
35 func mktemp(prefix string, content string) string {
36 f, err := ioutil.TempFile("", prefix)
37 if err != nil {
38@@ -39,6 +49,12 @@
39 }
40
41 func TestPackage(t *stdtesting.T) {
42+ // Change the default init dir in worker/deployer,
43+ // so the deployer doesn't try to remove upstart
44+ // jobs from tests.
45+ restore := testbase.PatchValue(&deployer.InitDir, mkdtemp("juju-worker-deployer"))
46+ defer restore()
47+
48 // Change the path to "juju-run", so that the
49 // tests don't try to write to /usr/local/bin.
50 jujuRun = mktemp("juju-run", "")
51
52=== modified file 'worker/deployer/simple.go'
53--- worker/deployer/simple.go 2014-01-22 22:48:54 +0000
54+++ worker/deployer/simple.go 2014-02-18 02:41:56 +0000
55@@ -21,6 +21,10 @@
56 "launchpad.net/juju-core/version"
57 )
58
59+// InitDir is the default upstart init directory.
60+// This is a var so it can be overridden by tests.
61+var InitDir = "/etc/init"
62+
63 // APICalls defines the interface to the API that the simple context needs.
64 type APICalls interface {
65 ConnectionInfo() (params.DeployerConnectionValues, error)
66@@ -65,7 +69,7 @@
67 return &SimpleContext{
68 api: api,
69 agentConfig: agentConfig,
70- initDir: "/etc/init",
71+ initDir: InitDir,
72 logDir: "/var/log/juju",
73 }
74 }

Subscribers

People subscribed via source and target branches

to status/vote changes: