Exemplo n.º 1
0
    def setUp(self):
        members = [{}, {}]
        res = ha_tools.start_replica_set(members)
        self.seed, self.name = res

        # Disable periodic refresh
        Monitor._refresh_interval = 1e6
Exemplo n.º 2
0
    def setUp(self):
        super(MotorTestReplicaSetAuth, self).setUp()
        members = [
            {},
            {'priority': 0},
            {'priority': 0},
        ]

        res = ha_tools.start_replica_set(members, auth=True)
        self.seed, self.name = res
        self.c = pymongo.mongo_replica_set_client.MongoReplicaSetClient(
            self.seed, replicaSet=self.name)

        # TODO: Use PyMongo's add_user once it's fixed for MongoDB 2.7.1+.
        try:
            self.c.admin.command(
                'createUser', 'admin', pwd='adminpass', roles=['root'])
        except OperationFailure:
            self.c.admin.add_user('admin', 'adminpass')

        self.c.admin.add_user('admin', password='******',
                              roles=['userAdminAnyDatabase'])
        self.c.admin.authenticate('admin', 'adminpass')
        self.c.pymongo_ha_auth.add_user('user', 'userpass', roles=['readWrite'])
        self.c.pymongo_ha_auth.authenticate('user', 'userpass')

        # Await replication.
        self.c.pymongo_ha_auth.collection.insert({}, w=3, wtimeout=30000)
        self.c.pymongo_ha_auth.collection.remove({}, w=3, wtimeout=30000)
Exemplo n.º 3
0
    def setUp(self):
        super(MotorTestTriggeredRefresh, self).setUp()
        members = [{}, {}]
        res = ha_tools.start_replica_set(members)
        self.seed, self.name = res

        # Disable periodic refresh
        Monitor._refresh_interval = 1e6
Exemplo n.º 4
0
 def setUp(self):
     members = [{},
                {'priority': 0},
                {'arbiterOnly': True},
                {'priority': 0, 'hidden': True},
                {'priority': 0, 'slaveDelay': 5}]
     res = ha_tools.start_replica_set(members)
     self.seed, self.name = res
Exemplo n.º 5
0
    def setUp(self):
        super(TestLastErrorDefaults, self).setUp()

        members = [{}, {}]
        res = ha_tools.start_replica_set(members)
        self.seed, self.name = res
        self.c = MongoClient(
            self.seed,
            replicaSet=self.name,
            serverSelectionTimeoutMS=self.server_selection_timeout)
Exemplo n.º 6
0
 def setUp(self):
     super(MotorTestPassiveAndHidden, self).setUp()
     members = [{},
             {'priority': 0},
             {'arbiterOnly': True},
             {'priority': 0, 'hidden': True},
             {'priority': 0, 'slaveDelay': 5}
     ]
     res = ha_tools.start_replica_set(members)
     self.seed, self.name = res
 def setUp(self):
     members = [
         {},
         {"priority": 0},
         {"arbiterOnly": True},
         {"priority": 0, "hidden": True},
         {"priority": 0, "slaveDelay": 5},
     ]
     res = ha_tools.start_replica_set(members)
     self.seed, self.name = res
