Check job before removing it
Change-Id: Ibbd4da25fac6016a0d76c8f810ac567f6fd075f1 Closes-Bug: #1782731
This commit is contained in:
@@ -62,10 +62,11 @@ class ContinuousAuditHandler(base.AuditHandler):
|
|||||||
if objects.audit.AuditStateTransitionManager().is_inactive(audit):
|
if objects.audit.AuditStateTransitionManager().is_inactive(audit):
|
||||||
# if audit isn't in active states, audit's job must be removed to
|
# if audit isn't in active states, audit's job must be removed to
|
||||||
# prevent using of inactive audit in future.
|
# prevent using of inactive audit in future.
|
||||||
if self.scheduler.get_jobs():
|
jobs = [job for job in self.scheduler.get_jobs()
|
||||||
[job for job in self.scheduler.get_jobs()
|
if job.name == 'execute_audit' and
|
||||||
if job.name == 'execute_audit' and
|
job.args[0].uuid == audit.uuid]
|
||||||
job.args[0].uuid == audit.uuid][0].remove()
|
if jobs:
|
||||||
|
jobs[0].remove()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -446,3 +446,23 @@ class TestContinuousAuditHandler(base.DbTestCase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
expected_calls,
|
expected_calls,
|
||||||
self.m_audit_notifications.send_action_notification.call_args_list)
|
self.m_audit_notifications.send_action_notification.call_args_list)
|
||||||
|
|
||||||
|
@mock.patch.object(scheduling.BackgroundSchedulerService, 'get_jobs')
|
||||||
|
def test_is_audit_inactive(self, mock_jobs):
|
||||||
|
audit_handler = continuous.ContinuousAuditHandler()
|
||||||
|
mock_jobs.return_value = mock.MagicMock()
|
||||||
|
audit_handler._scheduler = mock.MagicMock()
|
||||||
|
|
||||||
|
ap_jobs = [job.Job(mock.MagicMock(), name='execute_audit',
|
||||||
|
func=audit_handler.execute_audit,
|
||||||
|
args=(self.audits[0], mock.MagicMock()),
|
||||||
|
kwargs={}),
|
||||||
|
]
|
||||||
|
|
||||||
|
audit_handler.update_audit_state(self.audits[1],
|
||||||
|
objects.audit.State.CANCELLED)
|
||||||
|
mock_jobs.return_value = ap_jobs
|
||||||
|
is_inactive = audit_handler._is_audit_inactive(self.audits[1])
|
||||||
|
self.assertTrue(is_inactive)
|
||||||
|
is_inactive = audit_handler._is_audit_inactive(self.audits[0])
|
||||||
|
self.assertFalse(is_inactive)
|
||||||
|
|||||||
Reference in New Issue
Block a user