def test_remove_interface_from_lag_case_1(topology, step):
    """
    Case 1:
        Verify that an interface is correclty removed from a LAG
    """
    sw1 = topology.get('sw1')
    sw1_lag_id = '10'

    assert sw1 is not None

    step("Mapping interfaces")
    port = sw1.ports['1']

    step("Turning on interface 1 used in this test")
    turn_on_interface(sw1, port)

    step("Verify interface 1 is up")
    verify_turn_on_interfaces(sw1, [port])

    step("Create LAG")
    create_lag(sw1, sw1_lag_id, 'off')

    step("Associate interface [1] to LAG")
    associate_interface_to_lag(sw1, port, sw1_lag_id)

    step("Verify interface 1 is in LAG 1")
    verify_lag_config(sw1, sw1_lag_id, [port])

    step("Remove interface from LAG 1")
    remove_interface_from_lag(sw1, port, sw1_lag_id)

    step("Verify interface is shutdown")
    verify_turn_off_interfaces(sw1, [port])
def change_member_states(sw, sw_real_ports, before_state, new_state):
    for i, port in enumerate(sw_real_ports[sw][1:]):
        if before_state[i] == new_state[i]:
            continue
        elif before_state[i] is False and new_state[i] is True:
            associate_interface_to_lag(sw, port, LAG_ID)
        else:
            remove_interface_from_lag(sw, port, LAG_ID)
    lag_members = [
        port for port, state in zip(sw_real_ports[sw][1:], new_state)
        if state is True
    ]
    verify_lag_config(sw, LAG_ID, lag_members)
    return lag_members
def test_l2_l3_interface_switch_case_1(topology, step):
    """
    Case 1:
        This test verifies the functionality of 2 LAGs when an interface is
        changed from a L2 LAG to a L3 LAG and viceversa.
    """
    sw1 = topology.get('sw1')
    sw2 = topology.get('sw2')
    hs1 = topology.get('hs1')
    hs2 = topology.get('hs2')

    assert sw1 is not None
    assert sw2 is not None
    assert hs1 is not None
    assert hs2 is not None

    ip_address_mask = '24'
    hs1_ip_address = '10.0.10.1'
    hs2_ip_address = '10.0.10.2'
    hs1_ip_address_with_mask = hs1_ip_address + '/' + ip_address_mask
    hs2_ip_address_with_mask = hs2_ip_address + '/' + ip_address_mask
    sw1_l3_lag_ip_address = '10.0.0.1'
    sw2_l3_lag_ip_address = '10.0.0.2'
    l2_lag_id = '2'
    l3_lag_id = '3'
    vlan_identifier = '8'

    ports_sw1 = list()
    ports_sw2 = list()

    step("Mapping interfaces")
    for port in port_labels:
        ports_sw1.append(sw1.ports[port])
        ports_sw2.append(sw2.ports[port])
    step("Sorting the port list")
    ports_sw1.sort()
    ports_sw2.sort()

    p11 = ports_sw1[0]
    p12 = ports_sw1[1]
    p13 = ports_sw1[2]
    p14 = ports_sw1[3]
    p21 = ports_sw2[0]
    p22 = ports_sw2[1]
    p23 = ports_sw2[2]
    p24 = ports_sw2[3]

    step("Turning on all interfaces used in this test")
    for port in ports_sw1:
        turn_on_interface(sw1, port)

    for port in ports_sw2:
        turn_on_interface(sw2, port)

    step("Verify all interface are up")
    verify_turn_on_interfaces(sw1, ports_sw1)
    verify_turn_on_interfaces(sw2, ports_sw2)

    step("Assign an IP address on the same range to each workstation")
    hs1.libs.ip.interface('1', addr=hs1_ip_address_with_mask, up=True)
    hs2.libs.ip.interface('1', addr=hs2_ip_address_with_mask, up=True)

    step('Creating VLAN in both switches')
    create_vlan(sw1, vlan_identifier)
    create_vlan(sw2, vlan_identifier)

    step("Create L2 LAG in both switches")
    create_lag(sw1, l2_lag_id, 'off')
    create_lag(sw2, l2_lag_id, 'off')

    step("Associate interfaces [1, 2] to L2 LAG in both switches")
    associate_interface_to_lag(sw1, p11, l2_lag_id)
    associate_interface_to_lag(sw1, p12, l2_lag_id)
    associate_interface_to_lag(sw2, p21, l2_lag_id)
    associate_interface_to_lag(sw2, p22, l2_lag_id)

    step("Verify LAG configuration")
    verify_lag_config(sw1, l2_lag_id, [p11, p12])
    verify_lag_config(sw2, l2_lag_id, [p21, p22])

    step("Create L3 LAG in both switches")
    create_lag(sw1, l3_lag_id, 'off')
    create_lag(sw2, l3_lag_id, 'off')

    step("Associate interface 3 to L3 LAG in both switches")
    associate_interface_to_lag(sw1, p13, l3_lag_id)
    associate_interface_to_lag(sw2, p23, l3_lag_id)

    step("Verify LAG configuration")
    verify_lag_config(sw1, l3_lag_id, [p13])
    verify_lag_config(sw2, l3_lag_id, [p23])

    step("Configure LAGs and workstations interfaces with same VLAN")
    associate_vlan_to_lag(sw1, vlan_identifier, l2_lag_id)
    associate_vlan_to_lag(sw2, vlan_identifier, l2_lag_id)
    associate_vlan_to_l2_interface(sw1, vlan_identifier, p14)
    associate_vlan_to_l2_interface(sw2, vlan_identifier, p24)

    step("Assign IP on the same range to LAG in both switches")
    assign_ip_to_lag(sw1, l3_lag_id, sw1_l3_lag_ip_address, ip_address_mask)
    assign_ip_to_lag(sw2, l3_lag_id, sw2_l3_lag_ip_address, ip_address_mask)

    step("Test ping between clients work")
    verify_connectivity_between_hosts(hs1, hs1_ip_address, hs2, hs2_ip_address)
    verify_connectivity_between_switches(sw1, sw1_l3_lag_ip_address, sw2,
                                         sw2_l3_lag_ip_address)

    step("Associate interface 2 to L3 LAG in both switches")
    associate_interface_to_lag(sw1, p12, l3_lag_id)
    associate_interface_to_lag(sw2, p22, l3_lag_id)

    step("Test ping between clients work")
    verify_connectivity_between_hosts(hs1, hs1_ip_address, hs2, hs2_ip_address)
    verify_connectivity_between_switches(sw1, sw1_l3_lag_ip_address, sw2,
                                         sw2_l3_lag_ip_address)

    step("Associate interface 2 to L2 LAG in both switches")
    associate_interface_to_lag(sw1, p12, l2_lag_id)
    associate_interface_to_lag(sw2, p22, l2_lag_id)

    step("Test ping between clients work")
    verify_connectivity_between_hosts(hs1, hs1_ip_address, hs2, hs2_ip_address)
    verify_connectivity_between_switches(sw1, sw1_l3_lag_ip_address, sw2,
                                         sw2_l3_lag_ip_address)

    step("Remove interface 2 from L2 LAG in both switches")
    remove_interface_from_lag(sw1, p12, l2_lag_id)
    remove_interface_from_lag(sw2, p22, l2_lag_id)

    step("Associate interface 2 to L3 LAG in both switches")
    associate_interface_to_lag(sw1, p12, l3_lag_id)
    associate_interface_to_lag(sw2, p22, l3_lag_id)

    step("Test ping between clients work")
    verify_connectivity_between_hosts(hs1, hs1_ip_address, hs2, hs2_ip_address)
    verify_connectivity_between_switches(sw1, sw1_l3_lag_ip_address, sw2,
                                         sw2_l3_lag_ip_address)

    step("Remove interface 2 from L3 LAG in both switches")
    remove_interface_from_lag(sw1, p12, l3_lag_id)
    remove_interface_from_lag(sw2, p22, l3_lag_id)

    step("Associate interface 2 to L2 LAG in both switches")
    associate_interface_to_lag(sw1, p12, l2_lag_id)
    associate_interface_to_lag(sw2, p22, l2_lag_id)

    step("Test ping between clients work")
    verify_connectivity_between_hosts(hs1, hs1_ip_address, hs2, hs2_ip_address)
    verify_connectivity_between_switches(sw1, sw1_l3_lag_ip_address, sw2,
                                         sw2_l3_lag_ip_address)