Exemplo n.º 8
0
    def setUp(self):
        super(TestReadPreference, self).setUp()

        members = [
            # primary
            {'tags': {'dc': 'ny', 'name': 'primary'}},

            # secondary
            {'tags': {'dc': 'la', 'name': 'secondary'}, 'priority': 0},

            # other_secondary
            {'tags': {'dc': 'ny', 'name': 'other_secondary'}, 'priority': 0},
        ]

        res = ha_tools.start_replica_set(members)
        self.seed, self.name = res

        primary = ha_tools.get_primary()
        self.primary = partition_node(primary)
        self.primary_tags = ha_tools.get_tags(primary)
        # Make sure priority worked
        self.assertEqual('primary', self.primary_tags['name'])

        self.primary_dc = {'dc': self.primary_tags['dc']}

        secondaries = ha_tools.get_secondaries()

        (secondary, ) = [
            s for s in secondaries
            if ha_tools.get_tags(s)['name'] == 'secondary']

        self.secondary = partition_node(secondary)
        self.secondary_tags = ha_tools.get_tags(secondary)
        self.secondary_dc = {'dc': self.secondary_tags['dc']}

        (other_secondary, ) = [
            s for s in secondaries
            if ha_tools.get_tags(s)['name'] == 'other_secondary']

        self.other_secondary = partition_node(other_secondary)
        self.other_secondary_tags = ha_tools.get_tags(other_secondary)
        self.other_secondary_dc = {'dc': self.other_secondary_tags['dc']}

        self.c = MongoClient(
            self.seed,
            replicaSet=self.name,
            serverSelectionTimeoutMS=self.server_selection_timeout)
        self.w = len(self.c.secondaries) + 1
        self.db = self.c.get_database("pymongo_test",
                                      write_concern=WriteConcern(w=self.w))
        self.db.test.delete_many({})
        self.db.test.insert_many([{'foo': i} for i in xrange(10)])

        self.clear_ping_times()
Exemplo n.º 9
0
    def setUp(self):
        super(MotorTestReadPreference, self).setUp()
        members = [
            # primary
            {'tags': {'dc': 'ny', 'name': 'primary'}},

            # secondary
            {'tags': {'dc': 'la', 'name': 'secondary'}, 'priority': 0},

            # other_secondary
            {'tags': {'dc': 'ny', 'name': 'other_secondary'}, 'priority': 0},
        ]

        res = ha_tools.start_replica_set(members)
        self.seed, self.name = res

        primary = ha_tools.get_primary()
        self.primary = _partition_node(primary)
        self.primary_tags = ha_tools.get_tags(primary)
        # Make sure priority worked
        self.assertEqual('primary', self.primary_tags['name'])

        self.primary_dc = {'dc': self.primary_tags['dc']}

        secondaries = ha_tools.get_secondaries()

        (secondary, ) = [
            s for s in secondaries
            if ha_tools.get_tags(s)['name'] == 'secondary']

        self.secondary = _partition_node(secondary)
        self.secondary_tags = ha_tools.get_tags(secondary)
        self.secondary_dc = {'dc': self.secondary_tags['dc']}

        (other_secondary, ) = [
            s for s in secondaries
            if ha_tools.get_tags(s)['name'] == 'other_secondary']

        self.other_secondary = _partition_node(other_secondary)
        self.other_secondary_tags = ha_tools.get_tags(other_secondary)
        self.other_secondary_dc = {'dc': self.other_secondary_tags['dc']}

        # Synchronous PyMongo interfaces for convenience
        self.c = pymongo.mongo_replica_set_client.MongoReplicaSetClient(
            self.seed, replicaSet=self.name)
        self.db = self.c.motor_test
        self.w = len(self.c.secondaries) + 1
        self.db.test.remove({}, w=self.w)
        self.db.test.insert(
            [{'foo': i} for i in xrange(10)], w=self.w)

        self.clear_ping_times()
Exemplo n.º 10
0
    def setUp(self):
        members = [{}, {"priority": 0}, {"priority": 0}]

        res = ha_tools.start_replica_set(members, auth=True)
        self.c = ReplicaSetConnection(res[0], replicaSet=res[1], use_greenlets=use_greenlets)

        # Add an admin user to enable auth
        self.c.admin.add_user("admin", "adminpass")
        self.c.admin.authenticate("admin", "adminpass")

        self.db = self.c.pymongo_ha_auth
        self.db.add_user("user", "userpass")
        self.c.admin.logout()
