예제 #1
0
 def test_use_newly_added_node(self, session, monkeypatch):
     monkeypatch.setattr(util, "is_node_healthy", lambda node: True)
     n1 = Node("chacra01.ceph.com")
     n1.last_used = datetime.datetime.now()
     n2 = Node("chacra02.ceph.com")
     session.commit()
     assert n2 == util.get_next_node()
예제 #2
0
 def test_use_newly_added_node(self, session, monkeypatch):
     monkeypatch.setattr(util, "is_node_healthy", lambda node: True)
     n1 = Node("chacra01.ceph.com")
     n1.last_used = datetime.datetime.now()
     n2 = Node("chacra02.ceph.com")
     session.commit()
     assert n2 == util.get_next_node()
예제 #3
0
 def test_down_count_is_incremented(self, m_get, session):
     m_get.return_value.ok = False
     node = Node("chacra.ceph.com")
     session.commit()
     util.is_node_healthy(node)
     node = Node.get(1)
     assert node.down_count == 1
예제 #4
0
 def test_get_multiple_nodes(self, session):
     Node("chacra01.ceph.com")
     Node("chacra02.ceph.com")
     session.commit()
     result = session.app.get("/api/nodes/")
     assert set(result.json.keys()) == set(
         ["chacra01.ceph.com", "chacra02.ceph.com"])
예제 #5
0
 def test_pick_last_used_node(self, session, monkeypatch):
     monkeypatch.setattr(util, "is_node_healthy", lambda node: True)
     n1 = Node("chacra01.ceph.com")
     n1.last_used = datetime.datetime.now() - datetime.timedelta(days=1)
     n2 = Node("chacra02.ceph.com")
     n2.last_used = datetime.datetime.now()
     session.commit()
     assert n1 == util.get_next_node()
예제 #6
0
 def test_node_exceeds_down_count_limit(self, m_get, session):
     m_get.return_value.ok = False
     node = Node("chacra.ceph.com")
     node.down_count = 2
     session.commit()
     util.is_node_healthy(node)
     node = Node.get(1)
     assert not node.healthy
예제 #7
0
 def test_node_exceeds_down_count_limit(self, m_get, session):
     m_get.return_value.ok = False
     node = Node("chacra.ceph.com")
     node.down_count = 2
     session.commit()
     util.is_node_healthy(node)
     node = Node.get(1)
     assert not node.healthy
예제 #8
0
 def test_down_count_is_cleared_when_healthy(self, m_get, session):
     m_get.return_value.ok = True
     node = Node("chacra.ceph.com")
     node.down_count = 2
     session.commit()
     util.is_node_healthy(node)
     node = Node.get(1)
     assert node.down_count == 0
예제 #9
0
 def test_down_count_is_cleared_when_healthy(self, m_get, session):
     m_get.return_value.ok = True
     node = Node("chacra.ceph.com")
     node.down_count = 2
     session.commit()
     util.is_node_healthy(node)
     node = Node.get(1)
     assert node.down_count == 0
예제 #10
0
파일: test_nodes.py 프로젝트: ceph/shaman
 def test_updates_last_check_time(self, session, monkeypatch):
     monkeypatch.setattr(nodes, "check_node_health", mock_check_node_health(True))
     session.app.post("/api/nodes/chacra.ceph.com/")
     n = Node.get(1)
     last_check = n.last_check.time()
     session.app.post("/api/nodes/chacra.ceph.com/")
     n = Node.get(1)
     assert n.last_check.time() > last_check
예제 #11
0
 def test_last_check_is_updated(self, m_get, session):
     m_get.return_value.ok = True
     node = Node("chacra.ceph.com")
     last_check = datetime.datetime.now()
     node.last_check = datetime.datetime.now()
     session.commit()
     util.is_node_healthy(node)
     node = Node.get(1)
     assert node.last_check.time() > last_check.time()
