Ejemplo n.º 1
0
    def get_create_load_balancer_flow(self, topology, listeners=None):
        """Creates a conditional graph flow that allocates a loadbalancer to

        two spare amphorae.
        :raises InvalidTopology: Invalid topology specified
        :return: The graph flow for creating a loadbalancer.
        """
        f_name = constants.CREATE_LOADBALANCER_FLOW
        lb_create_flow = linear_flow.Flow(f_name)

        lb_create_flow.add(
            lifecycle_tasks.LoadBalancerIDToErrorOnRevertTask(
                requires=constants.LOADBALANCER_ID))

        # allocate VIP
        lb_create_flow.add(
            database_tasks.ReloadLoadBalancer(
                name=constants.RELOAD_LB_BEFOR_ALLOCATE_VIP,
                requires=constants.LOADBALANCER_ID,
                provides=constants.LOADBALANCER))
        lb_create_flow.add(
            network_tasks.AllocateVIP(requires=constants.LOADBALANCER,
                                      provides=constants.VIP))
        lb_create_flow.add(
            database_tasks.UpdateVIPAfterAllocation(
                requires=(constants.LOADBALANCER_ID, constants.VIP),
                provides=constants.LOADBALANCER))
        lb_create_flow.add(
            network_tasks.UpdateVIPSecurityGroup(
                requires=constants.LOADBALANCER_ID))
        lb_create_flow.add(
            network_tasks.GetSubnetFromVIP(requires=constants.LOADBALANCER,
                                           provides=constants.SUBNET))

        if topology == constants.TOPOLOGY_ACTIVE_STANDBY:
            lb_create_flow.add(*self._create_active_standby_topology())
        elif topology == constants.TOPOLOGY_SINGLE:
            lb_create_flow.add(*self._create_single_topology())
        else:
            LOG.error("Unknown topology: %s.  Unable to build load balancer.",
                      topology)
            raise exceptions.InvalidTopology(topology=topology)

        post_amp_prefix = constants.POST_LB_AMP_ASSOCIATION_SUBFLOW
        lb_create_flow.add(
            self.get_post_lb_amp_association_flow(post_amp_prefix,
                                                  topology,
                                                  mark_active=(not listeners)))

        if listeners:
            lb_create_flow.add(*self._create_listeners_flow())

        return lb_create_flow
Ejemplo n.º 2
0
    def test_LoadBalancerIDToErrorOnRevertTask(
            self, mock_loadbalancer_prov_status_error):

        loadbalancer_id_to_error_on_revert = (
            lifecycle_tasks.LoadBalancerIDToErrorOnRevertTask())

        # Execute
        loadbalancer_id_to_error_on_revert.execute(self.LOADBALANCER_ID)

        self.assertFalse(mock_loadbalancer_prov_status_error.called)

        # Revert
        loadbalancer_id_to_error_on_revert.revert(self.LOADBALANCER_ID)

        mock_loadbalancer_prov_status_error.assert_called_once_with(
            self.LOADBALANCER_ID)