diff options
-rw-r--r-- | buildscripts/resmokelib/testing/fixtures/shardedcluster.py | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/buildscripts/resmokelib/testing/fixtures/shardedcluster.py b/buildscripts/resmokelib/testing/fixtures/shardedcluster.py index c0c3624b69a..9a90c5b31e1 100644 --- a/buildscripts/resmokelib/testing/fixtures/shardedcluster.py +++ b/buildscripts/resmokelib/testing/fixtures/shardedcluster.py @@ -103,11 +103,7 @@ class ShardedClusterFixture(interface.Fixture): self.port = self.mongos.port client = utils.new_mongo_client(port=self.port) - if self.auth_options is not None: - auth_db = client[self.auth_options["authenticationDatabase"]] - auth_db.authenticate(self.auth_options["username"], - password=self.auth_options["password"], - mechanism=self.auth_options["authenticationMechanism"]) + self._auth_to_db(client) # Inform mongos about each of the shards for shard in self.shards: @@ -118,6 +114,20 @@ class ShardedClusterFixture(interface.Fixture): self.logger.info("Enabling sharding for '%s' database...", db_name) client.admin.command({"enablesharding": db_name}) + def _auth_to_db(self, client): + """Authenticate client for the 'authenticationDatabase'.""" + if self.auth_options is not None: + auth_db = client[self.auth_options["authenticationDatabase"]] + auth_db.authenticate(self.auth_options["username"], + password=self.auth_options["password"], + mechanism=self.auth_options["authenticationMechanism"]) + + def _stop_balancer(self, timeout_ms=60000): + """Stop the balancer.""" + client = utils.new_mongo_client(port=self.port) + self._auth_to_db(client) + client.admin.command({"balancerStop": 1}, maxTimeMS=timeout_ms) + def _do_teardown(self): """ Shuts down the sharded cluster. @@ -129,6 +139,8 @@ class ShardedClusterFixture(interface.Fixture): self.logger.info( "Sharded cluster was expected to be running in _do_teardown(), but wasn't.") + self._stop_balancer() + if self.configsvr is not None: if running_at_start: self.logger.info("Stopping config server...") @@ -149,6 +161,8 @@ class ShardedClusterFixture(interface.Fixture): if running_at_start: self.logger.info("Stopping shards...") + + for shard in self.shards: success = shard.teardown() and success if running_at_start: |