def get_create_load_balancer_flow(self): """Creates a flow to create a load balancer. :returns: The flow for creating a load balancer """ # Note this flow is a bit strange in how it handles building # Amphora if there are no spares. TaskFlow has a spec for # a conditional flow that would make this cleaner once implemented. # https://review.openstack.org/#/c/98946/ create_LB_flow = linear_flow.Flow(constants.CREATE_LOADBALANCER_FLOW) create_LB_flow.add(database_tasks.MapLoadbalancerToAmphora( requires=constants.LOADBALANCER_ID, provides=constants.AMPHORA_ID)) create_LB_flow.add(database_tasks.ReloadAmphora( requires=constants.AMPHORA_ID, provides=constants.AMPHORA)) create_LB_flow.add(database_tasks.ReloadLoadBalancer( name=constants.RELOAD_LB_AFTER_AMP_ASSOC, requires=constants.LOADBALANCER_ID, provides=constants.LOADBALANCER)) new_LB_net_subflow = self.get_new_LB_networking_subflow() create_LB_flow.add(new_LB_net_subflow) create_LB_flow.add(database_tasks.MarkLBActiveInDB( requires=constants.LOADBALANCER)) return create_LB_flow
def get_amphora_for_lb_subflow(self, prefix, role=constants.ROLE_STANDALONE): """Tries to allocate a spare amphora to a loadbalancer if none exists, create a new amphora. """ sf_name = prefix + '-' + constants.GET_AMPHORA_FOR_LB_SUBFLOW # We need a graph flow here for a conditional flow amp_for_lb_flow = graph_flow.Flow(sf_name) # Setup the task that maps an amphora to a load balancer allocate_and_associate_amp = database_tasks.MapLoadbalancerToAmphora( name=sf_name + '-' + constants.MAP_LOADBALANCER_TO_AMPHORA, requires=(constants.LOADBALANCER_ID, constants.FLAVOR), provides=constants.AMPHORA_ID) # Define a subflow for if we successfully map an amphora map_lb_to_amp = self._get_post_map_lb_subflow(prefix, role) # Define a subflow for if we can't map an amphora create_amp = self._get_create_amp_for_lb_subflow(prefix, role) # Add them to the graph flow amp_for_lb_flow.add(allocate_and_associate_amp, map_lb_to_amp, create_amp) # Setup the decider for the path if we can map an amphora amp_for_lb_flow.link(allocate_and_associate_amp, map_lb_to_amp, decider=self._allocate_amp_to_lb_decider, decider_depth='flow') # Setup the decider for the path if we can't map an amphora amp_for_lb_flow.link(allocate_and_associate_amp, create_amp, decider=self._create_new_amp_for_lb_decider, decider_depth='flow') # Plug the network # todo(xgerman): Rework failover flow if prefix != constants.FAILOVER_AMPHORA_FLOW: sf_name = prefix + '-' + constants.AMP_PLUG_NET_SUBFLOW amp_for_lb_net_flow = linear_flow.Flow(sf_name) amp_for_lb_net_flow.add(amp_for_lb_flow) amp_for_lb_net_flow.add(*self._get_amp_net_subflow(sf_name)) return amp_for_lb_net_flow return amp_for_lb_flow
def test_map_loadbalancer_to_amphora( self, mock_allocate_and_associate, mock_generate_uuid, mock_LOG, mock_get_session, mock_loadbalancer_repo_update, mock_listener_repo_update, mock_amphora_repo_update, mock_amphora_repo_delete): map_lb_to_amp = database_tasks.MapLoadbalancerToAmphora() amp_id = map_lb_to_amp.execute(self.loadbalancer_mock.id) repo.AmphoraRepository.allocate_and_associate.assert_called_once_with( 'TEST', LB_ID) assert amp_id == _amphora_mock.id self.assertRaises(exceptions.NoReadyAmphoraeException, map_lb_to_amp.execute, self.loadbalancer_mock.id)