Skip to content

Commit 01dfe61

Browse files
committed
SERVER-23741 Use MongoRunner.runMongoTool() to run tools from JS tests.
Changes all usages of runMongoProgram(<mongo tool>, ...) to MongoRunner.runMongoTool(<mongo tool>, {...}) to take advantage of the --dialTimeout command line option supported by the mongo tools. Adds support for specifying positional arguments to MongoRunner.runMongoTool() in order to support all invocations of the bsondump and mongofiles tools.
1 parent 0324244 commit 01dfe61

File tree

15 files changed

+296
-236
lines changed

15 files changed

+296
-236
lines changed

jstests/sharding/auth.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -280,18 +280,14 @@
280280
assert.commandWorked(res);
281281

282282
// Check that dump doesn't get stuck with auth
283-
var x = runMongoProgram("mongodump",
284-
"--host",
285-
s.s.host,
286-
"-d",
287-
testUser.db,
288-
"-u",
289-
testUser.username,
290-
"-p",
291-
testUser.password,
292-
"--authenticationMechanism",
293-
"SCRAM-SHA-1");
294-
print("result: " + x);
283+
var exitCode = MongoRunner.runMongoTool("mongodump", {
284+
host: s.s.host,
285+
db: testUser.db,
286+
username: testUser.username,
287+
password: testUser.password,
288+
authenticationMechanism: "SCRAM-SHA-1",
289+
});
290+
assert.eq(0, exitCode, "mongodump failed to run with authentication enabled");
295291

296292
// Test read only users
297293
print("starting read only tests");

jstests/ssl/ssl_cert_password.js

Lines changed: 53 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -41,32 +41,26 @@ assert.eq(0, c.count(), "dumprestore_ssl.foo collection is not initially empty")
4141
c.save({a: 22});
4242
assert.eq(1, c.count(), "failed to insert document into dumprestore_ssl.foo collection");
4343

44-
exit_code = runMongoProgram("mongodump",
45-
"--out",
46-
external_scratch_dir,
47-
"--port",
48-
md.port,
49-
"--ssl",
50-
"--sslPEMKeyFile",
51-
"jstests/libs/password_protected.pem",
52-
"--sslPEMKeyPassword",
53-
"qwerty");
44+
exit_code = MongoRunner.runMongoTool("mongodump", {
45+
out: external_scratch_dir,
46+
port: md.port,
47+
ssl: "",
48+
sslPEMKeyFile: "jstests/libs/password_protected.pem",
49+
sslPEMKeyPassword: "qwerty",
50+
});
5451

5552
assert.eq(exit_code, 0, "Failed to start mongodump with ssl");
5653

5754
c.drop();
5855
assert.eq(0, c.count(), "dumprestore_ssl.foo collection is not empty after drop");
5956

60-
exit_code = runMongoProgram("mongorestore",
61-
"--dir",
62-
external_scratch_dir,
63-
"--port",
64-
md.port,
65-
"--ssl",
66-
"--sslPEMKeyFile",
67-
"jstests/libs/password_protected.pem",
68-
"--sslPEMKeyPassword",
69-
"qwerty");
57+
exit_code = MongoRunner.runMongoTool("mongorestore", {
58+
dir: external_scratch_dir,
59+
port: md.port,
60+
ssl: "",
61+
sslPEMKeyFile: "jstests/libs/password_protected.pem",
62+
sslPEMKeyPassword: "qwerty",
63+
});
7064

7165
assert.eq(exit_code, 0, "Failed to start mongorestore with ssl");
7266

