コード例 #1
0
 def _create_listeners_flow(self):
     flows = []
     flows.append(
         database_tasks.ReloadLoadBalancer(
             name=constants.RELOAD_LB_AFTER_AMP_ASSOC_FULL_GRAPH,
             requires=constants.LOADBALANCER_ID,
             provides=constants.LOADBALANCER
         )
     )
     flows.append(
         network_tasks.CalculateDelta(
             requires=(constants.LOADBALANCER, constants.AVAILABILITY_ZONE),
             provides=constants.DELTAS
         )
     )
     flows.append(
         network_tasks.HandleNetworkDeltas(
             requires=constants.DELTAS, provides=constants.ADDED_PORTS
         )
     )
     flows.append(
         amphora_driver_tasks.AmphoraePostNetworkPlug(
             requires=(constants.LOADBALANCER, constants.ADDED_PORTS)
         )
     )
     flows.append(
         self.listener_flows.get_create_all_listeners_flow()
     )
     flows.append(
         database_tasks.MarkLBActiveInDB(
             mark_subobjects=True,
             requires=constants.LOADBALANCER
         )
     )
     return flows
コード例 #2
0
    def get_create_member_flow(self):
        """Create a flow to create a member

        :returns: The flow for creating a member
        """
        create_member_flow = linear_flow.Flow(constants.CREATE_MEMBER_FLOW)
        create_member_flow.add(
            lifecycle_tasks.MemberToErrorOnRevertTask(requires=[
                constants.MEMBER, constants.LISTENERS, constants.LOADBALANCER,
                constants.POOL
            ]))
        create_member_flow.add(
            database_tasks.MarkMemberPendingCreateInDB(
                requires=constants.MEMBER))
        create_member_flow.add(
            network_tasks.CalculateDelta(requires=constants.LOADBALANCER,
                                         provides=constants.DELTAS))
        create_member_flow.add(
            network_tasks.HandleNetworkDeltas(requires=constants.DELTAS,
                                              provides=constants.ADDED_PORTS))
        create_member_flow.add(
            amphora_driver_tasks.AmphoraePostNetworkPlug(
                requires=(constants.LOADBALANCER, constants.ADDED_PORTS)))
        create_member_flow.add(
            amphora_driver_tasks.ListenersUpdate(
                requires=(constants.LOADBALANCER, constants.LISTENERS)))
        create_member_flow.add(
            database_tasks.MarkMemberActiveInDB(requires=constants.MEMBER))
        create_member_flow.add(
            database_tasks.MarkPoolActiveInDB(requires=constants.POOL))
        create_member_flow.add(
            database_tasks.MarkLBAndListenersActiveInDB(
                requires=(constants.LOADBALANCER, constants.LISTENERS)))

        return create_member_flow
コード例 #3
0
    def get_batch_update_members_flow(self, old_members, new_members,
                                      updated_members):
        """Create a flow to batch update members

        :returns: The flow for batch updating members
        """
        batch_update_members_flow = linear_flow.Flow(
            constants.BATCH_UPDATE_MEMBERS_FLOW)
        unordered_members_flow = unordered_flow.Flow(
            constants.UNORDERED_MEMBER_UPDATES_FLOW)
        unordered_members_active_flow = unordered_flow.Flow(
            constants.UNORDERED_MEMBER_ACTIVE_FLOW)

        # Delete old members
        unordered_members_flow.add(
            lifecycle_tasks.MembersToErrorOnRevertTask(
                inject={constants.MEMBERS: old_members},
                name='{flow}-deleted'.format(
                    flow=constants.MEMBER_TO_ERROR_ON_REVERT_FLOW)))
        for m in old_members:
            unordered_members_flow.add(
                model_tasks.DeleteModelObject(
                    inject={constants.OBJECT: m},
                    name='{flow}-{id}'.format(
                        id=m.id, flow=constants.DELETE_MODEL_OBJECT_FLOW)))
            unordered_members_flow.add(
                database_tasks.DeleteMemberInDB(
                    inject={constants.MEMBER: m},
                    name='{flow}-{id}'.format(
                        id=m.id, flow=constants.DELETE_MEMBER_INDB)))
            unordered_members_flow.add(
                database_tasks.DecrementMemberQuota(
                    inject={constants.MEMBER: m},
                    name='{flow}-{id}'.format(
                        id=m.id, flow=constants.DECREMENT_MEMBER_QUOTA_FLOW)))

        # Create new members
        unordered_members_flow.add(
            lifecycle_tasks.MembersToErrorOnRevertTask(
                inject={constants.MEMBERS: new_members},
                name='{flow}-created'.format(
                    flow=constants.MEMBER_TO_ERROR_ON_REVERT_FLOW)))
        for m in new_members:
            unordered_members_active_flow.add(
                database_tasks.MarkMemberActiveInDB(
                    inject={constants.MEMBER: m},
                    name='{flow}-{id}'.format(
                        id=m.id, flow=constants.MARK_MEMBER_ACTIVE_INDB)))

        # Update existing members
        unordered_members_flow.add(
            lifecycle_tasks.MembersToErrorOnRevertTask(
                # updated_members is a list of (obj, dict), only pass `obj`
                inject={constants.MEMBERS: [m[0] for m in updated_members]},
                name='{flow}-updated'.format(
                    flow=constants.MEMBER_TO_ERROR_ON_REVERT_FLOW)))
        for m, um in updated_members:
            um.pop('id', None)
            unordered_members_active_flow.add(
                database_tasks.MarkMemberActiveInDB(
                    inject={constants.MEMBER: m},
                    name='{flow}-{id}'.format(
                        id=m.id, flow=constants.MARK_MEMBER_ACTIVE_INDB)))

        batch_update_members_flow.add(unordered_members_flow)

        # Done, do real updates
        batch_update_members_flow.add(
            network_tasks.CalculateDelta(requires=constants.LOADBALANCER,
                                         provides=constants.DELTAS))
        batch_update_members_flow.add(
            network_tasks.HandleNetworkDeltas(requires=constants.DELTAS,
                                              provides=constants.ADDED_PORTS))
        batch_update_members_flow.add(
            amphora_driver_tasks.AmphoraePostNetworkPlug(
                requires=(constants.LOADBALANCER, constants.ADDED_PORTS)))

        # Update the Listener (this makes the changes active on the Amp)
        batch_update_members_flow.add(
            amphora_driver_tasks.ListenersUpdate(
                requires=(constants.LOADBALANCER, constants.LISTENERS)))

        # Mark all the members ACTIVE here, then pool then LB/Listeners
        batch_update_members_flow.add(unordered_members_active_flow)
        batch_update_members_flow.add(
            database_tasks.MarkPoolActiveInDB(requires=constants.POOL))
        batch_update_members_flow.add(
            database_tasks.MarkLBAndListenersActiveInDB(
                requires=(constants.LOADBALANCER, constants.LISTENERS)))

        return batch_update_members_flow
