-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3235 from Uninett/feature/cancel-maintenance-task…
…s-without-components Cancel scheduled maintenance tasks when all their components are missing
- Loading branch information
Showing
3 changed files
with
78 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Active maintenance tasks that only reference deleted components will be automatically cancelled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from datetime import datetime, timedelta | ||
|
||
import pytest | ||
|
||
from nav import maintengine | ||
from nav.models.msgmaint import MaintenanceTask, MaintenanceComponent | ||
|
||
|
||
class TestCancelTasksWithoutComponents: | ||
def test_it_should_cancel_active_empty_tasks(self, empty_task): | ||
assert empty_task.state == MaintenanceTask.STATE_ACTIVE | ||
maintengine.cancel_tasks_without_components() | ||
empty_task.refresh_from_db() | ||
assert empty_task.state == MaintenanceTask.STATE_CANCELED | ||
|
||
def test_it_should_not_cancel_scheduled_empty_tasks(self, scheduled_empty_task): | ||
assert scheduled_empty_task.state == MaintenanceTask.STATE_SCHEDULED | ||
maintengine.cancel_tasks_without_components() | ||
scheduled_empty_task.refresh_from_db() | ||
assert scheduled_empty_task.state == MaintenanceTask.STATE_SCHEDULED | ||
|
||
def test_it_should_not_cancel_nonempty_tasks(self, half_empty_task): | ||
assert half_empty_task.state == MaintenanceTask.STATE_ACTIVE | ||
maintengine.cancel_tasks_without_components() | ||
half_empty_task.refresh_from_db() | ||
assert half_empty_task.state == MaintenanceTask.STATE_ACTIVE | ||
|
||
|
||
@pytest.fixture | ||
def empty_task(db): | ||
task = MaintenanceTask( | ||
start_time=datetime.now() - timedelta(minutes=30), | ||
end_time=datetime.now() + timedelta(minutes=30), | ||
description="Test task", | ||
state=MaintenanceTask.STATE_ACTIVE, | ||
) | ||
task.save() | ||
component = MaintenanceComponent( | ||
maintenance_task=task, | ||
key="netbox", | ||
value=99999, | ||
) | ||
component.save() | ||
|
||
yield task | ||
|
||
|
||
@pytest.fixture | ||
def scheduled_empty_task(empty_task): | ||
empty_task.state = MaintenanceTask.STATE_SCHEDULED | ||
empty_task.start_time = datetime.now() + timedelta(minutes=30) | ||
empty_task.end_time = datetime.now() + timedelta(minutes=60) | ||
empty_task.save() | ||
yield empty_task | ||
|
||
|
||
@pytest.fixture | ||
def half_empty_task(empty_task, localhost): | ||
component = MaintenanceComponent(maintenance_task=empty_task, component=localhost) | ||
component.save() | ||
yield empty_task |