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()
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()
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()
def next(self): next_node = get_next_node() if not next_node: abort(404, "There are no healthy chacra nodes available.") return "https://{}/".format(next_node.host)
def test_no_healthy_nodes(self, session): node = Node("chacra.ceph.com") node.healthy = False session.commit() assert not util.get_next_node()
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
def test_no_nodes(self, session): assert not util.get_next_node()