def test_vm_get_all_by_filters_throw_exception(self): self.mox.StubOutWithMock(db_session, 'get_session') db_session.get_session().AndRaise(Exception()) self.mox.ReplayAll() self.assertRaises(Exception, healthnmon_db_api.vm_get_all_by_filters, get_admin_context(), {}, 'id', 'asc')
def test_subnet_get_ids_throw_exception(self): self.mox.StubOutWithMock(db_session, 'get_session') db_session.get_session().AndRaise(Exception()) self.mox.ReplayAll() self.assertRaises(Exception, healthnmon_db_api.subnet_get_by_ids, self.admin_context, ['subnet-01'])
def test_vm_delete_throw_exception(self): self.mox.StubOutWithMock(db_session, 'get_session') db_session.get_session().AndRaise(Exception()) self.mox.ReplayAll() self.assertRaises(Exception, healthnmon_db_api.vm_delete_by_ids, get_admin_context(), ['test1'])
def test_storage_delete_throw_exception(self): self.mox.StubOutWithMock(session, 'get_session') session.get_session().AndRaise(Exception()) self.mox.ReplayAll() self.assertRaises(Exception, healthnmon_db_api.storage_volume_delete_by_ids, self.admin_context, ['test1'])
def test_storage_volume_get_all_by_filters_throw_exception(self): self.mox.StubOutWithMock(session, 'get_session') session.get_session().AndRaise(Exception()) self.mox.ReplayAll() self.assertRaises(Exception, healthnmon_db_api.storage_volume_get_all_by_filters, self.admin_context, {}, 'id', 'asc')
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, instance["uuid"], instance["project_id"], instance["user_id"], instance["availability_zone"], update_totals, session, ) # We have just updated the database, so send the notification now notifier.notify( context, "conductor.%s" % self.host, "volume.usage", notifier.INFO, compute_utils.usage_volume_info(vol_usage), )
def save(self, session=None): """Save this object.""" if not session: session = get_session() # NOTE(boris-42): This part of code should be look like: # sesssion.add(self) # session.flush() # But there is a bug in sqlalchemy and eventlet that # raises NoneType exception if there is no running # transaction and rollback is called. As long as # sqlalchemy has this bug we have to create transaction # explicity. with session.begin(subtransactions=True): session.add(self) session.flush()
def save(self, session=None): """Save this object.""" if not session: session = sa.get_session() # NOTE(boris-42): This part of code should be look like: # session.add(self) # session.flush() # But there is a bug in sqlalchemy and eventlet that # raises NoneType exception if there is no running # transaction and rollback is called. As long as # sqlalchemy has this bug we have to create transaction # explicitly. with session.begin(subtransactions=True): session.add(self) session.flush()
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, instance['uuid'], instance['project_id'], instance['user_id'], instance['availability_zone'], last_refreshed, update_totals, session) # We have just updated the database, so send the notification now notifier.notify(context, 'conductor.%s' % self.host, 'volume.usage', notifier.INFO, compute_utils.usage_volume_info(vol_usage))
def test_get_all_instance_types(self): # Ensures that all flavors can be retrieved. session = sql_session.get_session() total_instance_types = session.query(models.InstanceTypes).count() inst_types = flavors.get_all_flavors() self.assertEqual(total_instance_types, len(inst_types))
def test_port_group_delete_throw_exception(self): self.mox.StubOutWithMock(db_session, 'get_session') db_session.get_session().AndRaise(Exception()) self.mox.ReplayAll() self.assertRaises(Exception, api.port_group_delete_by_ids, get_admin_context(), ['portgroup-01'])
def power_status_change_create2(values): session = db_session.get_session() status_ref = models.VmStatNotification() status_ref.update(values) with session.begin(): session.add(status_ref)
def test_virtual_switch_get_all_by_filters_throw_exception(self): self.mox.StubOutWithMock(db_session, "get_session") db_session.get_session().AndRaise(Exception()) self.mox.ReplayAll() self.assertRaises(Exception, api.virtual_switch_get_all_by_filters, self.admin_context, {}, "id", "asc")
def test_virtual_switch_delete_throw_exception(self): self.mox.StubOutWithMock(db_session, "get_session") db_session.get_session().AndRaise(Exception()) self.mox.ReplayAll() self.assertRaises(Exception, api.virtual_switch_delete_by_ids, self.admin_context, ["test1"])
def setUp(self): super(CommonDbApiTestCase, self).setUp() # self.mock = mox.Mox() self.admin_context = get_admin_context() self.db_session = nova_session.get_session()
def test_port_group_get_all_throw_exception(self): self.mox.StubOutWithMock(db_session, 'get_session') db_session.get_session().AndRaise(Exception()) self.mox.ReplayAll() self.assertRaises(Exception, api.port_group_get_all, get_admin_context())