2013-12-18 03:16:12 +01:00
|
|
|
"""
|
|
|
|
Tests for faults command.
|
|
|
|
"""
|
|
|
|
|
2013-12-25 04:42:40 +01:00
|
|
|
from conftest import TEST_HOST
|
|
|
|
|
2013-12-18 03:16:12 +01:00
|
|
|
from django.core import management
|
|
|
|
from nsupdate.main.models import Host
|
|
|
|
|
|
|
|
|
|
|
|
def test_faults_reset():
|
|
|
|
# trigger execution of all code for coverage, test resetting
|
|
|
|
# set flags and counters
|
2013-12-25 04:42:40 +01:00
|
|
|
hostname = TEST_HOST.split('.', 1)[0]
|
2014-09-21 22:31:26 +02:00
|
|
|
h = Host.objects.get(name=hostname)
|
2013-12-18 03:16:12 +01:00
|
|
|
h.client_faults = 1
|
|
|
|
h.server_faults = 1
|
|
|
|
h.available = False
|
|
|
|
h.abuse = True
|
|
|
|
h.abuse_blocked = True
|
|
|
|
h.save()
|
|
|
|
# reset counters / flags
|
|
|
|
management.call_command('faults',
|
|
|
|
show_server=True, show_client=True,
|
|
|
|
reset_server=True, reset_client=True,
|
|
|
|
reset_abuse=True, reset_abuse_blocked=True,
|
|
|
|
reset_available=True)
|
|
|
|
# check if the resetting worked
|
2014-09-21 22:31:26 +02:00
|
|
|
h = Host.objects.get(name=hostname)
|
2013-12-18 03:16:12 +01:00
|
|
|
assert h.client_faults == 0
|
|
|
|
assert h.server_faults == 0
|
|
|
|
assert h.available is True
|
|
|
|
assert h.abuse is False
|
|
|
|
assert h.abuse_blocked is False
|
|
|
|
|
|
|
|
|
|
|
|
def test_faults_no_abuse():
|
2013-12-25 04:42:40 +01:00
|
|
|
hostname = TEST_HOST.split('.', 1)[0]
|
2014-09-21 22:31:26 +02:00
|
|
|
h = Host.objects.get(name=hostname)
|
2013-12-18 03:16:12 +01:00
|
|
|
h.client_faults = 10 # below threshold
|
|
|
|
h.abuse = False
|
|
|
|
h.save()
|
|
|
|
# flag abusive hosts
|
|
|
|
management.call_command('faults', flag_abuse=23)
|
|
|
|
# check if it did not get flagged
|
2014-09-21 22:31:26 +02:00
|
|
|
h = Host.objects.get(name=hostname)
|
2013-12-18 03:16:12 +01:00
|
|
|
assert h.client_faults == 10
|
|
|
|
assert h.abuse is False
|
|
|
|
|
|
|
|
|
|
|
|
def test_faults_abuse():
|
2013-12-25 04:42:40 +01:00
|
|
|
hostname = TEST_HOST.split('.', 1)[0]
|
2014-09-21 22:31:26 +02:00
|
|
|
h = Host.objects.get(name=hostname)
|
2013-12-18 03:16:12 +01:00
|
|
|
h.client_faults = 42 # above threshold
|
|
|
|
h.abuse = False
|
|
|
|
h.save()
|
|
|
|
# flag abusive hosts
|
|
|
|
management.call_command('faults', flag_abuse=23)
|
|
|
|
# check if it did get flagged
|
2014-09-21 22:31:26 +02:00
|
|
|
h = Host.objects.get(name=hostname)
|
2013-12-18 03:16:12 +01:00
|
|
|
assert h.client_faults == 0
|
|
|
|
assert h.abuse is True
|