Esempio n. 1
0
// resetReplicaSet re-initiates replica-set using the new state server
// values, this is required after a mongo restore.
// In case of failure returns error.
func resetReplicaSet(dialInfo *mgo.DialInfo, memberHostPort string) error {
	params := peergrouper.InitiateMongoParams{dialInfo,
		memberHostPort,
		dialInfo.Username,
		dialInfo.Password,
	}
	return peergrouper.InitiateMongoServer(params, true)
}
Esempio n. 2
0
func (s *InitiateSuite) TestInitiateReplicaSet(c *gc.C) {
	var err error
	inst := &gitjujutesting.MgoInstance{Params: []string{"--replSet", "juju"}}
	err = inst.Start(coretesting.Certs)
	c.Assert(err, jc.ErrorIsNil)
	defer inst.Destroy()

	info := inst.DialInfo()
	args := peergrouper.InitiateMongoParams{
		DialInfo:       info,
		MemberHostPort: inst.Addr(),
	}

	err = peergrouper.InitiateMongoServer(args)
	c.Assert(err, jc.ErrorIsNil)

	// Calling initiate again will re-create the replicaset even though it exists already
	err = peergrouper.InitiateMongoServer(args)
	c.Assert(err, jc.ErrorIsNil)

	// TODO test login
}
Esempio n. 3
0
func (s *InitiateSuite) TestInitiateReplicaSet(c *gc.C) {
	var err error
	inst := &gitjujutesting.MgoInstance{Params: []string{"--replSet", "juju"}}
	err = inst.Start(coretesting.Certs)
	c.Assert(err, jc.ErrorIsNil)
	defer inst.Destroy()

	info := inst.DialInfo()
	args := peergrouper.InitiateMongoParams{
		DialInfo:       info,
		MemberHostPort: inst.Addr(),
	}

	err = peergrouper.MaybeInitiateMongoServer(args)
	c.Assert(err, jc.ErrorIsNil)

	// This would return a mgo.QueryError if a ReplicaSet
	// configuration already existed but we tried to create
	// one with replicaset.Initiate again.
	// ErrReplicaSetAlreadyInitiated is not a failure but an
	// indication that we tried to initiate an initiated rs
	err = peergrouper.MaybeInitiateMongoServer(args)
	c.Assert(err, gc.Equals, peergrouper.ErrReplicaSetAlreadyInitiated)

	// Make sure running InitiateMongoServer without forcing will behave
	// in the same way as MaybeInitiateMongoServer
	err = peergrouper.InitiateMongoServer(args, false)
	c.Assert(err, gc.Equals, peergrouper.ErrReplicaSetAlreadyInitiated)

	// Assert that passing Force to initiate will re-create the replicaset
	// even though it exists already
	err = peergrouper.InitiateMongoServer(args, true)
	c.Assert(err, jc.ErrorIsNil)

	// TODO test login
}
Esempio n. 4
0
func (s *debugLogDbSuite) SetUpSuite(c *gc.C) {
	// Restart mongod with a the replicaset enabled.
	mongod := jujutesting.MgoServer
	mongod.Params = []string{"--replSet", "juju"}
	mongod.Restart()

	// Initiate the replicaset.
	info := mongod.DialInfo()
	args := peergrouper.InitiateMongoParams{
		DialInfo:       info,
		MemberHostPort: mongod.Addr(),
	}
	err := peergrouper.InitiateMongoServer(args)
	c.Assert(err, jc.ErrorIsNil)

	s.AgentSuite.SetUpSuite(c)
}
Esempio n. 5
0
func (s *oplogSuite) startMongoWithReplicaset(c *gc.C) (*jujutesting.MgoInstance, *mgo.Session) {
	inst := &jujutesting.MgoInstance{
		Params: []string{
			"--replSet", "juju",
		},
	}
	err := inst.Start(nil)
	c.Assert(err, jc.ErrorIsNil)
	s.AddCleanup(func(*gc.C) { inst.Destroy() })

	// Initiate replicaset.
	info := inst.DialInfo()
	args := peergrouper.InitiateMongoParams{
		DialInfo:       info,
		MemberHostPort: inst.Addr(),
	}
	err = peergrouper.InitiateMongoServer(args)
	c.Assert(err, jc.ErrorIsNil)

	return inst, s.dialMongo(c, inst)
}
Esempio n. 6
0
func (s *syslogSuite) SetUpSuite(c *gc.C) {
	s.LoggingSuite.SetUpSuite(c)
	// Tailing logs requires a replica set. Restart mongo with a
	// replicaset before initialising AgentSuite.
	mongod := gitjujutesting.MgoServer
	mongod.Params = []string{"--replSet", "juju"}
	mongod.Restart()

	info := mongod.DialInfo()
	args := peergrouper.InitiateMongoParams{
		DialInfo:       info,
		MemberHostPort: mongod.Addr(),
	}
	err := peergrouper.InitiateMongoServer(args)
	c.Assert(err, jc.ErrorIsNil)

	s.AgentSuite.SetUpSuite(c)
	s.AddCleanup(func(*gc.C) {
		mongod.Params = nil
		mongod.Restart()
	})
}
Esempio n. 7
0
func (s *mongoSuite) testStateWorkerDialSetsWriteMajority(c *gc.C, configureReplset bool) {
	inst := gitjujutesting.MgoInstance{
		Params: []string{"--replSet", "juju"},
	}
	err := inst.Start(coretesting.Certs)
	c.Assert(err, jc.ErrorIsNil)
	defer inst.Destroy()

	var expectedWMode string
	dialOpts := stateWorkerDialOpts
	dialOpts.Timeout = coretesting.LongWait
	if configureReplset {
		info := inst.DialInfo()
		info.Timeout = dialOpts.Timeout
		args := peergrouper.InitiateMongoParams{
			DialInfo:       info,
			MemberHostPort: inst.Addr(),
		}
		err = peergrouper.InitiateMongoServer(args)
		c.Assert(err, jc.ErrorIsNil)
		expectedWMode = "majority"
	} else {
		dialOpts.Direct = true
	}

	mongoInfo := mongo.Info{
		Addrs:  []string{inst.Addr()},
		CACert: coretesting.CACert,
	}
	session, err := mongo.DialWithInfo(mongoInfo, dialOpts)
	c.Assert(err, jc.ErrorIsNil)
	defer session.Close()

	safe := session.Safe()
	c.Assert(safe, gc.NotNil)
	c.Assert(safe.WMode, gc.Equals, expectedWMode)
	c.Assert(safe.J, jc.IsTrue) // always enabled
}