summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Hirschhorn <max.hirschhorn@mongodb.com>2016-06-07 20:03:52 -0400
committerMax Hirschhorn <max.hirschhorn@mongodb.com>2016-06-07 20:03:52 -0400
commit9bed098dfe197fefe598f7bdfa79a1eb3fa6c299 (patch)
tree40b7fca52dc6d99f9ffc517c73d57980d868858c
parent20ea43a6147731bc2ea78363d7a33dce2942884a (diff)
downloadmongo-9bed098dfe197fefe598f7bdfa79a1eb3fa6c299.tar.gz
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. (cherry picked from commit 01dfe61a6c03307f0384406bfbde486f8de15425)
-rw-r--r--jstests/sharding/auth.js21
-rw-r--r--jstests/ssl/ssl_cert_password.js131
-rw-r--r--jstests/tool/dumpauth.js28
-rw-r--r--jstests/tool/dumprestore10.js18
-rw-r--r--jstests/tool/dumprestore3.js29
-rw-r--r--jstests/tool/dumprestore7.js33
-rw-r--r--jstests/tool/dumprestore9.js22
-rw-r--r--jstests/tool/dumpsecondary.js47
-rw-r--r--jstests/tool/gridfs.js9
-rw-r--r--jstests/tool/oplog_all_ops.js7
-rw-r--r--jstests/tool/restorewithauth.js65
-rw-r--r--jstests/tool/stat1.js42
-rw-r--r--jstests/tool/tool1.js59
-rw-r--r--jstests/tool/tool_replset.js44
-rw-r--r--src/mongo/shell/servers.js21
15 files changed, 336 insertions, 240 deletions
diff --git a/jstests/sharding/auth.js b/jstests/sharding/auth.js
index 7b8d55ee075..4714755a3cb 100644
--- a/jstests/sharding/auth.js
+++ b/jstests/sharding/auth.js
@@ -302,18 +302,15 @@
assert.commandWorked(res);
// Check that dump doesn't get stuck with auth
- var x = runMongoProgram("mongodump",
- "--host",
- s.s.host,
- "-d",
- testUser.db,
- "-u",
- testUser.username,
- "-p",
- testUser.password,
- "--authenticationMechanism",
- "SCRAM-SHA-1");
- print("result: " + x);
+ var exitCode = MongoRunner.runMongoTool("mongodump",
+ {
+ host: s.s.host,
+ db: testUser.db,
+ username: testUser.username,
+ password: testUser.password,
+ authenticationMechanism: "SCRAM-SHA-1",
+ });
+ assert.eq(0, exitCode, "mongodump failed to run with authentication enabled");
// Test read only users
print("starting read only tests");
diff --git a/jstests/ssl/ssl_cert_password.js b/jstests/ssl/ssl_cert_password.js
index 772038f9970..a21f9610ed1 100644
--- a/jstests/ssl/ssl_cert_password.js
+++ b/jstests/ssl/ssl_cert_password.js
@@ -41,32 +41,28 @@ assert.eq(0, c.count(), "dumprestore_ssl.foo collection is not initially empty")
c.save({a: 22});
assert.eq(1, c.count(), "failed to insert document into dumprestore_ssl.foo collection");
-exit_code = runMongoProgram("mongodump",
- "--out",
- external_scratch_dir,
- "--port",
- md.port,
- "--ssl",
- "--sslPEMKeyFile",
- "jstests/libs/password_protected.pem",
- "--sslPEMKeyPassword",
- "qwerty");
+exit_code = MongoRunner.runMongoTool("mongodump",
+ {
+ out: external_scratch_dir,
+ port: md.port,
+ ssl: "",
+ sslPEMKeyFile: "jstests/libs/password_protected.pem",
+ sslPEMKeyPassword: "qwerty",
+ });
assert.eq(exit_code, 0, "Failed to start mongodump with ssl");
c.drop();
assert.eq(0, c.count(), "dumprestore_ssl.foo collection is not empty after drop");
-exit_code = runMongoProgram("mongorestore",
- "--dir",
- external_scratch_dir,
- "--port",
- md.port,
- "--ssl",
- "--sslPEMKeyFile",
- "jstests/libs/password_protected.pem",
- "--sslPEMKeyPassword",
- "qwerty");
+exit_code = MongoRunner.runMongoTool("mongorestore",
+ {
+ dir: external_scratch_dir,
+ port: md.port,
+ ssl: "",
+ sslPEMKeyFile: "jstests/libs/password_protected.pem",
+ sslPEMKeyPassword: "qwerty",
+ });
assert.eq(exit_code, 0, "Failed to start mongorestore with ssl");
@@ -85,40 +81,32 @@ assert.eq(1, c.count(), "failed to insert document into exportimport_ssl.foo col
var exportimport_file = "data.json";
-exit_code = runMongoProgram("mongoexport",
- "--out",
- external_scratch_dir + exportimport_file,
- "-d",
- exportimport_ssl_dbname,
- "-c",
- "foo",
- "--port",
- md.port,
- "--ssl",
- "--sslPEMKeyFile",
- "jstests/libs/password_protected.pem",
- "--sslPEMKeyPassword",
- "qwerty");
+exit_code = MongoRunner.runMongoTool("mongoexport",
+ {
+ out: external_scratch_dir + exportimport_file,
+ db: exportimport_ssl_dbname,
+ collection: "foo",
+ port: md.port,
+ ssl: "",
+ sslPEMKeyFile: "jstests/libs/password_protected.pem",
+ sslPEMKeyPassword: "qwerty",
+ });
assert.eq(exit_code, 0, "Failed to start mongoexport with ssl");
c.drop();
assert.eq(0, c.count(), "afterdrop", "-d", exportimport_ssl_dbname, "-c", "foo");
-exit_code = runMongoProgram("mongoimport",
- "--file",
- external_scratch_dir + exportimport_file,
- "-d",
- exportimport_ssl_dbname,
- "-c",
- "foo",
- "--port",
- md.port,
- "--ssl",
- "--sslPEMKeyFile",
- "jstests/libs/password_protected.pem",
- "--sslPEMKeyPassword",
- "qwerty");
+exit_code = MongoRunner.runMongoTool("mongoimport",
+ {
+ file: external_scratch_dir + exportimport_file,
+ db: exportimport_ssl_dbname,
+ collection: "foo",
+ port: md.port,
+ ssl: "",
+ sslPEMKeyFile: "jstests/libs/password_protected.pem",
+ sslPEMKeyPassword: "qwerty",
+ });
assert.eq(exit_code, 0, "Failed to start mongoimport with ssl");
@@ -135,18 +123,16 @@ mongofiles_db = md.getDB(mongofiles_ssl_dbname);
source_filename = 'jstests/ssl/ssl_cert_password.js';
filename = 'ssl_cert_password.js';
-exit_code = runMongoProgram("mongofiles",
- "-d",
- mongofiles_ssl_dbname,
- "put",
- source_filename,
- "--port",
- md.port,
- "--ssl",
- "--sslPEMKeyFile",
- "jstests/libs/password_protected.pem",
- "--sslPEMKeyPassword",
- "qwerty");
+exit_code = MongoRunner.runMongoTool("mongofiles",
+ {
+ db: mongofiles_ssl_dbname,
+ port: md.port,
+ ssl: "",
+ sslPEMKeyFile: "jstests/libs/password_protected.pem",
+ sslPEMKeyPassword: "qwerty",
+ },
+ "put",
+ source_filename);
assert.eq(exit_code, 0, "Failed to start mongofiles with ssl");
@@ -159,20 +145,17 @@ md5_computed = mongofiles_db.runCommand({filemd5: file_obj._id}).md5;
assert.eq(md5, md5_stored, "md5 incorrect for file");
assert.eq(md5, md5_computed, "md5 computed incorrectly by server");
-exit_code = runMongoProgram("mongofiles",
- "-d",
- mongofiles_ssl_dbname,
- "get",
- source_filename,
- "-l",
- external_scratch_dir + filename,
- "--port",
- md.port,
- "--ssl",
- "--sslPEMKeyFile",
- "jstests/libs/password_protected.pem",
- "--sslPEMKeyPassword",
- "qwerty");
+exit_code = MongoRunner.runMongoTool("mongofiles",
+ {
+ db: mongofiles_ssl_dbname,
+ local: external_scratch_dir + filename,
+ port: md.port,
+ ssl: "",
+ sslPEMKeyFile: "jstests/libs/password_protected.pem",
+ sslPEMKeyPassword: "qwerty",
+ },
+ "get",
+ source_filename);
assert.eq(exit_code, 0, "Failed to start mongofiles with ssl");
diff --git a/jstests/tool/dumpauth.js b/jstests/tool/dumpauth.js
index 7be119a9f54..5b34e894262 100644
--- a/jstests/tool/dumpauth.js
+++ b/jstests/tool/dumpauth.js
@@ -30,20 +30,18 @@ assert.eq(t.count(), 100, "testcol should have documents");
db.createUser({user: "backup", pwd: "password", roles: ["backup"]});
// Backup the database with the backup user
-x = runMongoProgram("mongodump",
- "--db",
- dbName,
- "--out",
- dumpDir,
- "--authenticationDatabase=admin",
- "-u",
- "backup",
- "-p",
- "password",
- "-h",
- "127.0.0.1:" + m.port);
-assert.eq(x, 0, "mongodump should succeed with authentication");
+var exitCode = MongoRunner.runMongoTool("mongodump",
+ {
+ db: dbName,
+ out: dumpDir,
+ authenticationDatabase: "admin",
+ username: "backup",
+ password: "password",
+ host: "127.0.0.1:" + m.port,
+ });
+assert.eq(exitCode, 0, "mongodump should succeed with authentication");
// Assert that a BSON document for admin.system.profile has been produced
-x = runMongoProgram("bsondump", dumpDir + "/" + dbName + "/" + profileName + ".bson");
-assert.eq(x, 0, "bsondump should succeed parsing the profile data");
+exitCode =
+ MongoRunner.runMongoTool("bsondump", {}, dumpDir + "/" + dbName + "/" + profileName + ".bson");
+assert.eq(exitCode, 0, "bsondump should succeed parsing the profile data");
diff --git a/jstests/tool/dumprestore10.js b/jstests/tool/dumprestore10.js
index 7c8cc0ada58..1c3f1d5adcc 100644
--- a/jstests/tool/dumprestore10.js
+++ b/jstests/tool/dumprestore10.js
@@ -33,7 +33,12 @@ step("mongodump from replset");
var data = MongoRunner.dataDir + "/dumprestore10-dump1/";
-runMongoProgram("mongodump", "--host", "127.0.0.1:" + master.port, "--out", data);
+var exitCode = MongoRunner.runMongoTool("mongodump",
+ {
+ host: "127.0.0.1:" + master.port,
+ out: data,
+ });
+assert.eq(0, exitCode, "mongodump failed to dump data from the replica set");
{
step("remove data after dumping");
@@ -47,8 +52,15 @@ runMongoProgram("mongodump", "--host", "127.0.0.1:" + master.port, "--out", data
step("try mongorestore with write concern");
-runMongoProgram(
- "mongorestore", "--writeConcern", "2", "--host", "127.0.0.1:" + master.port, "--dir", data);
+exitCode = MongoRunner.runMongoTool("mongorestore",
+ {
+ writeConcern: "2",
+ host: "127.0.0.1:" + master.port,
+ dir: data,
+ });
+assert.eq(0,
+ exitCode,
+ "mongorestore failed to restore the data to a replica set while using w=2 writes");
var x = 0;
diff --git a/jstests/tool/dumprestore3.js b/jstests/tool/dumprestore3.js
index 6ac6ae76c3f..82ed9d5094a 100644
--- a/jstests/tool/dumprestore3.js
+++ b/jstests/tool/dumprestore3.js
@@ -21,22 +21,39 @@ replTest.awaitReplication();
jsTestLog("mongodump from primary");
var data = MongoRunner.dataDir + "/dumprestore3-other1/";
resetDbpath(data);
-var ret = runMongoProgram("mongodump", "--host", primary.host, "--out", data);
+var ret = MongoRunner.runMongoTool("mongodump",
+ {
+ host: primary.host,
+ out: data,
+ });
assert.eq(ret, 0, "mongodump should exit w/ 0 on primary");
jsTestLog("try mongorestore to secondary");
-ret = runMongoProgram("mongorestore", "--host", secondary.host, "--dir", data);
+ret = MongoRunner.runMongoTool("mongorestore",
+ {
+ host: secondary.host,
+ dir: data,
+ });
assert.neq(ret, 0, "mongorestore should exit w/ 1 on secondary");
jsTestLog("mongoexport from primary");
dataFile = MongoRunner.dataDir + "/dumprestore3-other2.json";
-ret = runMongoProgram(
- "mongoexport", "--host", primary.host, "--out", dataFile, "--db", "foo", "--collection", "bar");
+ret = MongoRunner.runMongoTool("mongoexport",
+ {
+ host: primary.host,
+ out: dataFile,
+ db: "foo",
+ collection: "bar",
+ });
assert.eq(ret, 0, "mongoexport should exit w/ 0 on primary");
jsTestLog("mongoimport from secondary");
-ret = runMongoProgram("mongoimport", "--host", secondary.host, "--file", dataFile);
-assert.neq(ret, 0, "mongoreimport should exit w/ 1 on secondary");
+ret = MongoRunner.runMongoTool("mongoimport",
+ {
+ host: secondary.host,
+ file: dataFile,
+ });
+assert.neq(ret, 0, "mongoimport should exit w/ 1 on secondary");
jsTestLog("stopSet");
replTest.stopSet();
diff --git a/jstests/tool/dumprestore7.js b/jstests/tool/dumprestore7.js
index 0598e73c0a8..60e6ef374ea 100644
--- a/jstests/tool/dumprestore7.js
+++ b/jstests/tool/dumprestore7.js
@@ -46,25 +46,34 @@ var master = replTest.getPrimary();
step("try mongodump with $timestamp");
var data = MongoRunner.dataDir + "/dumprestore7-dump1/";
-var query = "{\"ts\":{\"$gt\":{\"$timestamp\":{\"t\":" + time.ts.t + ",\"i\":" + time.ts.i + "}}}}";
+var query = {
+ ts: {$gt: {$timestamp: {t: time.ts.t, i: time.ts.i}}}
+};
-MongoRunner.runMongoTool("mongodump",
- {
- "host": "127.0.0.1:" + replTest.ports[0],
- "db": "local",
- "collection": "oplog.rs",
- "query": query,
- "out": data
- });
+var exitCode = MongoRunner.runMongoTool("mongodump",
+ {
+ host: "127.0.0.1:" + replTest.ports[0],
+ db: "local",
+ collection: "oplog.rs",
+ query: tojson(query),
+ out: data,
+ });
+assert.eq(0, exitCode, "monogdump failed to dump the oplog");
step("try mongorestore from $timestamp");
-runMongoProgram(
- "mongorestore", "--host", "127.0.0.1:" + conn.port, "--dir", data, "--writeConcern", 1);
+exitCode = MongoRunner.runMongoTool("mongorestore",
+ {
+ host: "127.0.0.1:" + conn.port,
+ dir: data,
+ writeConcern: 1,
+ });
+assert.eq(0, exitCode, "mongorestore failed to restore the oplog");
+
var x = 9;
x = conn.getDB("local").getCollection("oplog.rs").count();
-assert.eq(x, 20, "mongorestore should only have the latter 20 entries");
+assert.eq(x, 20, "mongorestore should only have inserted the latter 20 entries");
step("stopSet");
replTest.stopSet();
diff --git a/jstests/tool/dumprestore9.js b/jstests/tool/dumprestore9.js
index 7db1f817b24..69797603c16 100644
--- a/jstests/tool/dumprestore9.js
+++ b/jstests/tool/dumprestore9.js
@@ -53,7 +53,12 @@ if (0) {
dumpdir = MongoRunner.dataDir + "/dumprestore9-dump1/";
resetDbpath(dumpdir);
- runMongoProgram("mongodump", "--host", s._mongos[0].host, "--out", dumpdir);
+ var exitCode = MongoRunner.runMongoTool("mongodump",
+ {
+ host: s.s0.host,
+ out: dumpdir,
+ });
+ assert.eq(0, exitCode, "mongodump failed to dump data through one of the mongos processes");
step("Shutting down cluster");
@@ -69,12 +74,15 @@ if (0) {
step("Restore data and config");
- runMongoProgram("mongorestore",
- dumpdir,
- "--host",
- s._mongos[1].host,
- "--restoreShardingConfig",
- "--forceConfigRestore");
+ exitCode = MongoRunner.runMongoTool("mongorestore",
+ {
+ dir: dumpdir,
+ host: s.s1.host,
+ restoreShardingConfig: "",
+ forceConfigRestore: "",
+ });
+ assert.eq(
+ 0, exitCode, "mongorestore failed to restore data through the other mongos process");
config = s.getDB("config");
assert(config.databases.findOne({_id: 'aaa'}).partitioned,
diff --git a/jstests/tool/dumpsecondary.js b/jstests/tool/dumpsecondary.js
index 9abe8d7476e..a0a19e42f98 100644
--- a/jstests/tool/dumpsecondary.js
+++ b/jstests/tool/dumpsecondary.js
@@ -15,32 +15,35 @@ var slaves = replTest.liveNodes.slaves;
assert(slaves.length == 1, "Expected 1 slave but length was " + slaves.length);
slave = slaves[0];
-var args = [
- 'mongodump',
- '-h',
- slave.host,
- '--out',
- MongoRunner.dataDir + '/jstests_tool_dumpsecondary_external/'
-];
-var authargs =
- ['--username', jsTest.options().authUser, '--password', jsTest.options().authPassword];
+var commonOptions = {};
if (jsTest.options().keyFile) {
- args = args.concat(authargs);
+ commonOptions.username = jsTest.options().authUser;
+ commonOptions.password = jsTest.options().authPassword;
}
-runMongoProgram.apply(null, args);
-db.foo.drop();
+var exitCode = MongoRunner.runMongoTool(
+ "mongodump",
+ Object.extend(
+ {
+ host: slave.host,
+ out: MongoRunner.dataDir + "/jstests_tool_dumpsecondary_external/",
+ },
+ commonOptions));
+assert.eq(0, exitCode, "mongodump failed to dump data from the secondary");
+
+db.foo.drop();
assert.eq(0, db.foo.count(), "after drop");
-args = [
- 'mongorestore',
- '-h',
- master.host,
- MongoRunner.dataDir + '/jstests_tool_dumpsecondary_external/'
-];
-if (jsTest.options().keyFile) {
- args = args.concat(authargs);
-}
-runMongoProgram.apply(null, args);
+
+exitCode = MongoRunner.runMongoTool(
+ "mongorestore",
+ Object.extend(
+ {
+ host: master.host,
+ dir: MongoRunner.dataDir + "/jstests_tool_dumpsecondary_external/",
+ },
+ commonOptions));
+assert.eq(0, exitCode, "mongorestore failed to restore data to the primary");
+
assert.soon("db.foo.findOne()", "no data after sleep");
assert.eq(1, db.foo.count(), "after restore");
assert.eq(1000, db.foo.findOne().a, "after restore 2");
diff --git a/jstests/tool/gridfs.js b/jstests/tool/gridfs.js
index 5fbf6e6036b..147a255d93e 100644
--- a/jstests/tool/gridfs.js
+++ b/jstests/tool/gridfs.js
@@ -18,7 +18,14 @@ function testGridFS(name) {
var rawmd5 = md5sumFile(filename);
// upload file (currently calls filemd5 internally)
- runMongoProgram("mongofiles", "--port", mongos.port, "put", filename, '--db', name);
+ var exitCode = MongoRunner.runMongoTool("mongofiles",
+ {
+ port: mongos.port,
+ db: name,
+ },
+ "put",
+ filename);
+ assert.eq(0, exitCode, "mongofiles failed to upload '" + filename + "' into a sharded cluster");
assert.eq(d.fs.files.count(), 1);
var fileObj = d.fs.files.findOne();
diff --git a/jstests/tool/oplog_all_ops.js b/jstests/tool/oplog_all_ops.js
index fb988174d24..899b99294ab 100644
--- a/jstests/tool/oplog_all_ops.js
+++ b/jstests/tool/oplog_all_ops.js
@@ -44,7 +44,12 @@ repl2.initiate();
repl2.awaitSecondaryNodes();
var srcConn = repl1.getPrimary();
-runMongoProgram('mongooplog', '--from', repl1.getPrimary().host, '--host', repl2.getPrimary().host);
+var exitCode = MongoRunner.runMongoTool('mongooplog',
+ {
+ from: repl1.getPrimary().host,
+ host: repl2.getPrimary().host,
+ });
+assert.eq(0, exitCode, 'mongooplog failed to poll operations from rs1 and apply them to rs2');
var repl1Hash = testDB.runCommand({dbhash: 1});
diff --git a/jstests/tool/restorewithauth.js b/jstests/tool/restorewithauth.js
index 0fd29706ee1..98d1df6a0cf 100644
--- a/jstests/tool/restorewithauth.js
+++ b/jstests/tool/restorewithauth.js
@@ -39,7 +39,14 @@ assert.eq(foo.baz.getIndexes().length, 1);
// get data dump
var dumpdir = MongoRunner.dataDir + "/restorewithauth-dump1/";
resetDbpath(dumpdir);
-x = runMongoProgram("mongodump", "--db", "foo", "-h", "127.0.0.1:" + conn.port, "--out", dumpdir);
+
+var exitCode = MongoRunner.runMongoTool("mongodump",
+ {
+ db: "foo",
+ host: "127.0.0.1:" + conn.port,
+ out: dumpdir,
+ });
+assert.eq(0, exitCode, "mongodump failed to dump data from mongod without auth enabled");
// now drop the db
foo.dropDatabase();
@@ -63,7 +70,15 @@ assert.eq(-1, collNames.indexOf("bar"), "bar collection already exists");
assert.eq(-1, collNames.indexOf("baz"), "baz collection already exists");
// now try to restore dump
-x = runMongoProgram("mongorestore", "-h", "127.0.0.1:" + conn.port, "--dir", dumpdir, "-vvvvv");
+exitCode = MongoRunner.runMongoTool("mongorestore",
+ {
+ host: "127.0.0.1:" + conn.port,
+ dir: dumpdir,
+ verbose: 5,
+ });
+assert.neq(0,
+ exitCode,
+ "mongorestore shouldn't have been able to restore data to mongod with auth enabled");
// make sure that the collection isn't restored
collNames = foo.getCollectionNames();
@@ -71,19 +86,17 @@ assert.eq(-1, collNames.indexOf("bar"), "bar collection was restored");
assert.eq(-1, collNames.indexOf("baz"), "baz collection was restored");
// now try to restore dump with correct credentials
-x = runMongoProgram("mongorestore",
- "-h",
- "127.0.0.1:" + conn.port,
- "-d",
- "foo",
- "--authenticationDatabase=admin",
- "-u",
- "admin",
- "-p",
- "admin",
- "--dir",
- dumpdir + "foo/",
- "-vvvvv");
+exitCode = MongoRunner.runMongoTool("mongorestore",
+ {
+ host: "127.0.0.1:" + conn.port,
+ db: "foo",
+ authenticationDatabase: "admin",
+ username: "admin",
+ password: "admin",
+ dir: dumpdir + "foo/",
+ verbose: 5,
+ });
+assert.eq(0, exitCode, "mongorestore failed to restore data to mongod with auth enabled");
// make sure that the collection was restored
collNames = foo.getCollectionNames();
@@ -99,18 +112,16 @@ foo.dropDatabase();
foo.createUser({user: 'user', pwd: 'password', roles: jsTest.basicUserRoles});
// now try to restore dump with foo database credentials
-x = runMongoProgram("mongorestore",
- "-h",
- "127.0.0.1:" + conn.port,
- "-d",
- "foo",
- "-u",
- "user",
- "-p",
- "password",
- "--dir",
- dumpdir + "foo/",
- "-vvvvv");
+exitCode = MongoRunner.runMongoTool("mongorestore",
+ {
+ host: "127.0.0.1:" + conn.port,
+ db: "foo",
+ username: "user",
+ password: "password",
+ dir: dumpdir + "foo/",
+ verbose: 5,
+ });
+assert.eq(0, exitCode, "mongorestore failed to restore the 'foo' database");
// make sure that the collection was restored
collNames = foo.getCollectionNames();
diff --git a/jstests/tool/stat1.js b/jstests/tool/stat1.js
index efdbcb0f376..dae12e67308 100644
--- a/jstests/tool/stat1.js
+++ b/jstests/tool/stat1.js
@@ -8,28 +8,22 @@ db = m.getDB("admin");
db.createUser({user: "eliot", pwd: "eliot", roles: jsTest.adminUserRoles});
assert(db.auth("eliot", "eliot"), "auth failed");
-x = runMongoProgram("mongostat",
- "--host",
- "127.0.0.1:" + m.port,
- "--username",
- "eliot",
- "--password",
- "eliot",
- "--rowcount",
- "1",
- "--authenticationDatabase",
- "admin");
-assert.eq(x, 0, "mongostat should exit successfully with eliot:eliot");
+var exitCode = MongoRunner.runMongoTool("mongostat",
+ {
+ host: "127.0.0.1:" + m.port,
+ username: "eliot",
+ password: "eliot",
+ rowcount: "1",
+ authenticationDatabase: "admin",
+ });
+assert.eq(exitCode, 0, "mongostat should exit successfully with eliot:eliot");
-x = runMongoProgram("mongostat",
- "--host",
- "127.0.0.1:" + m.port,
- "--username",
- "eliot",
- "--password",
- "wrong",
- "--rowcount",
- "1",
- "--authenticationDatabase",
- "admin");
-assert.neq(x, 0, "mongostat should exit with -1 with eliot:wrong");
+exitCode = MongoRunner.runMongoTool("mongostat",
+ {
+ host: "127.0.0.1:" + m.port,
+ username: "eliot",
+ password: "wrong",
+ rowcount: "1",
+ authenticationDatabase: "admin",
+ });
+assert.neq(exitCode, 0, "mongostat should exit with -1 with eliot:wrong");
diff --git a/jstests/tool/tool1.js b/jstests/tool/tool1.js
index ce5e880b4ba..ce8376ffcba 100644
--- a/jstests/tool/tool1.js
+++ b/jstests/tool/tool1.js
@@ -22,9 +22,22 @@ c = m.getDB(baseName).getCollection(baseName);
c.save({a: 1});
assert(c.findOne());
-runMongoProgram("mongodump", "--host", "127.0.0.1:" + m.port, "--out", externalPath);
+var exitCode = MongoRunner.runMongoTool("mongodump",
+ {
+ host: "127.0.0.1:" + m.port,
+ out: externalPath,
+ });
+assert.eq(0, exitCode, "mongodump failed to dump data from mongod");
+
c.drop();
-runMongoProgram("mongorestore", "--host", "127.0.0.1:" + m.port, "--dir", externalPath);
+
+exitCode = MongoRunner.runMongoTool("mongorestore",
+ {
+ host: "127.0.0.1:" + m.port,
+ dir: externalPath,
+ });
+assert.eq(0, exitCode, "mongorestore failed to restore data to mongod");
+
assert.soon("c.findOne()", "mongodump then restore has no data w/sleep");
assert(c.findOne(), "mongodump then restore has no data");
assert.eq(1, c.findOne().a, "mongodump then restore has no broken data");
@@ -32,26 +45,32 @@ assert.eq(1, c.findOne().a, "mongodump then restore has no broken data");
resetDbpath(externalPath);
assert.eq(-1, fileSize(), "mongoexport prep invalid");
-runMongoProgram("mongoexport",
- "--host",
- "127.0.0.1:" + m.port,
- "-d",
- baseName,
- "-c",
- baseName,
- "--out",
- externalFile);
+
+exitCode = MongoRunner.runMongoTool("mongoexport",
+ {
+ host: "127.0.0.1:" + m.port,
+ db: baseName,
+ collection: baseName,
+ out: externalFile,
+ });
+assert.eq(0,
+ exitCode,
+ "mongoexport failed to export collection '" + c.getFullName() + "' from mongod");
+
assert.lt(10, fileSize(), "file size changed");
c.drop();
-runMongoProgram("mongoimport",
- "--host",
- "127.0.0.1:" + m.port,
- "-d",
- baseName,
- "-c",
- baseName,
- "--file",
- externalFile);
+
+exitCode = MongoRunner.runMongoTool("mongoimport",
+ {
+ host: "127.0.0.1:" + m.port,
+ db: baseName,
+ collection: baseName,
+ file: externalFile,
+ });
+assert.eq(0,
+ exitCode,
+ "mongoimport failed to import collection '" + c.getFullName() + "' into mongod");
+
assert.soon("c.findOne()", "mongo import json A");
assert(c.findOne() && 1 == c.findOne().a, "mongo import json B");
diff --git a/jstests/tool/tool_replset.js b/jstests/tool/tool_replset.js
index efe55b46605..bdb7648c7f2 100644
--- a/jstests/tool/tool_replset.js
+++ b/jstests/tool/tool_replset.js
@@ -36,14 +36,24 @@
// Test with mongodump/mongorestore
print("dump the db");
var data = MongoRunner.dataDir + "/tool_replset-dump1/";
- runMongoProgram("mongodump", "--host", replSetConnString, "--out", data);
+ var exitCode = MongoRunner.runMongoTool("mongodump",
+ {
+ host: replSetConnString,
+ out: data,
+ });
+ assert.eq(0, exitCode, "mongodump failed to dump from the replica set");
print("db successfully dumped, dropping now");
master.getDB("foo").dropDatabase();
replTest.awaitReplication();
print("restore the db");
- runMongoProgram("mongorestore", "--host", replSetConnString, "--dir", data);
+ exitCode = MongoRunner.runMongoTool("mongorestore",
+ {
+ host: replSetConnString,
+ dir: data,
+ });
+ assert.eq(0, exitCode, "mongorestore failed to restore data to the replica set");
print("db successfully restored, checking count");
var x = master.getDB("foo").getCollection("bar").count();
@@ -54,16 +64,30 @@
// Test with mongoexport/mongoimport
print("export the collection");
var extFile = MongoRunner.dataDir + "/tool_replset/export";
- runMongoProgram(
- "mongoexport", "--host", replSetConnString, "--out", extFile, "-d", "foo", "-c", "bar");
+ exitCode = MongoRunner.runMongoTool("mongoexport",
+ {
+ host: replSetConnString,
+ out: extFile,
+ db: "foo",
+ collection: "bar",
+ });
+ assert.eq(
+ 0, exitCode, "mongoexport failed to export collection 'foo.bar' from the replica set");
print("collection successfully exported, dropping now");
master.getDB("foo").getCollection("bar").drop();
replTest.awaitReplication();
print("import the collection");
- runMongoProgram(
- "mongoimport", "--host", replSetConnString, "--file", extFile, "-d", "foo", "-c", "bar");
+ exitCode = MongoRunner.runMongoTool("mongoimport",
+ {
+ host: replSetConnString,
+ file: extFile,
+ db: "foo",
+ collection: "bar",
+ });
+ assert.eq(
+ 0, exitCode, "mongoimport failed to import collection 'foo.bar' into the replica set");
var x = master.getDB("foo").getCollection("bar").count();
assert.eq(x, 100, "mongoimport should have successfully imported the collection");
@@ -84,8 +108,12 @@
master.getDB("foo").getCollection("bar").count(),
"count before running " + "mongooplog was not 100 as expected");
- runMongoProgram(
- "mongooplog", "--from", "127.0.0.1:" + replTest.ports[0], "--host", replSetConnString);
+ exitCode = MongoRunner.runMongoTool("mongooplog",
+ {
+ from: "127.0.0.1:" + replTest.ports[0],
+ host: replSetConnString,
+ });
+ assert.eq(0, exitCode, "mongooplog failed to replay the oplog");
print("finished running mongooplog to replay the oplog");
diff --git a/src/mongo/shell/servers.js b/src/mongo/shell/servers.js
index d0b0de34fed..81f39701e9c 100644
--- a/src/mongo/shell/servers.js
+++ b/src/mongo/shell/servers.js
@@ -779,16 +779,18 @@ var MongoRunner, _startMongod, startMongoProgram, runMongoProgram, startMongoPro
/**
* Starts an instance of the specified mongo tool
*
- * @param {String} binaryName The name of the tool to run
- * @param {Object} opts options to pass to the tool
- * {
- * binVersion {string}: version of tool to run
- * }
+ * @param {String} binaryName - The name of the tool to run.
+ * @param {Object} [opts={}] - Options of the form --flag or --key=value to pass to the tool.
+ * @param {string} [opts.binVersion] - The version of the tool to run.
+ *
+ * @param {...string} positionalArgs - Positional arguments to pass to the tool after all
+ * options have been specified. For example,
+ * MongoRunner.runMongoTool("executable", {key: value}, arg1, arg2) would invoke
+ * ./executable --key value arg1 arg2.
*
* @see MongoRunner.arrOptions
*/
- MongoRunner.runMongoTool = function(binaryName, opts) {
-
+ MongoRunner.runMongoTool = function(binaryName, opts, ... positionalArgs) {
var opts = opts || {};
// Normalize and get the binary version to use
opts.binVersion = MongoRunner.getBinVersionFor(opts.binVersion);
@@ -802,10 +804,13 @@ var MongoRunner, _startMongod, startMongoProgram, runMongoProgram, startMongoPro
opts['dialTimeout'] = '30';
}
+ // Convert 'opts' into an array of arguments.
var argsArray = MongoRunner.arrOptions(binaryName, opts);
- return runMongoProgram.apply(null, argsArray);
+ // Append any positional arguments that were specified.
+ argsArray.push(... positionalArgs);
+ return runMongoProgram.apply(null, argsArray);
};
var _toolVersionSupportsDialTimeout = function(version) {