Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump required octodns >= 2.0, address pending deprecations #77

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## v1.0.0 - 2024-??-?? - ???

### Notedworthy Changes:

* `SPF` record support removed, records should be migrated to `TXT` before
upgrading.
* DS properties "algorithm", "flags", "public_key", and "protocol" support
removed
* Requires octoDNS >= 1.5.0

## v0.0.7 - 2024-08-28 - Less picky about names

* Support for fully managing zones with special characters in their names, e.g.
Expand Down
35 changes: 7 additions & 28 deletions octodns_powerdns/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from octodns.provider import ProviderException
from octodns.provider.base import BaseProvider
from octodns.record import Record
from octodns.record.ds import DsValue

try: # pragma: no cover
from octodns.record.https import HttpsValue
Expand Down Expand Up @@ -65,7 +64,6 @@ class PowerDnsBaseProvider(BaseProvider):
'NAPTR',
'NS',
'PTR',
'SPF',
'SSHFP',
'SRV',
'TLSA',
Expand All @@ -89,10 +87,6 @@ class PowerDnsBaseProvider(BaseProvider):
}
POWERDNS_LEGACY_MODES_OF_OPERATION = {'native', 'master', 'slave'}

# TODO: once we require octoDNS 2.0 this backwards compatibility code can go
# away
OLD_DS_FIELDS = hasattr(DsValue, 'flags')

def __init__(
self,
id,
Expand Down Expand Up @@ -213,20 +207,12 @@ def _data_for_DS(self, rrset):
(key_tag, algorithm, digest_type, digest) = record['content'].split(
' ', 3
)
if self.OLD_DS_FIELDS:
value = {
'flags': key_tag,
'protocol': algorithm,
'algorithm': digest_type,
'public_key': digest,
}
else:
value = {
'key_tag': key_tag,
'algorithm': algorithm,
'digest_type': digest_type,
'digest': digest,
}
value = {
'key_tag': key_tag,
'algorithm': algorithm,
'digest_type': digest_type,
'digest': digest,
}
values.append(value)

return {'type': rrset['type'], 'values': values, 'ttl': rrset['ttl']}
Expand Down Expand Up @@ -258,7 +244,6 @@ def _data_for_quoted(self, rrset):
'ttl': rrset['ttl'],
}

_data_for_SPF = _data_for_quoted
_data_for_TXT = _data_for_quoted

def _data_for_LOC(self, rrset):
Expand Down Expand Up @@ -544,12 +529,7 @@ def _records_for_TLSA(self, record):
def _records_for_DS(self, record):
data = []
for v in record.values:
if self.OLD_DS_FIELDS:
content = f'{v.flags} {v.protocol} {v.algorithm} {v.public_key}'
else:
content = (
f'{v.key_tag} {v.algorithm} {v.digest_type} {v.digest}'
)
content = f'{v.key_tag} {v.algorithm} {v.digest_type} {v.digest}'
data.append({'content': content, 'disabled': False})
return data, record._type

Expand All @@ -570,7 +550,6 @@ def _records_for_quoted(self, record):
{'content': f'"{v}"', 'disabled': False} for v in record.values
], record._type

_records_for_SPF = _records_for_quoted
_records_for_TXT = _records_for_quoted

def _records_for_LOC(self, record):
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,5 @@ sections="FUTURE,STDLIB,THIRDPARTY,OCTODNS,FIRSTPARTY,LOCALFOLDER"
[tool.pytest.ini_options]
filterwarnings = [
'error',
# TODO: remove once octodns 2.0 has been released
'ignore:.*DEPRECATED.*2.0',
]
pythonpath = "."
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def version():
),
'test': tests_require,
},
install_requires=('octodns>=0.9.17', 'requests>=2.26.0'),
install_requires=('octodns>=1.5.0', 'requests>=2.26.0'),
license='MIT',
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down
35 changes: 9 additions & 26 deletions tests/config/unit.tests.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
---
? ''
: - geo:
AF:
- 2.2.3.4
- 2.2.3.5
AS-JP:
- 3.2.3.4
- 3.2.3.5
NA-US:
- 4.2.3.4
- 4.2.3.5
NA-US-CA:
- 5.2.3.4
- 5.2.3.5
ttl: 300
: - ttl: 300
type: A
values:
- 1.2.3.4
Expand All @@ -39,10 +26,10 @@
value: ca.unit.tests
- type: 'DS'
values:
- algorithm: 2
flags: 2371
protocol: 13
public_key: 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF
- algorithm: 13
digest: 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF
digest_type: 2
key_tag: 2371
_853._tcp:
type: TLSA
values:
Expand Down Expand Up @@ -180,21 +167,17 @@ ptr:
ttl: 300
type: PTR
values: [foo.bar.com.]
spf:
ttl: 600
type: SPF
value: v=spf1 ip4:192.168.0.1/16-all
sub:
- type: 'NS'
values:
- 6.2.3.4.
- 7.2.3.4.
- type: 'DS'
values:
- algorithm: 2
flags: 12345
protocol: 13
public_key: 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF
- algorithm: 13
digest: 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF
digest_type: 2
key_tag: 12345
svcb:
type: SVCB
values:
Expand Down
12 changes: 0 additions & 12 deletions tests/fixtures/powerdns-full-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,6 @@
"ttl": 300,
"type": "PTR"
},
{
"comments": [],
"name": "spf.unit.tests.",
"records": [
{
"content": "\"v=spf1 ip4:192.168.0.1/16-all\"",
"disabled": false
}
],
"ttl": 600,
"type": "SPF"
},
{
"comments": [],
"name": "cname.unit.tests.",
Expand Down
60 changes: 14 additions & 46 deletions tests/test_octodns_provider_powerdns.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,15 @@ def test_provider(self):
)
source.populate(expected)
expected_n = len(expected.records) - 4
self.assertEqual(25, expected_n)
self.assertEqual(24, expected_n)

