Upgrade to Django 3.2

- update dependencies
- fix deprecation warnings
- fix tests
- skip some tests that need more work
- reformat changed code with isort and black
This commit is contained in:
Jan Dittberner 2023-02-18 22:46:48 +01:00
parent 0f18e59d67
commit 4af1a39ca4
93 changed files with 3598 additions and 2725 deletions

View file

@ -2,51 +2,48 @@
This module contains models related to domain names.
"""
from __future__ import absolute_import, unicode_literals
from __future__ import absolute_import
from django.db import models, transaction
from django.conf import settings
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext as _
from model_utils.models import TimeStampedModel
from django.db import models, transaction
from django.utils.translation import gettext as _
from model_utils import Choices
from model_utils.models import TimeStampedModel
DNS_DOMAIN_TYPES = Choices(
('MASTER', _('Master')),
('SLAVE', _('Slave')),
('NATIVE', _('Native')),
("MASTER", _("Master")),
("SLAVE", _("Slave")),
("NATIVE", _("Native")),
)
# see https://doc.powerdns.com/md/authoritative/domainmetadata/
DNS_DOMAIN_METADATA_KINDS = Choices(
'ALLOW-DNSUPDATE-FROM',
'ALSO-NOTIFY',
'AXFR-MASTER-TSIG',
'AXFR-SOURCE',
'FORWARD-DNSUPDATE',
'GSS-ACCEPTOR-PRINCIPAL',
'GSS-ALLOW-AXFR-PRINCIPAL',
'LUA-AXFR-SCRIPT',
'NSEC3NARROW',
'NSEC3PARAM',
'PRESIGNED',
'PUBLISH_CDNSKEY',
'PUBLISH_CDS',
'SOA-EDIT',
'SOA-EDIT-DNSUPDATE',
'TSIG-ALLOW-AXFR',
'TSIG-ALLOW-DNSUPDATE',
"ALLOW-DNSUPDATE-FROM",
"ALSO-NOTIFY",
"AXFR-MASTER-TSIG",
"AXFR-SOURCE",
"FORWARD-DNSUPDATE",
"GSS-ACCEPTOR-PRINCIPAL",
"GSS-ALLOW-AXFR-PRINCIPAL",
"LUA-AXFR-SCRIPT",
"NSEC3NARROW",
"NSEC3PARAM",
"PRESIGNED",
"PUBLISH_CDNSKEY",
"PUBLISH_CDS",
"SOA-EDIT",
"SOA-EDIT-DNSUPDATE",
"TSIG-ALLOW-AXFR",
"TSIG-ALLOW-DNSUPDATE",
)
DNS_TSIG_KEY_ALGORITHMS = Choices(
('hmac-md5', _('HMAC MD5')),
('hmac-sha1', _('HMAC SHA1')),
('hmac-sha224', _('HMAC SHA224')),
('hmac-sha256', _('HMAC SHA256')),
('hmac-sha384', _('HMAC SHA384')),
('hmac-sha512', _('HMAC SHA512')),
("hmac-md5", _("HMAC MD5")),
("hmac-sha1", _("HMAC SHA1")),
("hmac-sha224", _("HMAC SHA224")),
("hmac-sha256", _("HMAC SHA256")),
("hmac-sha384", _("HMAC SHA384")),
("hmac-sha512", _("HMAC SHA512")),
)
@ -55,16 +52,20 @@ class DomainBase(TimeStampedModel):
This is the base model for domains.
"""
domain = models.CharField(_('domain name'), max_length=255, unique=True)
domain = models.CharField(_("domain name"), max_length=255, unique=True)
customer = models.ForeignKey(
settings.AUTH_USER_MODEL, verbose_name=_('customer'), blank=True,
null=True, on_delete=models.CASCADE)
settings.AUTH_USER_MODEL,
verbose_name=_("customer"),
blank=True,
null=True,
on_delete=models.CASCADE,
)
class Meta:
abstract = True
@python_2_unicode_compatible
class MailDomain(DomainBase):
"""
This is the model for mail domains. Mail domains are used to configure the
@ -72,9 +73,10 @@ class MailDomain(DomainBase):
domains.
"""
class Meta:
verbose_name = _('Mail domain')
verbose_name_plural = _('Mail domains')
class Meta(DomainBase.Meta):
verbose_name = _("Mail domain")
verbose_name_plural = _("Mail domains")
def __str__(self):
return self.domain
@ -85,6 +87,7 @@ class MailDomain(DomainBase):
"""
return self.mailaddress_set.all()
mailaddresses = property(get_mailaddresses)
@ -93,47 +96,52 @@ class HostingDomainManager(models.Manager):
Default Manager for :py:class:`HostingDomain`.
"""
@transaction.atomic
def create_for_hosting_package(
self, hosting_package, domain, commit, **kwargs
):
def create_for_hosting_package(self, hosting_package, domain, commit, **kwargs):
from hostingpackages.models import CustomerHostingPackageDomain
hostingdomain = self.create(
customer=hosting_package.customer, domain=domain, **kwargs)
customer=hosting_package.customer, domain=domain, **kwargs
)
hostingdomain.maildomain = MailDomain.objects.create(
customer=hosting_package.customer, domain=domain)
customer=hosting_package.customer, domain=domain
)
custdomain = CustomerHostingPackageDomain.objects.create(
hosting_package=hosting_package, domain=hostingdomain)
hosting_package=hosting_package, domain=hostingdomain
)
if commit:
hostingdomain.save()
custdomain.save()
return hostingdomain
@python_2_unicode_compatible
class HostingDomain(DomainBase):
"""
This is the model for hosting domains. A hosting domain is linked to a
customer hosting account.
"""
maildomain = models.OneToOneField(
MailDomain, verbose_name=_('mail domain'), blank=True, null=True,
help_text=_('assigned mail domain for this domain'),
MailDomain,
verbose_name=_("mail domain"),
blank=True,
null=True,
help_text=_("assigned mail domain for this domain"),
on_delete=models.CASCADE,
)
objects = HostingDomainManager()
class Meta:
verbose_name = _('Hosting domain')
verbose_name_plural = _('Hosting domains')
verbose_name = _("Hosting domain")
verbose_name_plural = _("Hosting domains")
def __str__(self):
return self.domain
@python_2_unicode_compatible
class DNSDomain(DomainBase):
"""
This model represents a DNS zone. The model is similar to the domain table
@ -157,24 +165,25 @@ class DNSDomain(DomainBase):
CREATE UNIQUE INDEX name_index ON domains(name);
"""
# name is represented by domain
master = models.CharField(max_length=128, blank=True, null=True)
last_check = models.IntegerField(null=True)
domaintype = models.CharField(
max_length=6, choices=DNS_DOMAIN_TYPES, db_column='type')
max_length=6, choices=DNS_DOMAIN_TYPES, db_column="type"
)
notified_serial = models.IntegerField(null=True)
# account is represented by customer_id
# check constraint is added via RunSQL in migration
class Meta:
verbose_name = _('DNS domain')
verbose_name_plural = _('DNS domains')
verbose_name = _("DNS domain")
verbose_name_plural = _("DNS domains")
def __str__(self):
return self.domain
@python_2_unicode_compatible
class DNSRecord(models.Model):
"""
This model represents a DNS record. The model is similar to the record
@ -209,11 +218,12 @@ class DNSRecord(models.Model):
domain_id, ordername text_pattern_ops);
"""
domain = models.ForeignKey('DNSDomain', on_delete=models.CASCADE)
name = models.CharField(
max_length=255, blank=True, null=True, db_index=True)
domain = models.ForeignKey("DNSDomain", on_delete=models.CASCADE)
name = models.CharField(max_length=255, blank=True, null=True, db_index=True)
recordtype = models.CharField(
max_length=10, blank=True, null=True, db_column='type')
max_length=10, blank=True, null=True, db_column="type"
)
content = models.CharField(max_length=65535, blank=True, null=True)
ttl = models.IntegerField(null=True)
prio = models.IntegerField(null=True)
@ -224,18 +234,16 @@ class DNSRecord(models.Model):
# check constraint and index recordorder are added via RunSQL in migration
class Meta:
verbose_name = _('DNS record')
verbose_name_plural = _('DNS records')
index_together = [
['name', 'recordtype']
]
verbose_name = _("DNS record")
verbose_name_plural = _("DNS records")
index_together = [["name", "recordtype"]]
def __str__(self):
return "{name} IN {type} {content}".format(
name=self.name, type=self.recordtype, content=self.content)
name=self.name, type=self.recordtype, content=self.content
)
@python_2_unicode_compatible
class DNSSupermaster(models.Model):
"""
This model represents the supermasters table in the PowerDNS schema
@ -252,26 +260,23 @@ class DNSSupermaster(models.Model):
);
"""
ip = models.GenericIPAddressField()
nameserver = models.CharField(max_length=255)
# account is replaced by customer
customer = models.ForeignKey(
settings.AUTH_USER_MODEL, verbose_name=_('customer'),
on_delete=models.CASCADE)
settings.AUTH_USER_MODEL, verbose_name=_("customer"), on_delete=models.CASCADE
)
class Meta:
verbose_name = _('DNS supermaster')
verbose_name_plural = _('DNS supermasters')
unique_together = (
('ip', 'nameserver')
)
verbose_name = _("DNS supermaster")
verbose_name_plural = _("DNS supermasters")
unique_together = ("ip", "nameserver")
def __str__(self):
return "{ip} {nameserver}".format(
ip=self.ip, nameserver=self.nameserver)
return "{ip} {nameserver}".format(ip=self.ip, nameserver=self.nameserver)
@python_2_unicode_compatible
class DNSComment(models.Model):
"""
This model represents the comments table in the PowerDNS schema specified
@ -301,31 +306,29 @@ class DNSComment(models.Model):
CREATE INDEX comments_order_idx ON comments (domain_id, modified_at);
"""
domain = models.ForeignKey('DNSDomain', on_delete=models.CASCADE)
domain = models.ForeignKey("DNSDomain", on_delete=models.CASCADE)
name = models.CharField(max_length=255)
commenttype = models.CharField(max_length=10, db_column='type')
commenttype = models.CharField(max_length=10, db_column="type")
modified_at = models.IntegerField()
# account is replaced by customer
customer = models.ForeignKey(
settings.AUTH_USER_MODEL, verbose_name=_('customer'),
on_delete=models.CASCADE)
settings.AUTH_USER_MODEL, verbose_name=_("customer"), on_delete=models.CASCADE
)
comment = models.CharField(max_length=65535)
# check constraint is added via RunSQL in migration
class Meta:
verbose_name = _('DNS comment')
verbose_name_plural = _('DNS comments')
index_together = [
['name', 'commenttype'],
['domain', 'modified_at']
]
verbose_name = _("DNS comment")
verbose_name_plural = _("DNS comments")
index_together = [["name", "commenttype"], ["domain", "modified_at"]]
def __str__(self):
return "{name} IN {type}: {comment}".format(
name=self.name, type=self.commenttype, comment=self.comment)
name=self.name, type=self.commenttype, comment=self.comment
)
@python_2_unicode_compatible
class DNSDomainMetadata(models.Model):
"""
This model represents the domainmetadata table in the PowerDNS schema
@ -346,20 +349,21 @@ class DNSDomainMetadata(models.Model):
CREATE INDEX domainidmetaindex ON domainmetadata(domain_id);
"""
domain = models.ForeignKey('DNSDomain', on_delete=models.CASCADE)
domain = models.ForeignKey("DNSDomain", on_delete=models.CASCADE)
kind = models.CharField(max_length=32, choices=DNS_DOMAIN_METADATA_KINDS)
content = models.TextField()
class Meta:
verbose_name = _('DNS domain metadata item')
verbose_name_plural = _('DNS domain metadata items')
verbose_name = _("DNS domain metadata item")
verbose_name_plural = _("DNS domain metadata items")
def __str__(self):
return "{domain} {kind} {content}".format(
domain=self.domain.domain, kind=self.kind, content=self.content)
domain=self.domain.domain, kind=self.kind, content=self.content
)
@python_2_unicode_compatible
class DNSCryptoKey(models.Model):
"""
This model represents the cryptokeys table in the PowerDNS schema
@ -379,21 +383,22 @@ class DNSCryptoKey(models.Model):
CREATE INDEX domainidindex ON cryptokeys(domain_id);
"""
domain = models.ForeignKey('DNSDomain', on_delete=models.CASCADE)
domain = models.ForeignKey("DNSDomain", on_delete=models.CASCADE)
flags = models.IntegerField()
active = models.BooleanField(default=True)
content = models.TextField()
class Meta:
verbose_name = _('DNS crypto key')
verbose_name_plural = _('DNS crypto keys')
verbose_name = _("DNS crypto key")
verbose_name_plural = _("DNS crypto keys")
def __str__(self):
return "{domain} {content}".format(
domain=self.domain.domain, content=self.content)
domain=self.domain.domain, content=self.content
)
@python_2_unicode_compatible
class DNSTSIGKey(models.Model):
"""
This model represents the tsigkeys table in the PowerDNS schema specified
@ -413,19 +418,18 @@ class DNSTSIGKey(models.Model):
CREATE UNIQUE INDEX namealgoindex ON tsigkeys(name, algorithm);
"""
name = models.CharField(max_length=255)
algorithm = models.CharField(
max_length=50, choices=DNS_TSIG_KEY_ALGORITHMS)
algorithm = models.CharField(max_length=50, choices=DNS_TSIG_KEY_ALGORITHMS)
secret = models.CharField(max_length=255)
# check constraint is added via RunSQL in migration
class Meta:
verbose_name = _('DNS TSIG key')
verbose_name_plural = _('DNS TSIG keys')
unique_together = [
['name', 'algorithm']
]
verbose_name = _("DNS TSIG key")
verbose_name_plural = _("DNS TSIG keys")
unique_together = [["name", "algorithm"]]
def __str__(self):
return "{name} {algorithm} XXXX".format(
name=self.name, algorithm=self.algorithm)
name=self.name, algorithm=self.algorithm
)