예제 #12
0
파일: test_nodes.py 프로젝트: ceph/shaman
 def test_updates_healthy(self, session, monkeypatch):
     monkeypatch.setattr(nodes, "check_node_health", mock_check_node_health(True))
     session.app.post("/api/nodes/chacra.ceph.com/")
     n = Node.get(1)
     n.healthy = False
     session.commit()
     session.app.post("/api/nodes/chacra.ceph.com/")
     n = Node.get(1)
     assert n.healthy
예제 #13
0
 def test_updates_last_check_time(self, session, monkeypatch):
     monkeypatch.setattr(nodes, "check_node_health",
                         mock_check_node_health(True))
     session.app.post("/api/nodes/chacra.ceph.com/")
     n = Node.get(1)
     last_check = n.last_check.time()
     session.app.post("/api/nodes/chacra.ceph.com/")
     n = Node.get(1)
     assert n.last_check.time() > last_check
예제 #14
0
 def test_last_check_is_updated(self, m_get, session):
     m_get.return_value.ok = True
     node = Node("chacra.ceph.com")
     last_check = datetime.datetime.now()
     node.last_check = datetime.datetime.now()
     session.commit()
     util.is_node_healthy(node)
     node = Node.get(1)
     assert node.last_check.time() > last_check.time()
예제 #15
0
 def test_updates_healthy(self, session, monkeypatch):
     monkeypatch.setattr(nodes, "check_node_health",
                         mock_check_node_health(True))
     session.app.post("/api/nodes/chacra.ceph.com/")
     n = Node.get(1)
     n.healthy = False
     session.commit()
     session.app.post("/api/nodes/chacra.ceph.com/")
     n = Node.get(1)
     assert n.healthy
예제 #16
0
 def test_healthy_is_true_when_rejoining_pool(self, m_get, session):
     """
     Tests the scenario where a node has been marked down,
     but is now up again and needs to rejoin the pool.
     """
     m_get.return_value.ok = True
     node = Node("chacra.ceph.com")
     node.down_count = 3
     node.healthy = False
     session.commit()
     util.is_node_healthy(node)
     node = Node.get(1)
     assert node.down_count == 0
     assert node.healthy
예제 #17
0
파일: test_util.py 프로젝트: ceph/shaman
 def test_healthy_is_true_when_rejoining_pool(self, m_get, session):
     """
     Tests the scenario where a node has been marked down,
     but is now up again and needs to rejoin the pool.
     """
     m_get.return_value.ok = True
     node = Node("chacra.ceph.com")
     node.down_count = 3
     node.healthy = False
     session.commit()
     util.is_node_healthy(node)
     node = Node.get(1)
     assert node.down_count == 0
     assert node.healthy
예제 #18
0
 def test_sets_last_used_on_selection(self, session, monkeypatch):
     monkeypatch.setattr(util, "is_node_healthy", lambda node: True)
     node = Node("chacra.ceph.com")
     session.commit()
     last_used = node.last_used
     next_node = util.get_next_node()
     assert next_node.last_used.time() > last_used.time()
예제 #19
0
 def test_node_fails_initial_check(self, session, monkeypatch):
     monkeypatch.setattr(nodes, "check_node_health",
                         mock_check_node_health(False))
     session.app.post("/api/nodes/chacra.ceph.com/")
     n = Node.get(1)
     assert n.host == "chacra.ceph.com"
     assert not n.healthy
예제 #20
0
 def test_down_count_is_incremented(self, m_get, session):
     m_get.return_value.ok = False
     node = Node("chacra.ceph.com")
     session.commit()
     util.is_node_healthy(node)
     node = Node.get(1)
     assert node.down_count == 1
예제 #21
0
    def test_get_next_node_fails(self, session, monkeypatch):
        monkeypatch.setattr(nodes, "check_node_health",
                            mock_check_node_health(True))
        Node("chacra.ceph.com")
        session.commit()

        def _get_next_node():
            return None

        monkeypatch.setattr(nodes, "get_next_node", _get_next_node)
        result = session.app.get("/api/nodes/next/", expect_errors=True)
        assert result.status_int == 404
