summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Smith <danms@us.ibm.com>2013-06-18 09:49:38 -0700
committerDan Smith <danms@us.ibm.com>2013-06-18 17:39:03 -0700
commit824b49d5bd6262b2b16103a850d3e58b9ee14009 (patch)
tree659ac38b66ecf72eeb02d07378d1590b07f6a6c6
parent086ec7a5b857fa1b88877c10991801761d819c98 (diff)
Remove db session hack from conductor's vol_usage_update()
Commit 3cf4cb2534c387f287f118d4185d54b1435d3bc0 made the vol_usage_update() in conductor hack around a stale sqlalchemy object issue by keeping session active in the current context until the notification was completed. This layering violation led to some "creative" tests to try to verify this behavior. This removes that and refreshes the object before letting it out of the db/api layer so that all the attributes are present, thus avoiding the dynamic load during notification. Change-Id: Ia6ef5cb7f462ff72d170f3af33f2d020ee4d3e3c
-rw-r--r--nova/conductor/manager.py7
-rw-r--r--nova/db/api.py5
-rw-r--r--nova/db/sqlalchemy/api.py7
-rw-r--r--nova/tests/conductor/test_conductor.py2
4 files changed, 8 insertions, 13 deletions
diff --git a/nova/conductor/manager.py b/nova/conductor/manager.py
index 6693e7fee..3b8c5f55d 100644
--- a/nova/conductor/manager.py
+++ b/nova/conductor/manager.py
@@ -26,7 +26,6 @@ from nova import network
from nova.network.security_group import openstack_driver
from nova import notifications
from nova.objects import base as nova_object
-from nova.openstack.common.db.sqlalchemy import session as db_session
from nova.openstack.common import jsonutils
from nova.openstack.common import log as logging
from nova.openstack.common.notifier import api as notifier
@@ -343,9 +342,6 @@ class ConductorManager(manager.Manager):
def vol_usage_update(self, context, vol_id, rd_req, rd_bytes, wr_req,
wr_bytes, instance, last_refreshed=None,
update_totals=False):
- # The session object is needed here, as the vol_usage object returned
- # needs to bound to it in order to refresh its data
- session = db_session.get_session()
vol_usage = self.db.vol_usage_update(context, vol_id,
rd_req, rd_bytes,
wr_req, wr_bytes,
@@ -353,8 +349,7 @@ class ConductorManager(manager.Manager):
instance['project_id'],
instance['user_id'],
instance['availability_zone'],
- update_totals,
- session)
+ update_totals)
# We have just updated the database, so send the notification now
notifier.notify(context, 'conductor.%s' % self.host, 'volume.usage',
diff --git a/nova/db/api.py b/nova/db/api.py
index ceab5fcd8..973be1a26 100644
--- a/nova/db/api.py
+++ b/nova/db/api.py
@@ -1561,7 +1561,7 @@ def vol_get_usage_by_time(context, begin):
def vol_usage_update(context, id, rd_req, rd_bytes, wr_req, wr_bytes,
instance_id, project_id, user_id, availability_zone,
- update_totals=False, session=None):
+ update_totals=False):
"""Update cached volume usage for a volume
Creates new record if needed.
@@ -1569,8 +1569,7 @@ def vol_usage_update(context, id, rd_req, rd_bytes, wr_req, wr_bytes,
return IMPL.vol_usage_update(context, id, rd_req, rd_bytes, wr_req,
wr_bytes, instance_id, project_id, user_id,
availability_zone,
- update_totals=update_totals,
- session=session)
+ update_totals=update_totals)
###################
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index 25108b062..b8ee76053 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -4408,9 +4408,8 @@ def vol_get_usage_by_time(context, begin):
@require_context
def vol_usage_update(context, id, rd_req, rd_bytes, wr_req, wr_bytes,
instance_id, project_id, user_id, availability_zone,
- update_totals=False, session=None):
- if not session:
- session = get_session()
+ update_totals=False):
+ session = get_session()
refreshed = timeutils.utcnow()
@@ -4483,6 +4482,8 @@ def vol_usage_update(context, id, rd_req, rd_bytes, wr_req, wr_bytes,
current_usage['curr_write_bytes'] + wr_bytes)
current_usage.update(values)
+ current_usage.save(session=session)
+ session.refresh(current_usage)
return current_usage
vol_usage = models.VolumeUsage()
diff --git a/nova/tests/conductor/test_conductor.py b/nova/tests/conductor/test_conductor.py
index 7a33cfbb9..9bb2c00ec 100644
--- a/nova/tests/conductor/test_conductor.py
+++ b/nova/tests/conductor/test_conductor.py
@@ -389,7 +389,7 @@ class _BaseTestCase(object):
fake_inst['project_id'],
fake_inst['user_id'],
fake_inst['availability_zone'],
- False, mox.IgnoreArg()).AndReturn('fake-usage')
+ False).AndReturn('fake-usage')
compute_utils.usage_volume_info('fake-usage').AndReturn('fake-info')
notifier_api.notify(self.context,
'conductor.%s' % self.conductor_manager.host,