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
This commit is contained in:
Gary Kotton 2013-03-21 17:01:31 +00:00
parent c6bf10d86c
commit 7f21283ef3
4 changed files with 22 additions and 7 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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 = {}

View File

@ -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]