summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorEsha Maharishi <esha.maharishi@mongodb.com>2017-11-27 17:17:17 -0500
committerEsha Maharishi <esha.maharishi@mongodb.com>2017-12-05 13:48:04 -0500
commiteda6982ae8f5ebac140cb2420210776828cae947 (patch)
treea1e533720e03d69ebe42f74ac1be0be110d9ff2e /jstests
parent18851f31bbee892d558680536894968efa72feb7 (diff)
downloadmongo-eda6982ae8f5ebac140cb2420210776828cae947.tar.gz
SERVER-32105 Require shard servers and config servers to be started with --replSet or 'replSetName'
Diffstat (limited to 'jstests')
-rw-r--r--jstests/libs/config_files/set_shardingrole_configsvr.json (renamed from jstests/libs/config_files/set_shardingrole.json)3
-rw-r--r--jstests/libs/config_files/set_shardingrole_shardsvr.json8
-rw-r--r--jstests/sharding/require_shardsvrs_and_configsvrs_to_be_replica_sets.js62
-rw-r--r--jstests/sharding/shard_config_db_collections.js2
-rw-r--r--jstests/sharding/sharding_options.js18
5 files changed, 89 insertions, 4 deletions
diff --git a/jstests/libs/config_files/set_shardingrole.json b/jstests/libs/config_files/set_shardingrole_configsvr.json
index 71f92f122db..f6121cfd52b 100644
--- a/jstests/libs/config_files/set_shardingrole.json
+++ b/jstests/libs/config_files/set_shardingrole_configsvr.json
@@ -1,5 +1,8 @@
{
"sharding" : {
"clusterRole" : "configsvr"
+ },
+ "replication": {
+ "replSetName" : "dummy"
}
}
diff --git a/jstests/libs/config_files/set_shardingrole_shardsvr.json b/jstests/libs/config_files/set_shardingrole_shardsvr.json
new file mode 100644
index 00000000000..333a33528b9
--- /dev/null
+++ b/jstests/libs/config_files/set_shardingrole_shardsvr.json
@@ -0,0 +1,8 @@
+{
+ "sharding" : {
+ "clusterRole" : "shardsvr"
+ },
+ "replication" : {
+ "replSetName" : "dummy"
+ }
+}
diff --git a/jstests/sharding/require_shardsvrs_and_configsvrs_to_be_replica_sets.js b/jstests/sharding/require_shardsvrs_and_configsvrs_to_be_replica_sets.js
new file mode 100644
index 00000000000..5157a8ac12d
--- /dev/null
+++ b/jstests/sharding/require_shardsvrs_and_configsvrs_to_be_replica_sets.js
@@ -0,0 +1,62 @@
+/**
+ * Ensures that a server started with --shardsvr or --configsvr must also be started as a replica
+ * set, unless it is started with enableTestCommands=1.
+ */
+(function() {
+ var testAllPermutations = function(enableTestCommands) {
+ jsTest.setOption('enableTestCommands', enableTestCommands);
+ var mongod;
+
+ // Standalone tests.
+
+ jsTest.log("Starting shardsvr with enableTestCommands=" + enableTestCommands);
+ mongod = MongoRunner.runMongod({shardsvr: ''});
+ if (enableTestCommands) {
+ assert.neq(null, mongod);
+ MongoRunner.stopMongod(mongod);
+ } else {
+ assert.eq(null, mongod);
+ }
+
+ jsTest.log("Starting configsvr with enableTestCommands=" + enableTestCommands);
+ mongod = MongoRunner.runMongod({configsvr: ''});
+ if (enableTestCommands) {
+ assert.neq(null, mongod);
+ MongoRunner.stopMongod(mongod);
+ } else {
+ assert.eq(null, mongod);
+ }
+
+ // Replica set tests using the command line 'replSet' option.
+
+ jsTest.log("Starting shardsvr with --replSet and enableTestCommands=" + enableTestCommands);
+ mongod = MongoRunner.runMongod({shardsvr: '', replSet: 'dummy'});
+ assert.neq(null, mongod);
+ MongoRunner.stopMongod(mongod);
+
+ jsTest.log("Starting configsvr with --replSet and enableTestCommands=" +
+ enableTestCommands);
+ mongod = MongoRunner.runMongod({configsvr: '', replSet: 'dummy'});
+ assert.neq(null, mongod);
+ MongoRunner.stopMongod(mongod);
+
+ // Replica set tests using the config file 'replSetName' option.
+
+ jsTest.log("Starting shardsvr with 'replication.replSetName' and enableTestCommands=" +
+ enableTestCommands);
+ mongod = MongoRunner.runMongod(
+ {config: "jstests/libs/config_files/set_shardingrole_shardsvr.json"});
+ assert.neq(null, mongod);
+ MongoRunner.stopMongod(mongod);
+
+ jsTest.log("Starting configsvr with 'replication.replSetName' and enableTestCommands=" +
+ enableTestCommands);
+ mongod = MongoRunner.runMongod(
+ {config: "jstests/libs/config_files/set_shardingrole_configsvr.json"});
+ assert.neq(null, mongod);
+ MongoRunner.stopMongod(mongod);
+ };
+
+ testAllPermutations(true /* enableTestCommands */);
+ testAllPermutations(false /* enableTestCommands */);
+})();
diff --git a/jstests/sharding/shard_config_db_collections.js b/jstests/sharding/shard_config_db_collections.js
index d666f3c8d43..68f78f6bf94 100644
--- a/jstests/sharding/shard_config_db_collections.js
+++ b/jstests/sharding/shard_config_db_collections.js
@@ -148,7 +148,7 @@
{
jsTest.setOption('enableTestCommands', false);
- var st = new ShardingTest({shards: 2});
+ var st = new ShardingTest({shards: 2, rs: true});
var admin = st.s.getDB('admin');
assert.commandWorked(
diff --git a/jstests/sharding/sharding_options.js b/jstests/sharding/sharding_options.js
index 8af7bf01c53..8d6c63335b7 100644
--- a/jstests/sharding/sharding_options.js
+++ b/jstests/sharding/sharding_options.js
@@ -37,14 +37,26 @@ expectedResult = {
};
testGetCmdLineOptsMongod({shardsvr: ""}, expectedResult);
-jsTest.log("Testing \"sharding.clusterRole\" config file option");
+jsTest.log("Testing \"sharding.clusterRole\" config file option with 'configsvr'");
expectedResult = {
"parsed": {
- "config": "jstests/libs/config_files/set_shardingrole.json",
+ "config": "jstests/libs/config_files/set_shardingrole_configsvr.json",
+ "replication": {"replSetName": "dummy"},
"sharding": {"clusterRole": "configsvr"}
}
};
-testGetCmdLineOptsMongod({config: "jstests/libs/config_files/set_shardingrole.json"},
+testGetCmdLineOptsMongod({config: "jstests/libs/config_files/set_shardingrole_configsvr.json"},
+ expectedResult);
+
+jsTest.log("Testing \"sharding.clusterRole\" config file option with 'shardsvr'");
+expectedResult = {
+ "parsed": {
+ "config": "jstests/libs/config_files/set_shardingrole_shardsvr.json",
+ "replication": {"replSetName": "dummy"},
+ "sharding": {"clusterRole": "shardsvr"}
+ }
+};
+testGetCmdLineOptsMongod({config: "jstests/libs/config_files/set_shardingrole_shardsvr.json"},
expectedResult);
// Test that we preserve switches explicitly set to false in config files. See SERVER-13439.