Exemplo n.º 1
0
    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',
            ]))
Exemplo n.º 2
0
def update_interface_desc(device):
    """Updates device interface desc with the cdp information 
    from the get_cdp function in the GenieClient
    """

    print(f'Running commands on {device}...')
    cdp_dict = device.parse("show cdp neighbors detail"
                            )  #Get the cdp info on each call to the device

    management_interface = [
        'GigabitEthernet0/0', 'MgmtEth0/RP0/CPU0/0', 'GigabitEthernet0',
        'mgmt0'
    ]

    for index in cdp_dict["index"]:  # For each cdp entry in the cdp_dict
        local_interface = cdp_dict["index"][index]["local_interface"]
        remote_device_hostname = cdp_dict["index"][index]["device_id"]
        remote_device_interface = cdp_dict["index"][index]["port_id"]

        if local_interface in management_interface:  #Check if the local interface is on a BB Device
            interface_desc = (
                f'Conneted to backbone device {remote_device_hostname} via its {remote_device_interface} interface'
            )  # management interface, if so set this desc

        else:  #Set the desc based on hostname and remote interface
            interface_desc = (
                f"Connected to {remote_device_hostname} via its {remote_device_interface} interface"
            )

        #Here we create an inteface object so we can apply the desc string
        interface_obj = Interface(device=device, name=local_interface)
        interface_obj.description = interface_desc

        final_config = interface_obj.build_config(apply=True)
Exemplo n.º 3
0
def interface_description_configure(testbed, device_name, netbox_interfaces):
    device = testbed.devices[device_name]
    device.connect(learn_hostname=True, log_stdout=False)

    for interface in netbox_interfaces:
        print(f"Setting Interface {interface.name} description to '{interface.description}'")
        if (interface.name in device.interfaces.keys()):
            new_interface = device.interfaces[interface.name]
        else:
            new_interface = Interface(name = interface.name, device = device)

        new_interface.description = interface.description

        # Build and print out the configuration
        new_interface.build_config()
Exemplo n.º 4
0
def interface_enable_state_configure(netbox_interfaces):
    results = []
    for interface in netbox_interfaces:
        print(
            f"Setting Interface {interface.name} to enabled state {interface.enabled}"
        )
        if interface.name in device.interfaces.keys():
            new_interface = device.interfaces[interface.name]
        else:
            new_interface = Interface(name=interface.name, device=device)
        new_interface.enabled = interface.enabled
        output = new_interface.build_config()
        results.append(output)

    return results
Exemplo n.º 5
0
def interface_enable_state_configure(testbed, device_name, netbox_interfaces):
    device = testbed.devices[device_name]
    device.connect(learn_hostname=True, log_stdout=False)

    for interface in netbox_interfaces:
        print(f"Setting Interface {interface.name} to enabled state {interface.enabled}")
        if (interface.name in device.interfaces.keys()):
            new_interface = device.interfaces[interface.name]
        else:
            new_interface = Interface(name = interface.name, device = device)

        new_interface.enabled = interface.enabled

        # Build and print out the configuration
        new_interface.build_config()
Exemplo n.º 6
0
def interface_access_configure(netbox_interface):
    if netbox_interface.mode.label == "Access":
        # Configure native and tagged vlans on a trunk
        if netbox_interface.name in device.interfaces.keys():
            new_interface = device.interfaces[netbox_interface.name]
        else:
            new_interface = Interface(name=netbox_interface.name,
                                      device=device)
        new_interface.switchport_enable = True

        new_interface.switchport_mode = "access"
        new_interface.access_vlan = str(netbox_interface.untagged_vlan.vid)
        return new_interface
    else:
        print(f"Interface {netbox_interface.name} is NOT an access interface.")
        return False
