summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Skripnick <sskripnick@mirantis.com>2013-05-20 12:03:19 +0300
committerSergey Skripnick <sskripnick@mirantis.com>2013-05-22 09:31:27 +0300
commitda2638b0e04f77e10b54ca4622e863319896aa53 (patch)
tree591520a90d621518d2ee3b38f3f2f1f7a377a589
parent09cfefcdc977e1fff23c08cb3e1572ff48120bfa (diff)
Raise AgentBuildNotFound on updating/destroying deleted object
Methods below should raise an exception when attempting to operate with deleted AgentBuild objects: nova.db.sqlalchemy.api.agent_build_destroy() nova.db.sqlalchemy.api.agent_build_update() Fixes: bug 1181967 Change-Id: If6df202afb7ea41634c35f7a52988e19677f4d65
-rw-r--r--nova/db/sqlalchemy/api.py25
-rw-r--r--nova/tests/test_db_api.py2
2 files changed, 8 insertions, 19 deletions
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index e170cac55..a67d14d95 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -4264,28 +4264,19 @@ def agent_build_get_all(context, hypervisor=None):
@require_admin_context
def agent_build_destroy(context, agent_build_id):
- session = get_session()
- with session.begin():
- count = model_query(context, models.AgentBuild,
- session=session, read_deleted="yes").\
- filter_by(id=agent_build_id).\
- soft_delete()
- if count == 0:
- raise exception.AgentBuildNotFound(id=agent_build_id)
+ rows_affected = model_query(context, models.AgentBuild).filter_by(
+ id=agent_build_id).soft_delete()
+ if rows_affected == 0:
+ raise exception.AgentBuildNotFound(id=agent_build_id)
@require_admin_context
def agent_build_update(context, agent_build_id, values):
- session = get_session()
- with session.begin():
- agent_build_ref = model_query(context, models.AgentBuild,
- session=session, read_deleted="yes").\
+ rows_affected = model_query(context, models.AgentBuild).\
filter_by(id=agent_build_id).\
- first()
- if not agent_build_ref:
- raise exception.AgentBuildNotFound(id=agent_build_id)
- agent_build_ref.update(values)
- agent_build_ref.save(session=session)
+ update(values)
+ if rows_affected == 0:
+ raise exception.AgentBuildNotFound(id=agent_build_id)
####################
diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py
index 0ec1d2c06..56146cefe 100644
--- a/nova/tests/test_db_api.py
+++ b/nova/tests/test_db_api.py
@@ -3758,14 +3758,12 @@ class AgentBuildTestCase(test.TestCase, ModelsObjectComparatorMixin):
db.agent_build_update(self.ctxt, agent_build.id, {'os': 'ReactOS'})
self.assertEqual('ReactOS', db.agent_build_get_all(self.ctxt)[0].os)
- @test.testtools.skip("bug 1181967")
def test_agent_build_destroy_destroyed(self):
agent_build = db.agent_build_create(self.ctxt, {})
db.agent_build_destroy(self.ctxt, agent_build.id)
self.assertRaises(exception.AgentBuildNotFound,
db.agent_build_destroy, self.ctxt, agent_build.id)
- @test.testtools.skip("bug 1181967")
def test_agent_build_update_destroyed(self):
agent_build = db.agent_build_create(self.ctxt, {'os': 'HaikuOS'})
db.agent_build_destroy(self.ctxt, agent_build.id)