Exemplo n.º 1
0
    def _create_active_standby_topology(
            self, lf_name=constants.CREATE_LOADBALANCER_FLOW):
        # When we boot up amphora for an active/standby topology,
        # we should leverage the Nova anti-affinity capabilities
        # to place the amphora on different hosts, also we need to check
        # if anti-affinity-flag is enabled or not:
        anti_affinity = CONF.nova.enable_anti_affinity
        flows = []
        if anti_affinity:
            # we need to create a server group first
            flows.append(
                compute_tasks.NovaServerGroupCreate(
                    name=lf_name + '-' + constants.CREATE_SERVER_GROUP_FLOW,
                    requires=(constants.LOADBALANCER_ID),
                    provides=constants.SERVER_GROUP_ID))

            # update server group id in lb table
            flows.append(
                database_tasks.UpdateLBServerGroupInDB(
                    name=lf_name + '-' +
                    constants.UPDATE_LB_SERVERGROUPID_FLOW,
                    requires=(constants.LOADBALANCER_ID,
                              constants.SERVER_GROUP_ID)))

        f_name = constants.CREATE_LOADBALANCER_FLOW
        amps_flow = unordered_flow.Flow(f_name)
        master_amp_sf = self.amp_flows.get_amphora_for_lb_subflow(
            prefix=constants.ROLE_MASTER, role=constants.ROLE_MASTER)

        backup_amp_sf = self.amp_flows.get_amphora_for_lb_subflow(
            prefix=constants.ROLE_BACKUP, role=constants.ROLE_BACKUP)
        amps_flow.add(master_amp_sf, backup_amp_sf)

        return flows + [amps_flow]
Exemplo n.º 2
0
    def test_nova_server_group_create(self, mock_driver):
        nova_sever_group_obj = compute_tasks.NovaServerGroupCreate()

        server_group_test_id = '6789'
        fake_server_group = mock.MagicMock()
        fake_server_group.id = server_group_test_id
        fake_server_group.policy = 'anti-affinity'
        mock_driver.create_server_group.return_value = fake_server_group

        # Test execute()
        sg_id = nova_sever_group_obj.execute('123')

        # Validate that the build method was called properly
        mock_driver.create_server_group.assert_called_once_with(
            'octavia-lb-123', 'anti-affinity')

        # Make sure it returns the expected server group_id
        self.assertEqual(server_group_test_id, sg_id)

        # Test revert()
        nova_sever_group_obj.revert(sg_id)

        # Validate that the delete_server_group method was called properly
        mock_driver.delete_server_group.assert_called_once_with(sg_id)

        # Test revert with exception
        mock_driver.reset_mock()
        mock_driver.delete_server_group.side_effect = Exception('DelSGExcept')
        nova_sever_group_obj.revert(sg_id)
        mock_driver.delete_server_group.assert_called_once_with(sg_id)
Exemplo n.º 3
0
    def get_create_load_balancer_flow(self, topology):
        """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.
        """
        # create a linear flow as a wrapper
        lf_name = constants.PRE_CREATE_LOADBALANCER_FLOW
        create_lb_flow_wrapper = linear_flow.Flow(lf_name)

        f_name = constants.CREATE_LOADBALANCER_FLOW
        lb_create_flow = unordered_flow.Flow(f_name)

        if topology == constants.TOPOLOGY_ACTIVE_STANDBY:
            # When we boot up amphora for an active/standby topology,
            # we should leverage the Nova anti-affinity capabilities
            # to place the amphora on different hosts, also we need to check
            # if anti-affinity-flag is enabled or not:
            anti_affinity = CONF.nova.enable_anti_affinity
            if anti_affinity:
                # we need to create a server group first
                create_lb_flow_wrapper.add(
                    compute_tasks.NovaServerGroupCreate(
                        name=lf_name + '-' +
                        constants.CREATE_SERVER_GROUP_FLOW,
                        requires=(constants.LOADBALANCER_ID),
                        provides=constants.SERVER_GROUP_ID))

                # update server group id in lb table
                create_lb_flow_wrapper.add(
                    database_tasks.UpdateLBServerGroupInDB(
                        name=lf_name + '-' +
                        constants.UPDATE_LB_SERVERGROUPID_FLOW,
                        requires=(constants.LOADBALANCER_ID,
                                  constants.SERVER_GROUP_ID)))

            master_amp_sf = self.amp_flows.get_amphora_for_lb_subflow(
                prefix=constants.ROLE_MASTER, role=constants.ROLE_MASTER)

            backup_amp_sf = self.amp_flows.get_amphora_for_lb_subflow(
                prefix=constants.ROLE_BACKUP, role=constants.ROLE_BACKUP)

            lb_create_flow.add(master_amp_sf, backup_amp_sf)

        elif topology == constants.TOPOLOGY_SINGLE:
            amphora_sf = self.amp_flows.get_amphora_for_lb_subflow(
                prefix=constants.ROLE_STANDALONE,
                role=constants.ROLE_STANDALONE)
            lb_create_flow.add(amphora_sf)
        else:
            LOG.error(
                _LE("Unknown topology: %s.  Unable to build load "
                    "balancer."), topology)
            raise exceptions.InvalidTopology(topology=topology)

        create_lb_flow_wrapper.add(lb_create_flow)
        return create_lb_flow_wrapper