Exemplo n.º 11
0
    def setUp(self):
        members = [
            # primary
            {'tags': {'dc': 'ny', 'name': 'primary'}},

            # secondary
            {'tags': {'dc': 'la', 'name': 'secondary'}, 'priority': 0},

            # other_secondary
            {'tags': {'dc': 'ny', 'name': 'other_secondary'}, 'priority': 0},
        ]

        res = ha_tools.start_replica_set(members)
        self.seed, self.name = res

        primary = ha_tools.get_primary()
        self.primary = _partition_node(primary)
        self.primary_tags = ha_tools.get_tags(primary)
        # Make sure priority worked
        self.assertEqual('primary', self.primary_tags['name'])

        self.primary_dc = {'dc': self.primary_tags['dc']}

        secondaries = ha_tools.get_secondaries()

        (secondary, ) = [
            s for s in secondaries
            if ha_tools.get_tags(s)['name'] == 'secondary']

        self.secondary = _partition_node(secondary)
        self.secondary_tags = ha_tools.get_tags(secondary)
        self.secondary_dc = {'dc': self.secondary_tags['dc']}

        (other_secondary, ) = [
            s for s in secondaries
            if ha_tools.get_tags(s)['name'] == 'other_secondary']

        self.other_secondary = _partition_node(other_secondary)
        self.other_secondary_tags = ha_tools.get_tags(other_secondary)
        self.other_secondary_dc = {'dc': self.other_secondary_tags['dc']}

        self.c = ReplicaSetConnection(
            self.seed, replicaSet=self.name, use_greenlets=use_greenlets)
        self.db = self.c.pymongo_test
        self.w = len(self.c.secondaries) + 1
        self.db.test.remove({}, safe=True, w=self.w)
        self.db.test.insert(
            [{'foo': i} for i in xrange(10)], safe=True, w=self.w)

        self.clear_ping_times()
Exemplo n.º 12
0
    def setUp(self):
        super(MotorTestReplicaSetAuth, self).setUp()
        members = [
            {},
            {'priority': 0},
            {'priority': 0},
        ]

        res = ha_tools.start_replica_set(members, auth=True)
        self.seed, self.name = res
        self.c = pymongo.mongo_replica_set_client.MongoReplicaSetClient(
            self.seed, replicaSet=self.name)

        # Add an admin user to enable auth
        self.c.admin.add_user('admin', 'adminpass')
        self.c.admin.authenticate('admin', 'adminpass')
        self.c.pymongo_ha_auth.add_user('user', 'userpass')
Exemplo n.º 13
0
    def setUp(self):
        members = [
            {},
            {'priority': 0},
            {'priority': 0},
        ]

        res = ha_tools.start_replica_set(members, auth=True)
        self.c = MongoReplicaSetClient(res[0], replicaSet=res[1],
                                       use_greenlets=use_greenlets)

        # Add an admin user to enable auth
        self.c.admin.add_user('admin', 'adminpass')
        self.c.admin.authenticate('admin', 'adminpass')

        self.db = self.c.pymongo_ha_auth
        self.db.add_user('user', 'userpass')
        self.c.admin.logout()
Exemplo n.º 14
0
    def setUp(self):
        members = [
            # primary
            {"tags": {"dc": "ny", "name": "primary"}},
            # secondary
            {"tags": {"dc": "la", "name": "secondary"}, "priority": 0},
            # other_secondary
            {"tags": {"dc": "ny", "name": "other_secondary"}, "priority": 0},
        ]

        res = ha_tools.start_replica_set(members)
        self.seed, self.name = res

        primary = ha_tools.get_primary()
        self.primary = _partition_node(primary)
        self.primary_tags = ha_tools.get_tags(primary)
        # Make sure priority worked
        self.assertEqual("primary", self.primary_tags["name"])

        self.primary_dc = {"dc": self.primary_tags["dc"]}

        secondaries = ha_tools.get_secondaries()

        (secondary,) = [s for s in secondaries if ha_tools.get_tags(s)["name"] == "secondary"]

        self.secondary = _partition_node(secondary)
        self.secondary_tags = ha_tools.get_tags(secondary)
        self.secondary_dc = {"dc": self.secondary_tags["dc"]}

        (other_secondary,) = [s for s in secondaries if ha_tools.get_tags(s)["name"] == "other_secondary"]

        self.other_secondary = _partition_node(other_secondary)
        self.other_secondary_tags = ha_tools.get_tags(other_secondary)
        self.other_secondary_dc = {"dc": self.other_secondary_tags["dc"]}

        self.c = ReplicaSetConnection(self.seed, replicaSet=self.name, use_greenlets=use_greenlets)
        self.db = self.c.pymongo_test
        self.w = len(self.c.secondaries) + 1
        self.db.test.remove({}, safe=True, w=self.w)
        self.db.test.insert([{"foo": i} for i in xrange(10)], safe=True, w=self.w)

        self.clear_ping_times()
