Merge lp:~thumper/juju-core/better-local-destroy-environ 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: 2472
Proposed branch: lp:~thumper/juju-core/better-local-destroy-environ
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 235 lines (+90/-25)
4 files modified
provider/local/config_test.go (+1/-2)
provider/local/environ.go (+7/-0)
provider/local/environ_test.go (+81/-15)
provider/local/export_test.go (+1/-8)
To merge this branch: bzr merge lp:~thumper/juju-core/better-local-destroy-environ
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+212544@code.launchpad.net

Commit message

Local provider destroy removes upstart scripts forcibly.

During the force destroy part, forcibly remove the
mongo and machine agent upstart scripts.

Tests are added to show that these are removed.
A drive by test was added to show that the containers
are destroyed too.

https://codereview.appspot.com/79690043/

Description of the change

Add some tests for local provider destroy

During the force destroy part, forcably remove the
mongo and machine agent upstart scripts.

Tests are added to show that these are removed.
A drive by test was added to show that the containers
are destroyed too.

https://codereview.appspot.com/79690043/

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

Reviewers: mp+212544_code.launchpad.net,

Message:
Please take a look.

Description:
Add some tests for local provider destroy

During the force destroy part, forcably remove the
mongo and machine agent upstart scripts.

Tests are added to show that these are removed.
A drive by test was added to show that the containers
are destroyed too.

https://code.launchpad.net/~thumper/juju-core/better-local-destroy-environ/+merge/212544

(do not edit description out of merge proposal)

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

Affected files (+95, -25 lines):
   A [revision details]
   M provider/local/config_test.go
   M provider/local/environ.go
   M provider/local/environ_test.go
   M provider/local/export_test.go

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

On 2014/03/25 04:19:53, thumper wrote:
> Please take a look.

Lovely, LGTM.

https://codereview.appspot.com/79690043/

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

Oops, meant to mail this

https://codereview.appspot.com/79690043/diff/1/provider/local/environ.go
File provider/local/environ.go (right):

https://codereview.appspot.com/79690043/diff/1/provider/local/environ.go#newcode443
provider/local/environ.go:443: // Stop the mongo database. It's possible
that the service
// Stop the mongo database and machine agent. It's possible ...

?

https://codereview.appspot.com/79690043/

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

On 2014/03/25 04:29:55, axw wrote:
> Oops, meant to mail this

https://codereview.appspot.com/79690043/diff/1/provider/local/environ.go
> File provider/local/environ.go (right):

https://codereview.appspot.com/79690043/diff/1/provider/local/environ.go#newcode443
> provider/local/environ.go:443: // Stop the mongo database. It's
possible that
> the service
> // Stop the mongo database and machine agent. It's possible ...

> ?

Done.

https://codereview.appspot.com/79690043/

Revision history for this message
Go Bot (go-bot) wrote :
Download full text (9.7 KiB)

The attempt to merge lp:~thumper/juju-core/better-local-destroy-environ into lp:juju-core failed. Below is the output from the failed tests.