示例#4
0
def test_dynamic_modify_maximum_members(topology, step):

    sw1 = topology.get('sw1')
    sw2 = topology.get('sw2')
    hs1 = topology.get('hs1')
    hs2 = topology.get('hs2')

    assert sw1 is not None
    assert sw2 is not None
    assert hs1 is not None
    assert hs2 is not None

    ports_sw1 = list()
    ports_sw2 = list()
    port_labels = ['1', '2', '3', '4', '5', '6', '7', '8', '9']

    lag_id = '1'
    vlan_id = '900'
    mode_active = 'active'
    mode_passive = 'passive'

    step("### Mapping interfaces from Docker ###")
    for port in port_labels:
        ports_sw1.append(sw1.ports[port])
        ports_sw2.append(sw2.ports[port])

    step("#### Turning on interfaces in sw1 ###")
    for port in ports_sw1:
        turn_on_interface(sw1, port)

    step("#### Turning on interfaces in sw2 ###")
    for port in ports_sw2:
        turn_on_interface(sw2, port)

    step("#### Validate interfaces are turn on ####")
    verify_turn_on_interfaces(sw1, ports_sw1)
    verify_turn_on_interfaces(sw2, ports_sw2)

    step("##### Create LAGs ####")
    create_lag(sw1, lag_id, mode_active)
    create_lag(sw2, lag_id, mode_passive)

    step("#### Associate Interfaces to LAG ####")
    for intf in ports_sw1[1:9]:
        associate_interface_to_lag(sw1, intf, lag_id)

    for intf in ports_sw2[1:9]:
        associate_interface_to_lag(sw2, intf, lag_id)

    step("#### Verify LAG configuration ####")
    verify_lag_config(sw1, lag_id, ports_sw1[1:9], mode=mode_active)
    verify_lag_config(sw2, lag_id, ports_sw2[1:9], mode=mode_passive)

    step("#### Configure VLANs on switches ####")
    create_vlan(sw1, vlan_id)
    create_vlan(sw2, vlan_id)

    associate_vlan_to_l2_interface(sw1, vlan_id, ports_sw1[0])
    associate_vlan_to_lag(sw1, vlan_id, lag_id)

    associate_vlan_to_l2_interface(sw2, vlan_id, ports_sw2[0])
    associate_vlan_to_lag(sw2, vlan_id, lag_id)

    step("#### Configure workstations ####")
    hs1.libs.ip.interface('1', addr='140.1.1.10/24', up=True)
    hs2.libs.ip.interface('1', addr='140.1.1.11/24', up=True)

    step("### Verify if LAG is synchronized")
    verify_state_sync_lag(sw1, ports_sw1[1:9], LOCAL_STATE, mode_active)
    verify_state_sync_lag(sw1, ports_sw1[1:9], REMOTE_STATE, mode_passive)

    step("#### Test ping between clients work ####")
    check_connectivity_between_hosts(hs1, '140.1.1.10', hs2, '140.1.1.11', 5,
                                     True)

    step("### Remove one interface from each LAG ###")
    remove_interface_from_lag(sw1, ports_sw1[1], lag_id)
    remove_interface_from_lag(sw2, ports_sw2[1], lag_id)

    step("### Validate if the interface was removed of LAG ###")
    validate_interface_not_in_lag(sw1, ports_sw1[1], lag_id)
    validate_interface_not_in_lag(sw2, ports_sw2[1], lag_id)

    step("### Verify if LAG is synchronized")
    verify_state_sync_lag(sw1, ports_sw1[2:9], LOCAL_STATE, mode_active)
    verify_state_sync_lag(sw1, ports_sw1[2:9], REMOTE_STATE, mode_passive)

    step("#### Test ping between clients work ####")
    check_connectivity_between_hosts(hs1, '140.1.1.10', hs2, '140.1.1.11', 5,
                                     True)

    step("### Turning on interface ###")
    turn_on_interface(sw1, ports_sw1[1])
    turn_on_interface(sw2, ports_sw2[1])

    step("### Validate interface is turn on ###")
    verify_turn_on_interfaces(sw1, ports_sw1[1])
    verify_turn_on_interfaces(sw2, ports_sw2[1])

    step("### Associate Interface to LAG ###")
    associate_interface_to_lag(sw1, ports_sw1[1], lag_id)
    associate_interface_to_lag(sw2, ports_sw2[1], lag_id)

    step("### Verify if LAG is synchronized")
    verify_state_sync_lag(sw1, ports_sw1[1:9], LOCAL_STATE, mode_active)
    verify_state_sync_lag(sw1, ports_sw1[1:9], REMOTE_STATE, mode_passive)

    step("#### Test ping between clients work ####")
    check_connectivity_between_hosts(hs1, '140.1.1.10', hs2, '140.1.1.11', 5,
                                     True)
