Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty consumes of boefjes will trigger tasks in scheduler #3017

Merged
merged 9 commits into from
Jun 6, 2024
10 changes: 10 additions & 0 deletions mula/scheduler/schedulers/boefje.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,16 @@ def push_tasks_for_new_boefjes(self) -> None:
)

for boefje in new_boefjes:
if not boefje.consumes:
jpbruinsslot marked this conversation as resolved.
Show resolved Hide resolved
self.logger.debug(
"No consumes found for boefje: %s",
boefje.name,
boefje_id=boefje.id,
organisation_id=self.organisation.id,
scheduler_id=self.scheduler_id,
)
continue

oois_by_object_type: list[OOI] = []
try:
oois_by_object_type = self.ctx.services.octopoes.get_objects_by_object_types(
Expand Down
30 changes: 30 additions & 0 deletions mula/tests/integration/test_boefje_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1314,6 +1314,36 @@ def test_push_tasks_for_new_boefjes_no_new_boefjes(self):
# Task should not be on priority queue
self.assertEqual(0, self.scheduler.queue.qsize())

def test_push_tasks_for_new_boefjes_empty_consumes(self):
# Arrange
scan_profile = ScanProfileFactory(level=0)
ooi = OOIFactory(scan_profile=scan_profile)
boefje = PluginFactory(scan_level=0, consumes=[])

# Mocks
self.mock_get_objects_by_object_types.return_value = [ooi]
self.mock_get_new_boefjes_by_org_id.return_value = [boefje]

# Act
self.scheduler.push_tasks_for_new_boefjes()

# Task should not be on priority queue
self.assertEqual(0, self.scheduler.queue.qsize())

def test_push_tasks_for_new_boefjes_empty_consumes_no_ooi(self):
# Arrange
boefje = PluginFactory(scan_level=0, consumes=[])

# Mocks
self.mock_get_objects_by_object_types.return_value = []
self.mock_get_new_boefjes_by_org_id.return_value = [boefje]

# Act
self.scheduler.push_tasks_for_new_boefjes()

# Task should not be on priority queue
self.assertEqual(0, self.scheduler.queue.qsize())

def test_push_tasks_for_new_boefjes_no_oois_found(self):
# Arrange
scan_profile = ScanProfileFactory(level=0)
Expand Down