From ebf042b1f43ac6a020bc5d2c6870550fb51f2c87 Mon Sep 17 00:00:00 2001 From: Alp Kose Date: Thu, 10 Oct 2024 14:40:20 +0300 Subject: [PATCH] feat(network.StaticRoute): conditions and none value nexthop_type Add conditions to StaticRoute nexthop and nexthop_type params as well as accepting 'none' value as an input for nexthop_type. --- panos/network.py | 11 +++++++-- tests/test_integration.py | 50 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/panos/network.py b/panos/network.py index 1a9e1ad3..4e520ecf 100644 --- a/panos/network.py +++ b/panos/network.py @@ -1834,11 +1834,18 @@ def _setup(self): VersionedParamPath( "nexthop_type", default="ip-address", - values=["discard", "ip-address", "next-vr"], + values=["discard", "ip-address", "next-vr", "none"], path="nexthop/{nexthop_type}", + condition={"nexthop_type": ["discard", "ip-address", "next-vr"]}, + ) + ) + params.append( + VersionedParamPath( + "nexthop", + path="nexthop/{nexthop_type}", + condition={"nexthop_type": ["ip-address", "next-vr"]}, ) ) - params.append(VersionedParamPath("nexthop", path="nexthop/{nexthop_type}")) params.append(VersionedParamPath("interface", path="interface")) params.append( VersionedParamPath("admin_dist", vartype="int", path="admin-dist") diff --git a/tests/test_integration.py b/tests/test_integration.py index 3dabf0e2..73a6d0cd 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -260,6 +260,56 @@ def test_element_str_from_virtualrouter_with_sr_parent(self): self.assertEqual(expected, ret_val) + # VirtualRouter with nexthop_type=None StaticRoute child + def test_element_str_from_virtualrouter_with_sr_none(self): + """StaticRoute > VirtualRouter""" + expected = b"".join( + [ + b'ethernet1/3', + b"", + b'3.3.3.3/32', + b"", + b"ethernet1/410", + b"", + ] + ) + + vro = panos.network.VirtualRouter("default", "ethernet1/3") + sro = panos.network.StaticRoute( + "my none route", "3.3.3.3/32", None, None, "ethernet1/4" + ) + + vro.add(sro) + + ret_val = vro.element_str() + + self.assertEqual(expected, ret_val) + + # VirtualRouter with nexthop_type 'none' StaticRoute child + def test_element_str_from_virtualrouter_with_sr_none_str(self): + """StaticRoute > VirtualRouter""" + expected = b"".join( + [ + b'ethernet1/3', + b"", + b'3.3.3.3/32', + b"", + b"ethernet1/410", + b"", + ] + ) + + vro = panos.network.VirtualRouter("default", "ethernet1/3") + sro = panos.network.StaticRoute( + "my none route", "3.3.3.3/32", "none", None, "ethernet1/4" + ) + + vro.add(sro) + + ret_val = vro.element_str() + + self.assertEqual(expected, ret_val) + # 3) EthernetInterface def test_element_str_from_ethernetinterface(self): expected = b"".join(