示例#5
0
def test_show_lacp_events(topology, step):
    """Test output for show events.

    Main objective is to configure two switches with
    dynamic LAG (active/passive)
    Add and remove interfaces and turn off one of the LAGs
    Call show events to see results
    """

    # VID for testing
    test_vlan = '2'

    # LAG ID for testing
    test_lag = '2'
    test_lag_if = 'lag' + test_lag

    # interfaces to be added to LAG
    lag_intfs = ['1', '3']

    # interface connected to host
    host_intf = '4'

    # hosts addresses
    hs1_addr = '10.0.11.10'
    hs2_addr = '10.0.11.11'

    show_event_lacp_cmd = 'show events category lacp'
    removed_intf = '2'

    sw1 = topology.get('sw1')
    sw2 = topology.get('sw2')
    hs1 = topology.get('hs1')
    hs2 = topology.get('hs2')

    step('Verifying switches are not None')
    assert sw1 is not None, 'Topology failed getting object sw1'
    assert sw2 is not None, 'Topology failed getting object sw2'

    step('Verifying hosts are not None')
    assert hs1 is not None, 'Topology failed getting object hs1'
    assert hs2 is not None, 'Topology failed getting object hs2'

    step('Turning on interfaces')
    for switch in [sw1, sw2]:
        for intf in lag_intfs + [removed_intf, host_intf]:
            turn_on_interface(switch, intf)

    step('Verifying interfaces from Switch 1 are Up')
    verify_turn_on_interfaces(sw1, lag_intfs + [removed_intf, host_intf])

    step('Verifying interfaces from Switch 2 are Up')
    verify_turn_on_interfaces(sw1, lag_intfs + [removed_intf, host_intf])

    step('Creating VLAN (%s) on Switch 1' % test_vlan)
    create_vlan(sw1, test_vlan)

    step('Creating VLAN (%s) on Switch 2' % test_vlan)
    create_vlan(sw2, test_vlan)

    step('Creating LAG (%s) on Switch 1' % test_lag)
    create_lag(sw1, test_lag, 'active')
    config_lacp_rate(sw1, test_lag, True)
    associate_vlan_to_lag(sw1, test_vlan, test_lag)

    step('Creating LAG (%s) on Switch 2' % test_lag)
    create_lag(sw2, test_lag, 'passive')
    config_lacp_rate(sw2, test_lag, True)
    associate_vlan_to_lag(sw2, test_vlan, test_lag)

    for switch in [sw1, sw2]:
        for intf in lag_intfs + [removed_intf]:
            step('Assigning interface %s to LAG %s' % (intf, test_lag))
            associate_interface_to_lag(switch, intf, test_lag)

        step('Associating VLAN %s to host interface %s' % (test_vlan,
                                                           host_intf))
        associate_vlan_to_l2_interface(switch, test_vlan, host_intf)

    step('Configuring interface on Host 1')
    hs1.libs.ip.interface('1',
                          addr='{hs1_addr}/24'.format(**locals()),
                          up=True)

    step('Configuring interface on Host 2')
    hs2.libs.ip.interface('1',
                          addr='{hs2_addr}/24'.format(**locals()),
                          up=True)

    step('Verifying connectivity between hosts (Successful)')
    verify_connectivity_between_hosts(hs1, hs1_addr, hs2, hs2_addr, True)

    step('Removing interface (%s) from LAG (%s)' % (removed_intf, test_lag))
    remove_interface_from_lag(sw1, removed_intf, test_lag)

    step('Removing interface (%s) from LAG (%s)' % (removed_intf, test_lag))
    remove_interface_from_lag(sw2, removed_intf, test_lag)

    output = sw1(show_event_lacp_cmd, shell='vtysh')

    assert '|15007|LOG_INFO|LACP system ID set to'\
        and '|15006|LOG_INFO|LACP mode set to active for LAG {test_lag}'\
        .format(**locals())\
        and '|15001|LOG_INFO|Dynamic LAG {test_lag} created'\
        .format(**locals())\
        and '|15008|LOG_INFO|LACP rate set to fast for LAG {test_lag}'\
        .format(**locals())\
        and '|15004|LOG_INFO|Interface {removed_intf} removed from '\
        'LAG {test_lag}'.format(**locals())\
        in output

    for intf in lag_intfs + [removed_intf]:
        assert '|15003|LOG_INFO|Interface {intf} added to LAG {test_lag}'\
            .format(**locals())\
            and '|15009|LOG_INFO|Partner is detected for interface {intf}'\
            ' LAG {test_lag}'.format(**locals())\
            in output

    output = sw2(show_event_lacp_cmd, shell='vtysh')

    assert '|15007|LOG_INFO|LACP system ID set to'\
        and '|15006|LOG_INFO|LACP mode set to passive for LAG {test_lag}'\
        .format(**locals())\
        and '|15001|LOG_INFO|Dynamic LAG {test_lag} created'\
        .format(**locals())\
        and '|15008|LOG_INFO|LACP rate set to fast for LAG {test_lag}'\
        .format(**locals())\
        and '|15004|LOG_INFO|Interface {removed_intf} removed from '\
        'LAG {test_lag}'.format(**locals())\
        in output

    for intf in lag_intfs + [removed_intf]:
        assert '|15003|LOG_INFO|Interface {intf} added to LAG {test_lag}'\
            .format(**locals())\
            and '|15009|LOG_INFO|Partner is detected for interface {intf}'\
            ' LAG {test_lag}'.format(**locals())\
            in output

    with sw2.libs.vtysh.ConfigInterfaceLag(test_lag) as ctx:
        ctx.no_lacp_mode_passive()

    step('Verifying connectivity between hosts (Unsuccessful)')
    verify_connectivity_between_hosts(hs1, hs1_addr, hs2, hs2_addr, False)

    output = sw1(show_event_lacp_cmd, shell='vtysh')

    for intf in lag_intfs:
        assert '|15011|LOG_WARN|Partner is lost (timed out) '\
            'for interface {intf} '.format(**locals())\
            in output

    output = sw2(show_event_lacp_cmd, shell='vtysh')
    assert '|15006|LOG_INFO|LACP mode set to off for '\
        'LAG {test_lag}'.format(**locals())\
        and '|ops-lacpd|15002|LOG_INFO|Dynamic LAG {test_lag} deleted'\
        .format(**locals())\
        in output