本文整理汇总了Golang中github.com/juju/juju/mongo.EnsureServer函数的典型用法代码示例。如果您正苦于以下问题:Golang EnsureServer函数的具体用法?Golang EnsureServer怎么用?Golang EnsureServer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了EnsureServer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestQuantalAptAddRepo
func (s *MongoSuite) TestQuantalAptAddRepo(c *gc.C) {
dir := c.MkDir()
// patch manager.RunCommandWithRetry for repository addition:
s.PatchValue(&manager.RunCommandWithRetry, func(string) (string, int, error) {
return "", 1, fmt.Errorf("packaging command failed: exit status 1")
})
s.PatchEnvPathPrepend(dir)
failCmd(filepath.Join(dir, "add-apt-repository"))
mockShellCommand(c, &s.CleanupSuite, "apt-get")
var tw loggo.TestWriter
c.Assert(loggo.RegisterWriter("test-writer", &tw, loggo.ERROR), jc.ErrorIsNil)
defer loggo.RemoveWriter("test-writer")
// test that we call add-apt-repository only for quantal
// (and that if it fails, we log the error)
s.PatchValue(&version.Current.Series, "quantal")
err := mongo.EnsureServer(makeEnsureServerParams(dir, ""))
c.Assert(err, jc.ErrorIsNil)
c.Assert(tw.Log(), jc.LogMatches, []jc.SimpleMessage{
{loggo.ERROR, `cannot install/upgrade mongod \(will proceed anyway\): packaging command failed`},
})
s.PatchValue(&manager.RunCommandWithRetry, func(string) (string, int, error) {
return "", 0, nil
})
s.PatchValue(&version.Current.Series, "trusty")
failCmd(filepath.Join(dir, "mongod"))
err = mongo.EnsureServer(makeEnsureServerParams(dir, ""))
c.Assert(err, jc.ErrorIsNil)
}
示例2: TestEnsureServer
func (s *MongoSuite) TestEnsureServer(c *gc.C) {
dataDir := c.MkDir()
dbDir := filepath.Join(dataDir, "db")
namespace := "namespace"
mockShellCommand(c, &s.CleanupSuite, "apt-get")
err := mongo.EnsureServer(makeEnsureServerParams(dataDir, namespace))
c.Assert(err, gc.IsNil)
testJournalDirs(dbDir, c)
assertInstalled := func() {
c.Assert(s.installed, gc.HasLen, 1)
conf := s.installed[0]
c.Assert(conf.Name, gc.Equals, "juju-db-namespace")
c.Assert(conf.InitDir, gc.Equals, "/etc/init")
c.Assert(conf.Desc, gc.Equals, "juju state database")
c.Assert(conf.Cmd, gc.Matches, regexp.QuoteMeta(s.mongodPath)+".*")
// TODO(nate) set Out so that mongod output goes somewhere useful?
c.Assert(conf.Out, gc.Equals, "")
}
assertInstalled()
contents, err := ioutil.ReadFile(s.mongodConfigPath)
c.Assert(err, gc.IsNil)
c.Assert(contents, jc.DeepEquals, []byte("ENABLE_MONGODB=no"))
contents, err = ioutil.ReadFile(mongo.SSLKeyPath(dataDir))
c.Assert(err, gc.IsNil)
c.Assert(string(contents), gc.Equals, testInfo.Cert+"\n"+testInfo.PrivateKey)
contents, err = ioutil.ReadFile(mongo.SharedSecretPath(dataDir))
c.Assert(err, gc.IsNil)
c.Assert(string(contents), gc.Equals, testInfo.SharedSecret)
s.installed = nil
// now check we can call it multiple times without error
err = mongo.EnsureServer(makeEnsureServerParams(dataDir, namespace))
c.Assert(err, gc.IsNil)
assertInstalled()
// make sure that we log the version of mongodb as we get ready to
// start it
tlog := c.GetTestLog()
any := `(.|\n)*`
start := "^" + any
tail := any + "$"
c.Assert(tlog, gc.Matches, start+`using mongod: .*/mongod --version: "db version v2\.4\.9`+tail)
}
示例3: TestQuantalAptAddRepo
func (s *MongoSuite) TestQuantalAptAddRepo(c *gc.C) {
dir := c.MkDir()
s.PatchEnvPathPrepend(dir)
failCmd(filepath.Join(dir, "add-apt-repository"))
mockShellCommand(c, &s.CleanupSuite, "apt-get")
// test that we call add-apt-repository only for quantal (and that if it
// fails, we return the error)
s.PatchValue(&version.Current.Series, "quantal")
err := mongo.EnsureServer(makeEnsureServerParams(dir, ""))
c.Assert(err, gc.ErrorMatches, "cannot install mongod: cannot add apt repository: exit status 1.*")
s.PatchValue(&version.Current.Series, "trusty")
err = mongo.EnsureServer(makeEnsureServerParams(dir, ""))
c.Assert(err, gc.IsNil)
}
示例4: TestAddPPAInQuantal
func (s *MongoSuite) TestAddPPAInQuantal(c *gc.C) {
testing.PatchExecutableAsEchoArgs(c, s, "apt-get")
testing.PatchExecutableAsEchoArgs(c, s, "add-apt-repository")
s.patchSeries("quantal")
dataDir := c.MkDir()
err := mongo.EnsureServer(makeEnsureServerParams(dataDir))
c.Assert(err, jc.ErrorIsNil)
pack := [][]string{
{
"install",
"python-software-properties",
}, {
"install",
"--target-release",
"mongodb-server",
},
}
noCommand := len(expectedArgs.AptGetBase) - 1
for k := range pack {
cmd := append(expectedArgs.AptGetBase[:noCommand], pack[k]...)
testing.AssertEchoArgs(c, "apt-get", cmd...)
}
match := []string{
"--yes",
"\"ppa:juju/stable\"",
}
testing.AssertEchoArgs(c, "add-apt-repository", match...)
}
示例5: assertTestMongoGetFails
func (s *MongoSuite) assertTestMongoGetFails(c *gc.C, series string, packageManager string) {
s.patchSeries(series)
// Any exit code from apt-get that isn't 0 or 100 will be treated
// as unexpected, skipping the normal retry loop. failCmd causes
// the command to exit with 1.
binDir := c.MkDir()
s.PatchEnvPathPrepend(binDir)
failCmd(filepath.Join(binDir, packageManager))
// Set the mongodb service as installed but not running.
s.data.SetStatus(mongo.ServiceName, "installed")
var tw loggo.TestWriter
c.Assert(loggo.RegisterWriter("test-writer", &tw, loggo.ERROR), jc.ErrorIsNil)
defer loggo.RemoveWriter("test-writer")
dataDir := c.MkDir()
err := mongo.EnsureServer(makeEnsureServerParams(dataDir))
// Even though apt-get failed, EnsureServer should continue and
// not return the error - even though apt-get failed, the Juju
// mongodb package is most likely already installed.
// The error should be logged however.
c.Assert(err, jc.ErrorIsNil)
c.Check(tw.Log(), jc.LogMatches, []jc.SimpleMessage{
{loggo.ERROR, `packaging command failed: .+`},
{loggo.ERROR, `cannot install/upgrade mongod \(will proceed anyway\): packaging command failed`},
})
// Verify that EnsureServer continued and started the mongodb service.
c.Check(s.data.Installed(), gc.HasLen, 0)
s.data.CheckCallNames(c, "Installed", "Exists", "Running", "Start")
}
示例6: TestInstallMongod
func (s *MongoSuite) TestInstallMongod(c *gc.C) {
type installs struct {
series string
cmd [][]string
}
tests := []installs{
{"precise", [][]string{{"--target-release", "precise-updates/cloud-tools", "mongodb-server"}}},
{"quantal", [][]string{{"python-software-properties"}, {"--target-release", "mongodb-server"}}},
{"raring", [][]string{{"--target-release", "mongodb-server"}}},
{"saucy", [][]string{{"--target-release", "mongodb-server"}}},
{"trusty", [][]string{{"juju-mongodb"}}},
{"u-series", [][]string{{"juju-mongodb"}}},
}
testing.PatchExecutableAsEchoArgs(c, s, "add-apt-repository")
testing.PatchExecutableAsEchoArgs(c, s, "apt-get")
for _, test := range tests {
dataDir := c.MkDir()
namespace := "namespace" + test.series
s.patchSeries(test.series)
err := mongo.EnsureServer(makeEnsureServerParams(dataDir, namespace))
c.Assert(err, jc.ErrorIsNil)
for _, cmd := range test.cmd {
match := append(expectedArgs.AptGetBase, cmd...)
testing.AssertEchoArgs(c, "apt-get", match...)
}
}
}
示例7: testEnsureServerNumaCtl
func (s *MongoSuite) testEnsureServerNumaCtl(c *gc.C, setNumaPolicy bool) string {
dataDir := c.MkDir()
dbDir := filepath.Join(dataDir, "db")
namespace := "namespace"
mockShellCommand(c, &s.CleanupSuite, "apt-get")
testParams := makeEnsureServerParams(dataDir, namespace)
testParams.SetNumaControlPolicy = setNumaPolicy
err := mongo.EnsureServer(testParams)
c.Assert(err, jc.ErrorIsNil)
testJournalDirs(dbDir, c)
assertInstalled := func() {
installed := s.data.Installed()
c.Assert(installed, gc.HasLen, 1)
service := installed[0]
c.Assert(service.Name(), gc.Equals, "juju-db-namespace")
c.Assert(service.Conf().Desc, gc.Equals, "juju state database")
if setNumaPolicy {
stripped := strings.Replace(service.Conf().ExtraScript, "\n", "", -1)
c.Assert(stripped, gc.Matches, `.* sysctl .*`)
} else {
c.Assert(service.Conf().ExtraScript, gc.Equals, "")
}
c.Assert(service.Conf().ExecStart, gc.Matches, ".*"+regexp.QuoteMeta(s.mongodPath)+".*")
c.Assert(service.Conf().Logfile, gc.Equals, "")
}
assertInstalled()
return dataDir
}
示例8: testEnsureServerNumaCtl
func (s *MongoSuite) testEnsureServerNumaCtl(c *gc.C, setNumaPolicy bool) string {
dataDir := c.MkDir()
dbDir := filepath.Join(dataDir, "db")
pm, err := coretesting.GetPackageManager()
c.Assert(err, jc.ErrorIsNil)
testing.PatchExecutableAsEchoArgs(c, s, pm.PackageManager)
testParams := makeEnsureServerParams(dataDir)
testParams.SetNumaControlPolicy = setNumaPolicy
err = mongo.EnsureServer(testParams)
c.Assert(err, jc.ErrorIsNil)
testJournalDirs(dbDir, c)
assertInstalled := func() {
installed := s.data.Installed()
c.Assert(installed, gc.HasLen, 1)
service := installed[0]
c.Assert(service.Name(), gc.Equals, "juju-db")
c.Assert(service.Conf().Desc, gc.Equals, "juju state database")
if setNumaPolicy {
stripped := strings.Replace(service.Conf().ExtraScript, "\n", "", -1)
c.Assert(stripped, gc.Matches, `.* sysctl .*`)
} else {
c.Assert(service.Conf().ExtraScript, gc.Equals, "")
}
c.Assert(service.Conf().ExecStart, gc.Matches, `.*/mongod.*`)
c.Assert(service.Conf().Logfile, gc.Equals, "")
}
assertInstalled()
return dataDir
}
示例9: TestInstallMongod
func (s *MongoSuite) TestInstallMongod(c *gc.C) {
type installs struct {
series string
cmd [][]string
}
tests := []installs{
{"precise", [][]string{{"--target-release", "precise-updates/cloud-tools", "mongodb-server"}}},
{"trusty", [][]string{{"juju-mongodb3.2"}, {"juju-mongo-tools3.2"}}},
{"wily", [][]string{{"juju-mongodb3.2"}, {"juju-mongo-tools3.2"}}},
{"xenial", [][]string{{"juju-mongodb3.2"}, {"juju-mongo-tools3.2"}}},
}
testing.PatchExecutableAsEchoArgs(c, s, "add-apt-repository")
testing.PatchExecutableAsEchoArgs(c, s, "apt-get")
for _, test := range tests {
c.Logf("install for series %v", test.series)
dataDir := c.MkDir()
s.patchSeries(test.series)
err := mongo.EnsureServer(makeEnsureServerParams(dataDir))
c.Assert(err, jc.ErrorIsNil)
for _, cmd := range test.cmd {
match := append(expectedArgs.AptGetBase, cmd...)
testing.AssertEchoArgs(c, "apt-get", match...)
}
}
}
示例10: assertSuccessWithInstallStepFailCentOS
func (s *MongoSuite) assertSuccessWithInstallStepFailCentOS(c *gc.C, exec []string, execNameFail string, returnCode int, expectedResult []jc.SimpleMessage) {
type installs struct {
series string
pkg string
}
test := installs{
"centos7", "mongodb*",
}
for _, e := range exec {
testing.PatchExecutableAsEchoArgs(c, s, e)
}
testing.PatchExecutableThrowError(c, s, execNameFail, returnCode)
dataDir := c.MkDir()
s.patchSeries(test.series)
var tw loggo.TestWriter
c.Assert(loggo.RegisterWriter("mongosuite", &tw, loggo.INFO), jc.ErrorIsNil)
defer loggo.RemoveWriter("mongosuite")
err := mongo.EnsureServer(makeEnsureServerParams(dataDir))
c.Assert(err, jc.ErrorIsNil)
c.Assert(tw.Log(), jc.LogMatches, expectedResult)
}
示例11: TestInstallMongodFallsBack
func (s *MongoSuite) TestInstallMongodFallsBack(c *gc.C) {
if runtime.GOOS == "windows" {
c.Skip("Skipping TestInstallMongodFallsBack as mongo is not installed on windows")
}
type installs struct {
series string
cmd string
}
tests := []installs{
{"precise", "mongodb-server"},
{"trusty", "juju-mongodb3.2\njuju-mongodb"},
{"wily", "juju-mongodb3.2\njuju-mongodb"},
{"xenial", "juju-mongodb3.2\njuju-mongodb"},
}
dataDir := c.MkDir()
outputFile := filepath.Join(dataDir, "apt-get-args")
testing.PatchExecutable(c, s, "apt-get", fmt.Sprintf(fakeInstallScript, outputFile))
for _, test := range tests {
c.Logf("Testing mongo install for series: %s", test.series)
s.patchSeries(test.series)
err := mongo.EnsureServer(makeEnsureServerParams(dataDir))
c.Assert(err, jc.ErrorIsNil)
args, err := ioutil.ReadFile(outputFile)
c.Assert(err, jc.ErrorIsNil)
c.Check(strings.TrimSpace(string(args)), gc.Equals, test.cmd)
err = os.Remove(outputFile)
c.Assert(err, jc.ErrorIsNil)
}
}
示例12: TestInstallSuccessMongodCentOS
func (s *MongoSuite) TestInstallSuccessMongodCentOS(c *gc.C) {
type installs struct {
series string
pkg string
}
test := installs{
"centos7", "mongodb*",
}
testing.PatchExecutableAsEchoArgs(c, s, "yum")
testing.PatchExecutableAsEchoArgs(c, s, "chcon")
testing.PatchExecutableAsEchoArgs(c, s, "semanage")
dataDir := c.MkDir()
s.patchSeries(test.series)
err := mongo.EnsureServer(makeEnsureServerParams(dataDir))
c.Assert(err, jc.ErrorIsNil)
expected := append(expectedArgs.YumBase, "epel-release")
testing.AssertEchoArgs(c, "yum", expected...)
testing.AssertEchoArgs(c, "chcon", expectedArgs.Chcon...)
testing.AssertEchoArgs(c, "semanage", expectedArgs.Semanage...)
}
示例13: TestNoMongoDir
func (s *MongoSuite) TestNoMongoDir(c *gc.C) {
// Make a non-existent directory that can nonetheless be
// created.
mockShellCommand(c, &s.CleanupSuite, "apt-get")
dataDir := filepath.Join(c.MkDir(), "dir", "data")
err := mongo.EnsureServer(makeEnsureServerParams(dataDir, ""))
c.Check(err, gc.IsNil)
_, err = os.Stat(filepath.Join(dataDir, "db"))
c.Assert(err, gc.IsNil)
}
示例14: TestNoMongoDir
func (s *MongoSuite) TestNoMongoDir(c *gc.C) {
// Make a non-existent directory that can nonetheless be
// created.
pm, err := coretesting.GetPackageManager()
c.Assert(err, jc.ErrorIsNil)
testing.PatchExecutableAsEchoArgs(c, s, pm.PackageManager)
dataDir := filepath.Join(c.MkDir(), "dir", "data")
err = mongo.EnsureServer(makeEnsureServerParams(dataDir))
c.Check(err, jc.ErrorIsNil)
_, err = os.Stat(filepath.Join(dataDir, "db"))
c.Assert(err, jc.ErrorIsNil)
}
示例15: TestEnsureServerServerExistsNotRunningIsStarted
func (s *MongoSuite) TestEnsureServerServerExistsNotRunningIsStarted(c *gc.C) {
dataDir := c.MkDir()
namespace := "namespace"
mockShellCommand(c, &s.CleanupSuite, "apt-get")
s.data.SetStatus(mongo.ServiceName(namespace), "installed")
err := mongo.EnsureServer(makeEnsureServerParams(dataDir, namespace))
c.Assert(err, jc.ErrorIsNil)
c.Check(s.data.Installed(), gc.HasLen, 0)
s.data.CheckCallNames(c, "Installed", "Exists", "Running", "Start")
}