Exemplo n.º 15
0
    def setUp(self):
        super(MotorTestReplicaSetAuth, self).setUp()
        members = [
            {},
            {'priority': 0},
            {'priority': 0},
        ]

        res = ha_tools.start_replica_set(members, auth=True)
        self.seed, self.name = res
        self.c = pymongo.mongo_replica_set_client.MongoReplicaSetClient(
            self.seed, replicaSet=self.name)

        # TODO: Use PyMongo's add_user once it's fixed for MongoDB 2.7.1+.
        try:
            self.c.admin.command(
                'createUser', 'admin', pwd='adminpass', roles=['root'])
        except OperationFailure:
            self.c.admin.add_user('admin', 'adminpass')

        self.c.admin.authenticate('admin', 'adminpass')
        self.c.pymongo_ha_auth.add_user('user', 'userpass')
Exemplo n.º 16
0
    def setUp(self):
        super(TestReplicaSetAuth, self).setUp()

        members = [
            {},
            {'priority': 0},
            {'priority': 0},
        ]

        res = ha_tools.start_replica_set(members, auth=True)
        self.c = MongoClient(
            res[0],
            replicaSet=res[1],
            serverSelectionTimeoutMS=self.server_selection_timeout)

        # Add an admin user to enable auth
        self.c.admin.add_user('admin', 'adminpass')
        self.c.admin.authenticate('admin', 'adminpass')

        self.db = self.c.pymongo_ha_auth
        self.db.add_user('user', 'userpass')
        self.c.admin.logout()
Exemplo n.º 17
0
    def setUp(self):
        members = [
            # primary
            {
                'tags': {
                    'dc': 'ny',
                    'name': 'primary'
                }
            },

            # secondary
            {
                'tags': {
                    'dc': 'la',
                    'name': 'secondary'
                },
                'priority': 0
            },

            # other_secondary
            {
                'tags': {
                    'dc': 'ny',
                    'name': 'other_secondary'
                },
                'priority': 0
            },
        ]

        res = ha_tools.start_replica_set(members)
        self.seed, self.name = res

        primary = ha_tools.get_primary()
        self.primary = _partition_node(primary)
        self.primary_tags = ha_tools.get_tags(primary)
        # Make sure priority worked
        self.assertEqual('primary', self.primary_tags['name'])

        self.primary_dc = {'dc': self.primary_tags['dc']}

        secondaries = ha_tools.get_secondaries()

        (secondary, ) = [
            s for s in secondaries
            if ha_tools.get_tags(s)['name'] == 'secondary'
        ]

        self.secondary = _partition_node(secondary)
        self.secondary_tags = ha_tools.get_tags(secondary)
        self.secondary_dc = {'dc': self.secondary_tags['dc']}

        (other_secondary, ) = [
            s for s in secondaries
            if ha_tools.get_tags(s)['name'] == 'other_secondary'
        ]

        self.other_secondary = _partition_node(other_secondary)
        self.other_secondary_tags = ha_tools.get_tags(other_secondary)
        self.other_secondary_dc = {'dc': self.other_secondary_tags['dc']}

        self.c = MongoReplicaSetClient(self.seed,
                                       replicaSet=self.name,
                                       use_greenlets=use_greenlets)
        self.db = self.c.pymongo_test
        self.w = len(self.c.secondaries) + 1
        self.db.test.remove({}, w=self.w)
        self.db.test.insert([{'foo': i} for i in xrange(10)], w=self.w)

        self.clear_ping_times()