Exemplo n.º 7
0
def interface_trunk_configure(netbox_interface):
    if netbox_interface.mode.label in ["Tagged", "Tagged All"]:
        # Configure native and tagged vlans on a trunk
        if netbox_interface.name in device.interfaces.keys():
            new_interface = device.interfaces[netbox_interface.name]
        else:
            new_interface = Interface(name=netbox_interface.name,
                                      device=device)
        new_interface.switchport_enable = True

        new_interface.switchport_mode = "trunk"

        if netbox_interface.untagged_vlan:
            new_interface.native_vlan = str(netbox_interface.untagged_vlan.vid)

        if netbox_interface.tagged_vlans:
            vlan_list = [
                str(vlan.vid) for vlan in netbox_interface.tagged_vlans
            ]
            new_interface.trunk_vlans = ",".join(vlan_list)

        if netbox_interface.mode.label == "Tagged All":
            new_interface.trunk_add_vlans = "1-4094"

        return new_interface

    else:
        print(f"Interface {netbox_interface.name} is NOT a trunk interface.")
        return False
Exemplo n.º 8
0
def interface_description_configure(netbox_interfaces):
    results = []
    for interface in netbox_interfaces:
        print(f"Setting Interface {interface.name} description")
        if interface.name in device.interfaces.keys():
            new_interface = device.interfaces[interface.name]
        else:
            new_interface = Interface(name=interface.name, device=device)

        if interface.description in ["", " ", None]:
            output = new_interface.build_unconfig(
                attributes={'description': None}, apply=False)
        elif interface.description:
            new_interface.description = interface.description
            output = new_interface.build_config()
        results.append(output)

    return results
Exemplo n.º 9
0
 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',
         ]))
Exemplo n.º 10
0
 def get_os_specific_Interface_class(self):
     from genie.libs.conf.interface import Interface as xbuInterface
     return xbuInterface._get_os_specific_Interface_class(self.os)
Exemplo n.º 11
0
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',
            ]))
Exemplo n.º 12
0
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',
            ]))
Exemplo n.º 13
0
output = new_vlan.build_config(apply=False)
output
print(output["sbx-n9kv-ao"])

# Build and send the configuration to devices
output = new_vlan.build_config(apply=True)

# Build and print out the configuraiton to REMOVE the Vlan from the devices
output = new_vlan.build_unconfig(apply=False)
print(output["sbx-n9kv-ao"])

# Build and send the configuration to remove the Vlan from the device
output = new_vlan.build_unconfig()

# Create a new Interface object for the device
new_interface = Interface(name="Ethernet1/10", device=device)

# Configure interface properties
new_interface.description = "Genie set me!"
new_interface.enabled = False
new_interface.switchport_enable = True
new_interface.switchport_mode = "trunk"
new_interface.native_vlan = "101"
new_interface.trunk_vlans = "101-105"

# Build and print out the configuration
output = new_interface.build_config(apply=False)
print(output)

# Build and send the configuration to the device
output = new_interface.build_config()
Exemplo n.º 14
0
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'
            ]))
import os

try:
    assert all(os.environ[env] for env in ['PYATS_USERNAME', 'PYATS_PASSWORD'])
except KeyError as exc:
    sys.exit(f"ERROR: missing ENVAR: {exc}")

testbed = Genie.init("testbed.yml")

device = testbed.devices['r3']
device.connect(learn_hostname=True)

interfaces = device.learn("interface")

# Create a new Interface object for the device
new_interface = Interface(name="FastEthernet1/1", device=device)

# Configure interface properties
new_interface.description = "Genie set me!"
new_interface.enabled = True

# Build and print out the configuration
output = new_interface.build_config(apply=False)
print(output)

# Build and send the configuration to the device
output = new_interface.build_config()

# Build and print the configuration to UNCONFIG the interface
output = new_interface.build_unconfig(apply=False)
print(output)
Exemplo n.º 16
0
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'
            ]))
Exemplo n.º 17
0
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'
            ]))
Exemplo n.º 18
0
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',
            ]))
Exemplo n.º 19
0
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',
            ]))