Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support mongodb 6.0 #1416

Merged
merged 2 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/dockertests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ jobs:
'make TEST="pg_delete_garbage_test" pg_integration_test',
'make TEST="pg_daemon_test" pg_integration_test',
'make mongo_test',
'make MONGO_VERSION="5.0.10" MONGO_MAJOR="5.0" MONGO_REPO="repo.mongodb.org" MONGO_PACKAGE="mongodb-org" mongo_features',
'make MONGO_VERSION="5.0.10" MONGO_MAJOR="5.0" MONGO_REPO="repo.mongodb.com" MONGO_PACKAGE="mongodb-enterprise" mongo_features',
'make MONGO_VERSION="4.4.15" MONGO_MAJOR="4.4" MONGO_REPO="repo.mongodb.org" MONGO_PACKAGE="mongodb-org" mongo_features',
'make MONGO_VERSION="4.4.15" MONGO_MAJOR="4.4" MONGO_REPO="repo.mongodb.com" MONGO_PACKAGE="mongodb-enterprise" mongo_features',
'make MONGO_VERSION="4.2.21" MONGO_MAJOR="4.2" MONGO_REPO="repo.mongodb.org" MONGO_PACKAGE="mongodb-org" mongo_features',
'make MONGO_VERSION="4.0.25" MONGO_MAJOR="4.0" MONGO_REPO="repo.mongodb.org" MONGO_PACKAGE="mongodb-org" mongo_features',
'make MONGO_VERSION="3.6.21" MONGO_MAJOR="3.6" MONGO_REPO="repo.mongodb.org" MONGO_PACKAGE="mongodb-org" mongo_features',
'make MONGO_VERSION="6.0.3" MONGO_MAJOR="6.0" MONGO_REPO="repo.mongodb.org" MONGO_PACKAGE="mongodb-org" mongo_features',
'make MONGO_VERSION="6.0.3" MONGO_MAJOR="6.0" MONGO_REPO="repo.mongodb.com" MONGO_PACKAGE="mongodb-enterprise" mongo_features',
'make MONGO_VERSION="5.0.13" MONGO_MAJOR="5.0" MONGO_REPO="repo.mongodb.org" MONGO_PACKAGE="mongodb-org" mongo_features',
'make MONGO_VERSION="5.0.13" MONGO_MAJOR="5.0" MONGO_REPO="repo.mongodb.com" MONGO_PACKAGE="mongodb-enterprise" mongo_features',
'make MONGO_VERSION="4.4.17" MONGO_MAJOR="4.4" MONGO_REPO="repo.mongodb.org" MONGO_PACKAGE="mongodb-org" mongo_features',
'make MONGO_VERSION="4.4.17" MONGO_MAJOR="4.4" MONGO_REPO="repo.mongodb.com" MONGO_PACKAGE="mongodb-enterprise" mongo_features',
'make MONGO_VERSION="4.2.23" MONGO_MAJOR="4.2" MONGO_REPO="repo.mongodb.org" MONGO_PACKAGE="mongodb-org" mongo_features',
'make redis_test',
'make REDIS_VERSION="5.0.8" redis_features',
'make REDIS_VERSION="6.0.8" redis_features',
Expand Down
9 changes: 5 additions & 4 deletions tests_func/Dockerfile.mongodb
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ ARG WALG_REPO=${GOPATH}/src/github.com/wal-g/wal-g
ENV MONGO_PACKAGE=${MONGO_PACKAGE} MONGO_REPO=${MONGO_REPO}
ARG MONGO_MAJOR=
ARG MONGO_VERSION=
ARG MONGO_TOOLS_VERSION=100.4.0
ENV TMP_DIR /var/tmp/wal-g
ENV WALG_CONF_DIR /etc/wal-g/
ENV USE_BROTLI 1

RUN echo "deb http://$MONGO_REPO/apt/ubuntu bionic/${MONGO_PACKAGE}/${MONGO_MAJOR} multiverse" | tee "/etc/apt/sources.list.d/mongodb_${MONGO_MAJOR}.list" && \
wget -qO - https://www.mongodb.org/static/pgp/server-${MONGO_MAJOR}.asc | apt-key add -

# Starting with MongoDB 4.4, the MongoDB Database Tools (mongodb-database-tools) are now released separately
# You can remove this RUN after remove the support of MongoDB 4.2
RUN echo "deb http://$MONGO_REPO/apt/ubuntu bionic/${MONGO_PACKAGE}/4.4 multiverse" | tee "/etc/apt/sources.list.d/mongodb_4.4.list" && \
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | apt-key add -