Exemplo n.º 18
0
    def setUp(self):
        res = ha_tools.start_replica_set([{}, {}, {}])
        self.seed, self.name = res

        # Disable periodic refresh.
        Monitor._refresh_interval = 1e6
Exemplo n.º 19
0
 def setUp(self):
     super(MotorTestAlive, self).setUp()
     members = [{}, {}]
     self.seed, self.name = ha_tools.start_replica_set(members)
Exemplo n.º 20
0
 def setUp(self):
     members = [{}, {}]
     self.seed, self.name = ha_tools.start_replica_set(members)
Exemplo n.º 21
0
 def setUp(self):
     members = [{}, {}, {'arbiterOnly': True}]
     res = ha_tools.start_replica_set(members)
     self.c = MongoReplicaSetClient(res[0], replicaSet=res[1],
                                    use_greenlets=use_greenlets,
                                    auto_start_request=True)
Exemplo n.º 22
0
 def setUp(self):
     super(TestShipOfTheseus, self).setUp()
     res = ha_tools.start_replica_set([{}, {}])
     self.seed, self.name = res
Exemplo n.º 23
0
 def setUp(self):
     members = [{}, {'priority': 0}, {'priority': 0}]
     res = ha_tools.start_replica_set(members)
     self.seed, self.name = res
Exemplo n.º 24
0
 def setUp(self):
     super(TestDirectConnection, self).setUp()
     members = [{}, {}, {'arbiterOnly': True}]
     res = ha_tools.start_replica_set(members)
     self.seed, self.name = res
Exemplo n.º 25
0
    def setUp(self):
        super(TestReadPreference, self).setUp()

        members = [
            # primary
            {
                'tags': {
                    'dc': 'ny',
                    'name': 'primary'
                }
            },

            # secondary
            {
                'tags': {
                    'dc': 'la',
                    'name': 'secondary'
                },
                'priority': 0
            },

            # other_secondary
            {
                'tags': {
                    'dc': 'ny',
                    'name': 'other_secondary'
                },
                'priority': 0
            },
        ]

        res = ha_tools.start_replica_set(members)
        self.seed, self.name = res

        primary = ha_tools.get_primary()
        self.primary = partition_node(primary)
        self.primary_tags = ha_tools.get_tags(primary)
        # Make sure priority worked
        self.assertEqual('primary', self.primary_tags['name'])

        self.primary_dc = {'dc': self.primary_tags['dc']}

        secondaries = ha_tools.get_secondaries()

        (secondary, ) = [
            s for s in secondaries
            if ha_tools.get_tags(s)['name'] == 'secondary'
        ]

        self.secondary = partition_node(secondary)
        self.secondary_tags = ha_tools.get_tags(secondary)
        self.secondary_dc = {'dc': self.secondary_tags['dc']}

        (other_secondary, ) = [
            s for s in secondaries
            if ha_tools.get_tags(s)['name'] == 'other_secondary'
        ]

        self.other_secondary = partition_node(other_secondary)
        self.other_secondary_tags = ha_tools.get_tags(other_secondary)
        self.other_secondary_dc = {'dc': self.other_secondary_tags['dc']}

        self.c = MongoClient(
            self.seed,
            replicaSet=self.name,
            serverSelectionTimeoutMS=self.server_selection_timeout)
        self.w = len(self.c.secondaries) + 1
        self.db = self.c.get_database("pymongo_test",
                                      write_concern=WriteConcern(w=self.w))
        self.db.test.delete_many({})
        self.db.test.insert_many([{'foo': i} for i in xrange(10)])

        self.clear_ping_times()
