Merge lp:~natefinch/juju-core/034-juju-mongo into lp:~go-bot/juju-core/trunk

Proposed by Nate Finch
Status: Merged
Approved by: Nate Finch
Approved revision: no longer in the source branch.
Merged at revision: 2347
Proposed branch: lp:~natefinch/juju-core/034-juju-mongo
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 349 lines (+161/-27)
5 files modified
environs/cloudinit/cloudinit_test.go (+5/-1)
provider/local/prereqs.go (+36/-12)
provider/local/prereqs_test.go (+82/-13)
upstart/service.go (+18/-1)
upstart/upstart_test.go (+20/-0)
To merge this branch: bzr merge lp:~natefinch/juju-core/034-juju-mongo
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+207320@code.launchpad.net

Commit message

use juju-mongod if it exists

Description of the change

use juju-mongod if it exists

https://codereview.appspot.com/66230043/

To post a comment you must log in.
Revision history for this message
Nate Finch (natefinch) wrote :

Reviewers: mp+207320_code.launchpad.net,

Message:
Please take a look.

Description:
use juju-mongod if it exists

https://code.launchpad.net/~natefinch/juju-core/034-juju-mongo/+merge/207320

(do not edit description out of merge proposal)

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

Affected files (+162, -26 lines):
   A [revision details]
   M provider/local/prereqs.go
   M provider/local/prereqs_test.go
   A upstart/export_test.go
   M upstart/service.go
   M upstart/upstart_test.go

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

I think this looks good (modulo needing to actually install
juju-mongodb, bu I understand that's a distinct CL), but I'd like
another pair of eyes too please.

https://codereview.appspot.com/66230043/diff/1/provider/local/prereqs.go
File provider/local/prereqs.go (left):

https://codereview.appspot.com/66230043/diff/1/provider/local/prereqs.go#oldcode90
provider/local/prereqs.go:90: // TODO(axw) verify version/SSL
capabilities
Remind me: what's the latest story on SSL support? did we finally get it
compiled into all the mongos we might use?

https://codereview.appspot.com/66230043/diff/1/upstart/service.go
File upstart/service.go (right):

https://codereview.appspot.com/66230043/diff/1/upstart/service.go#newcode31
upstart/service.go:31: return "mongod"
I has a nervous about changes. Does life get any better if we use the
result of `which mongod`?

https://codereview.appspot.com/66230043/diff/1/upstart/service.go#newcode32
upstart/service.go:32: }
Also, I remain twitchy about mixing the juju-specific bits into the
supposedly-generic upstart package. Is this a simple enough CL that we
could move them out?

https://codereview.appspot.com/66230043/

Revision history for this message
Nate Finch (natefinch) wrote :

https://codereview.appspot.com/66230043/diff/1/provider/local/prereqs.go
File provider/local/prereqs.go (left):

https://codereview.appspot.com/66230043/diff/1/provider/local/prereqs.go#oldcode90
provider/local/prereqs.go:90: // TODO(axw) verify version/SSL
capabilities
On 2014/02/20 10:03:15, fwereade wrote:
> Remind me: what's the latest story on SSL support? did we finally get
it
> compiled into all the mongos we might use?

Good question, I don't know.

https://codereview.appspot.com/66230043/diff/1/upstart/service.go
File upstart/service.go (right):

https://codereview.appspot.com/66230043/diff/1/upstart/service.go#newcode31
upstart/service.go:31: return "mongod"
On 2014/02/20 10:03:15, fwereade wrote:
> I has a nervous about changes. Does life get any better if we use the
result of
> `which mongod`?

That's what I wrote first, but the problem is, many tests overwrite
$PATH in order to isolate themselves, and then this code can't find
"which" to run it. I suppose I could hardcode the location of "which"
to /usr/bin/which ... but I figured the only diffference between running
the results of which mongod and just running "mongod" is that the former
just hardcodes whatever mongod existed at the time, and the latter uses
whatever is first in the path when upstart runs. I don't know which is
worse.