ok launchpad.net/juju-core 0.019s
ok launchpad.net/juju-core/agent 1.037s
ok launchpad.net/juju-core/agent/mongo 0.607s
ok launchpad.net/juju-core/agent/tools 0.184s
ok launchpad.net/juju-core/bzr 5.184s
ok launchpad.net/juju-core/cert 2.875s
ok launchpad.net/juju-core/charm 0.419s
? launchpad.net/juju-core/charm/hooks [no test files]
? launchpad.net/juju-core/charm/testing [no test files]
ok launchpad.net/juju-core/cloudinit 0.030s
ok launchpad.net/juju-core/cloudinit/sshinit 0.757s
ok launchpad.net/juju-core/cmd 0.164s
ok launchpad.net/juju-core/cmd/charm-admin 0.759s
? launchpad.net/juju-core/cmd/charmd [no test files]
? launchpad.net/juju-core/cmd/charmload [no test files]
ok launchpad.net/juju-core/cmd/juju 200.061s
ok launchpad.net/juju-core/cmd/jujud 63.958s
ok launchpad.net/juju-core/cmd/plugins/juju-metadata 8.824s
? launchpad.net/juju-core/cmd/plugins/juju-restore [no test files]
ok launchpad.net/juju-core/cmd/plugins/local 0.158s
? launchpad.net/juju-core/cmd/plugins/local/juju-local [no test files]
ok launchpad.net/juju-core/constraints 0.026s
ok launchpad.net/juju-core/container 0.052s
ok launchpad.net/juju-core/container/factory 0.046s
ok launchpad.net/juju-core/container/kvm 0.232s
ok launchpad.net/juju-core/container/kvm/mock 0.053s
? launchpad.net/juju-core/container/kvm/testing [no test files]
ok launchpad.net/juju-core/container/lxc 4.316s
? launchpad.net/juju-core/container/lxc/mock [no test files]
? launchpad.net/juju-core/container/lxc/testing [no test files]
? launchpad.net/juju-core/container/testing [no test files]
ok launchpad.net/juju-core/downloader 5.213s
ok launchpad.net/juju-core/environs 2.354s
ok launchpad.net/juju-core/environs/bootstrap 10.152s
ok launchpad.net/juju-core/environs/cloudinit 0.441s
ok launchpad.net/juju-core/environs/config 2.806s
ok launchpad.net/juju-core/environs/configstore 0.036s
ok launchpad.net/juju-core/environs/filestorage 0.026s
ok launchpad.net/juju-core/environs/httpstorage 0.744s
ok launchpad.net/juju-core/environs/imagemetadata 0.433s
? launchpad.net/juju-core/environs/imagemetadata/testing [no test files]
ok launchpad.net/juju-core/environs/instances 0.051s
ok launchpad.net/juju-core/environs/jujutest 0.154s
ok launchpad.net/juju-core/environs/manual 14.050s
ok launchpad.net/juju-core/environs/simplestreams 0.265s
? launchpad.net/juju-core/environs/simplestreams/testing [no test files]
ok launchpad.net/juju-core/environs/sshstorage 0.880s
ok launchpad.net/juju-core/environs/storage 0.841s
ok launchpad.net/juju-core/environs/sync 43.653s
ok launchpad.net/juju-core/environs/testing 0.171s
ok launchpad.net/juju-core/environs/tools 4.443s
? launchpad.net/juju-core/environs/tools/testing [no test files]
ok launchpad.net/juju-core/errors 0.010s
ok launchpad.net/juju-core/instance 0.018s
? launchpad.net/juju-core/instance/testing [no test files]
ok launchpad.net/juju-core/juju 18.047s
ok launchpad.net/juju-core/juju/arch...

