Exemple #1
0
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
}
Exemple #2
0
func (s *prereqsSuite) SetUpTest(c *gc.C) {
	s.BaseSuite.SetUpTest(c)
	s.tmpdir = c.MkDir()
	s.testMongodPath = filepath.Join(s.tmpdir, "mongod")

	s.PatchEnvironment("PATH", s.tmpdir)

	s.PatchValue(&mongo.JujuMongodPath, "/somewhere/that/wont/exist")

	os.Setenv("JUJUTEST_LSB_RELEASE_ID", "Ubuntu")
	err := ioutil.WriteFile(filepath.Join(s.tmpdir, "lsb_release"), []byte(lsbrelease), 0777)
	c.Assert(err, jc.ErrorIsNil)

	// symlink $temp/dpkg-query to /bin/true, to
	// simulate package installation query responses.
	pm, err := testing.GetPackageManager()
	c.Assert(err, jc.ErrorIsNil)

	err = symlink.New("/bin/true", filepath.Join(s.tmpdir, pm.PackageQuery))
	c.Assert(err, jc.ErrorIsNil)
	s.PatchValue(&isPackageInstalled, func(pack string) bool {
		pacman, err := manager.NewPackageManager(series.HostSeries())
		c.Assert(err, jc.ErrorIsNil)
		return pacman.IsInstalled(pack)
	})
}
Exemple #3
0
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)

	pm, err := coretesting.GetPackageManager()
	c.Assert(err, jc.ErrorIsNil)
	failCmd(filepath.Join(dir, pm.RepositoryManager))
	testing.PatchExecutableAsEchoArgs(c, s, pm.PackageManager)

	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.patchSeries("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.patchSeries("trusty")
	failCmd(filepath.Join(dir, "mongod"))
	err = mongo.EnsureServer(makeEnsureServerParams(dir))
	c.Assert(err, jc.ErrorIsNil)
}
Exemple #4
0
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)
}
Exemple #5
0
func (s *UpgradeSuite) assertCommonUpgrades(c *gc.C) {
	// rsyslog-gnutls should have been installed.
	cmds := s.getInstallCmds()
	c.Assert(cmds, gc.HasLen, 1)
	args := cmds[0].Args
	c.Assert(len(args), jc.GreaterThan, 1)

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

	c.Assert(args[0], gc.Equals, pm.PackageManager)

	c.Assert(args[len(args)-1], gc.Equals, "rsyslog-gnutls")
}
Exemple #6
0
func (s *prereqsSuite) TestJujuLocalPrereq(c *gc.C) {

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

	err = os.Remove(filepath.Join(s.tmpdir, pm.PackageQuery))
	c.Assert(err, jc.ErrorIsNil)
	err = symlink.New("/bin/false", filepath.Join(s.tmpdir, pm.PackageQuery))
	c.Assert(err, jc.ErrorIsNil)

	err = VerifyPrerequisites(instance.LXC)
	c.Assert(err, gc.ErrorMatches, "(.|\n)*juju-local must be installed to enable the local provider(.|\n)*")
	c.Assert(err, gc.ErrorMatches, "(.|\n)*apt-get install juju-local(.|\n)*")
}
Exemple #7
0
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")
}
Exemple #8
0
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")
}
Exemple #9
0
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")
}
Exemple #10
0
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")
}