Exemplo n.º 26
0
 def setUp(self):
     super(MotorTestMonitorRemovesRecoveringMember, self).setUp()
     members = [{}, {'priority': 0}, {'priority': 0}]
     res = ha_tools.start_replica_set(members)
     self.seed, self.name = res
Exemplo n.º 27
0
 def setUp(self):
     members = [{}, {}, {'arbiterOnly': True}]
     res = ha_tools.start_replica_set(members)
     self.seed, self.name = res
Exemplo n.º 28
0
 def setUp(self):
     members = [{}, {}, {'arbiterOnly': True}]
     res = ha_tools.start_replica_set(members)
     self.c = MongoReplicaSetClient(res[0], replicaSet=res[1],
                                    use_greenlets=use_greenlets,
                                    auto_start_request=True)
Exemplo n.º 29
0
 def setUp(self):
     members = [{}, {'priority': 0}, {'priority': 0}]
     res = ha_tools.start_replica_set(members)
     self.seed, self.name = res
Exemplo n.º 30
0
 def setUp(self):
     super(TestReadWithFailover, self).setUp()
     res = ha_tools.start_replica_set([{}, {}, {}])
     self.seed, self.name = res
Exemplo n.º 31
0
 def setUp(self):
     members = [{}, {}, {'arbiterOnly': True}]
     res = ha_tools.start_replica_set(members)
     self.c = ReplicaSetConnection(res[0], replicaSet=res[1],
                                   use_greenlets=use_greenlets)
Exemplo n.º 32
0
    def setUp(self):
        super(MotorTestReadPreference, self).setUp()
        members = [
            # primary
            {
                'tags': {
                    'dc': 'ny',
                    'name': 'primary'
                }
            },

            # secondary
            {
                'tags': {
                    'dc': 'la',
                    'name': 'secondary'
                },
                'priority': 0
            },

            # other_secondary
            {
                'tags': {
                    'dc': 'ny',
                    'name': 'other_secondary'
                },
                'priority': 0
            },
        ]

        res = ha_tools.start_replica_set(members)
        self.seed, self.name = res

        primary = ha_tools.get_primary()
        self.primary = _partition_node(primary)
        self.primary_tags = ha_tools.get_tags(primary)
        # Make sure priority worked
        self.assertEqual('primary', self.primary_tags['name'])

        self.primary_dc = {'dc': self.primary_tags['dc']}

        secondaries = ha_tools.get_secondaries()

        (secondary, ) = [
            s for s in secondaries
            if ha_tools.get_tags(s)['name'] == 'secondary'
        ]

        self.secondary = _partition_node(secondary)
        self.secondary_tags = ha_tools.get_tags(secondary)
        self.secondary_dc = {'dc': self.secondary_tags['dc']}

        (other_secondary, ) = [
            s for s in secondaries
            if ha_tools.get_tags(s)['name'] == 'other_secondary'
        ]

        self.other_secondary = _partition_node(other_secondary)
        self.other_secondary_tags = ha_tools.get_tags(other_secondary)
        self.other_secondary_dc = {'dc': self.other_secondary_tags['dc']}

        # Synchronous PyMongo interfaces for convenience
        self.c = pymongo.mongo_replica_set_client.MongoReplicaSetClient(
            self.seed, replicaSet=self.name)
        self.db = self.c.motor_test
        self.w = len(self.c.secondaries) + 1
        self.db.test.remove({}, w=self.w)
        self.db.test.insert([{'foo': i} for i in range(10)], w=self.w)

        self.clear_ping_times()
Exemplo n.º 33
0
 def setUp(self):
     super(TestLastError, self).setUp()
     res = ha_tools.start_replica_set([{}, {}])
     self.seed, self.name = res
Exemplo n.º 34
0
 def setUp(self):
     super(MotorTestReadWithFailover, self).setUp()
     res = ha_tools.start_replica_set([{}, {}, {}])
     self.seed, self.name = res
Exemplo n.º 35
0
 def setUp(self):
     members = [{}, {}]
     self.seed, self.name = ha_tools.start_replica_set(members)
