Skip to content

added support for multiple IPs on juniper interface #347

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
Apr 3, 2025
Merged
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
1 change: 1 addition & 0 deletions changes/346.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed Juniper IP addresses not syncing secondary IP addresses.
25 changes: 21 additions & 4 deletions nautobot_device_onboarding/jinja_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from itertools import chain

from django_jinja import library
from netutils.ip import is_ip
from netutils.vlan import vlanconfig_to_list

from nautobot_device_onboarding.constants import INTERFACE_TYPE_MAP_STATIC
Expand Down Expand Up @@ -174,11 +175,27 @@ def parse_junos_ip_address(item):
"""
if isinstance(item, list) and len(item) > 0:
if item[0]["prefix_length"] and item[0]["ip_address"]:
return [
{"prefix_length": item[0]["prefix_length"][0].split("/")[-1], "ip_address": item[0]["ip_address"][0]}
]
result = []
for i in range(len(item[0]["ip_address"])):
prefix = item[0]["prefix_length"][i].split("/")[-1]
result.append(
{
"prefix_length": prefix,
"ip_address": item[0]["ip_address"][i],
}
)
return result
if not item[0]["prefix_length"] and item[0]["ip_address"]:
return [{"prefix_length": 32, "ip_address": item[0]["ip_address"][0]}]
result = []
for i in range(len(item[0]["ip_address"])):
if is_ip(item[0]["ip_address"][i]):
result.append(
{
"prefix_length": 32,
"ip_address": item[0]["ip_address"][i],
}
)
return result
return []


Expand Down
6 changes: 3 additions & 3 deletions nautobot_device_onboarding/tests/test_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ def test_perform_data_extraction_sync_network_data_no_options(self):
command_outputs,
job_debug=False,
)
self.assertEqual(expected_parsed_result, actual_result)
self.assertCountEqual(expected_parsed_result, actual_result)


class TestFormatterSyncNetworkDataWithVrfs(unittest.TestCase):
Expand Down Expand Up @@ -615,7 +615,7 @@ def test_perform_data_extraction_sync_network_data_with_vrfs(self):
command_outputs,
job_debug=False,
)
self.assertEqual(expected_parsed_result, actual_result)
self.assertCountEqual(expected_parsed_result, actual_result)


class TestFormatterSyncNetworkDataWithVlans(unittest.TestCase):
Expand Down Expand Up @@ -683,7 +683,7 @@ def test_perform_data_extraction_sync_network_data_with_vlans(self):
command_outputs,
job_debug=False,
)
self.assertEqual(expected_parsed_result, actual_result)
self.assertCountEqual(expected_parsed_result, actual_result)


@unittest.skip(reason="Todo test sync network data with all options.")
Expand Down
5 changes: 2 additions & 3 deletions nautobot_device_onboarding/tests/test_jinja_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,14 @@ def test_parse_junos_ip_address_values_as_list_single(self):
expected = [{"prefix_length": "31", "ip_address": "10.65.229.106"}]
self.assertEqual(parse_junos_ip_address(data), expected)

@unittest.skip("Need to correct assert used for list of dictionaries.")
def test_parse_junos_ip_address_values_as_list_multiple(self):
"""Parse Junos IP and destination prefix."""
data = [{"prefix_length": ["10.65.133.0/29", "10.65.133.0/29"], "ip_address": ["10.65.133.1", "10.65.133.3"]}]
expected = [
{"prefix_length": "29", "ip_address": "10.65.133.1"},
{"ip_address": "10.65.133.3", "prefix_length": "29"},
{"prefix_length": "29", "ip_address": "10.65.133.3"},
]
self.assertEqual(parse_junos_ip_address(data), expected)
self.assertCountEqual(parse_junos_ip_address(data), expected)

def test_parse_junos_ip_address_values_as_empty_list(self):
"""Parse Junos IP and destination prefix."""
Expand Down