From 460db962d80d904be76b6b6bba9293a7c9fa1fbf Mon Sep 17 00:00:00 2001 From: Juan Jose Nicola Date: Fri, 8 Oct 2021 03:24:41 -0500 Subject: [PATCH 1/2] Fix resume task. In some cases, the task is stopped and quickly resumed. In this cases there was race condition in which the scan id is present in the scan table but there is no target information. Although the quick resume can lead first into a stopped and scan followed by an interrupted scan, finally the scan can be resumed. (cherry picked from commit d4bf4721a7ea230883216fe6ff69f7b23a8b2fde) --- CHANGELOG.md | 2 ++ ospd/scan.py | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d69e0a4a..6592fc0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Deprecated ### Removed ### Fixed +- Fix resume scan. [#464](https://github.com/greenbone/ospd/pull/464) + [Unreleased]: https://github.com/greenbone/ospd/compare/v21.4.3...HEAD diff --git a/ospd/scan.py b/ospd/scan.py index c01f99e5..1ce0f30a 100644 --- a/ospd/scan.py +++ b/ospd/scan.py @@ -506,7 +506,17 @@ def get_end_time(self, scan_id: str) -> str: def get_host_list(self, scan_id: str) -> Dict: """Get a scan's host list.""" - return self.scans_table[scan_id]['target'].get('hosts') + target = None + try: + target = self.scans_table[scan_id]['target'].get('hosts') + except KeyError: + LOGGER.warning( + '%s: Scan ID is in the scan table, but it was ' + 'not initialized.', + scan_id, + ) + + return target def get_host_count(self, scan_id: str) -> int: """Get total host count in the target.""" From 37337a9f4693690f7f781877dba5766b453600f0 Mon Sep 17 00:00:00 2001 From: Juan Jose Nicola Date: Wed, 13 Oct 2021 01:09:06 -0500 Subject: [PATCH 2/2] Use logger instead of LOGGER --- ospd/scan.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ospd/scan.py b/ospd/scan.py index 1ce0f30a..7efd904e 100644 --- a/ospd/scan.py +++ b/ospd/scan.py @@ -510,7 +510,7 @@ def get_host_list(self, scan_id: str) -> Dict: try: target = self.scans_table[scan_id]['target'].get('hosts') except KeyError: - LOGGER.warning( + logger.warning( '%s: Scan ID is in the scan table, but it was ' 'not initialized.', scan_id,