diff --git a/nsupdate/main/models.py b/nsupdate/main/models.py index c436fb6..e04d5f3 100644 --- a/nsupdate/main/models.py +++ b/nsupdate/main/models.py @@ -20,7 +20,6 @@ from django.utils.translation import ugettext_lazy as _ from django.utils.encoding import python_2_unicode_compatible from django.utils.six import text_type - from . import dnstools RESULT_MSG_LEN = 255 @@ -64,6 +63,7 @@ def host_blacklist_validator(value): from collections import namedtuple + UpdateAlgorithm = namedtuple("update_algorithm", "bitlength bind_name") UPDATE_ALGORITHM_DEFAULT = 'HMAC_SHA512' @@ -128,7 +128,8 @@ class Domain(models.Model): last_update = models.DateTimeField(_("last update"), auto_now=True) created = models.DateTimeField(_("created at"), auto_now_add=True) - created_by = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='domains', verbose_name=_("created by"), on_delete=models.CASCADE) + created_by = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='domains', verbose_name=_("created by"), + on_delete=models.CASCADE) def __str__(self): return self.name @@ -149,7 +150,7 @@ class Domain(models.Model): class Meta: verbose_name = _('domain') verbose_name_plural = _('domains') - ordering = ('name', ) + ordering = ('name',) @python_2_unicode_compatible @@ -249,14 +250,15 @@ class Host(models.Model): last_update = models.DateTimeField(_("last update"), auto_now=True) created = models.DateTimeField(_("created at"), auto_now_add=True) - created_by = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='hosts', verbose_name=_("created by"), on_delete=models.CASCADE) + created_by = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='hosts', verbose_name=_("created by"), + on_delete=models.CASCADE) def __str__(self): return u"%s.%s" % (self.name, self.domain.name) class Meta(object): - unique_together = (('name', 'domain'), ) - index_together = (('name', 'domain'), ) + unique_together = (('name', 'domain'),) + index_together = (('name', 'domain'),) verbose_name = _('host') verbose_name_plural = _('hosts') ordering = ('domain', 'name') # groupby domain and sort by name @@ -345,10 +347,11 @@ def pre_delete_host(sender, **kwargs): except (dnstools.Timeout, dnstools.NameServerNotAvailable): # well, we tried to clean up, but we didn't reach the nameserver pass - except (dnstools.DnsUpdateError, ): + except (dnstools.DnsUpdateError,): # e.g. PeerBadSignature if host is protected by a key we do not have pass + pre_delete.connect(pre_delete_host, sender=Host) @@ -360,10 +363,11 @@ def post_save_host(sender, **kwargs): except (dnstools.Timeout, dnstools.NameServerNotAvailable): # well, we tried to clean up, but we didn't reach the nameserver pass - except (dnstools.DnsUpdateError, ): + except (dnstools.DnsUpdateError,): # e.g. PeerBadSignature if host is protected by a key we do not have pass + post_save.connect(post_save_host, sender=Host) @@ -411,7 +415,7 @@ class RelatedHost(models.Model): return u"%s.%s" % (self.name, text_type(self.main_host)) class Meta(object): - unique_together = (('name', 'main_host'), ) + unique_together = (('name', 'main_host'),) verbose_name = _('related host') verbose_name_plural = _('related hosts') ordering = ('main_host', 'name') @@ -528,7 +532,7 @@ class ServiceUpdaterHostConfig(models.Model): verbose_name=_("created by"), on_delete=models.CASCADE) def __str__(self): - return u"%s (%s)" % (self.hostname, self.service.name, ) + return u"%s (%s)" % (self.hostname, self.service.name,) class Meta(object): verbose_name = _('service updater host config') diff --git a/nsupdate/management/commands/faults.py b/nsupdate/management/commands/faults.py index 9b90b07..2c581c1 100644 --- a/nsupdate/management/commands/faults.py +++ b/nsupdate/management/commands/faults.py @@ -12,7 +12,6 @@ from django.utils.translation import ugettext_lazy as _ from nsupdate.main.models import Host from nsupdate.utils.mail import translate_for_user, send_mail_to_user - ABUSE_MSG = _("""\ Your host: %(fqdn)s (comment: %(comment)s) @@ -52,51 +51,51 @@ class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument('--show-server', - action='store_true', - dest='show_server', - default=False, - help='show server fault counters') + action='store_true', + dest='show_server', + default=False, + help='show server fault counters') parser.add_argument('--show-client', - action='store_true', - dest='show_client', - default=False, - help='show client fault counters') + action='store_true', + dest='show_client', + default=False, + help='show client fault counters') parser.add_argument('--reset-server', - action='store_true', - dest='reset_server', - default=False, - help='reset the server fault counters of all hosts') + action='store_true', + dest='reset_server', + default=False, + help='reset the server fault counters of all hosts') parser.add_argument('--reset-client', - action='store_true', - dest='reset_client', - default=False, - help='reset the client fault counters of all hosts') + action='store_true', + dest='reset_client', + default=False, + help='reset the client fault counters of all hosts') parser.add_argument('--reset-abuse', - action='store_true', - dest='reset_abuse', - default=False, - help='reset the abuse flag (to False) of all hosts') + action='store_true', + dest='reset_abuse', + default=False, + help='reset the abuse flag (to False) of all hosts') parser.add_argument('--reset-abuse-blocked', - action='store_true', - dest='reset_abuse_blocked', - default=False, - help='reset the abuse_blocked flag (to False) of all hosts') + action='store_true', + dest='reset_abuse_blocked', + default=False, + help='reset the abuse_blocked flag (to False) of all hosts') parser.add_argument('--reset-available', - action='store_true', - dest='reset_available', - default=False, - help='reset the available flag (to True) of all hosts') + action='store_true', + dest='reset_available', + default=False, + help='reset the available flag (to True) of all hosts') parser.add_argument('--flag-abuse', - action='store', - dest='flag_abuse', - default=None, - type='int', - help='if client faults > N then set abuse flag and reset client faults') + action='store', + dest='flag_abuse', + default=None, + type=int, + help='if client faults N then set abuse flag and reset client faults') parser.add_argument('--notify-user', - action='store_true', - dest='notify_user', - default=False, - help='notify the user by email when host gets flagged for abuse') + action='store_true', + dest='notify_user', + default=False, + help='notify the user by email when host gets flagged for abuse') def handle(self, *args, **options): show_client = options['show_client'] @@ -117,10 +116,10 @@ class Command(BaseCommand): output += u"%-6d " % h.client_faults if show_server: output += u"%-6d " % h.server_faults - output += u"%s %s\n" % (h.created_by.username, h.get_fqdn(), ) + output += u"%s %s\n" % (h.created_by.username, h.get_fqdn(),) self.stdout.write(output) if (flag_abuse is not None or reset_client or reset_server or - reset_available or reset_abuse or reset_abuse_blocked): + reset_available or reset_abuse or reset_abuse_blocked): if flag_abuse is not None: if h.client_faults > flag_abuse: h.abuse = True @@ -154,7 +153,7 @@ class Command(BaseCommand): h.save() except Exception: try: - msg = u"The following Exception occurred when processing host %s!\n" % (h.get_fqdn(), ) + msg = u"The following Exception occurred when processing host %s!\n" % (h.get_fqdn(),) self.stderr.write(msg) except Exception: pass diff --git a/setup.cfg b/setup.cfg index 901b485..e3fc537 100644 --- a/setup.cfg +++ b/setup.cfg @@ -21,7 +21,7 @@ all_files = 1 [upload_sphinx] upload-dir = docs/_build/html -[pytest] +[tool:pytest] DJANGO_SETTINGS_MODULE = nsupdate.settings.dev pep8maxlinelength = 120 norecursedirs = .git