コード例 #4
0
    def test_calculate_delta(self, mock_get_net_driver):
        mock_driver = mock.MagicMock()
        mock_get_net_driver.return_value = mock_driver
        EMPTY = {}
        empty_deltas = {
            self.amphora_mock.id:
            data_models.Delta(amphora_id=self.amphora_mock.id,
                              compute_id=self.amphora_mock.compute_id,
                              add_nics=[],
                              delete_nics=[])
        }

        calc_delta = network_tasks.CalculateDelta()

        self.assertEqual(EMPTY, calc_delta.execute(self.load_balancer_mock))

        # Test with one amp and no pools, nothing plugged
        # Delta should be empty
        mock_driver.reset_mock()

        self.amphora_mock.load_balancer = self.load_balancer_mock
        self.load_balancer_mock.amphorae = [self.amphora_mock]
        self.load_balancer_mock.pools = []

        self.assertEqual(empty_deltas,
                         calc_delta.execute(self.load_balancer_mock))
        mock_driver.get_plugged_networks.assert_called_once_with(COMPUTE_ID)

        # Pool mock should be configured explicitly for each test
        pool_mock = mock.MagicMock()
        self.load_balancer_mock.pools = [pool_mock]

        # Test with one amp and one pool but no members, nothing plugged
        # Delta should be empty
        pool_mock.members = []
        self.assertEqual(empty_deltas,
                         calc_delta.execute(self.load_balancer_mock))

        # Test with one amp and one pool and one member, nothing plugged
        # Delta should be one additional subnet to plug
        mock_driver.reset_mock()
        member_mock = mock.MagicMock()
        member_mock.subnet_id = 1
        pool_mock.members = [member_mock]
        mock_driver.get_subnet.return_value = data_models.Subnet(id=2,
                                                                 network_id=3)

        ndm = data_models.Delta(amphora_id=self.amphora_mock.id,
                                compute_id=self.amphora_mock.compute_id,
                                add_nics=[data_models.Interface(network_id=2)],
                                delete_nics=[])
        self.assertEqual({self.amphora_mock.id: ndm},
                         calc_delta.execute(self.load_balancer_mock))

        vrrp_port_call = mock.call(self.amphora_mock.vrrp_port_id)
        mock_driver.get_port.assert_has_calls([vrrp_port_call])
        self.assertEqual(1, mock_driver.get_port.call_count)

        member_subnet_call = mock.call(member_mock.subnet_id)
        mock_driver.get_subnet.assert_has_calls([member_subnet_call])
        self.assertEqual(1, mock_driver.get_subnet.call_count)

        # Test with one amp and one pool and one member, already plugged
        # Delta should be empty
        mock_driver.reset_mock()
        member_mock = mock.MagicMock()
        member_mock.subnet_id = 1
        pool_mock.members = [member_mock]
        mock_driver.get_plugged_networks.return_value = [
            data_models.Interface(network_id=2)
        ]

        self.assertEqual(empty_deltas,
                         calc_delta.execute(self.load_balancer_mock))

        # Test with one amp and one pool and one member, wrong network plugged
        # Delta should be one network to add and one to remove
        mock_driver.reset_mock()
        member_mock = mock.MagicMock()
        member_mock.subnet_id = 1
        pool_mock.members = [member_mock]
        mock_driver.get_plugged_networks.return_value = [
            data_models.Interface(network_id=3)
        ]

        ndm = data_models.Delta(
            amphora_id=self.amphora_mock.id,
            compute_id=self.amphora_mock.compute_id,
            add_nics=[data_models.Interface(network_id=2)],
            delete_nics=[data_models.Interface(network_id=3)])
        self.assertEqual({self.amphora_mock.id: ndm},
                         calc_delta.execute(self.load_balancer_mock))

        # Test with one amp and one pool and no members, one network plugged
        # Delta should be one network to remove
        mock_driver.reset_mock()
        pool_mock.members = []
        mock_driver.get_plugged_networks.return_value = [
            data_models.Interface(network_id=2)
        ]

        ndm = data_models.Delta(
            amphora_id=self.amphora_mock.id,
            compute_id=self.amphora_mock.compute_id,
            add_nics=[],
            delete_nics=[data_models.Interface(network_id=2)])
        self.assertEqual({self.amphora_mock.id: ndm},
                         calc_delta.execute(self.load_balancer_mock))