Ejemplo n.º 1
0
def test_discover_slaves(cluster, sentinel):
    assert sentinel.discover_slaves('mymaster') == []

    cluster.slaves = [
        {
            'ip': 'slave0',
            'port': 1234,
            'is_odown': False,
            'is_sdown': False
        },
        {
            'ip': 'slave1',
            'port': 1234,
            'is_odown': False,
            'is_sdown': False
        },
    ]
    assert sentinel.discover_slaves('mymaster') == [('slave0', 1234),
                                                    ('slave1', 1234)]

    # slave0 -> ODOWN
    cluster.slaves[0]['is_odown'] = True
    assert sentinel.discover_slaves('mymaster') == [('slave1', 1234)]

    # slave1 -> SDOWN
    cluster.slaves[1]['is_sdown'] = True
    assert sentinel.discover_slaves('mymaster') == []

    cluster.slaves[0]['is_odown'] = False
    cluster.slaves[1]['is_sdown'] = False

    # node0 -> DOWN
    cluster.nodes_down.add(('foo', 26379))
    assert sentinel.discover_slaves('mymaster') == [('slave0', 1234),
                                                    ('slave1', 1234)]
Ejemplo n.º 2
0
def test_discover_slaves(cluster, sentinel):
    assert sentinel.discover_slaves('mymaster') == []

    cluster.slaves = [
        {'ip': 'slave0', 'port': 1234, 'is_odown': False, 'is_sdown': False},
        {'ip': 'slave1', 'port': 1234, 'is_odown': False, 'is_sdown': False},
    ]
    assert sentinel.discover_slaves('mymaster') == [
        ('slave0', 1234), ('slave1', 1234)]

    # slave0 -> ODOWN
    cluster.slaves[0]['is_odown'] = True
    assert sentinel.discover_slaves('mymaster') == [
        ('slave1', 1234)]

    # slave1 -> SDOWN
    cluster.slaves[1]['is_sdown'] = True
    assert sentinel.discover_slaves('mymaster') == []

    cluster.slaves[0]['is_odown'] = False
    cluster.slaves[1]['is_sdown'] = False

    # node0 -> DOWN
    cluster.nodes_down.add(('foo', 26379))
    assert sentinel.discover_slaves('mymaster') == [
        ('slave0', 1234), ('slave1', 1234)]
Ejemplo n.º 3
0
    def check(self):
        log.info('检查 Redis Sentinel 连接: %s', self._master)

        try:
            sentinel = redis.sentinel.Sentinel(
                [s.split(':') for s in self._sentinels],
                password=self._password,
                socket_timeout=0.1)

            log.info('> master: %s', sentinel.discover_master(self._master))
            log.info('> slaves: %s', sentinel.discover_slaves(self._master))
            log.info('尝试获取 master 节点状态信息...')

            master = sentinel.master_for(self._master, socket_timeout=0.1)
            self._log_redis_info(master.info())
        except redis.sentinel.MasterNotFoundError as e:
            log.error('检查 Redis Sentinel 出错: %s - %s', e.__class__, e)
Ejemplo n.º 4
0
def test_discover_slaves(cluster, sentinel):
    assert sentinel.discover_slaves("mymaster") == []

    cluster.slaves = [
        {
            "ip": "slave0",
            "port": 1234,
            "is_odown": False,
            "is_sdown": False
        },
        {
            "ip": "slave1",
            "port": 1234,
            "is_odown": False,
            "is_sdown": False
        },
    ]
    assert sentinel.discover_slaves("mymaster") == [("slave0", 1234),
                                                    ("slave1", 1234)]

    # slave0 -> ODOWN
    cluster.slaves[0]["is_odown"] = True
    assert sentinel.discover_slaves("mymaster") == [("slave1", 1234)]

    # slave1 -> SDOWN
    cluster.slaves[1]["is_sdown"] = True
    assert sentinel.discover_slaves("mymaster") == []

    cluster.slaves[0]["is_odown"] = False
    cluster.slaves[1]["is_sdown"] = False

    # node0 -> DOWN
    cluster.nodes_down.add(("foo", 26379))
    assert sentinel.discover_slaves("mymaster") == [("slave0", 1234),
                                                    ("slave1", 1234)]
    cluster.nodes_down.clear()

    # node0 -> TIMEOUT
    cluster.nodes_timeout.add(("foo", 26379))
    assert sentinel.discover_slaves("mymaster") == [("slave0", 1234),
                                                    ("slave1", 1234)]