Example #1
0
    def test_good_response(self):
        """
        If the response code indicates success, the step returns a RETRY so
        that another convergence cycle can be done to update the active server
        list.
        """
        node_a_id = '825b8c72-9951-4aff-9cd8-fa3ca5551c90'
        lb_a_id = '2b0e17b6-0429-4056-b86c-e670ad5de853'

        node_b_id = "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2"
        lb_b_id = 'd95ae0c4-6ab8-4873-b82f-f8433840cff2'

        pairs = [(lb_a_id, node_a_id), (lb_b_id, node_b_id)]

        resp = StubResponse(201, {})
        body = [{"cloud_server": {"id": node_id},
                 "load_balancer_pool": {"id": lb_id}}
                for (lb_id, node_id) in pairs]
        res = _rcv3_check_bulk_add(pairs, (resp, body))
        self.assertEqual(
            res,
            (StepResult.RETRY,
             [ErrorReason.String(
              'must re-gather after adding to LB in order to update the '
              'active cache')]))
Example #2
0
    def test_node_already_a_member(self):
        """
        If all nodes were already member of the load balancers we were
        trying to add them to, the request is successful.
        """
        node_id = "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2"
        lb_id = 'd95ae0c4-6ab8-4873-b82f-f8433840cff2'
        pairs = [(lb_id, node_id)]

        resp = StubResponse(409, {})
        body = {"errors": [
            "Cloud Server {node_id} is already a member of Load "
            "Balancer Pool {lb_id}".format(node_id=node_id, lb_id=lb_id)]}
        result = _rcv3_check_bulk_add(pairs, (resp, body))
        self.assertEqual(result, (StepResult.SUCCESS, []))
Example #3
0
    def test_lb_does_not_exist(self):
        """
        If one of the LBs we tried to attach one or more nodes to does not
        exist, the request fails.
        """
        node_id = "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2"
        lb_id = 'd95ae0c4-6ab8-4873-b82f-f8433840cff2'
        pairs = [(lb_id, node_id)]

        resp = StubResponse(409, {})
        body = {"errors": [
            "Load Balancer Pool {lb_id} does not exist"
            .format(lb_id=lb_id)]}
        result = _rcv3_check_bulk_add(pairs, (resp, body))
        self.assertEqual(
            result,
            (StepResult.FAILURE,
             ["RCv3 LB {lb_id} does not exist".format(lb_id=lb_id)]))
Example #4
0
    def test_try_again(self):
        """
        If a node is already on the load balancer, returns an effect that
        removes the remaining load balancer pairs.
        """
        # This little piggy is already on the load balancer
        node_a_id = '825b8c72-9951-4aff-9cd8-fa3ca5551c90'
        lb_a_id = '2b0e17b6-0429-4056-b86c-e670ad5de853'

        # This little piggy is going to be added to this load balancer
        node_b_id = "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2"
        lb_b_id = 'd95ae0c4-6ab8-4873-b82f-f8433840cff2'

        seq = [
            (service_request(
                service_type=ServiceType.RACKCONNECT_V3,
                method="POST",
                url='load_balancer_pools/nodes',
                data=[
                    {'load_balancer_pool': {'id': lb_b_id},
                     'cloud_server': {'id': node_b_id}}],
                success_pred=has_code(201, 409)).intent,
             lambda _: (StubResponse(201, {}), None)),
        ]

        body = {"errors":
                ["Cloud Server {node_id} is already a member of Load "
                 "Balancer Pool {lb_id}"
                 .format(node_id=node_a_id, lb_id=lb_a_id)]}

        eff = _rcv3_check_bulk_add(
            [(lb_a_id, node_a_id),
             (lb_b_id, node_b_id)],
            (StubResponse(409, {}), body))

        self.assertEqual(
            perform_sequence(seq, eff),
            (StepResult.RETRY,
             [ErrorReason.String(reason="must re-gather after adding to LB in "
                                        "order to update the active cache")]))
Example #5
0
    def test_multiple_lbs_do_not_exist(self):
        """
        If multiple LBs we tried to attach one or more nodes to do not
        exist, the request fails, and all of the nonexistent LBs are
        reported.

        By logging as much of the failure as we can see, we will
        hopefully produce better audit logs.
        """
        node_id = "d6d3aa7c-dfa5-4e61-96ee-1d54ac1075d2"
        lb_1_id = 'd95ae0c4-6ab8-4873-b82f-f8433840cff2'
        lb_2_id = 'fb32470f-6ebe-44a9-9360-3f48c9ac768c'
        pairs = [(lb_1_id, node_id), (lb_2_id, node_id)]

        resp = StubResponse(409, {})
        body = {"errors": [
            "Load Balancer Pool {lb_id} does not exist"
            .format(lb_id=lb_id) for lb_id in [lb_1_id, lb_2_id]]}
        result = _rcv3_check_bulk_add(pairs, (resp, body))
        self.assertEqual(
            result,
            (StepResult.FAILURE,
             ["RCv3 LB {lb_id} does not exist".format(lb_id=lb_id)
              for lb_id in [lb_1_id, lb_2_id]]))