https://codereview.appspot.com/66230043/diff/1/upstart/service.go#newcode32
upstart/service.go:32: }
On 2014/02/20 10:03:15, fwereade wrote:
> Also, I remain twitchy about mixing the juju-specific bits into the
> supposedly-generic upstart package. Is this a simple enough CL that we
could
> move them out?

Absolutely. I actually put them here on purpose so someone would
complain and tell me where a better place would be. Keep in mind this
method is called both by upstart and the local provider.

https://codereview.appspot.com/66230043/

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

LGTM with a few suggestions below.

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

https://codereview.appspot.com/66230043/diff/1/provider/local/prereqs.go#newcode94
provider/local/prereqs.go:94: " Juju requires version %v or greater.",
s/" Juju/"Juju/ - no need for the extra space in here where there's
another in the previous line.

https://codereview.appspot.com/66230043/diff/1/provider/local/prereqs.go#newcode113
provider/local/prereqs.go:113: return version.Zero, errors.New("Couldn't
parse version")
s/Couldn't parse version/Could not parse mongod version/ - slightly
better and clearer I think.

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

https://codereview.appspot.com/66230043/diff/1/provider/local/prereqs_test.go#newcode129
provider/local/prereqs_test.go:129: c.Assert(err, gc.NotNil)
Check the actual error message?

https://codereview.appspot.com/66230043/diff/1/upstart/export_test.go
File upstart/export_test.go (right):

https://codereview.appspot.com/66230043/diff/1/upstart/export_test.go#newcode3
upstart/export_test.go:3: package upstart
Blank line before the package line. Also no need for 2013 in the
copyright.

https://codereview.appspot.com/66230043/diff/1/upstart/service.go
File upstart/service.go (right):

https://codereview.appspot.com/66230043/diff/1/upstart/service.go#newcode22
upstart/service.go:22: // MongoPath returns the executable path to be
used to run mongod on this machine.
// MongodPath ... (to match the func name). Also s/the executable//.
Actually, I'd prefer if you called this MongoDPath, so it matches the
SetMongoDPath from export_test.

https://codereview.appspot.com/66230043/diff/1/upstart/upstart_test.go
File upstart/upstart_test.go (right):

https://codereview.appspot.com/66230043/diff/1/upstart/upstart_test.go#newcode260
upstart/upstart_test.go:260: defer os.Remove(d)
os.RemoveAll(d) instead?

https://codereview.appspot.com/66230043/

Revision history for this message
Nate Finch (natefinch) wrote :

Please take a look.

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

https://codereview.appspot.com/66230043/diff/1/provider/local/prereqs.go#newcode94
provider/local/prereqs.go:94: " Juju requires version %v or greater.",
On 2014/02/20 16:41:56, dimitern wrote:
> s/" Juju/"Juju/ - no need for the extra space in here where there's
another in
> the previous line.

Done.

https://codereview.appspot.com/66230043/diff/1/provider/local/prereqs.go#newcode113
provider/local/prereqs.go:113: return version.Zero, errors.New("Couldn't
parse version")
On 2014/02/20 16:41:56, dimitern wrote:
> s/Couldn't parse version/Could not parse mongod version/ - slightly
better and
> clearer I think.

Done.

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

https://codereview.appspot.com/66230043/diff/1/provider/local/prereqs_test.go#newcode129
provider/local/prereqs_test.go:129: c.Assert(err, gc.NotNil)
On 2014/02/20 16:41:56, dimitern wrote:
> Check the actual error message?

Done.

https://codereview.appspot.com/66230043/diff/1/upstart/service.go
File upstart/service.go (right):

https://codereview.appspot.com/66230043/diff/1/upstart/service.go#newcode22
upstart/service.go:22: // MongoPath returns the executable path to be
used to run mongod on this machine.
On 2014/02/20 16:41:56, dimitern wrote:
> // MongodPath ... (to match the func name). Also s/the executable//.
> Actually, I'd prefer if you called this MongoDPath, so it matches the
> SetMongoDPath from export_test.

I removed the SetMongoDPath function since I needed to be able to set it
from outside the package too (for local provider tests)..... and I think
the capital d was a mistake anyway. The word should be all lowercase,
except for the first letter to make it public.

https://codereview.appspot.com/66230043/

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

The attempt to merge lp:~natefinch/juju-core/034-juju-mongo into lp:juju-core failed. Below is the output from the failed tests.

ok launchpad.net/juju-core 0.020s
ok launchpad.net/juju-core/agent 2.953s
ok launchpad.net/juju-core/agent/tools 0.446s
ok launchpad.net/juju-core/bzr 16.763s
ok launchpad.net/juju-core/cert 3.350s
ok launchpad.net/juju-core/charm 1.146s
? 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.049s
ok launchpad.net/juju-core/cloudinit/sshinit 1.399s
ok launchpad.net/juju-core/cmd 0.280s
ok launchpad.net/juju-core/cmd/charm-admin 0.959s
? 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 398.349s
[jujuc whatever]
[remote]
[/path/to/remote]
[remote --help]
[unknown]
[remote --error borken]
[remote --unknown]
[remote unwanted]

----------------------------------------------------------------------
FAIL: unit_test.go:240: UnitSuite.TestOpenStateFails

[LOG] 52.64466 DEBUG juju.environs.configstore Making /tmp/gocheck-1598098976185383115/6/home/ubuntu/.juju/environments
[LOG] 52.75078 DEBUG juju.environs.tools reading v1.* tools
[LOG] 52.75083 INFO juju environs/testing: uploading FAKE tools 1.17.3-precise-amd64
[LOG] 52.75176 DEBUG juju.environs.tools no architecture specified when finding tools, looking for any
[LOG] 52.75177 DEBUG juju.environs.tools no series specified when finding tools, looking for any
[LOG] 52.75183 DEBUG juju.environs.simplestreams fetchData failed for "tools/streams/v1/index.sjson": file "tools/streams/v1/index.sjson" not found not found
[LOG] 52.75184 DEBUG juju.environs.simplestreams cannot load index "streams/v1/index.sjson": invalid URL "tools/streams/v1/index.sjson" not found
[LOG] 52.75188 DEBUG juju.environs.simplestreams fetchData failed for "tools/streams/v1/index.json": file "tools/streams/v1/index.json" not found not found
[LOG] 52.75189 DEBUG juju.environs.simplestreams cannot load index "streams/v1/index.json": invalid URL "tools/streams/v1/index.json" not found
[LOG] 52.75213 INFO juju.environs.tools Writing tools/streams/v1/index.json
[LOG] 52.75219 INFO juju.environs.tools Writing tools/streams/v1/com.ubuntu.juju:released:tools.json
[LOG] 52.75224 INFO juju.environs.bootstrap bootstrapping environment "dummyenv"
[LOG] 52.75227 DEBUG juju.environs.bootstrap looking for bootstrap tools: series="precise", arch=<nil>, version=1.17.3
[LOG] 52.75228 INFO juju.environs.tools reading tools with major.minor version 1.17
[LOG] 52.75229 INFO juju.environs.tools filtering tools by version: 1.17.3
[LOG] 52.75230 INFO juju.environs.tools filtering tools by series: precise
[LOG] 52.75232 DEBUG juju.environs.tools no architecture specified when finding tools, looking for any
[LOG] 52.75235 DEBUG juju.environs.simplestreams fetchData failed for "tools/streams/v1/index.sjson": file "tools/streams/v1/index.sjson" not found not found
[LOG] 52.75237 DEBUG juju.environs.simplestreams cannot load index "streams/v1/index.sjson": invalid URL "tools/streams/v1/index.sjson" not found
[LOG] ...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'environs/cloudinit/cloudinit_test.go'
2--- environs/cloudinit/cloudinit_test.go 2014-02-20 15:03:08 +0000
3+++ environs/cloudinit/cloudinit_test.go 2014-02-21 17:13:58 +0000
4@@ -25,6 +25,7 @@
5 jc "launchpad.net/juju-core/testing/checkers"
6 "launchpad.net/juju-core/testing/testbase"
7 "launchpad.net/juju-core/tools"
8+ "launchpad.net/juju-core/upstart"
9 "launchpad.net/juju-core/version"
10 )
11
12@@ -56,6 +57,9 @@
13 return cfg
14 }
15
16+// mongodPath is the path where we should expect mongod in the environment.
17+var mongodPath = upstart.MongodPath()
18+
19 // Each test gives a cloudinit config - we check the
20 // output to see if it looks correct.
21 var cloudinitTests = []cloudinitTest{
22@@ -132,7 +136,7 @@
23 dd bs=1M count=1 if=/dev/zero of=/var/lib/juju/db/journal/prealloc\.1
24 dd bs=1M count=1 if=/dev/zero of=/var/lib/juju/db/journal/prealloc\.2
25 echo 'Starting MongoDB server \(juju-db\)'.*
26-cat >> /etc/init/juju-db\.conf << 'EOF'\\ndescription "juju state database"\\nauthor "Juju Team <juju@lists\.ubuntu\.com>"\\nstart on runlevel \[2345\]\\nstop on runlevel \[!2345\]\\nrespawn\\nnormal exit 0\\n\\nlimit nofile 65000 65000\\nlimit nproc 20000 20000\\n\\nexec /usr/bin/mongod --auth --dbpath=/var/lib/juju/db --sslOnNormalPorts --sslPEMKeyFile '/var/lib/juju/server\.pem' --sslPEMKeyPassword ignored --bind_ip 0\.0\.0\.0 --port 37017 --noprealloc --syslog --smallfiles\\nEOF\\n
27+cat >> /etc/init/juju-db\.conf << 'EOF'\\ndescription "juju state database"\\nauthor "Juju Team <juju@lists\.ubuntu\.com>"\\nstart on runlevel \[2345\]\\nstop on runlevel \[!2345\]\\nrespawn\\nnormal exit 0\\n\\nlimit nofile 65000 65000\\nlimit nproc 20000 20000\\n\\nexec ` + mongodPath + ` --auth --dbpath=/var/lib/juju/db --sslOnNormalPorts --sslPEMKeyFile '/var/lib/juju/server\.pem' --sslPEMKeyPassword ignored --bind_ip 0\.0\.0\.0 --port 37017 --noprealloc --syslog --smallfiles\\nEOF\\n
28 start juju-db
29 mkdir -p '/var/lib/juju/agents/bootstrap'
30 install -m 644 /dev/null '/var/lib/juju/agents/bootstrap/format'
31
32=== modified file 'provider/local/prereqs.go'
33--- provider/local/prereqs.go 2013-12-02 21:39:03 +0000
34+++ provider/local/prereqs.go 2014-02-21 17:13:58 +0000
35@@ -6,12 +6,13 @@
36 import (
37 "errors"
38 "fmt"
39- "os"
40 "os/exec"
41+ "regexp"
42 "runtime"
43
44 "launchpad.net/juju-core/container/kvm"
45 "launchpad.net/juju-core/instance"
46+ "launchpad.net/juju-core/upstart"
47 "launchpad.net/juju-core/utils"
48 "launchpad.net/juju-core/version"
49 )
50@@ -46,9 +47,8 @@
51 const errUnsupportedOS = `Unsupported operating system: %s
52 The local provider is currently only available for Linux`
53
54-// mongodPath is the path to "mongod", the MongoDB server.
55-// This is a variable only to support unit testing.
56-var mongodPath = "/usr/bin/mongod"
57+// lowestMongoVersion is the lowest version of mongo that juju supports.
58+var lowestMongoVersion = version.Number{Major: 2, Minor: 2, Patch: 4}
59
60 // lxclsPath is the path to "lxc-ls", an LXC userspace tool
61 // we check the presence of to determine whether the
62@@ -60,6 +60,9 @@
63 // This is a variable only to support unit testing.
64 var goos = runtime.GOOS
65
66+// This is the regex for processing the results of mongod --verison
67+var mongoVerRegex = regexp.MustCompile(`db version v(\d+\.\d+\.\d+)`)
68+
69 // VerifyPrerequisites verifies the prerequisites of
70 // the local machine (machine 0) for running the local
71 // provider.
72@@ -80,17 +83,38 @@
73 }
74
75 func verifyMongod() error {
76- if _, err := os.Stat(mongodPath); err != nil {
77- if os.IsNotExist(err) {
78- return wrapMongodNotExist(err)
79- } else {
80- return err
81- }
82- }
83- // TODO(axw) verify version/SSL capabilities
84+ path := upstart.MongodPath()
85+
86+ ver, err := mongodVersion(path)
87+ if err != nil {
88+ return err
89+ }
90+ if ver.Compare(lowestMongoVersion) < 0 {
91+ return fmt.Errorf("installed version of mongod (%v) is not supported by Juju. "+
92+ "Juju requires version %v or greater.",
93+ ver,
94+ lowestMongoVersion)
95+ }
96 return nil
97 }
98
99+func mongodVersion(path string) (version.Number, error) {
100+ data, err := utils.RunCommand(path, "--version")
101+ if err != nil {
102+ return version.Zero, wrapMongodNotExist(err)
103+ }
104+
105+ return parseVersion(data)
106+}
107+
108+func parseVersion(data string) (version.Number, error) {
109+ matches := mongoVerRegex.FindStringSubmatch(data)
110+ if len(matches) < 2 {
111+ return version.Zero, errors.New("could not parse mongod version")
112+ }
113+ return version.Parse(matches[1])
114+}
115+
116 func verifyLxc() error {
117 _, err := exec.LookPath(lxclsPath)
118 if err != nil {
119
120=== modified file 'provider/local/prereqs_test.go'
121--- provider/local/prereqs_test.go 2013-11-22 01:21:57 +0000
122+++ provider/local/prereqs_test.go 2014-02-21 17:13:58 +0000
123@@ -4,6 +4,7 @@
124 package local
125
126 import (
127+ "fmt"
128 "io/ioutil"
129 "os"
130 "path/filepath"
131@@ -12,12 +13,14 @@
132
133 "launchpad.net/juju-core/instance"
134 "launchpad.net/juju-core/testing/testbase"
135+ "launchpad.net/juju-core/upstart"
136+ "launchpad.net/juju-core/version"
137 )
138
139 type prereqsSuite struct {
140 testbase.LoggingSuite
141- tmpdir string
142- oldpath string
143+ tmpdir string
144+ testMongodPath string
145 }
146
147 var _ = gc.Suite(&prereqsSuite{})
148@@ -32,25 +35,25 @@
149 // all of the non-prereqs tests to pass
150 // even when mongodb and lxc-ls can't be
151 // found.
152- mongodPath = "/bin/true"
153 lxclsPath = "/bin/true"
154 }
155
156 func (s *prereqsSuite) SetUpTest(c *gc.C) {
157 s.LoggingSuite.SetUpTest(c)
158 s.tmpdir = c.MkDir()
159- s.oldpath = os.Getenv("PATH")
160- mongodPath = filepath.Join(s.tmpdir, "mongod")
161+ s.testMongodPath = filepath.Join(s.tmpdir, "mongod")
162 lxclsPath = filepath.Join(s.tmpdir, "lxc-ls")
163- os.Setenv("PATH", s.tmpdir)
164+ s.PatchEnvironment("PATH", s.tmpdir)
165+
166+ upstart.JujuMongodPath = "/somewhere/that/doesnt/exist"
167+
168 os.Setenv("JUJUTEST_LSB_RELEASE_ID", "Ubuntu")
169 err := ioutil.WriteFile(filepath.Join(s.tmpdir, "lsb_release"), []byte(lsbrelease), 0777)
170 c.Assert(err, gc.IsNil)
171 }
172
173 func (s *prereqsSuite) TearDownTest(c *gc.C) {
174- os.Setenv("PATH", s.oldpath)
175- mongodPath = "/bin/true"
176+ s.testMongodPath = ""
177 lxclsPath = "/bin/true"
178 s.LoggingSuite.TearDownTest(c)
179 }
180@@ -64,6 +67,72 @@
181 c.Assert(err, gc.ErrorMatches, "Unsupported operating system: windows(.|\n)*")
182 }
183
184+const fakeMongoFmt = `#!/bin/sh
185+echo db version v%d.%d.%d
186+echo Thu Feb 13 15:53:58.210 git version: b9925db5eac369d77a3a5f5d98a145eaaacd9673
187+`
188+
189+func (s *prereqsSuite) setMongoVersion(major, minor, patch int) {
190+ script := fmt.Sprintf(fakeMongoFmt, major, minor, patch)
191+ err := ioutil.WriteFile(s.testMongodPath, []byte(script), 0777)
192+
193+ if err != nil {
194+ panic(err)
195+ }
196+}
197+
198+func (s *prereqsSuite) TestParseMongoVersion(c *gc.C) {
199+ s.setMongoVersion(2, 2, 2)
200+
201+ ver, err := mongodVersion(s.testMongodPath)
202+ c.Assert(err, gc.IsNil)
203+ c.Assert(ver, gc.Equals, version.Number{2, 2, 2, 0})
204+}
205+
206+func (s *prereqsSuite) TestVerifyMongod(c *gc.C) {
207+ lowver := version.Number{2, 2, 2, 0}
208+ s.PatchValue(&lowestMongoVersion, lowver)
209+
210+ s.setMongoVersion(3, 0, 0)
211+ c.Assert(verifyMongod(), gc.IsNil)
212+
213+ s.setMongoVersion(2, 3, 0)
214+ c.Assert(verifyMongod(), gc.IsNil)
215+
216+ s.setMongoVersion(2, 2, 3)
217+ c.Assert(verifyMongod(), gc.IsNil)
218+
219+ s.setMongoVersion(2, 2, 2)
220+ c.Assert(verifyMongod(), gc.IsNil)
221+
222+ expected := fmt.Sprintf("installed version of mongod .* is not supported by Juju. "+
223+ "Juju requires version %v or greater.", lowver)
224+
225+ s.setMongoVersion(2, 2, 1)
226+ c.Assert(verifyMongod(), gc.ErrorMatches, expected)
227+
228+ s.setMongoVersion(2, 1, 3)
229+ c.Assert(verifyMongod(), gc.ErrorMatches, expected)
230+
231+ s.setMongoVersion(1, 3, 3)
232+ c.Assert(verifyMongod(), gc.ErrorMatches, expected)
233+}
234+
235+func (s *prereqsSuite) TestParseVersion(c *gc.C) {
236+ data := `
237+db version v3.2.1
238+Thu Feb 13 15:53:58.210 git version: b9925db5eac369d77a3a5f5d98a145eaaacd9673
239+`[1:]
240+ v, err := parseVersion(data)
241+ c.Assert(err, gc.IsNil)
242+ c.Assert(v, gc.Equals, version.Number{3, 2, 1, 0})
243+
244+ data = "this is total garbage"
245+ v, err = parseVersion(data)
246+ c.Assert(err, gc.ErrorMatches, "could not parse mongod version")
247+ c.Assert(v, gc.Equals, version.Zero)
248+}
249+
250 func (s *prereqsSuite) TestMongoPrereq(c *gc.C) {
251 err := VerifyPrerequisites(instance.LXC)
252 c.Assert(err, gc.ErrorMatches, "(.|\n)*MongoDB server must be installed(.|\n)*")
253@@ -74,8 +143,8 @@
254 c.Assert(err, gc.ErrorMatches, "(.|\n)*MongoDB server must be installed(.|\n)*")
255 c.Assert(err, gc.Not(gc.ErrorMatches), "(.|\n)*apt-get install(.|\n)*")
256
257- err = ioutil.WriteFile(mongodPath, nil, 0777)
258- c.Assert(err, gc.IsNil)
259+ s.PatchValue(&lowestMongoVersion, version.Number{2, 2, 2, 0})
260+ s.setMongoVersion(3, 0, 0)
261 err = ioutil.WriteFile(filepath.Join(s.tmpdir, "lxc-ls"), nil, 0777)
262 c.Assert(err, gc.IsNil)
263 err = VerifyPrerequisites(instance.LXC)
264@@ -83,10 +152,10 @@
265 }
266
267 func (s *prereqsSuite) TestLxcPrereq(c *gc.C) {
268- err := ioutil.WriteFile(mongodPath, nil, 0777)
269- c.Assert(err, gc.IsNil)
270+ s.PatchValue(&lowestMongoVersion, version.Number{2, 2, 2, 0})
271+ s.setMongoVersion(3, 0, 0)
272
273- err = VerifyPrerequisites(instance.LXC)
274+ err := VerifyPrerequisites(instance.LXC)
275 c.Assert(err, gc.ErrorMatches, "(.|\n)*Linux Containers \\(LXC\\) userspace tools must be\ninstalled(.|\n)*")
276 c.Assert(err, gc.ErrorMatches, "(.|\n)*apt-get install lxc(.|\n)*")
277
278
279=== modified file 'upstart/service.go'
280--- upstart/service.go 2013-11-19 08:53:40 +0000
281+++ upstart/service.go 2014-02-21 17:13:58 +0000
282@@ -5,6 +5,7 @@
283
284 import (
285 "fmt"
286+ "os"
287 "path"
288
289 "launchpad.net/juju-core/utils"
290@@ -15,6 +16,22 @@
291 maxAgentFiles = 20000
292 )
293
294+// JujuMongodPath is the path of the mongod that is bundled specifically for juju.
295+// This value is public only for testing purposes, please do not change.
296+var JujuMongodPath = "/usr/lib/juju/bin/mongod"
297+
298+// MongoPath returns the executable path to be used to run mongod on this machine.
299+// If the juju-bundled version of mongo exists, it will return that path, otherwise
300+// it will return the command to run mongod from the path.
301+func MongodPath() string {
302+ if _, err := os.Stat(JujuMongodPath); err == nil {
303+ return JujuMongodPath
304+ }
305+
306+ // just use whatever is in the path
307+ return "mongod"
308+}
309+
310 // MongoUpstartService returns the upstart config for the mongo state service.
311 func MongoUpstartService(name, dataDir, dbDir string, port int) *Conf {
312 keyFile := path.Join(dataDir, "server.pem")
313@@ -26,7 +43,7 @@
314 "nofile": fmt.Sprintf("%d %d", maxMongoFiles, maxMongoFiles),
315 "nproc": fmt.Sprintf("%d %d", maxAgentFiles, maxAgentFiles),
316 },
317- Cmd: "/usr/bin/mongod" +
318+ Cmd: MongodPath() +
319 " --auth" +
320 " --dbpath=" + dbDir +
321 " --sslOnNormalPorts" +
322
323=== modified file 'upstart/upstart_test.go'
324--- upstart/upstart_test.go 2014-02-18 17:08:55 +0000
325+++ upstart/upstart_test.go 2014-02-21 17:13:58 +0000
326@@ -254,3 +254,23 @@
327 c.Assert(err, gc.IsNil)
328 c.Assert(&conf.Service, jc.Satisfies, (*upstart.Service).Running)
329 }
330+
331+func (s *UpstartSuite) TestJujuMongodPath(c *gc.C) {
332+ d := c.MkDir()
333+ defer os.RemoveAll(d)
334+ mongoPath := filepath.Join(d, "mongod")
335+ upstart.JujuMongodPath = mongoPath
336+
337+ err := ioutil.WriteFile(mongoPath, []byte{}, 0777)
338+ c.Assert(err, gc.IsNil)
339+
340+ obtained := upstart.MongodPath()
341+ c.Assert(obtained, gc.Equals, mongoPath)
342+}
343+
344+func (s *UpstartSuite) TestDefaultMongodPath(c *gc.C) {
345+ upstart.JujuMongodPath = "/not/going/to/exist/mongod"
346+
347+ obtained := upstart.MongodPath()
348+ c.Assert(obtained, gc.Equals, "mongod")
349+}

Subscribers

People subscribed via source and target branches

to status/vote changes: