Skip to content

When writing RFC2317 zones, convert "/" to "-" in the filename. #77

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

Merged
merged 2 commits into from
Mar 28, 2025

Conversation

sim0nx
Copy link
Contributor

@sim0nx sim0nx commented Mar 27, 2025

When trying to write RFC2317 zones, of the form e.g. 0/25.10.10.10.in-addr.arpa., octodns-sync fails with:

...
with open(filename, 'w') as fh:
^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: './test/0/25.10.10.10.in-addr.arpa.'

To avoid this, we replace the / with a - in the filename.

Copy link
Contributor

@ross ross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch and the change makes sense. Main request would be to add a test of the new functionality so that we can make sure that it works as expected now and doesn't get broken in the future.

It'd probably look a lot like

@patch('octodns_bind.ZoneFileProvider._serial')
def test_apply(self, serial_mock):
serial_mock.side_effect = [424344, 454647, 484950]
with TemporaryDirectory() as td:
provider = ZoneFileProvider('target', td.dirname)
# no root NS
desired = Zone('unit.tests.', [])
# populate as a target, shouldn't find anything, file wouldn't even
# exist
provider.populate(desired, target=True)
self.assertEqual(0, len(desired.records))
cname = Record.new(
desired,
'cname',
{'type': 'CNAME', 'ttl': 42, 'value': 'target.unit.tests.'},
)
desired.add_record(cname)
changes = [Create(cname)]
plan = Plan(None, desired, changes, True)
provider._apply(plan)
with open(join(td.dirname, 'unit.tests.')) as fh:
self.assertEqual(
'''$ORIGIN unit.tests.
, just swapping the unit.tests. zone name for something with a /.

@sim0nx
Copy link
Contributor Author

sim0nx commented Mar 28, 2025

Good catch and the change makes sense. Main request would be to add a test of the new functionality so that we can make sure that it works as expected now and doesn't get broken in the future.

It'd probably look a lot like

@patch('octodns_bind.ZoneFileProvider._serial')
def test_apply(self, serial_mock):
serial_mock.side_effect = [424344, 454647, 484950]
with TemporaryDirectory() as td:
provider = ZoneFileProvider('target', td.dirname)
# no root NS
desired = Zone('unit.tests.', [])
# populate as a target, shouldn't find anything, file wouldn't even
# exist
provider.populate(desired, target=True)
self.assertEqual(0, len(desired.records))
cname = Record.new(
desired,
'cname',
{'type': 'CNAME', 'ttl': 42, 'value': 'target.unit.tests.'},
)
desired.add_record(cname)
changes = [Create(cname)]
plan = Plan(None, desired, changes, True)
provider._apply(plan)
with open(join(td.dirname, 'unit.tests.')) as fh:
self.assertEqual(
'''$ORIGIN unit.tests.

, just swapping the unit.tests. zone name for something with a /.

Thanks for your feedback.
I added a test-case inspired by test_apply as you suggested.
I had to add an NS record as else it would auto-generate one for the SOA record based on the zone name which is invalid. Same goes for the hostmaster_email.

After asserting that the written output is as expected, I stripped the rest of the test_apply part as that is IMHO not required to test again and was problematic with the NS I added earlier (duplicate records error..).

I am not too familiar with the code base so I hope it is fine like that :-)

@ross ross merged commit 4153baa into octodns:main Mar 28, 2025
7 checks passed
@ross
Copy link
Contributor

ross commented Mar 28, 2025

Thanks

@sim0nx sim0nx deleted the fix_rfc2317_filename branch March 28, 2025 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants