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 }
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, gc.IsNil) defer inst.Destroy() info := inst.DialInfo() args := peergrouper.InitiateMongoParams{ DialInfo: info, MemberHostPort: inst.Addr(), } err = peergrouper.MaybeInitiateMongoServer(args) c.Assert(err, gc.IsNil) // This would return a mgo.QueryError if a ReplicaSet // configuration already existed but we tried to create // one with replicaset.Initiate again. err = peergrouper.MaybeInitiateMongoServer(args) c.Assert(err, gc.IsNil) // TODO test login }
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.MaybeInitiateMongoServer(args) c.Assert(err, jc.ErrorIsNil) s.AgentSuite.SetUpSuite(c) }
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.MaybeInitiateMongoServer(args) c.Assert(err, jc.ErrorIsNil) return inst, s.dialMongo(c, inst) }
func (s *mongoSuite) testStateWorkerDialSetsWriteMajority(c *gc.C, configureReplset bool) { inst := gitjujutesting.MgoInstance{ EnableJournal: true, Params: []string{"--replSet", "juju"}, } err := inst.Start(coretesting.Certs) c.Assert(err, gc.IsNil) defer inst.Destroy() var expectedWMode string dialOpts := stateWorkerDialOpts if configureReplset { info := inst.DialInfo() args := peergrouper.InitiateMongoParams{ DialInfo: info, MemberHostPort: inst.Addr(), } err = peergrouper.MaybeInitiateMongoServer(args) c.Assert(err, gc.IsNil) 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, gc.IsNil) 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 }