Read more...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'provider/local/config_test.go'
2--- provider/local/config_test.go 2014-02-13 02:46:58 +0000
3+++ provider/local/config_test.go 2014-03-25 06:20:24 +0000
4@@ -106,8 +106,7 @@
5 }
6
7 func (s *configSuite) TestBootstrapAsRoot(c *gc.C) {
8- restore := local.SetRootCheckFunction(func() bool { return true })
9- defer restore()
10+ s.PatchValue(local.CheckIfRoot, func() bool { return true })
11 env, err := local.Provider.Prepare(testing.Context(c), minimalConfig(c))
12 c.Assert(err, gc.IsNil)
13 err = env.Bootstrap(testing.Context(c), constraints.Value{})
14
15=== modified file 'provider/local/environ.go'
16--- provider/local/environ.go 2014-03-25 02:46:17 +0000
17+++ provider/local/environ.go 2014-03-25 06:20:24 +0000
18@@ -39,6 +39,7 @@
19 "launchpad.net/juju-core/state"
20 "launchpad.net/juju-core/state/api"
21 "launchpad.net/juju-core/state/api/params"
22+ "launchpad.net/juju-core/upstart"
23 "launchpad.net/juju-core/utils/shell"
24 "launchpad.net/juju-core/version"
25 "launchpad.net/juju-core/worker/terminationworker"
26@@ -439,6 +440,12 @@
27 }
28 }
29 }
30+ // Stop the mongo database and machine agent. It's possible that the
31+ // service doesn't exist or is not running, so don't check the error.
32+ upstart.NewService(env.mongoServiceName()).StopAndRemove()
33+ upstart.NewService(env.machineAgentServiceName()).StopAndRemove()
34+
35+ // Finally, remove the data-dir.
36 if err := os.RemoveAll(env.config.rootDir()); err != nil && !os.IsNotExist(err) {
37 return err
38 }
39
40=== modified file 'provider/local/environ_test.go'
41--- provider/local/environ_test.go 2014-03-25 02:46:17 +0000
42+++ provider/local/environ_test.go 2014-03-25 06:20:24 +0000
43@@ -4,6 +4,7 @@
44 package local_test
45
46 import (
47+ "fmt"
48 "io/ioutil"
49 "os"
50 "path/filepath"
51@@ -14,6 +15,9 @@
52
53 coreCloudinit "launchpad.net/juju-core/cloudinit"
54 "launchpad.net/juju-core/constraints"
55+ "launchpad.net/juju-core/container"
56+ "launchpad.net/juju-core/container/lxc"
57+ containertesting "launchpad.net/juju-core/container/testing"
58 "launchpad.net/juju-core/environs"
59 "launchpad.net/juju-core/environs/cloudinit"
60 "launchpad.net/juju-core/environs/config"
61@@ -25,6 +29,7 @@
62 "launchpad.net/juju-core/provider/local"
63 "launchpad.net/juju-core/state/api/params"
64 coretesting "launchpad.net/juju-core/testing"
65+ "launchpad.net/juju-core/upstart"
66 )
67
68 const echoCommandScript = "#!/bin/sh\necho $0 \"$@\" >> $0.args"
69@@ -93,7 +98,6 @@
70 type localJujuTestSuite struct {
71 baseProviderSuite
72 jujutest.Tests
73- restoreRootCheck func()
74 oldUpstartLocation string
75 testPath string
76 dbServiceName string
77@@ -115,17 +119,20 @@
78
79 // Add in an admin secret
80 s.Tests.TestConfig["admin-secret"] = "sekrit"
81- s.restoreRootCheck = local.SetRootCheckFunction(func() bool { return false })
82+ s.PatchValue(local.CheckIfRoot, func() bool { return false })
83 s.Tests.SetUpTest(c)
84
85 cfg, err := config.New(config.NoDefaults, s.TestConfig)
86 c.Assert(err, gc.IsNil)
87 s.dbServiceName = "juju-db-" + local.ConfigNamespace(cfg)
88+
89+ s.PatchValue(local.FinishBootstrap, func(mcfg *cloudinit.MachineConfig, cloudcfg *coreCloudinit.Config, ctx environs.BootstrapContext) error {
90+ return nil
91+ })
92 }
93
94 func (s *localJujuTestSuite) TearDownTest(c *gc.C) {
95 s.Tests.TearDownTest(c)
96- s.restoreRootCheck()
97 s.baseProviderSuite.TearDownTest(c)
98 }
99
100@@ -179,9 +186,6 @@
101 }
102
103 func (s *localJujuTestSuite) TestDestroy(c *gc.C) {
104- s.PatchValue(local.FinishBootstrap, func(mcfg *cloudinit.MachineConfig, cloudcfg *coreCloudinit.Config, ctx environs.BootstrapContext) error {
105- return nil
106- })
107 env := s.testBootstrap(c, minimalConfig(c))
108 err := env.Destroy()
109 // Succeeds because there's no "agents" directory,
110@@ -191,16 +195,17 @@
111 c.Assert(s.fakesudo+".args", jc.DoesNotExist)
112 }
113
114-func (s *localJujuTestSuite) TestDestroyCallSudo(c *gc.C) {
115- s.PatchValue(local.FinishBootstrap, func(mcfg *cloudinit.MachineConfig, cloudcfg *coreCloudinit.Config, ctx environs.BootstrapContext) error {
116- return nil
117- })
118- env := s.testBootstrap(c, minimalConfig(c))
119+func (s *localJujuTestSuite) makeAgentsDir(c *gc.C, env environs.Environ) {
120 rootDir := env.Config().AllAttrs()["root-dir"].(string)
121 agentsDir := filepath.Join(rootDir, "agents")
122 err := os.Mkdir(agentsDir, 0755)
123 c.Assert(err, gc.IsNil)
124- err = env.Destroy()
125+}
126+
127+func (s *localJujuTestSuite) TestDestroyCallSudo(c *gc.C) {
128+ env := s.testBootstrap(c, minimalConfig(c))
129+ s.makeAgentsDir(c, env)
130+ err := env.Destroy()
131 c.Assert(err, gc.IsNil)
132 data, err := ioutil.ReadFile(s.fakesudo + ".args")
133 c.Assert(err, gc.IsNil)
134@@ -217,10 +222,71 @@
135 c.Assert(string(data), gc.Equals, strings.Join(expected, " ")+"\n")
136 }
137
138+func (s *localJujuTestSuite) makeFakeUpstartScripts(c *gc.C, env environs.Environ,
139+) (mongo *upstart.Service, machineAgent *upstart.Service) {
140+ upstartDir := c.MkDir()
141+ s.PatchValue(&upstart.InitDir, upstartDir)
142+ s.MakeTool(c, "start", `echo "some-service start/running, process 123"`)
143+
144+ namespace := env.Config().AllAttrs()["namespace"].(string)
145+ mongo = upstart.NewService(fmt.Sprintf("juju-db-%s", namespace))
146+ mongoConf := upstart.Conf{
147+ Service: *mongo,
148+ Desc: "fake mongo",
149+ Cmd: "echo FAKE",
150+ }
151+ err := mongoConf.Install()
152+ c.Assert(err, gc.IsNil)
153+ c.Assert(mongo.Installed(), jc.IsTrue)
154+
155+ machineAgent = upstart.NewService(fmt.Sprintf("juju-agent-%s", namespace))
156+ agentConf := upstart.Conf{
157+ Service: *machineAgent,
158+ Desc: "fake agent",
159+ Cmd: "echo FAKE",
160+ }
161+ err = agentConf.Install()
162+ c.Assert(err, gc.IsNil)
163+ c.Assert(machineAgent.Installed(), jc.IsTrue)
164+
165+ return mongo, machineAgent
166+}
167+
168+func (s *localJujuTestSuite) TestDestroyRemovesUpstartServices(c *gc.C) {
169+ env := s.testBootstrap(c, minimalConfig(c))
170+ s.makeAgentsDir(c, env)
171+ mongo, machineAgent := s.makeFakeUpstartScripts(c, env)
172+ s.PatchValue(local.CheckIfRoot, func() bool { return true })
173+
174+ err := env.Destroy()
175+ c.Assert(err, gc.IsNil)
176+
177+ c.Assert(mongo.Installed(), jc.IsFalse)
178+ c.Assert(machineAgent.Installed(), jc.IsFalse)
179+}
180+
181+func (s *localJujuTestSuite) TestDestroyRemovesContainers(c *gc.C) {
182+ env := s.testBootstrap(c, minimalConfig(c))
183+ s.makeAgentsDir(c, env)
184+ s.PatchValue(local.CheckIfRoot, func() bool { return true })
185+
186+ namespace := env.Config().AllAttrs()["namespace"].(string)
187+ manager, err := lxc.NewContainerManager(container.ManagerConfig{
188+ container.ConfigName: namespace,
189+ container.ConfigLogDir: "logdir",
190+ })
191+ c.Assert(err, gc.IsNil)
192+
193+ machine1 := containertesting.CreateContainer(c, manager, "1")
194+
195+ err = env.Destroy()
196+ c.Assert(err, gc.IsNil)
197+
198+ container := s.Factory.New(string(machine1.Id()))
199+ c.Assert(container.IsConstructed(), jc.IsFalse)
200+}
201+
202 func (s *localJujuTestSuite) TestBootstrapRemoveLeftovers(c *gc.C) {
203- s.PatchValue(local.FinishBootstrap, func(mcfg *cloudinit.MachineConfig, cloudcfg *coreCloudinit.Config, ctx environs.BootstrapContext) error {
204- return nil
205- })
206 cfg := minimalConfig(c)
207 rootDir := cfg.AllAttrs()["root-dir"].(string)
208
209
210=== modified file 'provider/local/export_test.go'
211--- provider/local/export_test.go 2014-03-18 15:43:41 +0000
212+++ provider/local/export_test.go 2014-03-25 06:20:24 +0000
213@@ -10,6 +10,7 @@
214 )
215
216 var (
217+ CheckIfRoot = &checkIfRoot
218 CheckLocalPort = &checkLocalPort
219 DetectAptProxies = &detectAptProxies
220 FinishBootstrap = &finishBootstrap
221@@ -19,14 +20,6 @@
222 UserCurrent = &userCurrent
223 )
224
225-// SetRootCheckFunction allows tests to override the check for a root user.
226-// The return value is the function to restore the old value.
227-func SetRootCheckFunction(f func() bool) func() {
228- old := checkIfRoot
229- checkIfRoot = f
230- return func() { checkIfRoot = old }
231-}
232-
233 // ConfigNamespace returns the result of the namespace call on the
234 // localConfig.
235 func ConfigNamespace(cfg *config.Config) string {

Subscribers

People subscribed via source and target branches

to status/vote changes: