Exemple #1
0
def add_server_to_lb(server, description, load_balancer):
    """
    Add a server to a load balancing entity as described by `description`.

    :ivar server: The server to be added
    :type server: :class:`NovaServer`

    :ivar description: The description of the load balancer and how to add
        the server to it.
    :type description: :class:`ILBDescription` provider
    """
    if isinstance(description, CLBDescription):
        if server.servicenet_address:
            if load_balancer is None:
                return fail_convergence(
                    CLBHealthInfoNotFound(description.lb_id))
            if load_balancer.health_monitor:
                description = assoc_obj(description,
                                        condition=CLBNodeCondition.DRAINING)
            return AddNodesToCLB(
                lb_id=description.lb_id,
                address_configs=pset(
                    [(server.servicenet_address, description)]))
    elif isinstance(description, RCv3Description):
        return BulkAddToRCv3(lb_node_pairs=pset(
            [(description.lb_id, server.id)]))
Exemple #2
0
 def test_bulk_add_to_rcv3(self):
     """Logs :obj:`BulkAddToRCv3`."""
     adds = pbag([
         BulkAddToRCv3(lb_node_pairs=pset([('lb1', 'node1'), (
             'lb1', 'node2'), ('lb2', 'node2'), ('lb2',
                                                 'node3'), ('lb3',
                                                            'node4')])),
         BulkAddToRCv3(
             lb_node_pairs=pset([('lba',
                                  'nodea'), ('lba',
                                             'nodeb'), ('lb1', 'nodea')]))
     ])
     self.assert_logs(adds, [
         Log('convergence-add-rcv3-nodes',
             fields={
                 'lb_id': 'lb1',
                 'servers': ['node1', 'node2', 'nodea'],
                 'cloud_feed': True
             }),
         Log('convergence-add-rcv3-nodes',
             fields={
                 'lb_id': 'lb2',
                 'servers': ['node2', 'node3'],
                 'cloud_feed': True
             }),
         Log('convergence-add-rcv3-nodes',
             fields={
                 'lb_id': 'lb3',
                 'servers': ['node4'],
                 'cloud_feed': True
             }),
         Log('convergence-add-rcv3-nodes',
             fields={
                 'lb_id': 'lba',
                 'servers': ['nodea', 'nodeb'],
                 'cloud_feed': True
             })
     ])
Exemple #3
0
 def test_rcv3_mixed(self):
     """
     Multiple BulkAddToRCv3 and BulkRemoveFromRCv3 steps are combined
     into one BulkAddToRCv3 step and one BulkRemoveFromRCv3 step
     """
     steps = [
         BulkAddToRCv3(lb_node_pairs=pset([("l1", "s1"), ("l1", "s2")])),
         # Same pair for different class does not conflict
         BulkRemoveFromRCv3(lb_node_pairs=pset([("l1", "s1")])),
         BulkAddToRCv3(lb_node_pairs=pset([("l1", "s3")])),
         BulkRemoveFromRCv3(lb_node_pairs=pset([("l3", "s3"), ("l2",
                                                               "s3")]))
     ]
     self.assertEqual(
         optimize_steps(steps),
         pbag([
             BulkAddToRCv3(lb_node_pairs=pset([("l1",
                                                "s1"), ("l1",
                                                        "s2"), ("l1",
                                                                "s3")])),
             BulkRemoveFromRCv3(
                 lb_node_pairs=pset([("l1", "s1"), ("l3", "s3"), ("l2",
                                                                  "s3")]))
         ]))
Exemple #4
0
 def test_optimize_leaves_other_steps(self):
     """
     Unoptimizable steps pass the optimizer unchanged.
     """
     steps = pbag([
         AddNodesToCLB(lb_id='5',
                       address_configs=s(
                           ('1.1.1.1', CLBDescription(lb_id='5',
                                                      port=80)))),
         RemoveNodesFromCLB(lb_id='6', node_ids=s('1')),
         CreateServer(server_config=pmap({})),
         BulkRemoveFromRCv3(lb_node_pairs=pset([("lb-1", "node-a")])),
         BulkAddToRCv3(lb_node_pairs=pset([("lb-2", "node-b")]))
         # Note that the add & remove pair should not be the same;
         # the optimizer might reasonably optimize opposite
         # operations away in the future.
     ])
     self.assertEqual(optimize_steps(steps), steps)
Exemple #5
0
def add_server_to_lb(server, description):
    """
    Add a server to a load balancing entity as described by `description`.

    :ivar server: The server to be added
    :type server: :class:`NovaServer`

    :ivar description: The description of the load balancer and how to add
        the server to it.
    :type description: :class:`ILBDescription` provider
    """
    if isinstance(description, CLBDescription):
        if server.servicenet_address:
            return AddNodesToCLB(
                lb_id=description.lb_id,
                address_configs=pset(
                    [(server.servicenet_address, description)]))
    elif isinstance(description, RCv3Description):
        return BulkAddToRCv3(lb_node_pairs=pset(
            [(description.lb_id, server.id)]))
Exemple #6
0
 def setUp(self):
     from otter.convergence.steps import rcv3 as step_rcv3
     self.patch(step_rcv3, "bulk_add", intent_func("ba"))
     self.pairs = pset([("l1", "n1"), ("l2", "n2")])
     self.step = BulkAddToRCv3(lb_node_pairs=self.pairs)