class test_hsrp(TestCase): def setUp(self): # Set Genie Tb testbed = Testbed() Genie.testbed = testbed # Device self.dev1 = Device(name='PE1', testbed=testbed, os='nxos') # Interface self.intf1 = Interface(name='Ethernet2/1', device=self.dev1) self.intf1.enabled = True self.intf1.switchport_enable = False # Hsrp object self.hsrp1 = Hsrp() # Build config cfgs = self.intf1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface Ethernet2/1', ' no shutdown', ' no switchport', ' exit', ])) def test_cli_config1(self): # Apply configuration self.hsrp1.device_attr[self.dev1].enabled = True key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.bfd_enabled = True key.version = 2 key.minimum_delay = 5 key.reload_delay = 10 key.use_bia = True key.group_number = 1 key.authentication = 'cisco123' key.primary_ipv4_address = '192.168.1.1/24' key.secondary_ipv4_address = '192.168.1.2/24' key.virtual_mac_address = 'dead.beef.dead' key.session_name = 'gandalf' key.preempt = True key.priority = 110 key.hello_sec = 1 key.hold_sec = 3 key.tracked_object = 1 key.tracked_object_priority_decrement = 20 # Build config cfgs = self.hsrp1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'feature hsrp', 'interface Ethernet2/1', ' hsrp bfd', ' hsrp version 2', ' hsrp delay minimum 5 reload 10', ' hsrp use-bia', ' hsrp 1', ' authentication cisco123', ' ip 192.168.1.1/24', ' ip 192.168.1.2/24 secondary', ' mac-address dead.beef.dead', ' name gandalf', ' preempt', ' priority 110', ' timers 1 3', ' track 1 decrement 20', ' exit', ' exit', ])) # Build unconfig cfgs = self.hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'no feature hsrp', 'interface Ethernet2/1', ' no hsrp bfd', ' no hsrp version 2', ' no hsrp delay minimum 5 reload 10', ' no hsrp use-bia', ' no hsrp 1', ' exit', ])) def test_cli_config2(self): # Apply configuration self.hsrp1.device_attr[self.dev1].enabled = True key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.version = 1 key.minimum_delay = 5 key.reload_delay = 10 key.group_number = 1 key.primary_ipv4_address = '192.168.1.1/24' key.priority = 110 key.preempt = True key.hello_msec_flag = True key.hello_msec = 300 key.hold_msec_flag = True key.hold_msec = 500 key.tracked_object = 1 key.authentication = 'cisco123' key.follow = 'group10' key.mac_refresh = 199 # Build config cfgs = self.hsrp1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'feature hsrp', 'interface Ethernet2/1', ' hsrp delay minimum 5 reload 10', ' hsrp mac-refresh 199', ' hsrp 1', ' authentication cisco123', ' ip 192.168.1.1/24', ' follow group10', ' preempt', ' priority 110', ' timers msec 300 msec 500', ' track 1', ' exit', ' exit', ])) # Build unconfig cfgs = self.hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'no feature hsrp', 'interface Ethernet2/1', ' no hsrp delay minimum 5 reload 10', ' no hsrp mac-refresh 199', ' no hsrp 1', ' exit', ])) def test_cli_config3(self): # Apply configuration self.hsrp1.device_attr[self.dev1].enabled = True key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.version = 2 key.minimum_delay = 5 key.reload_delay = 10 key.group_number = 1 key.primary_ipv4_address = '192.168.1.1/24' key.priority = 110 key.preempt = True key.hello_sec = 1 key.hold_sec = 3 key.tracked_object = 1 key.tracked_object_priority_decrement = 20 key.authentication = 'abc' # Build config cfgs = self.hsrp1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'feature hsrp', 'interface Ethernet2/1', ' hsrp version 2', ' hsrp delay minimum 5 reload 10', ' hsrp 1', ' authentication abc', ' ip 192.168.1.1/24', ' preempt', ' priority 110', ' timers 1 3', ' track 1 decrement 20', ' exit', ' exit', ])) # Build unconfig cfgs = self.hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'no feature hsrp', 'interface Ethernet2/1', ' no hsrp version 2', ' no hsrp delay minimum 5 reload 10', ' no hsrp 1', ' exit', ])) def test_cli_config4(self): # Apply configuration self.hsrp1.device_attr[self.dev1].enabled = True key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.version = 2 key.minimum_delay = 5 key.reload_delay = 10 key.group_number = 1 key.primary_ipv4_address = '192.168.1.1/24' key.priority = 110 key.preempt = True key.hello_sec = 1 key.hold_sec = 3 key.tracked_object = 1 key.tracked_object_priority_decrement = 20 key.authentication = 'xyz' # Build config cfgs = self.hsrp1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'feature hsrp', 'interface Ethernet2/1', ' hsrp version 2', ' hsrp delay minimum 5 reload 10', ' hsrp 1', ' authentication xyz', ' ip 192.168.1.1/24', ' preempt', ' priority 110', ' timers 1 3', ' track 1 decrement 20', ' exit', ' exit', ])) # Build unconfig cfgs = self.hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'no feature hsrp', 'interface Ethernet2/1', ' no hsrp version 2', ' no hsrp delay minimum 5 reload 10', ' no hsrp 1', ' exit', ])) def test_cli_config5(self): # Apply configuration self.hsrp1.device_attr[self.dev1].enabled = True key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.version = 2 key.minimum_delay = 5 key.group_number = 9 key.primary_ipv4_address = '192.168.1.1/24' key.priority = 110 key.preempt = True # Build config cfgs = self.hsrp1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'feature hsrp', 'interface Ethernet2/1', ' hsrp version 2', ' hsrp delay minimum 5', ' hsrp 9', ' ip 192.168.1.1/24', ' preempt', ' priority 110', ' exit', ' exit', ])) # Build unconfig cfgs = self.hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'no feature hsrp', 'interface Ethernet2/1', ' no hsrp version 2', ' no hsrp delay minimum 5', ' no hsrp 9', ' exit', ])) def test_cli_config6(self): # Apply configuration self.hsrp1.device_attr[self.dev1].enabled = True key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.version = 1 key.minimum_delay = 5 key.group_number = 9 key.virtual_ip_learn = True key.priority = 110 key.preempt = True # Build config cfgs = self.hsrp1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'feature hsrp', 'interface Ethernet2/1', ' hsrp delay minimum 5', ' hsrp 9', ' ip', ' preempt', ' priority 110', ' exit', ' exit', ])) # Build unconfig cfgs = self.hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'no feature hsrp', 'interface Ethernet2/1', ' no hsrp delay minimum 5', ' no hsrp 9', ' exit', ])) def test_cli_config_args(self): # create Hsrp conf by taking args hsrp1 = Hsrp(group_number=0, address_family='ipv6') # Apply configuration hsrp1.device_attr[self.dev1].enabled = True key = hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.version = 1 key.minimum_delay = 5 key.global_ipv6_address = '192:168::1:1:1/128' key.link_local_ipv6_address = 'fe80::1' key.hsrp_linklocal = 'auto' key.priority = 110 key.preempt = True # create Hsrp conf by taking args hsrp2 = Hsrp(group_number=0) # Apply configuration hsrp2.device_attr[self.dev1].enabled = True key = hsrp2.device_attr[self.dev1].interface_attr[self.intf1] key.version = 1 key.minimum_delay = 5 key.primary_ipv4_address = '192.168.1.1/24' key.priority = 110 key.preempt = True # Build config cfgs_1 = hsrp1.build_config( apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs_1[self.dev1.name]), '\n'.join([ 'feature hsrp', 'interface Ethernet2/1', ' hsrp delay minimum 5', ' hsrp 0 ipv6', ' ip 192:168::1:1:1/128', ' ip fe80::1', ' ip autoconfig', ' preempt', ' priority 110', ' exit', ' exit', ])) # Build unconfig cfgs_1 = hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs_1[self.dev1.name]), '\n'.join([ 'no feature hsrp', 'interface Ethernet2/1', ' no hsrp delay minimum 5', ' no hsrp 0 ipv6', ' exit', ])) cfgs_2 = hsrp2.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs_2[self.dev1.name]), '\n'.join([ 'feature hsrp', 'interface Ethernet2/1', ' hsrp delay minimum 5', ' hsrp 0', ' ip 192.168.1.1/24', ' preempt', ' priority 110', ' exit', ' exit', ])) # Build unconfig cfgs_2 = hsrp2.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs_2[self.dev1.name]), '\n'.join([ 'no feature hsrp', 'interface Ethernet2/1', ' no hsrp delay minimum 5', ' no hsrp 0', ' exit', ]))
def test_cli_config_args(self): # create Hsrp conf by taking args hsrp1 = Hsrp(group_number=0, address_family='ipv6') # Apply configuration hsrp1.device_attr[self.dev1].enabled = True key = hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.version = 1 key.minimum_delay = 5 key.global_ipv6_address = '192:168::1:1:1/128' key.link_local_ipv6_address = 'fe80::1' key.hsrp_linklocal = 'auto' key.priority = 110 key.preempt = True # create Hsrp conf by taking args hsrp2 = Hsrp(group_number=0) # Apply configuration hsrp2.device_attr[self.dev1].enabled = True key = hsrp2.device_attr[self.dev1].interface_attr[self.intf1] key.version = 1 key.minimum_delay = 5 key.primary_ipv4_address = '192.168.1.1/24' key.priority = 110 key.preempt = True # Build config cfgs_1 = hsrp1.build_config( apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs_1[self.dev1.name]), '\n'.join([ 'feature hsrp', 'interface Ethernet2/1', ' hsrp delay minimum 5', ' hsrp 0 ipv6', ' ip 192:168::1:1:1/128', ' ip fe80::1', ' ip autoconfig', ' preempt', ' priority 110', ' exit', ' exit', ])) # Build unconfig cfgs_1 = hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs_1[self.dev1.name]), '\n'.join([ 'no feature hsrp', 'interface Ethernet2/1', ' no hsrp delay minimum 5', ' no hsrp 0 ipv6', ' exit', ])) cfgs_2 = hsrp2.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs_2[self.dev1.name]), '\n'.join([ 'feature hsrp', 'interface Ethernet2/1', ' hsrp delay minimum 5', ' hsrp 0', ' ip 192.168.1.1/24', ' preempt', ' priority 110', ' exit', ' exit', ])) # Build unconfig cfgs_2 = hsrp2.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs_2[self.dev1.name]), '\n'.join([ 'no feature hsrp', 'interface Ethernet2/1', ' no hsrp delay minimum 5', ' no hsrp 0', ' exit', ]))
class test_hsrp(TestCase): def setUp(self): # Set Genie Tb testbed = Testbed() Genie.testbed = testbed # Device self.dev1 = Device(name='PE1', testbed=testbed, os='iosxe') # Interface self.intf1 = Interface(name='GigabitEthernet1/0/1', device=self.dev1) self.intf1.enabled = False self.intf1.switchport = False # Hsrp object self.hsrp1 = Hsrp() # Build config cfgs = self.intf1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface GigabitEthernet1/0/1', ' shutdown', ' no switchport', ' exit', ])) def test_cli_config1(self): # Apply configuration key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.version = 2 key.minimum_delay = 5 key.reload_delay = 10 key.group_number = 1 key.primary_ipv4_address = '192.168.1.254' key.priority = 110 key.preempt = True key.hello_sec = 1 key.hold_sec = 3 key.tracked_object = 1 key.tracked_object_priority_decrement = 20 key.authentication = 'cisco123' key.bfd_enabled = True key.mac_refresh = 11 key.follow = 'test' # Build config cfgs = self.hsrp1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'interface GigabitEthernet1/0/1', ' standby version 2', ' standby bfd', ' standby delay minimum 5 reload 10', ' standby mac-refresh 11', ' standby 1 authentication cisco123', ' standby 1 follow test', ' standby 1 ip 192.168.1.254', ' standby 1 preempt', ' standby 1 priority 110', ' standby 1 timers 1 3', ' standby 1 track 1 decrement 20', ' exit', ])) # Build unconfig cfgs = self.hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'interface GigabitEthernet1/0/1', ' no standby version 2', ' no standby bfd', ' no standby delay minimum 5 reload 10', ' no standby mac-refresh 11', ' no standby 1 authentication cisco123', ' no standby 1 follow test', ' no standby 1 ip 192.168.1.254', ' no standby 1 preempt', ' no standby 1 priority 110', ' no standby 1 timers 1 3', ' no standby 1 track 1 decrement 20', ' exit', ])) def test_cli_config2(self): # Apply configuration key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.version = 2 key.minimum_delay = 5 key.reload_delay = 10 key.group_number = 1 key.primary_ipv4_address = '192.168.1.254' key.secondary_ipv4_address = '192.168.1.253' key.priority = 110 key.preempt = True key.hello_sec = 1 key.hold_sec = 3 key.tracked_object = 1 key.tracked_object_priority_decrement = 20 key.authentication = 'cisco123' # Build config cfgs = self.hsrp1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'interface GigabitEthernet1/0/1', ' standby version 2', ' standby delay minimum 5 reload 10', ' standby 1 authentication cisco123', ' standby 1 ip 192.168.1.254', ' standby 1 ip 192.168.1.253 secondary', ' standby 1 preempt', ' standby 1 priority 110', ' standby 1 timers 1 3', ' standby 1 track 1 decrement 20', ' exit', ])) # Build unconfig cfgs = self.hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'interface GigabitEthernet1/0/1', ' no standby version 2', ' no standby delay minimum 5 reload 10', ' no standby 1 authentication cisco123', ' no standby 1 ip 192.168.1.254', ' no standby 1 ip 192.168.1.253 secondary', ' no standby 1 preempt', ' no standby 1 priority 110', ' no standby 1 timers 1 3', ' no standby 1 track 1 decrement 20', ' exit', ])) def test_cli_config3(self): # Apply configuration key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.version = 2 key.minimum_delay = 5 key.reload_delay = 10 key.group_number = 1 key.primary_ipv4_address = '192.168.1.254' key.priority = 110 key.preempt = True key.hello_sec = 1 key.hold_sec = 3 key.tracked_object = 1 key.tracked_object_priority_decrement = 20 key.authentication = 'abc' # Build config cfgs = self.hsrp1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'interface GigabitEthernet1/0/1', ' standby version 2', ' standby delay minimum 5 reload 10', ' standby 1 authentication abc', ' standby 1 ip 192.168.1.254', ' standby 1 preempt', ' standby 1 priority 110', ' standby 1 timers 1 3', ' standby 1 track 1 decrement 20', ' exit', ])) # Build unconfig cfgs = self.hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'interface GigabitEthernet1/0/1', ' no standby version 2', ' no standby delay minimum 5 reload 10', ' no standby 1 authentication abc', ' no standby 1 ip 192.168.1.254', ' no standby 1 preempt', ' no standby 1 priority 110', ' no standby 1 timers 1 3', ' no standby 1 track 1 decrement 20', ' exit', ])) def test_cli_config4(self): # Apply configuration key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.version = 2 key.minimum_delay = 5 key.reload_delay = 10 key.group_number = 1 key.primary_ipv4_address = '192.168.1.254' key.virtual_ip_learn = True key.priority = 110 key.preempt = True key.hello_sec = 1 key.hold_sec = 3 key.tracked_object = 1 key.tracked_object_priority_decrement = 20 key.authentication = 'xyz' # Build config cfgs = self.hsrp1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'interface GigabitEthernet1/0/1', ' standby version 2', ' standby delay minimum 5 reload 10', ' standby 1 authentication xyz', ' standby 1 ip 192.168.1.254', ' standby 1 ip', ' standby 1 preempt', ' standby 1 priority 110', ' standby 1 timers 1 3', ' standby 1 track 1 decrement 20', ' exit', ])) # Build unconfig cfgs = self.hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'interface GigabitEthernet1/0/1', ' no standby version 2', ' no standby delay minimum 5 reload 10', ' no standby 1 authentication xyz', ' no standby 1 ip 192.168.1.254', ' no standby 1 ip', ' no standby 1 preempt', ' no standby 1 priority 110', ' no standby 1 timers 1 3', ' no standby 1 track 1 decrement 20', ' exit', ])) def test_cli_config5(self): # Apply configuration key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.version = 2 key.address_family = 'ipv6' key.global_ipv6_address = '2001:db8::1/24' key.link_local_ipv6_address = 'fe80::1' key.hsrp_linklocal = 'auto' key.minimum_delay = 5 key.group_number = 15 key.priority = 110 key.preempt = True key.bfd_enabled = True key.use_bia = True key.hello_msec_flag = True key.hello_msec = 55 key.hold_msec_flag = True key.hold_msec = 100 key.tracked_object = 1 key.session_name = 'gandalf' key.virtual_mac_address = 'dead.beef.dead' key.redirects_disable = False # Build config cfgs = self.hsrp1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'interface GigabitEthernet1/0/1', ' standby version 2', ' standby bfd', ' standby delay minimum 5', ' standby use-bia', ' standby redirect', ' standby 15 ipv6 2001:db8::1/24', ' standby 15 ipv6 fe80::1', ' standby 15 ipv6 autoconfig', ' standby 15 mac-address dead.beef.dead', ' standby 15 name gandalf', ' standby 15 preempt', ' standby 15 priority 110', ' standby 15 timers msec 55 msec 100', ' standby 15 track 1', ' exit', ])) # Build unconfig cfgs = self.hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'interface GigabitEthernet1/0/1', ' no standby version 2', ' no standby bfd', ' no standby delay minimum 5', ' no standby use-bia', ' no standby redirect', ' no standby 15 ipv6 2001:db8::1/24', ' no standby 15 ipv6 fe80::1', ' no standby 15 ipv6 autoconfig', ' no standby 15 mac-address dead.beef.dead', ' no standby 15 name gandalf', ' no standby 15 preempt', ' no standby 15 priority 110', ' no standby 15 timers msec 55 msec 100', ' no standby 15 track 1', ' exit', ])) def test_cli_config6(self): # Hsrp object self.hsrp1 = Hsrp() # Apply configuration key1 = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key1.version = 2 key1.group_number = 10 key1.priority = 110 key1.preempt = True # Hsrp object self.hsrp2 = Hsrp() # Apply configuration key2 = self.hsrp2.device_attr[self.dev1].interface_attr[self.intf1] key2.group_number = 20 key2.priority = 120 key2.preempt = True # Build config cfgs1 = self.hsrp1.build_config(apply=False) cfgs2 = self.hsrp2.build_config(apply=False) cfgs = str(cfgs1[self.dev1.name]) + '\n' + str(cfgs2[self.dev1.name]) # Check config correctly unconfigured self.assertMultiLineEqual( cfgs, '\n'.join([ 'interface GigabitEthernet1/0/1\n' ' standby version 2\n' ' standby 10 preempt\n' ' standby 10 priority 110\n' ' exit\n' 'interface GigabitEthernet1/0/1\n' ' standby 20 preempt\n' ' standby 20 priority 120\n' ' exit' ]))
class test_hsrp_old(TestCase): def setUp(self): # Set Genie Tb testbed = Testbed() Genie.testbed = testbed # Device self.dev1 = Device(name='PE1', testbed=testbed, os='nxos') # Interface self.intf1 = Interface(name='Ethernet2/1', device=self.dev1) self.intf1.enabled = True self.intf1.switchport_enable = False # Hsrp object self.hsrp1 = Hsrp() # Build config cfgs = self.intf1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface Ethernet2/1', ' no shutdown', ' no switchport', ' exit', ])) def test_cli_config1(self): # Apply configuration self.hsrp1.device_attr[self.dev1].enabled = True key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.bfd = True key.version = 2 key.minimum_delay = 5 key.reload_delay = 10 key.use_bia = True key.group_number = 1 key.authentication_word = 'cisco123' key.ip_address = '192.168.1.1/24' key.mac_address = 'dead.beef.dead' key.group_name = 'gandalf' key.preempt = True key.preempt_minimum_delay = 5 key.preempt_reload_delay = 10 key.preempt_sync_delay = 20 key.priority = 110 key.hello_interval_seconds = 1 key.holdtime_seconds = 3 key.track_object = 1 key.priority_decrement = 20 # Build config cfgs = self.hsrp1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'feature hsrp', 'interface Ethernet2/1', ' hsrp bfd', ' hsrp version 2', ' hsrp delay minimum 5 reload 10', ' hsrp use-bia', ' hsrp 1', ' authentication cisco123', ' ip 192.168.1.1/24', ' mac-address dead.beef.dead', ' name gandalf', ' preempt delay minimum 5 reload 10 sync 20', ' priority 110', ' timers 1 3', ' track 1 decrement 20', ' exit', ' exit', ])) # Build unconfig cfgs = self.hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'no feature hsrp', 'interface Ethernet2/1', ' no hsrp bfd', ' no hsrp version 2', ' no hsrp delay minimum 5 reload 10', ' no hsrp use-bia', ' no hsrp 1', ' exit', ])) def test_cli_config2(self): # Apply configuration self.hsrp1.device_attr[self.dev1].enabled = True key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.version = 1 key.minimum_delay = 5 key.reload_delay = 10 key.group_number = 1 key.ip_address = '192.168.1.1/24' key.priority = 110 key.preempt = True key.preempt_minimum_delay = 5 key.preempt_reload_delay = 10 key.hello_interval_msec = 300 key.holdtime_msec = 500 key.track_object = 1 key.authentication_text = 'cisco123' # Build config cfgs = self.hsrp1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'feature hsrp', 'interface Ethernet2/1', ' hsrp delay minimum 5 reload 10', ' hsrp 1', ' authentication text cisco123', ' ip 192.168.1.1/24', ' preempt delay minimum 5 reload 10', ' priority 110', ' timers msec 300 msec 500', ' track 1', ' exit', ' exit', ])) # Build unconfig cfgs = self.hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'no feature hsrp', 'interface Ethernet2/1', ' no hsrp delay minimum 5 reload 10', ' no hsrp 1', ' exit', ])) def test_cli_config3(self): # Apply configuration self.hsrp1.device_attr[self.dev1].enabled = True key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.version = 2 key.minimum_delay = 5 key.reload_delay = 10 key.group_number = 1 key.ip_address = '192.168.1.1/24' key.priority = 110 key.preempt = True key.preempt_minimum_delay = 5 key.hello_interval_seconds = 1 key.holdtime_seconds = 3 key.track_object = 1 key.priority_decrement = 20 key.authentication_md5_keychain = 'abc' # Build config cfgs = self.hsrp1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'feature hsrp', 'interface Ethernet2/1', ' hsrp version 2', ' hsrp delay minimum 5 reload 10', ' hsrp 1', ' authentication md5 key-chain abc', ' ip 192.168.1.1/24', ' preempt delay minimum 5', ' priority 110', ' timers 1 3', ' track 1 decrement 20', ' exit', ' exit', ])) # Build unconfig cfgs = self.hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'no feature hsrp', 'interface Ethernet2/1', ' no hsrp version 2', ' no hsrp delay minimum 5 reload 10', ' no hsrp 1', ' exit', ])) def test_cli_config4(self): # Apply configuration self.hsrp1.device_attr[self.dev1].enabled = True key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.version = 2 key.minimum_delay = 5 key.reload_delay = 10 key.group_number = 1 key.ip_address = '192.168.1.1/24' key.priority = 110 key.preempt = True key.preempt_reload_delay = 10 key.hello_interval_seconds = 1 key.holdtime_seconds = 3 key.track_object = 1 key.priority_decrement = 20 key.authentication_md5_keystring = 'xyz' # Build config cfgs = self.hsrp1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'feature hsrp', 'interface Ethernet2/1', ' hsrp version 2', ' hsrp delay minimum 5 reload 10', ' hsrp 1', ' authentication md5 key-string xyz', ' ip 192.168.1.1/24', ' preempt delay reload 10', ' priority 110', ' timers 1 3', ' track 1 decrement 20', ' exit', ' exit', ])) # Build unconfig cfgs = self.hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'no feature hsrp', 'interface Ethernet2/1', ' no hsrp version 2', ' no hsrp delay minimum 5 reload 10', ' no hsrp 1', ' exit', ])) def test_cli_config5(self): # Apply configuration self.hsrp1.device_attr[self.dev1].enabled = True key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.version = 2 key.minimum_delay = 5 key.group_number = 9 key.ip_address = '192.168.1.1/24' key.priority = 110 key.preempt = True key.preempt_sync_delay = 10 # Build config cfgs = self.hsrp1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'feature hsrp', 'interface Ethernet2/1', ' hsrp version 2', ' hsrp delay minimum 5', ' hsrp 9', ' ip 192.168.1.1/24', ' preempt delay sync 10', ' priority 110', ' exit', ' exit', ])) # Build unconfig cfgs = self.hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'no feature hsrp', 'interface Ethernet2/1', ' no hsrp version 2', ' no hsrp delay minimum 5', ' no hsrp 9', ' exit', ])) def test_cli_config6(self): # Apply configuration self.hsrp1.device_attr[self.dev1].enabled = True key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.version = 1 key.minimum_delay = 5 key.group_number = 9 key.ip_address = '192.168.1.1/24' key.priority = 110 key.preempt = True # Build config cfgs = self.hsrp1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'feature hsrp', 'interface Ethernet2/1', ' hsrp delay minimum 5', ' hsrp 9', ' ip 192.168.1.1/24', ' preempt', ' priority 110', ' exit', ' exit', ])) # Build unconfig cfgs = self.hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'no feature hsrp', 'interface Ethernet2/1', ' no hsrp delay minimum 5', ' no hsrp 9', ' exit', ])) def test_cli_config_args(self): # create Hsrp conf by taking args hsrp1 = Hsrp(group_number=0, address_family='ipv6') # Apply configuration hsrp1.device_attr[self.dev1].enabled = True key = hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.version = 1 key.minimum_delay = 5 key.ip_address = '192:168::1:1:1/128' key.priority = 110 key.preempt = True # create Hsrp conf by taking args hsrp2 = Hsrp(group_number=0) # Apply configuration hsrp2.device_attr[self.dev1].enabled = True key = hsrp2.device_attr[self.dev1].interface_attr[self.intf1] key.version = 1 key.minimum_delay = 5 key.ip_address = '192.168.1.1/24' key.priority = 110 key.preempt = True # Build config cfgs_1 = hsrp1.build_config( apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs_1[self.dev1.name]), '\n'.join([ 'feature hsrp', 'interface Ethernet2/1', ' hsrp delay minimum 5', ' hsrp 0 ipv6', ' ipv6 192:168::1:1:1/128', ' preempt', ' priority 110', ' exit', ' exit', ])) # Build unconfig cfgs_1 = hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs_1[self.dev1.name]), '\n'.join([ 'no feature hsrp', 'interface Ethernet2/1', ' no hsrp delay minimum 5', ' no hsrp 0 ipv6', ' exit', ])) cfgs_2 = hsrp2.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs_2[self.dev1.name]), '\n'.join([ 'feature hsrp', 'interface Ethernet2/1', ' hsrp delay minimum 5', ' hsrp 0', ' ip 192.168.1.1/24', ' preempt', ' priority 110', ' exit', ' exit', ])) # Build unconfig cfgs_2 = hsrp2.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs_2[self.dev1.name]), '\n'.join([ 'no feature hsrp', 'interface Ethernet2/1', ' no hsrp delay minimum 5', ' no hsrp 0', ' exit', ]))
class test_hsrp_old(TestCase): def setUp(self): # Set Genie Tb testbed = Testbed() Genie.testbed = testbed # Device self.dev1 = Device(name='PE1', testbed=testbed, os='iosxe') # Interface self.intf1 = Interface(name='GigabitEthernet1/0/1', device=self.dev1) self.intf1.shutdown = False self.intf1.switchport = False # Hsrp object self.hsrp1 = Hsrp() # Build config cfgs = self.intf1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface GigabitEthernet1/0/1', ' no shutdown', ' no switchport', ' exit', ])) def test_cli_config1(self): # Apply configuration key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.version = 2 key.minimum_delay = 5 key.reload_delay = 10 key.group_number = 1 key.ip_address = '192.168.1.254' key.priority = 110 key.preempt = True key.preempt_minimum_delay = 5 key.preempt_reload_delay = 10 key.preempt_sync_delay = 20 key.hello_interval_seconds = 1 key.holdtime_seconds = 3 key.track_object = 1 key.priority_decrement = 20 key.authentication_word = 'cisco123' key.bfd = True key.mac_refresh = 11 key.follow = 'test' # Build config cfgs = self.hsrp1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'interface GigabitEthernet1/0/1', ' standby version 2', ' standby bfd', ' standby delay minimum 5 reload 10', ' standby mac-refresh 11', ' standby 1 authentication cisco123', ' standby 1 follow test', ' standby 1 ip 192.168.1.254', ' standby 1 preempt delay minimum 5 reload 10 sync 20', ' standby 1 priority 110', ' standby 1 timers 1 3', ' standby 1 track 1 decrement 20', ' exit', ])) # Build unconfig cfgs = self.hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'interface GigabitEthernet1/0/1', ' no standby version 2', ' no standby bfd', ' no standby delay minimum 5 reload 10', ' no standby mac-refresh 11', ' no standby 1 authentication cisco123', ' no standby 1 follow test', ' no standby 1 ip 192.168.1.254', ' no standby 1 preempt delay minimum 5 reload 10 sync 20', ' no standby 1 priority 110', ' no standby 1 timers 1 3', ' no standby 1 track 1 decrement 20', ' exit', ])) def test_cli_config2(self): # Apply configuration key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.version = 2 key.minimum_delay = 5 key.reload_delay = 10 key.group_number = 1 key.ip_address = '192.168.1.254' key.priority = 110 key.preempt = True key.preempt_minimum_delay = 5 key.preempt_reload_delay = 10 key.hello_interval_seconds = 1 key.holdtime_seconds = 3 key.track_object = 1 key.priority_decrement = 20 key.authentication_text = 'cisco123' # Build config cfgs = self.hsrp1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'interface GigabitEthernet1/0/1', ' standby version 2', ' standby delay minimum 5 reload 10', ' standby 1 authentication text cisco123', ' standby 1 ip 192.168.1.254', ' standby 1 preempt delay minimum 5 reload 10', ' standby 1 priority 110', ' standby 1 timers 1 3', ' standby 1 track 1 decrement 20', ' exit', ])) # Build unconfig cfgs = self.hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'interface GigabitEthernet1/0/1', ' no standby version 2', ' no standby delay minimum 5 reload 10', ' no standby 1 authentication text cisco123', ' no standby 1 ip 192.168.1.254', ' no standby 1 preempt delay minimum 5 reload 10', ' no standby 1 priority 110', ' no standby 1 timers 1 3', ' no standby 1 track 1 decrement 20', ' exit', ])) def test_cli_config3(self): # Apply configuration key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.version = 2 key.minimum_delay = 5 key.reload_delay = 10 key.group_number = 1 key.ip_address = '192.168.1.254' key.priority = 110 key.preempt = True key.preempt_minimum_delay = 5 key.hello_interval_seconds = 1 key.holdtime_seconds = 3 key.track_object = 1 key.priority_decrement = 20 key.authentication_md5_keychain = 'abc' # Build config cfgs = self.hsrp1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'interface GigabitEthernet1/0/1', ' standby version 2', ' standby delay minimum 5 reload 10', ' standby 1 authentication md5 key-chain abc', ' standby 1 ip 192.168.1.254', ' standby 1 preempt delay minimum 5', ' standby 1 priority 110', ' standby 1 timers 1 3', ' standby 1 track 1 decrement 20', ' exit', ])) # Build unconfig cfgs = self.hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'interface GigabitEthernet1/0/1', ' no standby version 2', ' no standby delay minimum 5 reload 10', ' no standby 1 authentication md5 key-chain abc', ' no standby 1 ip 192.168.1.254', ' no standby 1 preempt delay minimum 5', ' no standby 1 priority 110', ' no standby 1 timers 1 3', ' no standby 1 track 1 decrement 20', ' exit', ])) def test_cli_config4(self): # Apply configuration key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.version = 2 key.minimum_delay = 5 key.reload_delay = 10 key.group_number = 1 key.ip_address = '192.168.1.254' key.priority = 110 key.preempt = True key.preempt_minimum_delay = 5 key.preempt_reload_delay = 10 key.hello_interval_seconds = 1 key.holdtime_seconds = 3 key.track_object = 1 key.priority_decrement = 20 key.authentication_md5_keystring = 'xyz' # Build config cfgs = self.hsrp1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'interface GigabitEthernet1/0/1', ' standby version 2', ' standby delay minimum 5 reload 10', ' standby 1 authentication md5 key-string xyz', ' standby 1 ip 192.168.1.254', ' standby 1 preempt delay minimum 5 reload 10', ' standby 1 priority 110', ' standby 1 timers 1 3', ' standby 1 track 1 decrement 20', ' exit', ])) # Build unconfig cfgs = self.hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'interface GigabitEthernet1/0/1', ' no standby version 2', ' no standby delay minimum 5 reload 10', ' no standby 1 authentication md5 key-string xyz', ' no standby 1 ip 192.168.1.254', ' no standby 1 preempt delay minimum 5 reload 10', ' no standby 1 priority 110', ' no standby 1 timers 1 3', ' no standby 1 track 1 decrement 20', ' exit', ])) def test_cli_config5(self): # Apply configuration key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.version = 2 key.minimum_delay = 5 key.group_number = 15 key.priority = 110 key.preempt = True key.bfd = True key.use_bia = True key.hello_interval_msec = 55 key.holdtime_msec = 100 key.track_object = 1 key.track_shutdown = True key.group_name = 'gandalf' key.mac_address = 'dead.beef.dead' key.redirect = True # Build config cfgs = self.hsrp1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'interface GigabitEthernet1/0/1', ' standby version 2', ' standby bfd', ' standby delay minimum 5', ' standby use-bia', ' standby redirect', ' standby 15 mac-address dead.beef.dead', ' standby 15 name gandalf', ' standby 15 preempt', ' standby 15 priority 110', ' standby 15 timers msec 55 msec 100', ' standby 15 track 1 shutdown', ' exit', ])) # Build unconfig cfgs = self.hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'interface GigabitEthernet1/0/1', ' no standby version 2', ' no standby bfd', ' no standby delay minimum 5', ' no standby use-bia', ' no standby redirect', ' no standby 15 mac-address dead.beef.dead', ' no standby 15 name gandalf', ' no standby 15 preempt', ' no standby 15 priority 110', ' no standby 15 timers msec 55 msec 100', ' no standby 15 track 1 shutdown', ' exit', ])) def test_cli_config6(self): # Hsrp object self.hsrp1 = Hsrp() # Apply configuration key1 = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key1.version = 2 key1.group_number = 10 key1.priority = 110 key1.preempt = True key1.preempt_reload_delay = 30 # Hsrp object self.hsrp2 = Hsrp() # Apply configuration key2 = self.hsrp2.device_attr[self.dev1].interface_attr[self.intf1] key2.group_number = 20 key2.priority = 120 key2.preempt = True key2.preempt_sync_delay = 60 # Build config cfgs1 = self.hsrp1.build_config(apply=False) cfgs2 = self.hsrp2.build_config(apply=False) cfgs = str(cfgs1[self.dev1.name]) + '\n' + str(cfgs2[self.dev1.name]) # Check config correctly unconfigured self.assertMultiLineEqual( cfgs, '\n'.join([ 'interface GigabitEthernet1/0/1\n' ' standby version 2\n' ' standby 10 preempt delay reload 30\n' ' standby 10 priority 110\n' ' exit\n' 'interface GigabitEthernet1/0/1\n' ' standby 20 preempt delay sync 60\n' ' standby 20 priority 120\n' ' exit' ]))
def test_cli_config_args(self): # create Hsrp conf by taking args hsrp1 = Hsrp(group_number=5, address_family='ipv6') # Apply configuration key = hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.hsrp_linklocal = 'auto' key.priority = 110 key.preempt = True key.virtual_ip_learn = True key.hello_msec_flag = True key.hello_msec = 300 key.hold_msec_flag = True key.hold_msec = 500 # Build config cfgs = hsrp1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'router hsrp', 'interface GigabitEthernet0/0/0/1', ' address-family ipv6', ' hsrp 5', ' address learn', ' address linklocal autoconfig', ' preempt', ' priority 110', ' timers msec 300 msec 500', ' exit', ' exit', ' exit', ])) # Build unconfig cfgs = hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'no router hsrp', 'interface GigabitEthernet0/0/0/1', ' no address-family ipv6', ' exit', ])) # create Ipv4 Hsrp conf by taking args hsrp2 = Hsrp(group_number=5) # Apply configuration key = hsrp2.device_attr[self.dev1].interface_attr[self.intf1] key.priority = 110 key.preempt = True key.hello_msec_flag = True key.hello_msec = 400 key.hold_msec_flag = True key.hold_msec = 500 key.follow = 'group10' # Build config cfgs = hsrp2.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'router hsrp', 'interface GigabitEthernet0/0/0/1', ' address-family ipv4', ' hsrp 5', ' slave follow group10', ' preempt', ' priority 110', ' timers msec 400 msec 500', ' exit', ' exit', ' exit', ])) # Build unconfig cfgs = hsrp2.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'no router hsrp', 'interface GigabitEthernet0/0/0/1', ' no address-family ipv4', ' exit', ]))
class test_hsrp(TestCase): def setUp(self): # Set Genie Tb testbed = Testbed() Genie.testbed = testbed # Device self.dev1 = Device(name='PE1', testbed=testbed, os='iosxr') # Interface self.intf1 = Interface(name='GigabitEthernet0/0/0/1', device=self.dev1) self.intf1.shutdown = False # Hsrp object self.hsrp1 = Hsrp() # Build config cfgs = self.intf1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface GigabitEthernet0/0/0/1', ' no shutdown', ' exit', ])) def test_cli_config1(self): # Apply configuration key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.bfd_interval = 30 key.bfd_detection_multiplier = 50 key.bfd_address = '192.168.1.2' key.bfd_interface_name = 'GigabitEthernet0/0/0/1' key.minimum_delay = 5 key.reload_delay = 10 key.mac_refresh = 20 key.use_bia = True key.redirects_disable = True key.address_family = 'ipv4' key.version = 2 key.group_number = 30 key.primary_ipv4_address = '192.168.1.254' key.secondary_ipv4_address = '192.168.1.253' key.authentication = 'cisco123' key.bfd_enabled = True key.virtual_mac_address = 'dead.beef.dead' key.session_name = 'gandalf' key.preempt = True key.priority = 110 key.hello_sec = 1 key.hold_sec = 3 key.tracked_object = 1 key.tracked_object_priority_decrement = 20 key.state_change_disable = True # Build config cfgs = self.hsrp1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'router hsrp', 'message state disable', 'interface GigabitEthernet0/0/0/1', ' hsrp bfd minimum-interval 30', ' hsrp bfd multiplier 50', ' hsrp delay minimum 5 reload 10', ' hsrp use-bia', ' hsrp redirect disable', ' hsrp mac-refresh 20', ' address-family ipv4', ' hsrp version 2', ' hsrp bfd fast-detect peer 192.168.1.2 GigabitEthernet0/0/0/1', ' hsrp 30', ' address 192.168.1.254', ' address 192.168.1.253 secondary', ' authentication cisco123', ' bfd fast-detect', ' mac-address dead.beef.dead', ' name gandalf', ' preempt', ' priority 110', ' timers 1 3', ' track object 1 20', ' exit', ' exit', ' exit', ])) # Build unconfig cfgs = self.hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'no router hsrp', 'no message state disable', 'interface GigabitEthernet0/0/0/1', ' no hsrp bfd minimum-interval 30', ' no hsrp bfd multiplier 50', ' no hsrp delay minimum 5 reload 10', ' no hsrp use-bia', ' no hsrp redirect disable', ' no hsrp mac-refresh 20', ' no address-family ipv4', ' exit', ])) def test_cli_config2(self): # Apply configuration key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.address_family = 'ipv6' key.global_ipv6_address = '2001:db8:1:1::254/64' key.link_local_ipv6_address = 'fe80::205:73ff:fea0:19' key.group_number = 5 key.priority = 110 key.preempt = True key.hello_msec_flag = True key.hello_msec = 300 key.hold_msec_flag = True key.hold_msec = 500 key.tracked_interface = 'GigabitEthernet0/0/0/0' key.tracked_intf_priority_decrement = 20 # Build config cfgs = self.hsrp1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'router hsrp', 'interface GigabitEthernet0/0/0/1', ' address-family ipv6', ' hsrp 5', ' address global 2001:db8:1:1::254/64', ' address linklocal fe80::205:73ff:fea0:19', ' preempt', ' priority 110', ' timers msec 300 msec 500', ' track GigabitEthernet0/0/0/0 20', ' exit', ' exit', ' exit', ])) # Build unconfig cfgs = self.hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'no router hsrp', 'interface GigabitEthernet0/0/0/1', ' no address-family ipv6', ' exit', ])) def test_cli_config_args(self): # create Hsrp conf by taking args hsrp1 = Hsrp(group_number=5, address_family='ipv6') # Apply configuration key = hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.hsrp_linklocal = 'auto' key.priority = 110 key.preempt = True key.virtual_ip_learn = True key.hello_msec_flag = True key.hello_msec = 300 key.hold_msec_flag = True key.hold_msec = 500 # Build config cfgs = hsrp1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'router hsrp', 'interface GigabitEthernet0/0/0/1', ' address-family ipv6', ' hsrp 5', ' address learn', ' address linklocal autoconfig', ' preempt', ' priority 110', ' timers msec 300 msec 500', ' exit', ' exit', ' exit', ])) # Build unconfig cfgs = hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'no router hsrp', 'interface GigabitEthernet0/0/0/1', ' no address-family ipv6', ' exit', ])) # create Ipv4 Hsrp conf by taking args hsrp2 = Hsrp(group_number=5) # Apply configuration key = hsrp2.device_attr[self.dev1].interface_attr[self.intf1] key.priority = 110 key.preempt = True key.hello_msec_flag = True key.hello_msec = 400 key.hold_msec_flag = True key.hold_msec = 500 key.follow = 'group10' # Build config cfgs = hsrp2.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'router hsrp', 'interface GigabitEthernet0/0/0/1', ' address-family ipv4', ' hsrp 5', ' slave follow group10', ' preempt', ' priority 110', ' timers msec 400 msec 500', ' exit', ' exit', ' exit', ])) # Build unconfig cfgs = hsrp2.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'no router hsrp', 'interface GigabitEthernet0/0/0/1', ' no address-family ipv4', ' exit', ]))
class test_hsrp_old(TestCase): def setUp(self): # Set Genie Tb testbed = Testbed() Genie.testbed = testbed # Device self.dev1 = Device(name='PE1', testbed=testbed, os='iosxr') # Interface self.intf1 = Interface(name='GigabitEthernet0/0/0/1', device=self.dev1) self.intf1.shutdown = False # Hsrp object self.hsrp1 = Hsrp() # Build config cfgs = self.intf1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface GigabitEthernet0/0/0/1', ' no shutdown', ' exit', ])) def test_cli_config1(self): # Apply configuration key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.bfd_min_interval = 30 key.bfd_multiplier = 50 key.minimum_delay = 5 key.reload_delay = 10 key.mac_refresh = 20 key.use_bia = True key.redirect = True key.address_family = 'ipv4' key.version = 2 key.group_number = 30 key.ip_address = '192.168.1.254' key.authentication_word = 'cisco123' key.bfd_fast_detect = True key.mac_address = 'dead.beef.dead' key.group_name = 'gandalf' key.preempt = True key.preempt_minimum_delay = 5 key.priority = 110 key.hello_interval_seconds = 1 key.holdtime_seconds = 3 key.track_object = 1 key.priority_decrement = 20 # Build config cfgs = self.hsrp1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'router hsrp', 'interface GigabitEthernet0/0/0/1', ' hsrp bfd minimum-interval 30', ' hsrp bfd multiplier 50', ' hsrp delay minimum 5 reload 10', ' hsrp use-bia', ' hsrp redirect disable', ' hsrp mac-refresh 20', ' address-family ipv4', ' hsrp version 2', ' hsrp 30', ' address 192.168.1.254', ' authentication cisco123', ' bfd fast-detect', ' mac-address dead.beef.dead', ' name gandalf', ' preempt delay 5', ' priority 110', ' timers 1 3', ' track object 1 20', ' exit', ' exit', ' exit', ])) # Build unconfig cfgs = self.hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'no router hsrp', 'interface GigabitEthernet0/0/0/1', ' no hsrp bfd minimum-interval 30', ' no hsrp bfd multiplier 50', ' no hsrp delay minimum 5 reload 10', ' no hsrp use-bia', ' no hsrp redirect disable', ' no hsrp mac-refresh 20', ' no address-family ipv4', ' exit', ])) def test_cli_config2(self): # Apply configuration key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.address_family = 'ipv6' key.group_number = 5 key.priority = 110 key.preempt = True key.hello_interval_msec = 300 key.holdtime_msec = 500 # Build config cfgs = self.hsrp1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'router hsrp', 'interface GigabitEthernet0/0/0/1', ' address-family ipv6', ' hsrp 5', ' preempt', ' priority 110', ' timers msec 300 msec 500', ' exit', ' exit', ' exit', ])) # Build unconfig cfgs = self.hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'no router hsrp', 'interface GigabitEthernet0/0/0/1', ' no address-family ipv6', ' exit', ])) def test_cli_config_args(self): # create Hsrp conf by taking args hsrp1 = Hsrp(group_number=5, address_family='ipv6') # Apply configuration key = hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.priority = 110 key.preempt = True key.hello_interval_msec = 300 key.holdtime_msec = 500 # Build config cfgs = hsrp1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'router hsrp', 'interface GigabitEthernet0/0/0/1', ' address-family ipv6', ' hsrp 5', ' preempt', ' priority 110', ' timers msec 300 msec 500', ' exit', ' exit', ' exit', ])) # Build unconfig cfgs = hsrp1.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'no router hsrp', 'interface GigabitEthernet0/0/0/1', ' no address-family ipv6', ' exit', ])) # create Ipv4 Hsrp conf by taking args hsrp2 = Hsrp(group_number=5) # Apply configuration key = hsrp2.device_attr[self.dev1].interface_attr[self.intf1] key.priority = 110 key.preempt = True key.hello_interval_msec = 300 key.holdtime_msec = 500 # Build config cfgs = hsrp2.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'router hsrp', 'interface GigabitEthernet0/0/0/1', ' address-family ipv4', ' hsrp 5', ' preempt', ' priority 110', ' timers msec 300 msec 500', ' exit', ' exit', ' exit', ])) # Build unconfig cfgs = hsrp2.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'no router hsrp', 'interface GigabitEthernet0/0/0/1', ' no address-family ipv4', ' exit', ]))
class test_hsrp(TestCase): def setUp(self): # Set Genie Tb self.testbed = Testbed() Genie.testbed = self.testbed # Device self.dev1 = Device(name='PE1', testbed=self.testbed, os='iosxe', context='yang') # Interface self.intf1 = Interface(name='GigabitEthernet1/0/1', device=self.dev1) self.intf1.shutdown = False self.intf1.switchport = False # Hsrp object self.hsrp1 = Hsrp() # Build config cfgs = self.intf1.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface GigabitEthernet1/0/1', ' no shutdown', ' no switchport', ' exit', ])) def test_yang_config1(self): # Apply configuration key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.version = 2 key.minimum_delay = 5 key.reload_delay = 10 key.group_number = 25 key.ip_address = '192.168.1.254' key.priority = 110 key.preempt = True key.preempt_minimum_delay = 5 key.preempt_reload_delay = 10 key.preempt_sync_delay = 20 key.hello_interval_seconds = 1 key.holdtime_seconds = 3 key.track_object = 1 key.priority_decrement = 20 key.authentication_word = 'cisco123' key.bfd = True key.mac_refresh = 11 key.follow = 'test' for dev in self.testbed.devices: dev.connections = Mock() dev.connections = {'netconf': NetconfConnectionInfo()} # Build config build_cfgs = self.hsrp1.build_config(apply=False) compare1 = "" for i in build_cfgs['PE1']: compare1 += str(i) self.assertMultiLineEqual( compare1, '\n'.join([ '<edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">\n' ' <target>\n' ' <running></running>\n' ' </target>\n' ' <config>\n' ' <GigabitEthernet xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">\n' ' <name></name>\n' ' <standby>\n' ' <bfd></bfd>\n' ' <delay>\n' ' <minimum>5</minimum>\n' ' <reload>10</reload>\n' ' </delay>\n' ' <mac-refresh>11</mac-refresh>\n' ' <standby-list>\n' ' <group-number>25</group-number>\n' ' <authentication>\n' ' <word>cisco123</word>\n' ' </authentication>\n' ' <follow>test</follow>\n' ' <ip>\n' ' <address>192.168.1.254</address>\n' ' </ip>\n' ' <preempt>\n' ' <delay>\n' ' <minimum>5</minimum>\n' ' <reload>10</reload>\n' ' <sync>20</sync>\n' ' </delay>\n' ' </preempt>\n' ' <priority>110</priority>\n' ' <timers>\n' ' <hello-interval>\n' ' <seconds>1</seconds>\n' ' </hello-interval>\n' ' <hold-time>\n' ' <seconds>3</seconds>\n' ' </hold-time>\n' ' </timers>\n' ' <track>\n' ' <number>1</number>\n' ' <decrement>20</decrement>\n' ' </track>\n' ' </standby-list>\n' ' <version>2</version>\n' ' </standby>\n' ' </GigabitEthernet>\n' ' </config>\n' '</edit-config>\n' ])) # Build config build_uncfgs = self.hsrp1.build_unconfig(apply=False) compare2 = "" for i in build_uncfgs['PE1']: compare2 += str(i) self.assertMultiLineEqual( compare2, '\n'.join([ '<edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">\n' ' <target>\n' ' <running></running>\n' ' </target>\n' ' <config>\n' ' <GigabitEthernet xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">\n' ' <name></name>\n' ' <standby>\n' ' <bfd></bfd>\n' ' <delay>\n' ' <minimum>5</minimum>\n' ' <reload>10</reload>\n' ' </delay>\n' ' <mac-refresh>11</mac-refresh>\n' ' <standby-list>\n' ' <group-number>25</group-number>\n' ' <authentication>\n' ' <word>cisco123</word>\n' ' </authentication>\n' ' <follow>test</follow>\n' ' <ip>\n' ' <address>192.168.1.254</address>\n' ' </ip>\n' ' <preempt>\n' ' <delay>\n' ' <minimum>5</minimum>\n' ' <reload>10</reload>\n' ' <sync>20</sync>\n' ' </delay>\n' ' </preempt>\n' ' <priority>110</priority>\n' ' <timers>\n' ' <hello-interval>\n' ' <seconds>1</seconds>\n' ' </hello-interval>\n' ' <hold-time>\n' ' <seconds>3</seconds>\n' ' </hold-time>\n' ' </timers>\n' ' <track>\n' ' <number>1</number>\n' ' <decrement>20</decrement>\n' ' </track>\n' ' </standby-list>\n' ' <version>2</version>\n' ' </standby>\n' ' </GigabitEthernet>\n' ' </config>\n' '</edit-config>\n' ])) def test_yang_config2(self): # Apply configuration key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.version = 1 key.minimum_delay = 5 key.reload_delay = 10 key.group_number = 25 key.ip_address = '192.168.1.254' key.priority = 110 key.preempt = True key.preempt_minimum_delay = 5 key.preempt_reload_delay = 10 key.hello_interval_seconds = 1 key.holdtime_seconds = 3 key.track_object = 1 key.priority_decrement = 20 key.authentication_text = 'cisco123' # Build config build_cfgs = self.hsrp1.build_config(apply=False) compare1 = "" for i in build_cfgs['PE1']: compare1 += str(i) # Check config built correctly self.assertMultiLineEqual( compare1, '\n'.join([ '<edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">\n' ' <target>\n' ' <running></running>\n' ' </target>\n' ' <config>\n' ' <GigabitEthernet xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">\n' ' <name></name>\n' ' <standby>\n' ' <delay>\n' ' <minimum>5</minimum>\n' ' <reload>10</reload>\n' ' </delay>\n' ' <standby-list>\n' ' <group-number>25</group-number>\n' ' <authentication>\n' ' <word>cisco123</word>\n' ' </authentication>\n' ' <ip>\n' ' <address>192.168.1.254</address>\n' ' </ip>\n' ' <preempt>\n' ' <delay>\n' ' <minimum>5</minimum>\n' ' <reload>10</reload>\n' ' </delay>\n' ' </preempt>\n' ' <priority>110</priority>\n' ' <timers>\n' ' <hello-interval>\n' ' <seconds>1</seconds>\n' ' </hello-interval>\n' ' <hold-time>\n' ' <seconds>3</seconds>\n' ' </hold-time>\n' ' </timers>\n' ' <track>\n' ' <number>1</number>\n' ' <decrement>20</decrement>\n' ' </track>\n' ' </standby-list>\n' ' <version>1</version>\n' ' </standby>\n' ' </GigabitEthernet>\n' ' </config>\n' '</edit-config>\n' ])) # Build unconfig build_uncfgs = self.hsrp1.build_unconfig(apply=False) compare2 = "" for i in build_uncfgs['PE1']: compare2 += str(i) # Check config built correctly self.assertMultiLineEqual( compare2, '\n'.join([ '<edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">\n' ' <target>\n' ' <running></running>\n' ' </target>\n' ' <config>\n' ' <GigabitEthernet xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">\n' ' <name></name>\n' ' <standby>\n' ' <delay>\n' ' <minimum>5</minimum>\n' ' <reload>10</reload>\n' ' </delay>\n' ' <standby-list>\n' ' <group-number>25</group-number>\n' ' <authentication>\n' ' <word>cisco123</word>\n' ' </authentication>\n' ' <ip>\n' ' <address>192.168.1.254</address>\n' ' </ip>\n' ' <preempt>\n' ' <delay>\n' ' <minimum>5</minimum>\n' ' <reload>10</reload>\n' ' </delay>\n' ' </preempt>\n' ' <priority>110</priority>\n' ' <timers>\n' ' <hello-interval>\n' ' <seconds>1</seconds>\n' ' </hello-interval>\n' ' <hold-time>\n' ' <seconds>3</seconds>\n' ' </hold-time>\n' ' </timers>\n' ' <track>\n' ' <number>1</number>\n' ' <decrement>20</decrement>\n' ' </track>\n' ' </standby-list>\n' ' <version>1</version>\n' ' </standby>\n' ' </GigabitEthernet>\n' ' </config>\n' '</edit-config>\n' ])) def test_yang_config3(self): # Apply configuration key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.version = 2 key.minimum_delay = 5 key.reload_delay = 10 key.group_number = 25 key.ip_address = '192.168.1.254' key.priority = 110 key.preempt = True key.preempt_minimum_delay = 5 key.hello_interval_seconds = 1 key.holdtime_seconds = 3 key.track_object = 1 key.priority_decrement = 20 key.authentication_md5_keychain = 'abc' # Build config build_cfgs = self.hsrp1.build_config(apply=False) compare1 = "" for i in build_cfgs['PE1']: compare1 += str(i) # Check config built correctly self.assertMultiLineEqual( compare1, '\n'.join([ '<edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">\n' ' <target>\n' ' <running></running>\n' ' </target>\n' ' <config>\n' ' <GigabitEthernet xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">\n' ' <name></name>\n' ' <standby>\n' ' <delay>\n' ' <minimum>5</minimum>\n' ' <reload>10</reload>\n' ' </delay>\n' ' <standby-list>\n' ' <group-number>25</group-number>\n' ' <authentication>\n' ' <md5>\n' ' <key-chain>abc</key-chain>\n' ' </md5>\n' ' </authentication>\n' ' <ip>\n' ' <address>192.168.1.254</address>\n' ' </ip>\n' ' <preempt>\n' ' <delay>\n' ' <minimum>5</minimum>\n' ' </delay>\n' ' </preempt>\n' ' <priority>110</priority>\n' ' <timers>\n' ' <hello-interval>\n' ' <seconds>1</seconds>\n' ' </hello-interval>\n' ' <hold-time>\n' ' <seconds>3</seconds>\n' ' </hold-time>\n' ' </timers>\n' ' <track>\n' ' <number>1</number>\n' ' <decrement>20</decrement>\n' ' </track>\n' ' </standby-list>\n' ' <version>2</version>\n' ' </standby>\n' ' </GigabitEthernet>\n' ' </config>\n' '</edit-config>\n' ])) # Build unconfig build_uncfgs = self.hsrp1.build_unconfig(apply=False) compare2 = "" for i in build_uncfgs['PE1']: compare2 += str(i) # Check config built correctly self.assertMultiLineEqual( compare2, '\n'.join([ '<edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">\n' ' <target>\n' ' <running></running>\n' ' </target>\n' ' <config>\n' ' <GigabitEthernet xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">\n' ' <name></name>\n' ' <standby>\n' ' <delay>\n' ' <minimum>5</minimum>\n' ' <reload>10</reload>\n' ' </delay>\n' ' <standby-list>\n' ' <group-number>25</group-number>\n' ' <authentication>\n' ' <md5>\n' ' <key-chain>abc</key-chain>\n' ' </md5>\n' ' </authentication>\n' ' <ip>\n' ' <address>192.168.1.254</address>\n' ' </ip>\n' ' <preempt>\n' ' <delay>\n' ' <minimum>5</minimum>\n' ' </delay>\n' ' </preempt>\n' ' <priority>110</priority>\n' ' <timers>\n' ' <hello-interval>\n' ' <seconds>1</seconds>\n' ' </hello-interval>\n' ' <hold-time>\n' ' <seconds>3</seconds>\n' ' </hold-time>\n' ' </timers>\n' ' <track>\n' ' <number>1</number>\n' ' <decrement>20</decrement>\n' ' </track>\n' ' </standby-list>\n' ' <version>2</version>\n' ' </standby>\n' ' </GigabitEthernet>\n' ' </config>\n' '</edit-config>\n' ])) def test_yang_config4(self): # Apply configuration key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.version = 1 key.minimum_delay = 5 key.reload_delay = 10 key.group_number = 25 key.ip_address = '192.168.1.254' key.priority = 110 key.preempt = True key.preempt_minimum_delay = 5 key.preempt_reload_delay = 10 key.hello_interval_seconds = 1 key.holdtime_seconds = 3 key.track_object = 1 key.priority_decrement = 20 key.authentication_md5_keystring = 'xyz' # Build config build_cfgs = self.hsrp1.build_config(apply=False) compare1 = "" for i in build_cfgs['PE1']: compare1 += str(i) # Check config built correctly self.assertMultiLineEqual( compare1, '\n'.join([ '<edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">\n' ' <target>\n' ' <running></running>\n' ' </target>\n' ' <config>\n' ' <GigabitEthernet xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">\n' ' <name></name>\n' ' <standby>\n' ' <delay>\n' ' <minimum>5</minimum>\n' ' <reload>10</reload>\n' ' </delay>\n' ' <standby-list>\n' ' <group-number>25</group-number>\n' ' <authentication>\n' ' <md5>\n' ' <key-string>\n' ' <string>xyz</string>\n' ' </key-string>\n' ' </md5>\n' ' </authentication>\n' ' <ip>\n' ' <address>192.168.1.254</address>\n' ' </ip>\n' ' <preempt>\n' ' <delay>\n' ' <minimum>5</minimum>\n' ' <reload>10</reload>\n' ' </delay>\n' ' </preempt>\n' ' <priority>110</priority>\n' ' <timers>\n' ' <hello-interval>\n' ' <seconds>1</seconds>\n' ' </hello-interval>\n' ' <hold-time>\n' ' <seconds>3</seconds>\n' ' </hold-time>\n' ' </timers>\n' ' <track>\n' ' <number>1</number>\n' ' <decrement>20</decrement>\n' ' </track>\n' ' </standby-list>\n' ' <version>1</version>\n' ' </standby>\n' ' </GigabitEthernet>\n' ' </config>\n' '</edit-config>\n' ])) # Build unconfig build_uncfgs = self.hsrp1.build_unconfig(apply=False) compare2 = "" for i in build_uncfgs['PE1']: compare2 += str(i) # Check config built correctly self.assertMultiLineEqual( compare2, '\n'.join([ '<edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">\n' ' <target>\n' ' <running></running>\n' ' </target>\n' ' <config>\n' ' <GigabitEthernet xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">\n' ' <name></name>\n' ' <standby>\n' ' <delay>\n' ' <minimum>5</minimum>\n' ' <reload>10</reload>\n' ' </delay>\n' ' <standby-list>\n' ' <group-number>25</group-number>\n' ' <authentication>\n' ' <md5>\n' ' <key-string>\n' ' <string>xyz</string>\n' ' </key-string>\n' ' </md5>\n' ' </authentication>\n' ' <ip>\n' ' <address>192.168.1.254</address>\n' ' </ip>\n' ' <preempt>\n' ' <delay>\n' ' <minimum>5</minimum>\n' ' <reload>10</reload>\n' ' </delay>\n' ' </preempt>\n' ' <priority>110</priority>\n' ' <timers>\n' ' <hello-interval>\n' ' <seconds>1</seconds>\n' ' </hello-interval>\n' ' <hold-time>\n' ' <seconds>3</seconds>\n' ' </hold-time>\n' ' </timers>\n' ' <track>\n' ' <number>1</number>\n' ' <decrement>20</decrement>\n' ' </track>\n' ' </standby-list>\n' ' <version>1</version>\n' ' </standby>\n' ' </GigabitEthernet>\n' ' </config>\n' '</edit-config>\n' ])) def test_yang_config5(self): # Apply configuration key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.version = 2 key.minimum_delay = 5 key.group_number = 25 key.priority = 110 key.preempt = True key.bfd = True key.use_bia = True key.hello_interval_msec = 55 key.holdtime_msec = 100 key.track_object = 1 key.track_shutdown = True key.group_name = 'gandalf' key.mac_address = 'dead.beef.dead' # Build config build_cfgs = self.hsrp1.build_config(apply=False) compare1 = "" for i in build_cfgs['PE1']: compare1 += str(i) # Check config built correctly self.assertMultiLineEqual( compare1, '\n'.join([ '<edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">\n' ' <target>\n' ' <running></running>\n' ' </target>\n' ' <config>\n' ' <GigabitEthernet xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">\n' ' <name></name>\n' ' <standby>\n' ' <bfd></bfd>\n' ' <delay>\n' ' <minimum>5</minimum>\n' ' </delay>\n' ' <standby-list>\n' ' <group-number>25</group-number>\n' ' <mac-address>dead.beef.dead</mac-address>\n' ' <name>gandalf</name>\n' ' <preempt/>\n' ' <priority>110</priority>\n' ' <timers>\n' ' <hello-interval>\n' ' <msec>55</msec>\n' ' </hello-interval>\n' ' <hold-time>\n' ' <msec>100</msec>\n' ' </hold-time>\n' ' </timers>\n' ' <track>\n' ' <number>1</number>\n' ' <shutdown></shutdown>\n' ' </track>\n' ' </standby-list>\n' ' <use-bia>\n' ' <scope>\n' ' <interface></interface>\n' ' </scope>\n' ' </use-bia>\n' ' <version>2</version>\n' ' </standby>\n' ' </GigabitEthernet>\n' ' </config>\n' '</edit-config>\n' ])) # Build unconfig build_uncfgs = self.hsrp1.build_unconfig(apply=False) compare2 = "" for i in build_uncfgs['PE1']: compare2 += str(i) # Check config built correctly self.assertMultiLineEqual( compare2, '\n'.join([ '<edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">\n' ' <target>\n' ' <running></running>\n' ' </target>\n' ' <config>\n' ' <GigabitEthernet xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">\n' ' <name></name>\n' ' <standby>\n' ' <bfd></bfd>\n' ' <delay>\n' ' <minimum>5</minimum>\n' ' </delay>\n' ' <standby-list>\n' ' <group-number>25</group-number>\n' ' <mac-address>dead.beef.dead</mac-address>\n' ' <name>gandalf</name>\n' ' <preempt/>\n' ' <priority>110</priority>\n' ' <timers>\n' ' <hello-interval>\n' ' <msec>55</msec>\n' ' </hello-interval>\n' ' <hold-time>\n' ' <msec>100</msec>\n' ' </hold-time>\n' ' </timers>\n' ' <track>\n' ' <number>1</number>\n' ' <shutdown></shutdown>\n' ' </track>\n' ' </standby-list>\n' ' <use-bia>\n' ' <scope>\n' ' <interface></interface>\n' ' </scope>\n' ' </use-bia>\n' ' <version>2</version>\n' ' </standby>\n' ' </GigabitEthernet>\n' ' </config>\n' '</edit-config>\n' ])) def test_yang_config6(self): # Apply configuration key = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key.version = 2 key.minimum_delay = 5 key.group_number = 25 key.priority = 110 key.preempt = True key.ipv6_address = 'autoconfig' # Build config build_cfgs = self.hsrp1.build_config(apply=False) compare1 = "" for i in build_cfgs['PE1']: compare1 += str(i) # Check config built correctly self.assertMultiLineEqual( compare1, '\n'.join([ '<edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">\n' ' <target>\n' ' <running></running>\n' ' </target>\n' ' <config>\n' ' <GigabitEthernet xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">\n' ' <name></name>\n' ' <standby>\n' ' <delay>\n' ' <minimum>5</minimum>\n' ' </delay>\n' ' <standby-list>\n' ' <group-number>25</group-number>\n' ' <ipv6>autoconfig</ipv6>\n' ' <preempt/>\n' ' <priority>110</priority>\n' ' </standby-list>\n' ' <version>2</version>\n' ' </standby>\n' ' </GigabitEthernet>\n' ' </config>\n' '</edit-config>\n' ])) # Build unconfig build_uncfgs = self.hsrp1.build_unconfig(apply=False) compare2 = "" for i in build_uncfgs['PE1']: compare2 += str(i) # Check config built correctly self.assertMultiLineEqual( compare2, '\n'.join([ '<edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">\n' ' <target>\n' ' <running></running>\n' ' </target>\n' ' <config>\n' ' <GigabitEthernet xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">\n' ' <name></name>\n' ' <standby>\n' ' <delay>\n' ' <minimum>5</minimum>\n' ' </delay>\n' ' <standby-list>\n' ' <group-number>25</group-number>\n' ' <ipv6>autoconfig</ipv6>\n' ' <preempt/>\n' ' <priority>110</priority>\n' ' </standby-list>\n' ' <version>2</version>\n' ' </standby>\n' ' </GigabitEthernet>\n' ' </config>\n' '</edit-config>\n' ])) def test_yang_config7(self): # Hsrp object self.hsrp1 = Hsrp() # Apply configuration key1 = self.hsrp1.device_attr[self.dev1].interface_attr[self.intf1] key1.version = 2 key1.group_number = 10 key1.priority = 110 key1.preempt = True key1.preempt_reload_delay = 30 # Hsrp object self.hsrp2 = Hsrp() # Apply configuration key2 = self.hsrp2.device_attr[self.dev1].interface_attr[self.intf1] key2.group_number = 20 key2.priority = 120 key2.preempt = True key2.preempt_sync_delay = 60 # Build config cfgs1 = self.hsrp1.build_config(apply=False) cfgs2 = self.hsrp2.build_config(apply=False) compare = "" for i in cfgs1['PE1']: compare += str(i) for i in cfgs2['PE1']: compare += str(i) # Check config built correctly self.assertMultiLineEqual( compare, '\n'.join([ '<edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">\n' ' <target>\n' ' <running></running>\n' ' </target>\n' ' <config>\n' ' <GigabitEthernet xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">\n' ' <name></name>\n' ' <standby>\n' ' <standby-list>\n' ' <group-number>10</group-number>\n' ' <preempt/>\n' ' <priority>110</priority>\n' ' </standby-list>\n' ' <version>2</version>\n' ' </standby>\n' ' </GigabitEthernet>\n' ' </config>\n' '</edit-config>\n' '<edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">\n' ' <target>\n' ' <running></running>\n' ' </target>\n' ' <config>\n' ' <GigabitEthernet xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">\n' ' <name></name>\n' ' <standby>\n' ' <standby-list>\n' ' <group-number>20</group-number>\n' ' <preempt/>\n' ' <priority>120</priority>\n' ' </standby-list>\n' ' </standby>\n' ' </GigabitEthernet>\n' ' </config>\n' '</edit-config>\n' ]))