From 86f5c0753fa29ae39b68b12106575ecf1fcaa18a Mon Sep 17 00:00:00 2001 From: "Tagawa, Masaki" Date: Mon, 17 Oct 2022 13:28:41 +0900 Subject: [PATCH] Fix a fatal bug with records w/o FQDN in the field --- octodns_netbox/__init__.py | 2 ++ tests/test_octodns_netbox.py | 32 ++++++++++++++++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/octodns_netbox/__init__.py b/octodns_netbox/__init__.py index ded9f87..6d86072 100644 --- a/octodns_netbox/__init__.py +++ b/octodns_netbox/__init__.py @@ -135,11 +135,13 @@ def _populate_PTR(self, zone: Zone, family: Literal[4, 6]) -> typing.List[Rr]: ret = [] network = octodns_netbox.reversename.to_network(zone) + kw = {f"{self.field_name}__empty": "false"} ipam_records = self._nb_client.ipam.ip_addresses.filter( parent=network.compressed, family=family, vrf_id=self.populate_vrf_id, tag=self.populate_tags, + **kw, ) for ipam_record in ipam_records: diff --git a/tests/test_octodns_netbox.py b/tests/test_octodns_netbox.py index 0fee521..717823d 100644 --- a/tests/test_octodns_netbox.py +++ b/tests/test_octodns_netbox.py @@ -32,32 +32,52 @@ def mock_requests(): json=load_fixture("vrf.json"), ) mock.get( - "http://netbox.example.com/api/ipam/ip-addresses/?parent=192.0.2.0%2F27&family=4&limit=0", + "http://netbox.example.com/api/ipam/ip-addresses/?parent=192.0.2.0%2F27&family=4&description__empty=false&limit=0", complete_qs=True, json=load_fixture("ip_addresses_v4_non_octet_boundary.json"), ) mock.get( - "http://netbox.example.com/api/ipam/ip-addresses/?parent=192.0.2.0%2F27&family=4&vrf_id=1&limit=0", + "http://netbox.example.com/api/ipam/ip-addresses/?parent=192.0.2.0%2F27&family=4&dns_name__empty=false&limit=0", + complete_qs=True, + json=load_fixture("ip_addresses_v4_non_octet_boundary.json"), + ) + mock.get( + "http://netbox.example.com/api/ipam/ip-addresses/?parent=192.0.2.0%2F27&family=4&vrf_id=1&description__empty=false&limit=0", complete_qs=True, json=load_fixture("ip_addresses_v4_non_octet_boundary_vrf_mgmt.json"), ) mock.get( - "http://netbox.example.com/api/ipam/ip-addresses/?parent=192.0.2.0%2F24&family=4&limit=0", + "http://netbox.example.com/api/ipam/ip-addresses/?parent=192.0.2.0%2F24&family=4&description__empty=false&limit=0", + complete_qs=True, + json=load_fixture("ip_addresses_v4_octet_boundary.json"), + ) + mock.get( + "http://netbox.example.com/api/ipam/ip-addresses/?parent=192.0.2.0%2F24&family=4&dns_name__empty=false&limit=0", complete_qs=True, json=load_fixture("ip_addresses_v4_octet_boundary.json"), ) mock.get( - "http://netbox.example.com/api/ipam/ip-addresses/?parent=192.0.3.0%2F24&family=4&vrf_id=null&limit=0", + "http://netbox.example.com/api/ipam/ip-addresses/?parent=192.0.3.0%2F24&family=4&vrf_id=null&description__empty=false&limit=0", complete_qs=True, json=load_fixture("ip_addresses_v4_octet_boundary_vrf_global.json"), ) mock.get( - "http://netbox.example.com/api/ipam/ip-addresses/?parent=2001%3Adb8%3A%3A%2F100&family=6&limit=0", + "http://netbox.example.com/api/ipam/ip-addresses/?parent=2001%3Adb8%3A%3A%2F100&family=6&description__empty=false&limit=0", complete_qs=True, json=load_fixture("ip_addresses_v6_non_nibble_boundary.json"), ) mock.get( - "http://netbox.example.com/api/ipam/ip-addresses/?parent=2001%3Adb8%3A%3A%2F64&family=6&limit=0", + "http://netbox.example.com/api/ipam/ip-addresses/?parent=2001%3Adb8%3A%3A%2F100&family=6&dns_name__empty=false&limit=0", + complete_qs=True, + json=load_fixture("ip_addresses_v6_non_nibble_boundary.json"), + ) + mock.get( + "http://netbox.example.com/api/ipam/ip-addresses/?parent=2001%3Adb8%3A%3A%2F64&family=6&description__empty=false&limit=0", + complete_qs=True, + json=load_fixture("ip_addresses_v6_nibble_boundary.json"), + ) + mock.get( + "http://netbox.example.com/api/ipam/ip-addresses/?parent=2001%3Adb8%3A%3A%2F64&family=6&dns_name__empty=false&limit=0", complete_qs=True, json=load_fixture("ip_addresses_v6_nibble_boundary.json"), )