diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-06-20 19:54:56 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-06-20 19:54:56 +0000 |
| commit | 6e0db0d25ba6689126c8d3479c3ef8bf5a534538 (patch) | |
| tree | 59ad8877c4da76c9a1264530b856650eb220ea4c | |
| parent | f40154db38d728609c9706ce57f4360ee0b0bd71 (diff) | |
| parent | 824b49d5bd6262b2b16103a850d3e58b9ee14009 (diff) | |
| download | nova-6e0db0d25ba6689126c8d3479c3ef8bf5a534538.tar.gz nova-6e0db0d25ba6689126c8d3479c3ef8bf5a534538.tar.xz nova-6e0db0d25ba6689126c8d3479c3ef8bf5a534538.zip | |
Merge "Remove db session hack from conductor's vol_usage_update()"
| -rw-r--r-- | nova/conductor/manager.py | 7 | ||||
| -rw-r--r-- | nova/db/api.py | 5 | ||||
| -rw-r--r-- | nova/db/sqlalchemy/api.py | 7 | ||||
| -rw-r--r-- | nova/tests/conductor/test_conductor.py | 2 |
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 69157a86a..fd79ae215 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -4396,9 +4396,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() @@ -4471,6 +4470,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, |
