Example #1
0
func (s *mongoRestoreSuite) TestRestoreDatabase24(c *gc.C) {
	s.PatchValue(backups.GetMongorestorePath, func() (string, error) { return "/a/fake/mongorestore", nil })
	var ranCommand string
	var ranWithArgs []string
	fakeRunCommand := func(c string, args ...string) error {
		ranCommand = c
		ranWithArgs = args
		return nil
	}
	args := backups.RestorerArgs{
		Version:         mongo.Mongo24,
		TagUser:         "******",
		TagUserPassword: "******",
		RunCommandFn:    fakeRunCommand,
		StartMongo:      func() error { return nil },
		StopMongo:       func() error { return nil },
	}

	s.PatchValue(backups.MongoInstalledVersion, func() mongo.Version { return mongo.Mongo24 })
	restorer, err := backups.NewDBRestorer(args)
	c.Assert(err, jc.ErrorIsNil)
	err = restorer.Restore("fakePath", nil)
	c.Assert(err, jc.ErrorIsNil)

	c.Assert(ranCommand, gc.Equals, "/a/fake/mongorestore")
	c.Assert(ranWithArgs, gc.DeepEquals, []string{"--drop", "--journal", "--oplogReplay", "--dbpath", "/var/lib/juju/db", "fakePath"})
}
Example #2
0
func (s *mongoRestoreSuite) TestRestoreDatabase32(c *gc.C) {
	s.PatchValue(backups.GetMongorestorePath, func() (string, error) { return "/a/fake/mongorestore", nil })
	var ranCommand string
	var ranWithArgs []string
	fakeRunCommand := func(c string, args ...string) error {
		ranCommand = c
		ranWithArgs = args
		return nil
	}
	mgoDb := &mongoDb{}
	mgoSession := &mongoSession{}

	args := backups.RestorerArgs{
		DialInfo: &mgo.DialInfo{
			Username: "******",
			Password: "******",
			Addrs:    []string{"127.0.0.1"},
		},
		Version:         mongo.Mongo32wt,
		TagUser:         "******",
		TagUserPassword: "******",
		GetDB:           func(string, backups.MongoSession) backups.MongoDB { return mgoDb },
		NewMongoSession: func(dialInfo *mgo.DialInfo) (backups.MongoSession, error) {
			return mgoSession, nil
		},
		RunCommandFn: fakeRunCommand,
	}
	s.PatchValue(backups.MongoInstalledVersion, func() mongo.Version { return mongo.Mongo32wt })
	restorer, err := backups.NewDBRestorer(args)
	c.Assert(err, jc.ErrorIsNil)
	err = restorer.Restore("fakePath", nil)
	c.Assert(err, jc.ErrorIsNil)

	c.Assert(ranCommand, gc.Equals, "/a/fake/mongorestore")
	c.Assert(ranWithArgs, gc.DeepEquals, []string{"--ssl", "--authenticationDatabase", "admin", "--host", "127.0.0.1", "--username", "fakeUsername", "--password", "fakePassword", "--drop", "--oplogReplay", "--batchSize", "10", "fakePath"})
	user := &mgo.User{Username: "******", Password: "******"}
	c.Assert(mgoDb.user, gc.DeepEquals, user)
	c.Assert(mgoSession.closed, jc.IsTrue)
	mgoSessionCmd := []bson.D{
		bson.D{
			bson.DocElem{Name: "createRole", Value: "oploger"},
			bson.DocElem{Name: "privileges", Value: []bson.D{
				bson.D{
					bson.DocElem{Name: "resource", Value: bson.M{"anyResource": true}},
					bson.DocElem{Name: "actions", Value: []string{"anyAction"}}}}},
			bson.DocElem{Name: "roles", Value: []string{}}},
		bson.D{
			bson.DocElem{Name: "grantRolesToUser", Value: "fakeUsername"},
			bson.DocElem{Name: "roles", Value: []string{"oploger"}}},
		bson.D{
			bson.DocElem{Name: "grantRolesToUser", Value: "admin"},
			bson.DocElem{Name: "roles", Value: []string{"oploger"}}}}
	c.Assert(mgoSession.cmd, gc.DeepEquals, mgoSessionCmd)
}
Example #3
0
func (s *mongoRestoreSuite) TestRestoreFailsOnOlderMongo(c *gc.C) {
	s.PatchValue(backups.GetMongorestorePath, func() (string, error) { return "/a/fake/mongorestore", nil })
	args := backups.RestorerArgs{
		DialInfo: &mgo.DialInfo{
			Username: "******",
			Password: "******",
			Addrs:    []string{"127.0.0.1"},
		},
		Version:         mongo.Mongo32wt,
		TagUser:         "******",
		TagUserPassword: "******",
	}
	s.PatchValue(backups.MongoInstalledVersion, func() mongo.Version { return mongo.Mongo24 })
	_, err := backups.NewDBRestorer(args)
	c.Assert(err, gc.ErrorMatches, "restore mongo version 3.2/wiredTiger into version 2.4/mmapv1 not supported")
}