def test_rip_expired_instances_not_found(self): server_mgr = self.fake_client_set.compute.servers instances.admin_client_set().AndReturn(self.fake_client_set) instances.datetime.utcnow().AndReturn('UTCNOW') instances.InstanceDataDAO.expired_list('UTCNOW')\ .AndReturn([InstanceData(instance_id='v1'), InstanceData(instance_id='v2')]) server_mgr.delete('v1').AndRaise(osc_exc.NotFound('deleted')) instances.InstanceDataDAO.delete('v1') # check we continued to iterate after exception server_mgr.delete('v2') instances.AuditDAO.create_record(mox.IsA(dict)) self.mox.ReplayAll() with self.app.test_request_context(): instances.rip_expired_instances()
def test_rip_expired_instances(self): server_mgr = self.fake_client_set.compute.servers instances.admin_client_set().AndReturn(self.fake_client_set) instances.datetime.utcnow().AndReturn('UTCNOW') instances.InstanceDataDAO.expired_list('UTCNOW')\ .AndReturn([InstanceData(instance_id='v1')]) server_mgr.delete('v1') instances.AuditDAO.create_record({ 'resource': '/v1/instances/v1', 'method': 'DELETE', 'response_status': 200, 'message': 'Automatically deleted expired instance' }) self.mox.ReplayAll() with self.app.test_request_context(): instances.rip_expired_instances()
def test_rip_expired_instances_other_exception(self): server_mgr = self.fake_client_set.compute.servers instances.admin_client_set().AndReturn(self.fake_client_set) instances.datetime.utcnow().AndReturn('UTCNOW') instances.InstanceDataDAO.expired_list('UTCNOW')\ .AndReturn([InstanceData(instance_id='v1'), InstanceData(instance_id='v2')]) server_mgr.delete('v1').AndRaise(RuntimeError('log me')) self.app.logger.exception(mox.IsA(basestring)) # check we continued to iterate after exception server_mgr.delete('v2') instances.AuditDAO.create_record(mox.IsA(dict)) self.mox.ReplayAll() with self.app.test_request_context(): instances.rip_expired_instances()