RUN apt-get update -qq && \
apt-get install -y apt-transport-https tzdata && apt-get update -qq && \
apt-get install snmp libsasl2-modules-gssapi-mit && \
Expand All @@ -27,9 +29,8 @@ RUN apt-get update -qq && \
sed -i 's/systemctl daemon-reload/echo "SKIPPED: systemctl daemon-reload"/' /var/lib/dpkg/info/${MONGO_PACKAGE}-server.postinst && \
dpkg --configure ${MONGO_PACKAGE}-server && \
apt-get install -yf && \
apt-get install --allow-unauthenticated -y \
mongodb-database-tools=$MONGO_TOOLS_VERSION \
${MONGO_PACKAGE}-shell=$MONGO_VERSION && \
apt-get install --allow-unauthenticated -y mongodb-database-tools && \
apt-get install -y mongodb-mongosh && \
rm -rf /var/lib/apt/lists/* /var/cache/debconf /var/lib/mongodb/* && \
apt-get clean

Expand Down
60 changes: 43 additions & 17 deletions tests_func/helpers/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ type AuthCreds struct {
Database string
}

type AuthPolicy int64

const (
NoneAuth AuthPolicy = iota
AdminAuth
AutoDetectAuth
)

func AdminCredsFromEnv(env map[string]string) AuthCreds {
return AuthCreds{
Username: env["MONGO_ADMIN_USERNAME"],
Expand Down Expand Up @@ -371,6 +379,34 @@ func (mc *MongoCtl) LastTS() (OpTimestamp, error) {
return OpTimestamp{TS: ts.T, Inc: ts.I}, nil
}

func (mc *MongoCtl) runMongoShellEval(eval string, auth AuthPolicy, quiet bool, db string) (ExecResult, error) {
cmd := []string{"mongosh", "--host", "localhost", "--port", "27018", "--norc"}

if quiet {
cmd = append(cmd, "--quiet")
}

adminCredCliParams := []string{"--username", mc.adminCreds.Username, "--password", mc.adminCreds.Password}

switch {
case auth == AdminAuth:
cmd = append(cmd, adminCredCliParams...)
case auth == AutoDetectAuth:
authedCmd := append(cmd, adminCredCliParams...)
if _, err := mc.runCmd(append(authedCmd, "--eval", "quit()", AdminDB)...); err == nil {
cmd = authedCmd
}
}

cmd = append(cmd, "--eval", eval)

if db != "" {
cmd = append(cmd, db)
}

return mc.runCmd(cmd...)
}

func (mc *MongoCtl) InitReplSet() error {
im, err := mc.runIsMaster()
if err != nil {
Expand All @@ -379,12 +415,7 @@ func (mc *MongoCtl) InitReplSet() error {
if im.SetName != "" {
return nil
}
cli := []string{"mongo", "--host", "localhost", "--port", "27018", "--norc"}
authedCli := append(cli, "--username", mc.adminCreds.Username, "--password", mc.adminCreds.Password)
if _, err := mc.runCmd(append(authedCli, "--eval", "quit()", AdminDB)...); err == nil {
cli = authedCli
}
_, err = mc.runCmd(append(cli, "--eval", "rs.initiate()")...)
_, err = mc.runMongoShellEval("rs.initiate()", AutoDetectAuth, false, "")
time.Sleep(3 * time.Second) // TODO: wait until rs initiated

return err
Expand All @@ -393,7 +424,7 @@ func (mc *MongoCtl) InitReplSet() error {
func (mc *MongoCtl) GetVersion() (version string, err error) {
for attempt := 0; attempt < 5; attempt++ {
var result ExecResult
result, err = mc.runCmd("mongo", "--host", "localhost", "--quiet", "--port", "27018", "--eval", "db.version()")
result, err = mc.runMongoShellEval("db.version()", NoneAuth, true, "")
if err != nil {
continue
}
Expand Down Expand Up @@ -430,12 +461,11 @@ func (mc *MongoCtl) GetConfigPath() (string, error) {
}

func (mc *MongoCtl) EnableAuth() error {
cmd := []string{"mongo", "--host", "localhost", "--quiet", "--norc", "--port", "27018",
"--eval", fmt.Sprintf("db.createUser({user: '%s', pwd: '%s', roles: ['root']})",
mc.adminCreds.Username,
mc.adminCreds.Password,
), AdminDB}
response, err := RunCommand(mc.ctx, mc.host, cmd)
eval := fmt.Sprintf("db.createUser({user: '%s', pwd: '%s', roles: ['root']})",
mc.adminCreds.Username,
mc.adminCreds.Password,
)
response, err := mc.runMongoShellEval(eval, NoneAuth, true, AdminDB)
if err != nil {
return err
}
Expand All @@ -445,10 +475,6 @@ func (mc *MongoCtl) EnableAuth() error {
strings.Contains(response.Combined(), "there are no users authenticated") {
return nil
}
if !strings.Contains(response.Combined(), "Successfully added user") {
tracelog.ErrorLogger.Printf("can not create admin user: %s", response.Combined())
return fmt.Errorf("can not initialize auth")
}

conn, err := mc.AdminConnect()
if err != nil {
Expand Down
24 changes: 0 additions & 24 deletions tests_func/images/mongodb/config/wal-g-4.0.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"AWS_S3_FORCE_PATH_STYLE": "true",

"WALG_STREAM_CREATE_COMMAND": "mongodump --archive --uri=\"mongodb://admin:password@127.0.0.1:27018\"",
"WALG_STREAM_RESTORE_COMMAND": "mongorestore --archive --drop --uri=\"mongodb://admin:password@127.0.0.1:27018\"",
"WALG_STREAM_RESTORE_COMMAND": "mongorestore --archive --uri=\"mongodb://admin:password@127.0.0.1:27018\"",
"MONGODB_URI": "mongodb://admin:password@127.0.0.1:27018/admin?authSource=admin&keepAlive=true&autoReconnect=true&socketTimeoutMS=3000&connectTimeoutMS=3000&readPreference=primary&connect=direct",

"WALG_SENTINEL_USER_DATA": "{\"key\": \"value\"}",
Expand All @@ -20,5 +20,6 @@
"WALG_DISK_RATE_LIMIT": "41943040",
"WALG_NETWORK_RATE_LIMIT": "10485760",
"WALG_LOG_LEVEL": "DEVEL",
"WALG_UPLOAD_CONCURRENCY" : 1
"WALG_UPLOAD_CONCURRENCY" : 1,
"OPLOG_PITR_DISCOVERY_INTERVAL": "168h"
}