]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix issues with db pooling
authorGary Kotton <gkotton@redhat.com>
Thu, 21 Mar 2013 17:01:31 +0000 (17:01 +0000)
committerGary Kotton <gkotton@redhat.com>
Thu, 21 Mar 2013 18:02:15 +0000 (18:02 +0000)
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
quantum/db/agents_db.py
quantum/tests/unit/openvswitch/test_agent_scheduler.py
quantum/tests/unit/test_agent_ext_plugin.py

index 6360ad494f37664a96bb8aadade600b193cbd0b2..428dd611dd88fd57c73a424b3b3e83b5935c2ffd 100644 (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)
 
 
index 2f5230af33fa38a9137ea9d97742024e0a93247b..90f8cf504f51b8324b7c6092710272c9595d9b91 100644 (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)
index 14dc33ca17cfd4393b94ca4ead2cdb681e9f7d36..f02377f27529a4dadff2056abe4096f9a9d576ad 100644 (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 = {}
index 5f0dbc0f4e15e687c10d170658d39c5714322a7d..4fb934b93da31982cd87703fea4f27689e24f125 100644 (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]