コード例 #1
0
ファイル: mongo_test.go プロジェクト: Pankov404/juju
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
0
ファイル: mongo_test.go プロジェクト: klyachin/juju
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
0
ファイル: mongo_test.go プロジェクト: klyachin/juju
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
0
ファイル: mongo_test.go プロジェクト: AlexisBruemmer/juju
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
0
ファイル: mongo_test.go プロジェクト: xushiwei/juju
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
0
ファイル: mongo_test.go プロジェクト: imoapps/juju
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
0
ファイル: mongo_test.go プロジェクト: Pankov404/juju
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
0
ファイル: mongo_test.go プロジェクト: xushiwei/juju
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
0
ファイル: mongo_test.go プロジェクト: xushiwei/juju
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
0
ファイル: mongo_test.go プロジェクト: xushiwei/juju
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
0
ファイル: mongo_test.go プロジェクト: xushiwei/juju
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
0
ファイル: mongo_test.go プロジェクト: xushiwei/juju
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
0
ファイル: mongo_test.go プロジェクト: kapilt/juju
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
0
ファイル: mongo_test.go プロジェクト: xushiwei/juju
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
0
ファイル: mongo_test.go プロジェクト: Pankov404/juju
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")
}
コード例 #16
0
ファイル: mongo_test.go プロジェクト: kapilt/juju
func (s *MongoSuite) TestAddPPAInQuantal(c *gc.C) {
	mockShellCommand(c, &s.CleanupSuite, "apt-get")

	addAptRepoOut := mockShellCommand(c, &s.CleanupSuite, "add-apt-repository")
	s.PatchValue(&version.Current.Series, "quantal")

	dataDir := c.MkDir()
	err := mongo.EnsureServer(makeEnsureServerParams(dataDir, ""))
	c.Assert(err, gc.IsNil)

	c.Assert(getMockShellCalls(c, addAptRepoOut), gc.DeepEquals, [][]string{{
		"-y",
		"ppa:juju/stable",
	}})
}
コード例 #17
0
ファイル: mongo_test.go プロジェクト: Pankov404/juju
func (s *MongoSuite) TestEnsureServerServerExistsNotRunningStartError(c *gc.C) {
	dataDir := c.MkDir()
	namespace := "namespace"

	mockShellCommand(c, &s.CleanupSuite, "apt-get")

	s.data.SetStatus(mongo.ServiceName(namespace), "installed")
	failure := errors.New("won't start")
	s.data.SetErrors(nil, nil, nil, failure) // Installed, Exists, Running, Running, Start

	err := mongo.EnsureServer(makeEnsureServerParams(dataDir, namespace))

	c.Check(errors.Cause(err), gc.Equals, failure)
	c.Check(s.data.Installed(), gc.HasLen, 0)
	s.data.CheckCallNames(c, "Installed", "Exists", "Running", "Start")
}
コード例 #18
0
ファイル: mongo_test.go プロジェクト: xushiwei/juju
func (s *MongoSuite) TestEnsureServerServerExistsNotRunningStartError(c *gc.C) {
	dataDir := c.MkDir()

	pm, err := coretesting.GetPackageManager()
	c.Assert(err, jc.ErrorIsNil)
	testing.PatchExecutableAsEchoArgs(c, s, pm.PackageManager)

	s.data.SetStatus(mongo.ServiceName, "installed")
	failure := errors.New("won't start")
	s.data.SetErrors(nil, nil, nil, failure) // Installed, Exists, Running, Running, Start

	err = mongo.EnsureServer(makeEnsureServerParams(dataDir))

	c.Check(errors.Cause(err), gc.Equals, failure)
	c.Check(s.data.Installed(), gc.HasLen, 0)
	s.data.CheckCallNames(c, "Installed", "Exists", "Running", "Start")
}
コード例 #19
0
ファイル: mongo_test.go プロジェクト: Pankov404/juju
func (s *MongoSuite) TestInstallMongodServiceExists(c *gc.C) {
	output := mockShellCommand(c, &s.CleanupSuite, "apt-get")
	dataDir := c.MkDir()
	namespace := "namespace"

	s.data.SetStatus(mongo.ServiceName(namespace), "running")
	s.data.SetErrors(nil, nil, nil, errors.New("shouldn't be called"))

	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")

	// We still attempt to install mongodb, despite the service existing.
	cmds := getMockShellCalls(c, output)
	c.Check(cmds, gc.HasLen, 1)
}
コード例 #20
0
ファイル: mongo_test.go プロジェクト: mhilton/juju
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)

	// These should still be written out even if the service was installed.
	s.assertSSLKeyFile(c, dataDir)
	s.assertSharedSecretFile(c, dataDir)
	s.assertMongoConfigFile(c)

	c.Check(s.data.Installed(), gc.HasLen, 0)
	s.data.CheckCallNames(c, "Installed", "Exists", "Running", "Start")
}
コード例 #21
0
ファイル: mongo_test.go プロジェクト: kapilt/juju
func (s *MongoSuite) TestEnsureServerServerExistsNotRunningStartError(c *gc.C) {
	dataDir := c.MkDir()
	namespace := "namespace"

	mockShellCommand(c, &s.CleanupSuite, "apt-get")

	s.PatchValue(mongo.UpstartServiceExists, func(svc *upstart.Service) bool {
		return true
	})
	s.PatchValue(mongo.UpstartServiceRunning, func(svc *upstart.Service) bool {
		return false
	})
	s.PatchValue(mongo.UpstartServiceStart, func(svc *upstart.Service) error {
		return fmt.Errorf("won't start")
	})

	err := mongo.EnsureServer(makeEnsureServerParams(dataDir, namespace))
	c.Assert(err, gc.ErrorMatches, `.*won't start`)
	c.Assert(s.installed, gc.HasLen, 0)
}
コード例 #22
0
ファイル: mongo_test.go プロジェクト: xushiwei/juju
func (s *MongoSuite) TestInstallMongodServiceExists(c *gc.C) {
	pm, err := coretesting.GetPackageManager()
	c.Assert(err, jc.ErrorIsNil)
	testing.PatchExecutableAsEchoArgs(c, s, pm.PackageManager)
	if pm.PackageManager == "yum" {
		testing.PatchExecutableAsEchoArgs(c, s, "chcon")
		testing.PatchExecutableAsEchoArgs(c, s, "semanage")
	}

	dataDir := c.MkDir()

	s.data.SetStatus(mongo.ServiceName, "running")
	s.data.SetErrors(nil, nil, nil, errors.New("shouldn't be called"))

	err = mongo.EnsureServer(makeEnsureServerParams(dataDir))
	c.Assert(err, jc.ErrorIsNil)

	c.Check(s.data.Installed(), gc.HasLen, 0)
	s.data.CheckCallNames(c, "Installed", "Exists", "Running")
}
コード例 #23
0
ファイル: mongo_test.go プロジェクト: xushiwei/juju
func (s *MongoSuite) TestEnsureServerServerExistsNotRunningIsStarted(c *gc.C) {
	dataDir := c.MkDir()

	pm, err := coretesting.GetPackageManager()
	c.Assert(err, jc.ErrorIsNil)
	testing.PatchExecutableAsEchoArgs(c, s, pm.PackageManager)

	s.data.SetStatus(mongo.ServiceName, "installed")

	err = mongo.EnsureServer(makeEnsureServerParams(dataDir))
	c.Assert(err, jc.ErrorIsNil)

	// These should still be written out even if the service was installed.
	s.assertSSLKeyFile(c, dataDir)
	s.assertSharedSecretFile(c, dataDir)
	s.assertMongoConfigFile(c)

	c.Check(s.data.Installed(), gc.HasLen, 0)
	s.data.CheckCallNames(c, "Installed", "Exists", "Running", "Start")
}
コード例 #24
0
ファイル: mongo_test.go プロジェクト: kapilt/juju
func (s *MongoSuite) TestInstallMongod(c *gc.C) {
	type installs struct {
		series string
		pkg    string
	}
	tests := []installs{
		{"precise", "mongodb-server"},
		{"quantal", "mongodb-server"},
		{"raring", "mongodb-server"},
		{"saucy", "mongodb-server"},
		{"trusty", "juju-mongodb"},
		{"u-series", "juju-mongodb"},
	}

	mockShellCommand(c, &s.CleanupSuite, "add-apt-repository")
	output := mockShellCommand(c, &s.CleanupSuite, "apt-get")
	for _, test := range tests {
		c.Logf("Testing %s", test.series)
		dataDir := c.MkDir()
		namespace := "namespace" + test.series

		s.PatchValue(&version.Current.Series, test.series)

		err := mongo.EnsureServer(makeEnsureServerParams(dataDir, namespace))
		c.Assert(err, gc.IsNil)

		cmds := getMockShellCalls(c, output)

		// quantal does an extra apt-get install for python software properties
		// so we need to remember to skip that one
		index := 0
		if test.series == "quantal" {
			index = 1
		}
		match := fmt.Sprintf(`.* install .*%s`, test.pkg)
		c.Assert(strings.Join(cmds[index], " "), gc.Matches, match)
		// remove the temp file between tests
		c.Assert(os.Remove(output), gc.IsNil)
	}
}
コード例 #25
0
ファイル: mongo_test.go プロジェクト: imoapps/juju
func (s *MongoSuite) TestAddEpelInCentOS(c *gc.C) {
	testing.PatchExecutableAsEchoArgs(c, s, "yum")

	s.patchSeries("centos7")

	testing.PatchExecutableAsEchoArgs(c, s, "chcon")
	testing.PatchExecutableAsEchoArgs(c, s, "semanage")

	dataDir := c.MkDir()
	err := mongo.EnsureServer(makeEnsureServerParams(dataDir, ""))
	c.Assert(err, jc.ErrorIsNil)

	expectedEpelRelease := append(expectedArgs.YumBase, "epel-release")
	testing.AssertEchoArgs(c, "yum", expectedEpelRelease...)

	expectedMongodbServer := append(expectedArgs.YumBase, "mongodb-server")
	testing.AssertEchoArgs(c, "yum", expectedMongodbServer...)

	testing.AssertEchoArgs(c, "chcon", expectedArgs.Chcon...)

	testing.AssertEchoArgs(c, "semanage", expectedArgs.Semanage...)
}
コード例 #26
0
ファイル: mongo_test.go プロジェクト: kapilt/juju
func (s *MongoSuite) TestEnsureServerServerExistsNotRunningIsStarted(c *gc.C) {
	dataDir := c.MkDir()
	namespace := "namespace"

	mockShellCommand(c, &s.CleanupSuite, "apt-get")

	s.PatchValue(mongo.UpstartServiceExists, func(svc *upstart.Service) bool {
		return true
	})
	s.PatchValue(mongo.UpstartServiceRunning, func(svc *upstart.Service) bool {
		return false
	})
	var started bool
	s.PatchValue(mongo.UpstartServiceStart, func(svc *upstart.Service) error {
		started = true
		return nil
	})

	err := mongo.EnsureServer(makeEnsureServerParams(dataDir, namespace))
	c.Assert(err, gc.IsNil)
	c.Assert(s.installed, gc.HasLen, 0)
	c.Assert(started, jc.IsTrue)
}
コード例 #27
0
ファイル: mongo_test.go プロジェクト: imoapps/juju
func (s *MongoSuite) TestEnsureServerServerExistsAndRunning(c *gc.C) {
	dataDir := c.MkDir()
	namespace := "namespace"

	pm, err := coretesting.GetPackageManager()
	c.Assert(err, jc.ErrorIsNil)

	testing.PatchExecutableAsEchoArgs(c, s, pm.PackageManager)

	s.data.SetStatus(mongo.ServiceName(namespace), "running")
	s.data.SetErrors(nil, nil, nil, errors.New("shouldn't be called"))

	err = mongo.EnsureServer(makeEnsureServerParams(dataDir, namespace))
	c.Assert(err, jc.ErrorIsNil)

	// These should still be written out even if the service was installed.
	s.assertSSLKeyFile(c, dataDir)
	s.assertSharedSecretFile(c, dataDir)
	s.assertMongoConfigFile(c)

	c.Check(s.data.Installed(), gc.HasLen, 0)
	s.data.CheckCallNames(c, "Installed", "Exists", "Running")
}
コード例 #28
0
ファイル: mongo_test.go プロジェクト: kapilt/juju
func (s *MongoSuite) TestInstallMongodServiceExists(c *gc.C) {
	output := mockShellCommand(c, &s.CleanupSuite, "apt-get")
	dataDir := c.MkDir()
	namespace := "namespace"

	s.PatchValue(mongo.UpstartServiceExists, func(svc *upstart.Service) bool {
		return true
	})
	s.PatchValue(mongo.UpstartServiceRunning, func(svc *upstart.Service) bool {
		return true
	})
	s.PatchValue(mongo.UpstartServiceStart, func(svc *upstart.Service) error {
		return fmt.Errorf("shouldn't be called")
	})

	err := mongo.EnsureServer(makeEnsureServerParams(dataDir, namespace))
	c.Assert(err, gc.IsNil)
	c.Assert(s.installed, gc.HasLen, 0)

	// We still attempt to install mongodb, despite the service existing.
	cmds := getMockShellCalls(c, output)
	c.Assert(cmds, gc.HasLen, 1)
}