|
15 | 15 | import unittest
|
16 | 16 |
|
17 | 17 | from flexmock import flexmock, flexmock_teardown
|
18 |
| -from hamcrest import assert_that, equal_to, instance_of, contains_string, has_length |
| 18 | +from hamcrest import assert_that, equal_to, instance_of, contains_string, has_length, is_ |
19 | 19 | from ncclient.operations import RPCError
|
20 | 20 | from ncclient.xml_ import to_ele
|
21 | 21 | from netaddr import IPAddress, IPNetwork
|
22 |
| - |
23 | 22 | from netman.adapters.switches.juniper.base import Juniper
|
24 | 23 | from netman.adapters.switches.juniper.mx import netconf
|
25 | 24 | from netman.core.objects.access_groups import IN, OUT
|
@@ -924,6 +923,122 @@ def test_get_vlan_with_interface(self):
|
924 | 923 | assert_that(str(vlan20ip1.ip), equal_to("1.1.1.1"))
|
925 | 924 | assert_that(vlan20ip1.prefixlen, equal_to(24))
|
926 | 925 |
|
| 926 | + def test_get_vlan_with_vrrp(self): |
| 927 | + self.switch.in_transaction = False |
| 928 | + self.netconf_mock.should_receive("get_config").with_args(source="running", filter=is_xml(""" |
| 929 | + <filter> |
| 930 | + <configuration> |
| 931 | + <bridge-domains /> |
| 932 | + <interfaces /> |
| 933 | + </configuration> |
| 934 | + </filter> |
| 935 | + """)).and_return(a_configuration(""" |
| 936 | + <bridge-domains> |
| 937 | + <domain> |
| 938 | + <name>WITH-IF</name> |
| 939 | + <vlan-id>20</vlan-id> |
| 940 | + <routing-interface>irb.20</routing-interface> |
| 941 | + </domain> |
| 942 | + </bridge-domains> |
| 943 | + <interfaces> |
| 944 | + <interface> |
| 945 | + <name>irb</name> |
| 946 | + <unit> |
| 947 | + <name>20</name> |
| 948 | + <family> |
| 949 | + <inet> |
| 950 | + <address> |
| 951 | + <name>1.1.1.2/24</name> |
| 952 | + <vrrp-group> |
| 953 | + <name>1</name> |
| 954 | + <virtual-address>1.1.1.1</virtual-address> |
| 955 | + <priority>90</priority> |
| 956 | + <preempt> |
| 957 | + <hold-time>60</hold-time> |
| 958 | + </preempt> |
| 959 | + <accept-data/> |
| 960 | + <authentication-type>simple</authentication-type> |
| 961 | + <authentication-key>$9$1/aElvwsgoaGz3reKvLX.Pf5n/</authentication-key> |
| 962 | + <track> |
| 963 | + <route> |
| 964 | + <route_address>0.0.0.0/0</route_address> |
| 965 | + <routing-instance>default</routing-instance> |
| 966 | + <priority-cost>50</priority-cost> |
| 967 | + </route> |
| 968 | + </track> |
| 969 | + </vrrp-group> |
| 970 | + </address> |
| 971 | + </inet> |
| 972 | + </family> |
| 973 | + </unit> |
| 974 | + </interface> |
| 975 | + </interfaces> |
| 976 | + """)) |
| 977 | + |
| 978 | + vlan = self.switch.get_vlan(20) |
| 979 | + |
| 980 | + vrrp = vlan.vrrp_groups[0] |
| 981 | + assert_that(vrrp.id, is_(1)) |
| 982 | + assert_that(vrrp.ips, has_length(1)) |
| 983 | + assert_that(vrrp.ips[0], is_(IPAddress('1.1.1.1'))) |
| 984 | + assert_that(vrrp.priority, is_(90)) |
| 985 | + assert_that(vrrp.hello_interval, is_(None)) |
| 986 | + assert_that(vrrp.dead_interval, is_(None)) |
| 987 | + assert_that(vrrp.track_id, is_("0.0.0.0/0")) |
| 988 | + assert_that(vrrp.track_decrement, is_(50)) |
| 989 | + |
| 990 | + def test_get_vlan_with_vrrp_without_optional_fields_and_multiple_vips(self): |
| 991 | + self.switch.in_transaction = False |
| 992 | + self.netconf_mock.should_receive("get_config").with_args(source="running", filter=is_xml(""" |
| 993 | + <filter> |
| 994 | + <configuration> |
| 995 | + <bridge-domains /> |
| 996 | + <interfaces /> |
| 997 | + </configuration> |
| 998 | + </filter> |
| 999 | + """)).and_return(a_configuration(""" |
| 1000 | + <bridge-domains> |
| 1001 | + <domain> |
| 1002 | + <name>WITH-IF</name> |
| 1003 | + <vlan-id>20</vlan-id> |
| 1004 | + <routing-interface>irb.20</routing-interface> |
| 1005 | + </domain> |
| 1006 | + </bridge-domains> |
| 1007 | + <interfaces> |
| 1008 | + <interface> |
| 1009 | + <name>irb</name> |
| 1010 | + <unit> |
| 1011 | + <name>20</name> |
| 1012 | + <family> |
| 1013 | + <inet> |
| 1014 | + <address> |
| 1015 | + <name>1.1.1.2/24</name> |
| 1016 | + <vrrp-group> |
| 1017 | + <name>1</name> |
| 1018 | + <virtual-address>1.1.1.1</virtual-address> |
| 1019 | + <virtual-address>1.1.1.3</virtual-address> |
| 1020 | + </vrrp-group> |
| 1021 | + </address> |
| 1022 | + </inet> |
| 1023 | + </family> |
| 1024 | + </unit> |
| 1025 | + </interface> |
| 1026 | + </interfaces> |
| 1027 | + """)) |
| 1028 | + |
| 1029 | + vlan = self.switch.get_vlan(20) |
| 1030 | + |
| 1031 | + vrrp = vlan.vrrp_groups[0] |
| 1032 | + assert_that(vrrp.id, is_(1)) |
| 1033 | + assert_that(vrrp.ips, has_length(2)) |
| 1034 | + assert_that(vrrp.ips[0], is_(IPAddress('1.1.1.1'))) |
| 1035 | + assert_that(vrrp.ips[1], is_(IPAddress('1.1.1.3'))) |
| 1036 | + assert_that(vrrp.priority, is_(None)) |
| 1037 | + assert_that(vrrp.hello_interval, is_(None)) |
| 1038 | + assert_that(vrrp.dead_interval, is_(None)) |
| 1039 | + assert_that(vrrp.track_id, is_(None)) |
| 1040 | + assert_that(vrrp.track_decrement, is_(None)) |
| 1041 | + |
927 | 1042 | def test_add_vrrp_success(self):
|
928 | 1043 | self.netconf_mock.should_receive("get_config").with_args(source="candidate", filter=is_xml("""
|
929 | 1044 | <filter>
|
|
0 commit comments