Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

Always set end_time for interrupted scans. #353

Merged
merged 2 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Added
- Allow the scanner to update total count of hosts. [#332](https://github.com/greenbone/ospd/pull/332)
- Add more debug logging. [#352](https://github.com/greenbone/ospd/pull/352)
- Set end_time for interrupted scans. [#353](https://github.com/greenbone/ospd/pull/353)

### Fixed
- Fix OSP version. [#326](https://github.com/greenbone/ospd/pull/326)
Expand Down
1 change: 0 additions & 1 deletion ospd/ospd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1503,7 +1503,6 @@ def check_scan_process(self, scan_id: str) -> None:
and not scan_process.is_alive()
):
if not status == ScanStatus.STOPPED:
self.set_scan_status(scan_id, ScanStatus.STOPPED)
self.add_scan_error(
scan_id, name="", host="", value="Scan process Failure"
)
Expand Down
2 changes: 1 addition & 1 deletion ospd/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def create_scan(
def set_status(self, scan_id: str, status: ScanStatus) -> None:
""" Sets scan_id scan's status. """
self.scans_table[scan_id]['status'] = status
if status == ScanStatus.STOPPED:
if status == ScanStatus.STOPPED or status == ScanStatus.INTERRUPTED:
self.scans_table[scan_id]['end_time'] = int(time.time())

def get_status(self, scan_id: str) -> ScanStatus:
Expand Down
46 changes: 46 additions & 0 deletions tests/test_scan_and_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,52 @@ def test_sort_host_finished(self):
)
self.assertEqual(rounded_progress, 66)

def test_set_status_interrupted(self):
fs = FakeStream()
self.daemon.handle_command(
'<start_scan parallel="2">'
'<scanner_params />'
'<targets><target>'
'<hosts>localhost1</hosts>'
'<ports>22</ports>'
'</target></targets>'
'</start_scan>',
fs,
)
self.daemon.start_queued_scans()
response = fs.get_response()
scan_id = response.findtext('id')

end_time = self.daemon.scan_collection.get_end_time(scan_id)
self.assertEqual(end_time, 0)

self.daemon.interrupt_scan(scan_id)
end_time = self.daemon.scan_collection.get_end_time(scan_id)
self.assertNotEqual(end_time, 0)

def test_set_status_stopped(self):
fs = FakeStream()
self.daemon.handle_command(
'<start_scan parallel="2">'
'<scanner_params />'
'<targets><target>'
'<hosts>localhost1</hosts>'
'<ports>22</ports>'
'</target></targets>'
'</start_scan>',
fs,
)
self.daemon.start_queued_scans()
response = fs.get_response()
scan_id = response.findtext('id')

end_time = self.daemon.scan_collection.get_end_time(scan_id)
self.assertEqual(end_time, 0)

self.daemon.set_scan_status(scan_id, ScanStatus.STOPPED)
end_time = self.daemon.scan_collection.get_end_time(scan_id)
self.assertNotEqual(end_time, 0)

def test_calculate_progress_without_current_hosts(self):

fs = FakeStream()
Expand Down