def test_get_vacant_binding_index_several_agents(self):
        ret = base_scheduler.get_vacant_binding_index(1, [], 1)
        self.assertEqual(1, ret)

        ret = base_scheduler.get_vacant_binding_index(
            1, [mock.Mock(binding_index=1)], 1)
        self.assertEqual(-1, ret)

        ret = base_scheduler.get_vacant_binding_index(
            3, [mock.Mock(binding_index=1), mock.Mock(binding_index=3)], 1)
        self.assertEqual(2, ret)
    def test_get_vacant_binding_index_force_scheduling(self):
        ret = base_scheduler.get_vacant_binding_index(
            3, [mock.Mock(binding_index=1), mock.Mock(binding_index=2),
                mock.Mock(binding_index=3), mock.Mock(binding_index=5),
                mock.Mock(binding_index=7)], 1, force_scheduling=True)
        self.assertEqual(4, ret)

        ret = base_scheduler.get_vacant_binding_index(
            3, [mock.Mock(binding_index=1), mock.Mock(binding_index=2),
                mock.Mock(binding_index=3), mock.Mock(binding_index=4),
                mock.Mock(binding_index=5)], 1, force_scheduling=True)
        self.assertEqual(6, ret)
    def get_vacant_network_dhcp_agent_binding_index(self, context, network_id,
                                                    force_scheduling):
        """Return a vacant binding_index to use and whether or not it exists.

        Each NetworkDhcpAgentBinding has a binding_index which is unique per
        network_id, and when creating a single binding we require to find a
        'vacant' binding_index which isn't yet used - for example if we have
        bindings with indices 1 and 3, then clearly binding_index == 2 is free.

        :returns: binding_index.
        """
        num_agents = agent_obj.Agent.count(
            context, agent_type=constants.AGENT_TYPE_DHCP)
        num_agents = min(num_agents, cfg.CONF.dhcp_agents_per_network)
        bindings = network.NetworkDhcpAgentBinding.get_objects(
            context, network_id=network_id)
        return base_scheduler.get_vacant_binding_index(
            num_agents,
            bindings,
            ndab_model.LOWEST_BINDING_INDEX,
            force_scheduling=force_scheduling)
Exemple #4
0
    def get_vacant_binding_index(self,
                                 context,
                                 router_id,
                                 is_manual_scheduling=False):
        """Return a vacant binding_index to use and whether or not it exists.

        Each RouterL3AgentBinding has a binding_index which is unique per
        router_id, and when creating a single binding we require to find a
        'vacant' binding_index which isn't yet used - for example if we have
        bindings with indices 1 and 3, then clearly binding_index == 2 is free.

        :returns: binding_index.
        """
        num_agents = self.get_number_of_agents_for_scheduling(context)

        pager = base_obj.Pager(sorts=[('binding_index', True)])
        bindings = rb_obj.RouterL3AgentBinding.get_objects(context,
                                                           _pager=pager,
                                                           router_id=router_id)
        return base_scheduler.get_vacant_binding_index(
            num_agents,
            bindings,
            rb_model.LOWEST_BINDING_INDEX,
            force_scheduling=is_manual_scheduling)
 def test_get_vacant_binding_index_no_agents(self):
     ret = base_scheduler.get_vacant_binding_index(0, [], 1)
     self.assertEqual(-1, ret)