summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-04-21 01:09:05 +0000
committerGerrit Code Review <review@openstack.org>2016-04-21 01:09:05 +0000
commit88ee671682b137b4118bf9f703f4455e1281c75f (patch)
tree80d4bbce584224db69112e5a00226fa901375f57
parent749c8fc6095538104ed71dc20f8760c237940b48 (diff)
parent2b6c5f0eba65a247c35e07b2c6b614577daf3af2 (diff)
downloadneutron-88ee671682b137b4118bf9f703f4455e1281c75f.tar.gz
Merge "Move db query to fetch down bindings under try/except" into stable/kilo
-rw-r--r--neutron/db/agentschedulers_db.py14
-rw-r--r--neutron/db/l3_agentschedulers_db.py22
-rw-r--r--neutron/tests/unit/plugins/openvswitch/test_agent_scheduler.py10
-rw-r--r--neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py8
4 files changed, 37 insertions, 17 deletions
diff --git a/neutron/db/agentschedulers_db.py b/neutron/db/agentschedulers_db.py
index f6789eeb13..5080364fb5 100644
--- a/neutron/db/agentschedulers_db.py
+++ b/neutron/db/agentschedulers_db.py
@@ -259,14 +259,14 @@ class DhcpAgentSchedulerDbMixin(dhcpagentscheduler
cutoff = self.get_cutoff_time(agent_dead_limit)
context = ncontext.get_admin_context()
- down_bindings = (
- context.session.query(NetworkDhcpAgentBinding).
- join(agents_db.Agent).
- filter(agents_db.Agent.heartbeat_timestamp < cutoff,
- agents_db.Agent.admin_state_up))
- dhcp_notifier = self.agent_notifiers.get(constants.AGENT_TYPE_DHCP)
-
try:
+ down_bindings = (
+ context.session.query(NetworkDhcpAgentBinding).
+ join(agents_db.Agent).
+ filter(agents_db.Agent.heartbeat_timestamp < cutoff,
+ agents_db.Agent.admin_state_up))
+ dhcp_notifier = self.agent_notifiers.get(constants.AGENT_TYPE_DHCP)
+
for binding in self._filter_bindings(context, down_bindings):
LOG.warn(_LW("Removing network %(network)s from agent "
"%(agent)s because the agent did not report "
diff --git a/neutron/db/l3_agentschedulers_db.py b/neutron/db/l3_agentschedulers_db.py
index f96bd8b38d..27203f1560 100644
--- a/neutron/db/l3_agentschedulers_db.py
+++ b/neutron/db/l3_agentschedulers_db.py
@@ -90,17 +90,19 @@ class L3AgentSchedulerDbMixin(l3agentscheduler.L3AgentSchedulerPluginBase,
cutoff = self.get_cutoff_time(agent_dead_limit)
context = n_ctx.get_admin_context()
- down_bindings = (
- context.session.query(RouterL3AgentBinding).
- join(agents_db.Agent).
- filter(agents_db.Agent.heartbeat_timestamp < cutoff,
- agents_db.Agent.admin_state_up).
- outerjoin(l3_attrs_db.RouterExtraAttributes,
- l3_attrs_db.RouterExtraAttributes.router_id ==
- RouterL3AgentBinding.router_id).
- filter(sa.or_(l3_attrs_db.RouterExtraAttributes.ha == sql.false(),
- l3_attrs_db.RouterExtraAttributes.ha == sql.null())))
try:
+ down_bindings = (
+ context.session.query(RouterL3AgentBinding).
+ join(agents_db.Agent).
+ filter(agents_db.Agent.heartbeat_timestamp < cutoff,
+ agents_db.Agent.admin_state_up).
+ outerjoin(l3_attrs_db.RouterExtraAttributes,
+ l3_attrs_db.RouterExtraAttributes.router_id ==
+ RouterL3AgentBinding.router_id).
+ filter(sa.or_(
+ l3_attrs_db.RouterExtraAttributes.ha == sql.false(),
+ l3_attrs_db.RouterExtraAttributes.ha == sql.null())))
+
for binding in down_bindings:
LOG.warn(_LW(
"Rescheduling router %(router)s from agent %(agent)s "
diff --git a/neutron/tests/unit/plugins/openvswitch/test_agent_scheduler.py b/neutron/tests/unit/plugins/openvswitch/test_agent_scheduler.py
index 53ca75ab91..f22063b1e5 100644
--- a/neutron/tests/unit/plugins/openvswitch/test_agent_scheduler.py
+++ b/neutron/tests/unit/plugins/openvswitch/test_agent_scheduler.py
@@ -741,6 +741,16 @@ class OvsAgentSchedulerTestCase(OvsAgentSchedulerTestCaseBase):
self._take_down_agent_and_run_reschedule(L3_HOSTA) # Value error
self._take_down_agent_and_run_reschedule(L3_HOSTA) # Exception
+ def test_router_rescheduler_catches_exceptions_on_fetching_bindings(self):
+ with mock.patch('neutron.context.get_admin_context') as get_ctx:
+ mock_ctx = mock.Mock()
+ get_ctx.return_value = mock_ctx
+ mock_ctx.session.query.side_effect = db_exc.DBError()
+ plugin = manager.NeutronManager.get_service_plugins().get(
+ service_constants.L3_ROUTER_NAT)
+ # check that no exception is raised
+ plugin.reschedule_routers_from_down_agents()
+
def test_router_rescheduler_iterates_after_reschedule_failure(self):
plugin = manager.NeutronManager.get_service_plugins().get(
service_constants.L3_ROUTER_NAT)
diff --git a/neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py b/neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py
index 8783f42704..9ad99b9159 100644
--- a/neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py
+++ b/neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py
@@ -351,6 +351,14 @@ class TestNetworksFailover(TestDhcpSchedulerBaseTestCase,
# just make sure that no exception is raised
self.remove_networks_from_down_agents()
+ def test_reschedule_network_catches_exceptions_on_fetching_bindings(self):
+ with mock.patch('neutron.context.get_admin_context') as get_ctx:
+ mock_ctx = mock.Mock()
+ get_ctx.return_value = mock_ctx
+ mock_ctx.session.query.side_effect = Exception()
+ # just make sure that no exception is raised
+ self.remove_networks_from_down_agents()
+
class DHCPAgentWeightSchedulerTestCase(TestDhcpSchedulerBaseTestCase):
"""Unit test scenarios for WeightScheduler.schedule."""