Ejemplo n.º 1
0
 def test_member_del(self):
     repl_id = self.rs.create(
         {'members': [{"rsParams": {"priority": 1.5}}, {}, {}]})
     self.assertEqual(len(self.rs.members(repl_id)), 3)
     assert_eventually(lambda: len(self.rs.secondaries(repl_id)) > 0)
     secondary = self.rs.secondaries(repl_id)[0]
     connected(pymongo.MongoClient(secondary['host']))  # No error.
     self.assertTrue(self.rs.member_del(repl_id, secondary['_id']))
     self.assertEqual(len(self.rs.members(repl_id)), 2)
     with self.assertRaises(pymongo.errors.PyMongoError):
         connected(pymongo.MongoClient(secondary['host']))
Ejemplo n.º 2
0
 def test_member_del(self):
     repl_id = self.rs.create(
         {'members': [{
             "rsParams": {
                 "priority": 1.5
             }
         }, {}, {}]})
     self.assertEqual(len(self.rs.members(repl_id)), 3)
     assert_eventually(lambda: len(self.rs.secondaries(repl_id)) > 0)
     secondary = self.rs.secondaries(repl_id)[0]
     connected(pymongo.MongoClient(secondary['host']))  # No error.
     self.assertTrue(self.rs.member_del(repl_id, secondary['_id']))
     self.assertEqual(len(self.rs.members(repl_id)), 2)
     with self.assertRaises(pymongo.errors.PyMongoError):
         connected(pymongo.MongoClient(secondary['host']))
Ejemplo n.º 3
0
    def test_member_freeze(self):
        # This tests Server, but only makes sense in the context of a replica set.
        repl_id = self.rs.create({
            'members': [{
                "rsParams": {
                    "priority": 19
                }
            }, {
                "rsParams": {
                    "priority": 5
                }
            }, {}]
        })
        next_primary_info = self.rs.member_info(repl_id, 2)
        next_primary = next_primary_info['mongodb_uri']
        secondary_info = self.rs.member_info(repl_id, 1)
        secondary_server = Servers()._storage[secondary_info['server_id']]
        primary_info = self.rs.member_info(repl_id, 0)
        primary_server = Servers()._storage[primary_info['server_id']]

        assert_eventually(lambda: primary_server.connection.is_primary)

        def freeze_and_stop():
            self.assertTrue(secondary_server.freeze(10))
            try:
                # Call replSetStepDown before killing the primary's process.
                # This raises OperationFailure if no secondaries are capable
                # of taking over.
                primary_server.connection.admin.command('replSetStepDown', 10)
            except pymongo.errors.AutoReconnect:
                # Have to stop the server as well so it doesn't get reelected.
                primary_server.stop()
                return True
            except pymongo.errors.OperationFailure:
                # No secondaries within 10 seconds of my optime...
                return False

        assert_eventually(freeze_and_stop, "Primary didn't step down.")
        assert_eventually(
            lambda: (self.rs.primary(repl_id)['mongodb_uri'] == next_primary),
            "Secondary did not freeze.",
            max_tries=120)
        assert_eventually(
            lambda: (self.rs.primary(repl_id)['mongodb_uri'] == self.rs.
                     member_info(repl_id, 1)['mongodb_uri']),
            "Higher priority secondary never promoted.")
Ejemplo n.º 4
0
    def test_member_freeze(self):
        # This tests Server, but only makes sense in the context of a replica set.
        repl_id = self.rs.create(
            {'members': [{"rsParams": {"priority": 19}},
                         {"rsParams": {"priority": 5}}, {}]})
        next_primary_info = self.rs.member_info(repl_id, 2)
        next_primary = next_primary_info['mongodb_uri']
        secondary_info = self.rs.member_info(repl_id, 1)
        secondary_server = Servers()._storage[secondary_info['server_id']]
        primary_info = self.rs.member_info(repl_id, 0)
        primary_server = Servers()._storage[primary_info['server_id']]

        assert_eventually(lambda: primary_server.connection.is_primary)

        def freeze_and_stop():
            self.assertTrue(secondary_server.freeze(100))
            try:
                # Call replSetStepDown before killing the primary's process.
                # This raises OperationFailure if no secondaries are capable
                # of taking over.
                primary_server.connection.admin.command('replSetStepDown', 10)
            except pymongo.errors.AutoReconnect:
                # Have to stop the server as well so it doesn't get reelected.
                primary_server.stop()
                return True
            except pymongo.errors.OperationFailure:
                # No secondaries within 10 seconds of my optime...
                return False

        assert_eventually(freeze_and_stop, "Primary didn't step down.")
        assert_eventually(lambda: (
            self.rs.primary(repl_id)['mongodb_uri'] == next_primary),
            "Secondary did not freeze.",
            max_tries=120
        )
        assert_eventually(lambda: (
            self.rs.primary(repl_id)['mongodb_uri'] ==
            self.rs.member_info(repl_id, 1)['mongodb_uri']),
            "Higher priority secondary never promoted.",
            max_tries=120
        )