~ubuntu-branches/ubuntu/wily/juju-core/wily

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/provider/local/prereqs.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-02-28 16:53:15 UTC
  • mfrom: (1.1.19)
  • Revision ID: package-import@ubuntu.com-20140228165315-g8n1ds0jrtekhxq6
Tags: 1.17.4-0ubuntu1
* New upstream point release (LP: #1261628):
  - https://launchpad.net/juju-core/trunk/1.17.4
  - d/control: Prefer juju-mongodb over mongodb-server for juju-local
    package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
import (
7
7
        "errors"
8
8
        "fmt"
9
 
        "os"
10
9
        "os/exec"
 
10
        "regexp"
11
11
        "runtime"
12
12
 
13
13
        "launchpad.net/juju-core/container/kvm"
14
14
        "launchpad.net/juju-core/instance"
 
15
        "launchpad.net/juju-core/upstart"
15
16
        "launchpad.net/juju-core/utils"
16
17
        "launchpad.net/juju-core/version"
17
18
)
46
47
const errUnsupportedOS = `Unsupported operating system: %s
47
48
The local provider is currently only available for Linux`
48
49
 
49
 
// mongodPath is the path to "mongod", the MongoDB server.
50
 
// This is a variable only to support unit testing.
51
 
var mongodPath = "/usr/bin/mongod"
 
50
// lowestMongoVersion is the lowest version of mongo that juju supports.
 
51
var lowestMongoVersion = version.Number{Major: 2, Minor: 2, Patch: 4}
52
52
 
53
53
// lxclsPath is the path to "lxc-ls", an LXC userspace tool
54
54
// we check the presence of to determine whether the
60
60
// This is a variable only to support unit testing.
61
61
var goos = runtime.GOOS
62
62
 
 
63
// This is the regex for processing the results of mongod --verison
 
64
var mongoVerRegex = regexp.MustCompile(`db version v(\d+\.\d+\.\d+)`)
 
65
 
63
66
// VerifyPrerequisites verifies the prerequisites of
64
67
// the local machine (machine 0) for running the local
65
68
// provider.
80
83
}
81
84
 
82
85
func verifyMongod() error {
83
 
        if _, err := os.Stat(mongodPath); err != nil {
84
 
                if os.IsNotExist(err) {
85
 
                        return wrapMongodNotExist(err)
86
 
                } else {
87
 
                        return err
88
 
                }
89
 
        }
90
 
        // TODO(axw) verify version/SSL capabilities
 
86
        path := upstart.MongodPath()
 
87
 
 
88
        ver, err := mongodVersion(path)
 
89
        if err != nil {
 
90
                return err
 
91
        }
 
92
        if ver.Compare(lowestMongoVersion) < 0 {
 
93
                return fmt.Errorf("installed version of mongod (%v) is not supported by Juju. "+
 
94
                        "Juju requires version %v or greater.",
 
95
                        ver,
 
96
                        lowestMongoVersion)
 
97
        }
91
98
        return nil
92
99
}
93
100
 
 
101
func mongodVersion(path string) (version.Number, error) {
 
102
        data, err := utils.RunCommand(path, "--version")
 
103
        if err != nil {
 
104
                return version.Zero, wrapMongodNotExist(err)
 
105
        }
 
106
 
 
107
        return parseVersion(data)
 
108
}
 
109
 
 
110
func parseVersion(data string) (version.Number, error) {
 
111
        matches := mongoVerRegex.FindStringSubmatch(data)
 
112
        if len(matches) < 2 {
 
113
                return version.Zero, errors.New("could not parse mongod version")
 
114
        }
 
115
        return version.Parse(matches[1])
 
116
}
 
117
 
94
118
func verifyLxc() error {
95
119
        _, err := exec.LookPath(lxclsPath)
96
120
        if err != nil {