"""
min_agents = cfg.CONF.min_l3_agents_per_router
- num_agents = len(self.get_l3_agents(context,
+ num_agents = len(self.get_l3_agents(context, active=True,
filters={'agent_modes': [constants.L3_AGENT_MODE_LEGACY,
constants.L3_AGENT_MODE_DVR_SNAT]}))
max_agents = cfg.CONF.max_l3_agents_per_router
if max_agents:
if max_agents > num_agents:
- LOG.info(_LI("Number of available agents lower than "
+ LOG.info(_LI("Number of active agents lower than "
"max_l3_agents_per_router. L3 agents "
"available: %s"), num_agents)
else:
# License for the specific language governing permissions and limitations
# under the License.
+import datetime
import mock
from oslo_config import cfg
+from oslo_utils import timeutils
from neutron.api.v2 import attributes
from neutron.common import constants
cfg.CONF.set_override('allow_overlapping_ips', True)
self.plugin = FakeL3PluginWithAgents()
- self._register_agents()
+ self.agent1 = self._register_agent('legacy', 'l3host')
+ self.agent2 = self._register_agent('dvr_snat', 'l3host_2')
- def _register_agents(self):
+ def _register_agent(self, agent_mode, host):
agent_status = {
'agent_type': constants.AGENT_TYPE_L3,
'binary': 'neutron-l3-agent',
- 'host': 'l3host',
+ 'host': host,
'topic': 'N/A',
- 'configurations': {'agent_mode': 'legacy'}
+ 'configurations': {'agent_mode': agent_mode}
}
self.plugin.create_or_update_agent(self.admin_ctx, agent_status)
- agent_status['host'] = 'l3host_2'
- agent_status['configurations'] = {'agent_mode': 'dvr_snat'}
- self.plugin.create_or_update_agent(self.admin_ctx, agent_status)
- self.agent1, self.agent2 = self.plugin.get_agents(self.admin_ctx)
+ return self.plugin.get_agents(
+ self.admin_ctx, filters={'host': [host]})[0]
+
+ def _bring_down_agent(self, agent_id):
+ update = {
+ 'agent': {
+ 'heartbeat_timestamp':
+ timeutils.utcnow() - datetime.timedelta(hours=1)}}
+ self.plugin.update_agent(self.admin_ctx, agent_id, update)
def _create_router(self, ha=True, tenant_id='tenant1', distributed=None,
ctx=None):
self.admin_ctx)
self.assertEqual(2, num_ha_candidates)
+ def test_get_number_of_agents_for_scheduling_not_enough_agents(self):
+ cfg.CONF.set_override('min_l3_agents_per_router', 3)
+ agent_to_bring_down = self._register_agent('legacy', 'l3host_3')
+ self._bring_down_agent(agent_to_bring_down['id'])
+ self.assertRaises(l3_ext_ha_mode.HANotEnoughAvailableAgents,
+ self.plugin.get_number_of_agents_for_scheduling,
+ self.admin_ctx)
+
class L3HAModeDbTestCase(L3HATestFramework):