Beispiel #1
0
 def _change_node_eff(self):
     change_node = ChangeCLBNode(
         lb_id='abc123',
         node_id='node1',
         condition=CLBNodeCondition.DRAINING,
         weight=50,
         type=CLBNodeType.PRIMARY)
     return change_node.as_effect()
Beispiel #2
0
 def test_change_clb_node(self):
     """Logs :obj:`ChangeCLBNode`."""
     changes = pbag([
         ChangeCLBNode(lb_id='lbid1',
                       node_id='node1',
                       condition=CLBNodeCondition.DRAINING,
                       type=CLBNodeType.PRIMARY,
                       weight=50),
         ChangeCLBNode(lb_id='lbid1',
                       node_id='node2',
                       condition=CLBNodeCondition.DRAINING,
                       type=CLBNodeType.PRIMARY,
                       weight=50),
         ChangeCLBNode(lb_id='lbid1',
                       node_id='node3',
                       condition=CLBNodeCondition.ENABLED,
                       type=CLBNodeType.PRIMARY,
                       weight=50),
         ChangeCLBNode(lb_id='lbid2',
                       node_id='node4',
                       condition=CLBNodeCondition.ENABLED,
                       type=CLBNodeType.PRIMARY,
                       weight=50),
     ])
     self.assert_logs(changes, [
         Log('convergence-change-clb-nodes',
             fields={
                 'lb_id': 'lbid1',
                 'nodes': ['node3'],
                 'type': 'PRIMARY',
                 'condition': 'ENABLED',
                 'weight': 50,
                 'cloud_feed': True
             }),
         Log('convergence-change-clb-nodes',
             fields={
                 'lb_id': 'lbid1',
                 'nodes': ['node1', 'node2'],
                 'type': 'PRIMARY',
                 'condition': 'DRAINING',
                 'weight': 50,
                 'cloud_feed': True
             }),
         Log('convergence-change-clb-nodes',
             fields={
                 'lb_id': 'lbid2',
                 'nodes': ['node4'],
                 'type': 'PRIMARY',
                 'condition': 'ENABLED',
                 'weight': 50,
                 'cloud_feed': True
             }),
     ])
Beispiel #3
0
def change_lb_node(node, description, lb, now, timeout):
    """
    Change the configuration of a load balancer node to desired description.
    If CLB has health monitor enabled and the node is DRAINING then it will be
    ENABLEDed.

    :param node: The node to be changed.
    :type node: :class:`ILBNode` provider
    :param description: The description of the load balancer and how to add
        the server to it.
    :type description: :class:`ILBDescription` provider
    :param float now: Number of seconds since EPOCH
    :param float timeout: How long can node remain OFFLINE after adding
        in seconds?

    :return: :obj:`IStep` object or None
    """
    if (type(node.description) == type(description) and
            isinstance(description, CLBDescription)):
        if lb is None:
            return fail_convergence(CLBHealthInfoNotFound(description.lb_id))
        if (lb.health_monitor and
                node.description.condition == CLBNodeCondition.DRAINING):
            # Enable node if it is ONLINE
            if node.is_online:
                return ChangeCLBNode(lb_id=description.lb_id,
                                     node_id=node.node_id,
                                     condition=CLBNodeCondition.ENABLED,
                                     weight=description.weight,
                                     type=description.type)
            # For a new node created in DRAINING, drained_at represents
            # node's creation time.
            if now - node.drained_at > timeout:
                rsfmt = ("Node {} has remained OFFLINE for more than "
                         "{} seconds")
                return FailConvergence(
                    [ErrorReason.String(rsfmt.format(node.node_id, timeout))])
            else:
                return ConvergeLater(
                    [ErrorReason.String(("Waiting for node {} to come "
                                         "ONLINE").format(node.node_id))])
        return ChangeCLBNode(lb_id=description.lb_id,
                             node_id=node.node_id,
                             condition=description.condition,
                             weight=description.weight,
                             type=description.type)
Beispiel #4
0
 def test_mixed(self):
     """
     When there are multiple steps of same CLB then first step of each CLB
     is returned
     """
     steps = [
         CreateServer(server_config=pmap({"name": "server"})),
         DeleteServer(server_id="abc"),
         AddNodesToCLB(lb_id='5',
                       address_configs=s(
                           ('1.1.1.1', CLBDescription(lb_id='5',
                                                      port=80)))),
         RemoveNodesFromCLB(lb_id='5', node_ids=s('1')),
         RemoveNodesFromCLB(lb_id='6', node_ids=s('3')),
         AddNodesToCLB(lb_id='6',
                       address_configs=s(
                           ('2.1.1.1', CLBDescription(lb_id='6',
                                                      port=80)))),
         ChangeCLBNode(lb_id='7',
                       node_id='9',
                       condition=CLBNodeCondition.ENABLED,
                       weight=10,
                       type=CLBNodeType.PRIMARY),
         RemoveNodesFromCLB(lb_id='7', node_ids=s('4')),
         AddNodesToCLB(lb_id='7',
                       address_configs=s(
                           ('3.1.1.1', CLBDescription(lb_id='9',
                                                      port=80)))),
         ChangeCLBNode(lb_id='5',
                       node_id='11',
                       condition=CLBNodeCondition.ENABLED,
                       weight=10,
                       type=CLBNodeType.PRIMARY)
     ]
     self.assertEqual(
         list(one_clb_step(steps)),
         (
             steps[:3] +  # Non-CLB steps and 1 step for CLB 5
             [steps[4]] +  # One step for CLB 6
             [steps[6]])  # One step for CLB 7
     )
Beispiel #5
0
def drain_lb_node(node):
    """
    Drain the node balancing node.

    :ivar node: The node to be changed.
    :type node: :class:`ILBNode` provider
    """
    if isinstance(node, CLBNode):
        return ChangeCLBNode(lb_id=node.description.lb_id,
                             node_id=node.node_id,
                             condition=CLBNodeCondition.DRAINING,
                             weight=node.description.weight,
                             type=node.description.type)
Beispiel #6
0
def change_lb_node(node, description):
    """
    Change the configuration of a load balancer node.

    :ivar node: The node to be changed.
    :type node: :class:`ILBNode` provider

    :ivar description: The description of the load balancer and how to add
        the server to it.
    :type description: :class:`ILBDescription` provider
    """
    if type(node.description) == type(description):
        if isinstance(description, CLBDescription):
            return ChangeCLBNode(lb_id=description.lb_id,
                                 node_id=node.node_id,
                                 condition=description.condition,
                                 weight=description.weight,
                                 type=description.type)