From 7f21283ef36eadd5e600f08e5572580f11d06a7c Mon Sep 17 00:00:00 2001 From: Gary Kotton Date: Thu, 21 Mar 2013 17:01:31 +0000 Subject: [PATCH] Fix issues with db pooling Fixes bug 1157045 In addition to this a cast is used instead of a call for the report update. Change-Id: I1b0ea5b18b3d75dc3d047975b234275420af189c --- quantum/agent/rpc.py | 6 ++++-- quantum/db/agents_db.py | 6 ++++++ .../tests/unit/openvswitch/test_agent_scheduler.py | 4 +++- quantum/tests/unit/test_agent_ext_plugin.py | 13 +++++++++---- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/quantum/agent/rpc.py b/quantum/agent/rpc.py index 6360ad494f..428dd611dd 100644 --- a/quantum/agent/rpc.py +++ b/quantum/agent/rpc.py @@ -24,6 +24,7 @@ from quantum.openstack.common.notifier import api from quantum.openstack.common.notifier import rpc_notifier from quantum.openstack.common import rpc from quantum.openstack.common.rpc import proxy +from quantum.openstack.common import timeutils from quantum.openstack.common import uuidutils @@ -57,10 +58,11 @@ class PluginReportStateAPI(proxy.RpcProxy): topic=topic, default_version=self.BASE_RPC_API_VERSION) def report_state(self, context, agent_state): - return self.call(context, + return self.cast(context, self.make_msg('report_state', agent_state={'agent_state': - agent_state}), + agent_state}, + time=timeutils.utcnow()), topic=self.topic) diff --git a/quantum/db/agents_db.py b/quantum/db/agents_db.py index 2f5230af33..90f8cf504f 100644 --- a/quantum/db/agents_db.py +++ b/quantum/db/agents_db.py @@ -159,9 +159,15 @@ class AgentDbMixin(ext_agent.AgentPluginBase): class AgentExtRpcCallback(object): """Processes the rpc report in plugin implementations.""" RPC_API_VERSION = '1.0' + START_TIME = timeutils.utcnow() def report_state(self, context, **kwargs): """Report state from agent to server. """ + time = kwargs['time'] + time = timeutils.parse_strtime(time) + if self.START_TIME > time: + LOG.debug(_("Message with invalid timestamp received")) + return agent_state = kwargs['agent_state']['agent_state'] plugin = manager.QuantumManager.get_plugin() plugin.create_or_update_agent(context, agent_state) diff --git a/quantum/tests/unit/openvswitch/test_agent_scheduler.py b/quantum/tests/unit/openvswitch/test_agent_scheduler.py index 14dc33ca17..f02377f275 100644 --- a/quantum/tests/unit/openvswitch/test_agent_scheduler.py +++ b/quantum/tests/unit/openvswitch/test_agent_scheduler.py @@ -28,6 +28,7 @@ from quantum.db import dhcp_rpc_base from quantum.db import l3_rpc_base from quantum.extensions import agentscheduler from quantum import manager +from quantum.openstack.common import timeutils from quantum.openstack.common import uuidutils from quantum.tests.unit import test_agent_ext_plugin from quantum.tests.unit.testlib_api import create_request @@ -167,7 +168,8 @@ class AgentSchedulerTestMixIn(object): def _register_one_agent_state(self, agent_state): callback = agents_db.AgentExtRpcCallback() callback.report_state(self.adminContext, - agent_state={'agent_state': agent_state}) + agent_state={'agent_state': agent_state}, + time=timeutils.strtime()) def _disable_agent(self, agent_id, admin_state_up=False): new_agent = {} diff --git a/quantum/tests/unit/test_agent_ext_plugin.py b/quantum/tests/unit/test_agent_ext_plugin.py index 5f0dbc0f4e..4fb934b93d 100644 --- a/quantum/tests/unit/test_agent_ext_plugin.py +++ b/quantum/tests/unit/test_agent_ext_plugin.py @@ -29,6 +29,7 @@ from quantum.db import agents_db from quantum.db import db_base_plugin_v2 from quantum.extensions import agent from quantum.openstack.common import log as logging +from quantum.openstack.common import timeutils from quantum.openstack.common import uuidutils from quantum.tests.unit import test_api_v2 from quantum.tests.unit import test_db_plugin @@ -103,13 +104,17 @@ class AgentDBTestMixIn(object): dhcp_hostc['host'] = DHCP_HOSTC callback = agents_db.AgentExtRpcCallback() callback.report_state(self.adminContext, - agent_state={'agent_state': l3_hosta}) + agent_state={'agent_state': l3_hosta}, + time=timeutils.strtime()) callback.report_state(self.adminContext, - agent_state={'agent_state': l3_hostb}) + agent_state={'agent_state': l3_hostb}, + time=timeutils.strtime()) callback.report_state(self.adminContext, - agent_state={'agent_state': dhcp_hosta}) + agent_state={'agent_state': dhcp_hosta}, + time=timeutils.strtime()) callback.report_state(self.adminContext, - agent_state={'agent_state': dhcp_hostc}) + agent_state={'agent_state': dhcp_hostc}, + time=timeutils.strtime()) return [l3_hosta, l3_hostb, dhcp_hosta, dhcp_hostc]