예제 #22
0
    def test_get_next_node_succeeds(self, session, monkeypatch):
        monkeypatch.setattr(nodes, "check_node_health",
                            mock_check_node_health(True))
        Node("chacra.ceph.com")
        session.commit()

        def _get_next_node():
            node = Node.get(1)
            return node

        monkeypatch.setattr(nodes, "get_next_node", _get_next_node)
        result = session.app.get("/api/nodes/next/")
        assert result.body == "https://chacra.ceph.com/"
예제 #23
0
 def test_pick_last_used_node(self, session, monkeypatch):
     monkeypatch.setattr(util, "is_node_healthy", lambda node: True)
     n1 = Node("chacra01.ceph.com")
     n1.last_used = datetime.datetime.now() - datetime.timedelta(days=1)
     n2 = Node("chacra02.ceph.com")
     n2.last_used = datetime.datetime.now()
     session.commit()
     assert n1 == util.get_next_node()
예제 #24
0
파일: test_nodes.py 프로젝트: ceph/shaman
 def test_node_fails_initial_check(self, session, monkeypatch):
     monkeypatch.setattr(nodes, "check_node_health", mock_check_node_health(False))
     session.app.post("/api/nodes/chacra.ceph.com/")
     n = Node.get(1)
     assert n.host == "chacra.ceph.com"
     assert not n.healthy
예제 #25
0
파일: test_nodes.py 프로젝트: ceph/shaman
 def test_create_node(self, session, monkeypatch):
     monkeypatch.setattr(nodes, "check_node_health", mock_check_node_health(True))
     session.app.post("/api/nodes/chacra.ceph.com/")
     n = Node.get(1)
     assert n.host == "chacra.ceph.com"
예제 #26
0
 def _get_next_node():
     node = Node.get(1)
     return node
예제 #27
0
 def test_no_healthy_nodes(self, session):
     node = Node("chacra.ceph.com")
     node.healthy = False
     session.commit()
     assert not util.get_next_node()
예제 #28
0
 def test_no_healthy_nodes(self, session):
     node = Node("chacra.ceph.com")
     node.healthy = False
     session.commit()
     assert not util.get_next_node()
예제 #29
0
 def test_create_node(self, session, monkeypatch):
     monkeypatch.setattr(nodes, "check_node_health",
                         mock_check_node_health(True))
     session.app.post("/api/nodes/chacra.ceph.com/")
     n = Node.get(1)
     assert n.host == "chacra.ceph.com"
예제 #30
0
 def test_node_raises_requests_exception(self, exc, session, monkeypatch):
     monkeypatch.setattr(requests, "get",
                         lambda *a, **kw: request_exception(exc))
     healthy = util.check_node_health(Node("chacra.ceph.com"))
     assert healthy is False
예제 #31
0
 def test_get_one_node(self, session):
     Node("chacra.ceph.com")
     session.commit()
     result = session.app.get("/api/nodes/")
     assert result.json.keys() == ["chacra.ceph.com"]
예제 #32
0
 def test_unhealthy(self, session, monkeypatch):
     response = RequestsResponse(ok=False)
     monkeypatch.setattr(requests, "get", lambda *a, **kw: response)
     healthy = util.check_node_health(Node("chacra.ceph.com"))
     assert healthy is False
예제 #33
0
 def test_finds_a_node(self, session, monkeypatch):
     monkeypatch.setattr(util, "is_node_healthy", lambda node: True)
     node = Node("chacra.ceph.com")
     session.commit()
     next_node = util.get_next_node()
     assert next_node == node
예제 #34
0
파일: test_nodes.py 프로젝트: ceph/shaman
 def _get_next_node():
     node = Node.get(1)
     return node
예제 #35
0
 def test_node_is_not_healthy(self, m_get, session):
     m_get.return_value.ok = False
     node = Node("chacra.ceph.com")
     session.commit()
     assert not util.is_node_healthy(node)