# No diffs == no changes
with requests_mock() as mock:
mock.get(ANY, status_code=200, text=FULL_TEXT)

zone = Zone('unit.tests.', [])
provider.populate(zone)
self.assertEqual(25, len(zone.records))
self.assertEqual(24, len(zone.records))
changes = expected.changes(zone, provider)
self.assertEqual(0, len(changes))

Expand Down Expand Up @@ -400,7 +400,7 @@ def test_small_change(self):
'test', join(dirname(__file__), 'config'), supports_root_ns=False
)
source.populate(expected)
self.assertEqual(29, len(expected.records))
self.assertEqual(28, len(expected.records))

# A small change to a single record
with requests_mock() as mock:
Expand All @@ -417,7 +417,7 @@ def test_small_change(self):
missing = Zone(expected.name, [])
# Find and delete the SPF record
for record in expected.records:
if record._type != 'SPF':
if record._type != 'SVCB':
missing.add_record(record)

def assert_delete_callback(request, context):
Expand All @@ -427,14 +427,18 @@ def assert_delete_callback(request, context):
{
'records': [
{
'content': '"v=spf1 ip4:192.168.0.1/16-all"',
'content': '1 www.unit.tests.',
'disabled': False,
}
},
{
'content': '2 backups.unit.tests.',
'disabled': False,
},
],
'changetype': 'DELETE',
'type': 'SPF',
'name': 'spf.unit.tests.',
'ttl': 600,
'type': 'SVCB',
'name': 'svcb.unit.tests.',
'ttl': 3600,
}
]
},
Expand Down Expand Up @@ -478,7 +482,7 @@ def test_notify(self):
missing = Zone(expected.name, [])
# Find and delete the SPF record
for record in expected.records:
if record._type != 'SPF':
if record._type != 'SVCB':
missing.add_record(record)

plan = provider.plan(missing)
Expand Down Expand Up @@ -610,21 +614,7 @@ def test_data_for_DS_compat(self):
'type': 'DS',
}

# old
provider.OLD_DS_FIELDS = True
value = provider._data_for_DS(rrset)['values'][0]
self.assertEqual(
{
'algorithm': 'three',
'flags': 'one',
'protocol': 'two',
'public_key': 'four',
},
value,
)

# new
provider.OLD_DS_FIELDS = False
value = provider._data_for_DS(rrset)['values'][0]
self.assertEqual(
{
Expand All @@ -645,14 +635,6 @@ class DummyRecord:
def __init__(self, value):
self.values = [value]

class OldFields:
flags = 'flags'
protocol = 'protocol'
algorithm = 'algorithm'
public_key = 'public_key'

old_fields = OldFields()

class NewFields:
key_tag = 'key_tag'
algorithm = 'algorithm'
Expand All @@ -661,21 +643,7 @@ class NewFields:

new_fields = NewFields()

# old
provider.OLD_DS_FIELDS = True
data = provider._records_for_DS(DummyRecord(old_fields))[0]
self.assertEqual(
[
{
'content': 'flags protocol algorithm public_key',
'disabled': False,
}
],
data,
)

# new
provider.OLD_DS_FIELDS = False
data = provider._records_for_DS(DummyRecord(new_fields))[0]
self.assertEqual(
[
Expand Down
Loading