Exemplo n.º 36
0
 def setUp(self):
     super(MotorTestWritesWithFailover, self).setUp()
     res = ha_tools.start_replica_set([{}, {}, {}])
     self.seed, self.name = res
Exemplo n.º 37
0
 def setUp(self):
     super(MotorTestMonitorRemovesRecoveringMember, self).setUp()
     members = [{}, {'priority': 0}, {'priority': 0}]
     res = ha_tools.start_replica_set(members)
     self.seed, self.name = res
Exemplo n.º 38
0
 def setUp(self):
     res = ha_tools.start_replica_set([{}, {}, {}])
     self.seed, self.name = res
Exemplo n.º 39
0
 def setUp(self):
     super(MotorTestHealthMonitor, self).setUp()
     res = ha_tools.start_replica_set([{}, {}, {}])
     self.seed, self.name = res
Exemplo n.º 40
0
    def setUp(self):
        res = ha_tools.start_replica_set([{}, {}, {}])
        self.seed, self.name = res

        # Disable periodic refresh.
        Monitor._refresh_interval = 1e6
Exemplo n.º 41
0
 def setUp(self):
     super(MotorTestShipOfTheseus, self).setUp()
     res = ha_tools.start_replica_set([{}, {}])
     self.seed, self.name = res
Exemplo n.º 42
0
    def post(self, op):
        """ Respond to a POST
        """
        # Start RS
        if op == 'start':
            request = self._parse_json(self.request.body)
            members = request['members']

            rs_id = uuid.uuid4()
            rs_name = 'repl' + str(get_new_repl_id())

            try:
                # start RS and get its' params
                res = ha_tools.start_replica_set(members, rs_name=rs_name)
            except:
                self.error("Couldn't start RS!")

            # Let's gather all the info about RS and save it
            rs_uri, rs_name, nodes, arbiters = res

            # Try to connect to new RS
            try:
                for _ in range(1 * 60 / 2):
                    time.sleep(2)

                    try:
                        c = ReplicaSetConnection(rs_uri, replicaSet=rs_name)
                    except:
                        pass
            except:
                self.error("Couldn't connect to the new RS: " + rs_uri + ", " + rs_name)

            secondaries_uris = []

            for secondary in c.secondaries:
                secondaries_uris.append('%s:%d' % (secondary))

            rs_t = {}

            rs_t['id'] = str(rs_id)
            rs_t['name'] = rs_name
            rs_t['primary'] = rs_uri
            rs_t['secondaries'] = secondaries_uris
            rs_t['nodes'] = nodes
            rs_t['arbiters'] = arbiters

            rs.append(rs_t)

            self.write(self._template.load(op + self._ext).generate(rs_id=rs_id, rs_uri=rs_uri, rs_name=rs_name))

        # FIXME: Some checks should be implemented

        # Stop rs
        elif op == 'stop':
            request = self._parse_json(self.request.body)
            rs_id = request['rs']['id']

            found_index = self._get_index(rs, 'id', rs_id)

            try:
                ha_tools.kill_members(rs[found_index]['nodes'].keys(), 2, rs[found_index]['nodes'])
                rs_t = rs.pop(found_index)
            except:
                self.error("Couldn't stop RS!")

            rs_id = rs_t['id']

            self.write(self._template.load(op + self._ext).generate(rs_id=rs_id))

        # Get primary
        elif op == 'get_primary':
            request = self._parse_json(self.request.body)
            rs_id = request['rs']['id']

            found_index = self._get_index(rs, 'id', rs_id)
            rs_primary_uri = rs[found_index]['primary']

            self.write(self._template.load(op + self._ext).generate(rs_id=rs_id, rs_primary_uri=rs_primary_uri))

        # Get secondaries
        elif op == 'get_secondaries':
            request = self._parse_json(self.request.body)
            rs_id = request['rs']['id']

            found_index = self._get_index(rs, 'id', rs_id)
            rs_secondaries_uris = rs[found_index]['secondaries']

            self.write(self._template.load(op + self._ext).generate(rs_id=rs_id, rs_secondaries_uris=rs_secondaries_uris))

        # Get the arbiters
        elif op == 'get_arbiters':
            request = self._parse_json(self.request.body)
            rs_id = request['rs']['id']

            found_index = self._get_index(rs, 'id', rs_id)
            rs_arbiters_uris = rs[found_index]['arbiters']

            self.write(self._template.load(op + self._ext).generate(rs_id=rs_id, rs_arbiters_uris=rs_arbiters_uris))

        # Kill the primary
        elif op == 'kill_primary':
            request = self._parse_json(self.request.body)
            rs_id = request['rs']['id']

            found_index = self._get_index(rs, 'id', rs_id)

            try:
                rs_primary_uri = rs[found_index]['primary']
                ha_tools.kill_members([rs_primary_uri], 2, rs[found_index]['nodes'])
                del rs[found_index]['primary']
            except:
                self.error("No primary found for this RS!")

            self.write(self._template.load(op + self._ext).generate(rs_id=rs_id, rs_killed_primary_uri=rs_primary_uri))

        # Kill the secondary
        elif op == 'kill_secondary':
            request = self._parse_json(self.request.body)
            rs_id = request['rs']['id']

            try:
                found_index = self._get_index(rs, 'id', rs_id)
            except:
                self.error("No secondaries found for this RS!")

            rs_secondaries_uris = rs[found_index]['secondaries']

            try:
                # Get a random secondary for this RS

                # Get a random index first
                rs_secondary_uri_index = random.randrange( len(rs_secondaries_uris) )
                # Pop out the element by this random index
                rs_secondary_uri = rs[found_index]['secondaries'].pop(rs_secondary_uri_index)

                ha_tools.kill_members([rs_secondary_uri], 2, rs[found_index]['nodes'])
                del rs[found_index]['nodes'][rs_secondary_uri]
            except:
                self.error("No secondaries found for this RS!")

            self.write(self._template.load(op + self._ext).generate(rs_id=rs_id, rs_killed_secondary_uri=rs_secondary_uri))

        # Kill all the secondaries
        elif op == 'kill_all_secondaries':
            request = self._parse_json(self.request.body)
            rs_id = request['rs']['id']

            found_index = self._get_index(rs, 'id', rs_id)

            try:
                rs_secondaries_uris = rs[found_index]['secondaries']
                ha_tools.kill_members(rs_secondaries_uris, 2, rs[found_index]['nodes'])
                del rs[found_index]['secondaries']
            except:
                self.error("No secondaries found for this RS!")

            self.write(self._template.load(op + self._ext).generate(rs_id=rs_id, rs_killed_secondaries_uris=rs_secondaries_uris))
Exemplo n.º 43
0
 def setUp(self):
     super(MotorTestDirectConnection, self).setUp()
     members = [{}, {}, {'arbiterOnly': True}]
     res = ha_tools.start_replica_set(members)
     self.seed, self.name = res
Exemplo n.º 44
0
 def setUp(self):
     super(TestHealthMonitor, self).setUp()
     res = ha_tools.start_replica_set([{}, {}, {}])
     self.seed, self.name = res
Exemplo n.º 45
0
 def setUp(self):
     res = ha_tools.start_replica_set([{}, {}, {}])
     self.seed, self.name = res
Exemplo n.º 46
0
 def setUp(self):
     super(TestTriggeredRefresh, self).setUp()
     members = [{}, {}]
     res = ha_tools.start_replica_set(members)
     self.seed, self.name = res
Exemplo n.º 47
0
 def setUp(self):
     members = [{}, {}, {'arbiterOnly': True}]
     res = ha_tools.start_replica_set(members)
     self.seed, self.name = res
Exemplo n.º 48
0
    def setUp(self):
        super(TestAlive, self).setUp()

        members = [{}, {}]
        self.seed, self.name = ha_tools.start_replica_set(members)