示例#1
0
 def test_provides_ILBDescription_and_IDrainable(self):
     """
     An instance of :class:`CLBNode` provides :class:`ILBNode` and
     :class:`IDrainable`.
     """
     node = CLBNode(node_id="1234", description=self.desc, address="10.1.1.1")
     self.assertTrue(ILBNode.providedBy(node))
     self.assertTrue(IDrainable.providedBy(node))
示例#2
0
 def test_provides_ILBDescription_and_IDrainable(self):
     """
     An instance of :class:`CLBNode` provides :class:`ILBNode` and
     :class:`IDrainable`.
     """
     node = CLBNode(node_id='1234', description=self.desc, address='10.1.1.1')
     self.assertTrue(ILBNode.providedBy(node))
     self.assertTrue(IDrainable.providedBy(node))
示例#3
0
def _remove_from_lb_with_draining(timeout, nodes, now):
    """
    Produce a series of steps that will eventually remove all the given nodes.
    It does this in three steps:

    For any particular node in ``nodes``:

    1. If the timeout is greater than zero, and the node is ``ENABLED``, the
       node will be changed to ``DRAINING``.

    2. If the node is ``DRAINING``, and the timeout (greater than zero) has
       already expired or there are no more active connections, the node will
       be removed from the load balancer.  If the timeout (greater than zero)
       has not expired and active connections != 0, then nothing is done to the
       node.

    3. If the node is in any other state other than `DRAINING` or `ENABLED`, or
       if the timeout is zero, it will be removed from the load balancer.

    :param float timeout: the time the node should remain in draining until
        removed
    :param list nodes: `list` of :obj:`CLBNode` that should be
        drained, then removed
    :param float now: number of seconds since the POSIX epoch indicating the
        time at which the convergence was requested.

    :rtype: `list` of :class:`IStep`
    """
    to_drain = ()
    in_drain = ()

    # only put nodes into draining if a timeout is specified
    if timeout > 0:
        draining, to_drain = partition_bool(
            lambda node: node.currently_draining(),
            [node for node in nodes
             if IDrainable.providedBy(node) and node.is_active()])

        # Nothing should be done to these, because the timeout has not expired
        # and the nodes are still active
        in_drain = [node for node in draining
                    if not node.is_done_draining(now, timeout)]

    removes = [remove_node_from_lb(node=node)
               for node in (set(nodes) - set(to_drain) - set(in_drain))]

    changes = [drain_lb_node(node=node) for node in to_drain]

    retry = (
        [ConvergeLater(reasons=[ErrorReason.String('draining servers')])]
        if in_drain else [])

    return removes + changes + retry