@@ -85,40 +79,30 @@ assert.eq(1, c.count(), "failed to insert document into exportimport_ssl.foo col
8579

8680
var exportimport_file = "data.json";
8781

88-
exit_code = runMongoProgram("mongoexport",
89-
"--out",
90-
external_scratch_dir + exportimport_file,
91-
"-d",
92-
exportimport_ssl_dbname,
93-
"-c",
94-
"foo",
95-
"--port",
96-
md.port,
97-
"--ssl",
98-
"--sslPEMKeyFile",
99-
"jstests/libs/password_protected.pem",
100-
"--sslPEMKeyPassword",
101-
"qwerty");
82+
exit_code = MongoRunner.runMongoTool("mongoexport", {
83+
out: external_scratch_dir + exportimport_file,
84+
db: exportimport_ssl_dbname,
85+
collection: "foo",
86+
port: md.port,
87+
ssl: "",
88+
sslPEMKeyFile: "jstests/libs/password_protected.pem",
89+
sslPEMKeyPassword: "qwerty",
90+
});
10291

10392
assert.eq(exit_code, 0, "Failed to start mongoexport with ssl");
10493

10594
c.drop();
10695
assert.eq(0, c.count(), "afterdrop", "-d", exportimport_ssl_dbname, "-c", "foo");
10796

108-
exit_code = runMongoProgram("mongoimport",
109-
"--file",
110-
external_scratch_dir + exportimport_file,
111-
"-d",
112-
exportimport_ssl_dbname,
113-
"-c",
114-
"foo",
115-
"--port",
116-
md.port,
117-
"--ssl",
118-
"--sslPEMKeyFile",
119-
"jstests/libs/password_protected.pem",
120-
"--sslPEMKeyPassword",
121-
"qwerty");
97+
exit_code = MongoRunner.runMongoTool("mongoimport", {
98+
file: external_scratch_dir + exportimport_file,
99+
db: exportimport_ssl_dbname,
100+
collection: "foo",
101+
port: md.port,
102+
ssl: "",
103+
sslPEMKeyFile: "jstests/libs/password_protected.pem",
104+
sslPEMKeyPassword: "qwerty",
105+
});
122106

123107
assert.eq(exit_code, 0, "Failed to start mongoimport with ssl");
124108

@@ -135,18 +119,16 @@ mongofiles_db = md.getDB(mongofiles_ssl_dbname);
135119
source_filename = 'jstests/ssl/ssl_cert_password.js';
136120
filename = 'ssl_cert_password.js';
137121

138-
exit_code = runMongoProgram("mongofiles",
139-
"-d",
140-
mongofiles_ssl_dbname,
141-
"put",
142-
source_filename,
143-
"--port",
144-
md.port,
145-
"--ssl",
146-
"--sslPEMKeyFile",
147-
"jstests/libs/password_protected.pem",
148-
"--sslPEMKeyPassword",
149-
"qwerty");
122+
exit_code = MongoRunner.runMongoTool("mongofiles",
123+
{
124+
db: mongofiles_ssl_dbname,
125+
port: md.port,
126+
ssl: "",
127+
sslPEMKeyFile: "jstests/libs/password_protected.pem",
128+
sslPEMKeyPassword: "qwerty",
129+
},
130+
"put",
131+
source_filename);
150132

151133
assert.eq(exit_code, 0, "Failed to start mongofiles with ssl");
152134

@@ -159,20 +141,17 @@ md5_computed = mongofiles_db.runCommand({filemd5: file_obj._id}).md5;
159141
assert.eq(md5, md5_stored, "md5 incorrect for file");
160142
assert.eq(md5, md5_computed, "md5 computed incorrectly by server");
161143

162-
exit_code = runMongoProgram("mongofiles",
163-
"-d",
164-
mongofiles_ssl_dbname,
165-
"get",
166-
source_filename,
167-
"-l",
168-
external_scratch_dir + filename,
169-
"--port",
170-
md.port,
171-
"--ssl",
172-
"--sslPEMKeyFile",
173-
"jstests/libs/password_protected.pem",
174-
"--sslPEMKeyPassword",
175-
"qwerty");
144+
exit_code = MongoRunner.runMongoTool("mongofiles",
145+
{
146+
db: mongofiles_ssl_dbname,
147+
local: external_scratch_dir + filename,
148+
port: md.port,
149+
ssl: "",
150+
sslPEMKeyFile: "jstests/libs/password_protected.pem",
151+
sslPEMKeyPassword: "qwerty",
152+
},
153+
"get",
154+
source_filename);
176155

177156
assert.eq(exit_code, 0, "Failed to start mongofiles with ssl");
178157

jstests/tool/dumpauth.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,17 @@ assert.eq(t.count(), 100, "testcol should have documents");
3030
db.createUser({user: "backup", pwd: "password", roles: ["backup"]});
3131

3232
// Backup the database with the backup user
33-
x = runMongoProgram("mongodump",
34-
"--db",
35-
dbName,
36-
"--out",
37-
dumpDir,
38-
"--authenticationDatabase=admin",
39-
"-u",
40-
"backup",
41-
"-p",
42-
"password",
43-
"-h",
44-
"127.0.0.1:" + m.port);
45-
assert.eq(x, 0, "mongodump should succeed with authentication");
33+
var exitCode = MongoRunner.runMongoTool("mongodump", {
34+
db: dbName,
35+
out: dumpDir,
36+
authenticationDatabase: "admin",
37+
username: "backup",
38+
password: "password",
39+
host: "127.0.0.1:" + m.port,
40+
});
41+
assert.eq(exitCode, 0, "mongodump should succeed with authentication");
4642

4743
// Assert that a BSON document for admin.system.profile has been produced
48-
x = runMongoProgram("bsondump", dumpDir + "/" + dbName + "/" + profileName + ".bson");
49-
assert.eq(x, 0, "bsondump should succeed parsing the profile data");
44+
exitCode =
45+
MongoRunner.runMongoTool("bsondump", {}, dumpDir + "/" + dbName + "/" + profileName + ".bson");
46+
assert.eq(exitCode, 0, "bsondump should succeed parsing the profile data");

jstests/tool/dumprestore10.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ step("mongodump from replset");
3333

3434
var data = MongoRunner.dataDir + "/dumprestore10-dump1/";
3535

36-
runMongoProgram("mongodump", "--host", "127.0.0.1:" + master.port, "--out", data);
36+
var exitCode = MongoRunner.runMongoTool("mongodump", {
37+
host: "127.0.0.1:" + master.port,
38+
out: data,
39+
});
40+
assert.eq(0, exitCode, "mongodump failed to dump data from the replica set");
3741

3842
{
3943
step("remove data after dumping");
@@ -47,8 +51,13 @@ runMongoProgram("mongodump", "--host", "127.0.0.1:" + master.port, "--out", data
4751

4852
step("try mongorestore with write concern");
4953

50-
runMongoProgram(
51-
"mongorestore", "--writeConcern", "2", "--host", "127.0.0.1:" + master.port, "--dir", data);
54+
exitCode = MongoRunner.runMongoTool("mongorestore", {
55+
writeConcern: "2",
56+
host: "127.0.0.1:" + master.port,
57+
dir: data,
58+
});
59+
assert.eq(
60+
0, exitCode, "mongorestore failed to restore the data to a replica set while using w=2 writes");
5261

5362
var x = 0;
5463

jstests/tool/dumprestore3.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,35 @@ replTest.awaitReplication();
2121
jsTestLog("mongodump from primary");
2222
var data = MongoRunner.dataDir + "/dumprestore3-other1/";
2323
resetDbpath(data);
24-
var ret = runMongoProgram("mongodump", "--host", primary.host, "--out", data);
24+
var ret = MongoRunner.runMongoTool("mongodump", {
25+
host: primary.host,
26+
out: data,
27+
});
2528
assert.eq(ret, 0, "mongodump should exit w/ 0 on primary");
2629

2730
jsTestLog("try mongorestore to secondary");
28-
ret = runMongoProgram("mongorestore", "--host", secondary.host, "--dir", data);
31+
ret = MongoRunner.runMongoTool("mongorestore", {
32+
host: secondary.host,
33+
dir: data,
34+
});
2935
assert.neq(ret, 0, "mongorestore should exit w/ 1 on secondary");
3036

3137
jsTestLog("mongoexport from primary");
3238
dataFile = MongoRunner.dataDir + "/dumprestore3-other2.json";
33-
ret = runMongoProgram(
34-
"mongoexport", "--host", primary.host, "--out", dataFile, "--db", "foo", "--collection", "bar");
39+
ret = MongoRunner.runMongoTool("mongoexport", {
40+
host: primary.host,
41+
out: dataFile,
42+
db: "foo",
43+
collection: "bar",
44+
});
3545
assert.eq(ret, 0, "mongoexport should exit w/ 0 on primary");
3646

3747
jsTestLog("mongoimport from secondary");
38-
ret = runMongoProgram("mongoimport", "--host", secondary.host, "--file", dataFile);
39-
assert.neq(ret, 0, "mongoreimport should exit w/ 1 on secondary");
48+
ret = MongoRunner.runMongoTool("mongoimport", {
49+
host: secondary.host,
50+
file: dataFile,
51+
});
52+
assert.neq(ret, 0, "mongoimport should exit w/ 1 on secondary");
4053

4154
jsTestLog("stopSet");
4255
replTest.stopSet();

jstests/tool/dumprestore7.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,30 @@ var master = replTest.getPrimary();
4646
step("try mongodump with $timestamp");
4747

4848
var data = MongoRunner.dataDir + "/dumprestore7-dump1/";
49-
var query = "{\"ts\":{\"$gt\":{\"$timestamp\":{\"t\":" + time.ts.t + ",\"i\":" + time.ts.i + "}}}}";
49+
var query = {ts: {$gt: {$timestamp: {t: time.ts.t, i: time.ts.i}}}};
5050

51-
MongoRunner.runMongoTool("mongodump", {
52-
"host": "127.0.0.1:" + replTest.ports[0],
53-
"db": "local",
54-
"collection": "oplog.rs",
55-
"query": query,
56-
"out": data
51+
var exitCode = MongoRunner.runMongoTool("mongodump", {
52+
host: "127.0.0.1:" + replTest.ports[0],
53+
db: "local",
54+
collection: "oplog.rs",
55+
query: tojson(query),
56+
out: data,
5757
});
58+
assert.eq(0, exitCode, "monogdump failed to dump the oplog");
5859

5960
step("try mongorestore from $timestamp");
6061

61-
runMongoProgram(
62-
"mongorestore", "--host", "127.0.0.1:" + conn.port, "--dir", data, "--writeConcern", 1);
62+
exitCode = MongoRunner.runMongoTool("mongorestore", {
63+
host: "127.0.0.1:" + conn.port,
64+
dir: data,
65+
writeConcern: 1,
66+
});
67+
assert.eq(0, exitCode, "mongorestore failed to restore the oplog");
68+
6369
var x = 9;
6470
x = conn.getDB("local").getCollection("oplog.rs").count();
6571

66-
assert.eq(x, 20, "mongorestore should only have the latter 20 entries");
72+
assert.eq(x, 20, "mongorestore should only have inserted the latter 20 entries");
6773

6874
step("stopSet");
6975
replTest.stopSet();

jstests/tool/dumprestore9.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ if (0) {
5353

5454
dumpdir = MongoRunner.dataDir + "/dumprestore9-dump1/";
5555
resetDbpath(dumpdir);
56-
runMongoProgram("mongodump", "--host", s._mongos[0].host, "--out", dumpdir);
56+
var exitCode = MongoRunner.runMongoTool("mongodump", {
57+
host: s.s0.host,
58+
out: dumpdir,
59+
});
60+
assert.eq(0, exitCode, "mongodump failed to dump data through one of the mongos processes");
5761

5862
step("Shutting down cluster");
5963

@@ -69,12 +73,14 @@ if (0) {
6973

7074
step("Restore data and config");
7175

72-
runMongoProgram("mongorestore",
73-
dumpdir,
74-
"--host",
75-
s._mongos[1].host,
76-
"--restoreShardingConfig",
77-
"--forceConfigRestore");
76+
exitCode = MongoRunner.runMongoTool("mongorestore", {
77+
dir: dumpdir,
78+
host: s.s1.host,
79+
restoreShardingConfig: "",
80+
forceConfigRestore: "",
81+
});
82+
assert.eq(
83+
0, exitCode, "mongorestore failed to restore data through the other mongos process");
7884

7985
config = s.getDB("config");
8086
assert(config.databases.findOne({_id: 'aaa'}).partitioned,

0 commit comments

Comments
 (0)