def main_setup(request, topology):
    """Common tests configuration.

    This configuration will be applied for all Fallback test cases, enabled or
    not, and after each test case the configuration must remains the same to
    keep the atomicity of each test.
    """

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

    assert sw1 is not None
    assert sw2 is not None

    # Create two dynamic LAG with two ports each.
    sw_create_bond(sw1, test_lag, intf_labels, lacp_mode='active')
    sw_create_bond(sw2, test_lag, intf_labels, lacp_mode='active')

    set_port_parameter(sw1, test_lag, ['other_config:lacp-time=fast'])
    set_port_parameter(sw2, test_lag, ['other_config:lacp-time=fast'])

    # Enable both the interfaces.
    for intf in intf_labels:
        set_intf_parameter(
            sw1, intf,
            ['user_config:admin=up', 'other_config:lacp-aggregation-key=1'])
        set_intf_parameter(
            sw2, intf,
            ['user_config:admin=up', 'other_config:lacp-aggregation-key=1'])

    sw_wait_until_ready([sw1, sw2], intf_labels)

    print('Verify all interfaces SM from both switches are working')
    sw_wait_until_all_sm_ready([sw1, sw2], intf_labels, active_ready)
def test_nf_toggle_lacp_flag_active(topology, step, main_setup):
    """Toggle 'lacp' flag to 'active'.

    To disable LAG 1 on both switches, 'lacp' flag will be toggled between
    '[]' and 'active'.
    """

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

    assert sw1 is not None
    assert sw2 is not None

    print_header('Fallback disabled, toggle "lacp" flag to active')

    ##########################################################################
    # LAG 1 disabled on sw1
    ##########################################################################
    print('Shutting down LAG1 on sw1')
    set_port_parameter(sw1, test_lag, disable_lag)
    print('Verify that all sw2 SMs are in "Defaulted and Expired"')
    sw_wait_until_all_sm_ready([sw2], intf_labels, active_no_fallback)

    print('Enabling LAG1 on sw1')
    set_port_parameter(sw1, test_lag, active_lag)
    print('Verify all interface SM from both switches are working')
    sw_wait_until_all_sm_ready([sw1, sw2], intf_labels, active_ready)

    ##########################################################################
    # LAG 1 disabled on sw2
    ##########################################################################
    print('Shutting down LAG1 on sw2')
    set_port_parameter(sw2, test_lag, disable_lag)
    print('Verify that all sw1 SMs are in "Defaulted and Expired"')
    sw_wait_until_all_sm_ready([sw1], intf_labels, active_no_fallback)

    print('Enabling LAG1 on sw2')
    set_port_parameter(sw2, test_lag, active_lag)
    print('Verify all interface SM from both switches are working')
    sw_wait_until_all_sm_ready([sw1, sw2], intf_labels, active_ready)
Exemplo n.º 3
0
def test_lacpd_lag_dynamic_partner_priority(topology, step, main_setup, setup):
    """
    Case 2:
        Test the port priority functionality of LACP by testing the partner
        port priority. If two interfaces have the same port priority, the
        decision is made using the partner port priority
        Two switches are connected with 4 interfaces
        In switch 1, LAG 1 is formed with interfaces 1 to 4.
        In switch 2, LAG 1 is formed with interfaces 1 and 2, LAG 2 is
        formed with interfaces 3 and 4
    """
    step("\n=========== lacpd dynamic LAG partner priority test ===========\n")
    sw1 = topology.get('sw1')
    sw2 = topology.get('sw2')

    assert sw1 is not None
    assert sw2 is not None

    # Enable all the interfaces under test.
    step("Enabling interfaces [1, 2, 3, 4] in all switches\n")
    for intf in sw_1g_intf[0:4]:
        sw_set_intf_user_config(sw1, intf, ['admin=up'])
        sw_set_intf_user_config(sw2, intf, ['admin=up'])

    step("Creating active LAGs in switches\n")
    sw_create_bond(sw1, "lag1", sw_1g_intf[0:4], lacp_mode="active")
    sw_create_bond(sw2, "lag1", sw_1g_intf[0:2], lacp_mode="active")
    sw_create_bond(sw2, "lag2", sw_1g_intf[2:4], lacp_mode="active")

    step("Setting LAGs lacp rate as fast in switches\n")
    set_port_parameter(sw1, "lag1", ['other_config:lacp-time=fast'])
    set_port_parameter(sw2, "lag1", ['other_config:lacp-time=fast'])
    set_port_parameter(sw2, "lag2", ['other_config:lacp-time=fast'])

    step("Setting port priorities\n")
    set_intf_other_config(sw1, '1', ['lacp-port-priority=100'])
    set_intf_other_config(sw1, '2', ['lacp-port-priority=100'])
    set_intf_other_config(sw1, '3', ['lacp-port-priority=100'])
    set_intf_other_config(sw1, '4', ['lacp-port-priority=100'])

    set_intf_other_config(sw2, '1', ['lacp-port-priority=100'])
    set_intf_other_config(sw2, '2', ['lacp-port-priority=100'])
    set_intf_other_config(sw2, '3', ['lacp-port-priority=1'])
    set_intf_other_config(sw2, '4', ['lacp-port-priority=1'])

    step("Waiting for LACP to complete negotiation\n")
    """
    Interface 3 and 4 in switch 2 have the higher priority, LAG 1 in switch 1
    will connect to the LAG 2 because the partner has higher priority

    In switch 1:
        Interface 1 must not be collecting and distributing
        Interface 2 must not be collecting and distributing
        Interface 3 must be collecting and distributing
        Interface 4 must be collecting and distributing
    In switch 2:
        Interface 1 must not be collecting and distributing
        Interface 2 must not be collecting and distributing
        Interface 3 must be collecting and distributing
        Interface 4 must be collecting and distributing
    """
    step("Verify state machines in all switches\n")
    sw_wait_until_all_sm_ready([sw1, sw2], sw1_intf_labels_1G[0:2],
                               active_different_lag_intf)
    sw_wait_until_all_sm_ready([sw1, sw2], sw1_intf_labels_1G[2:4],
                               active_ready)

    # finish testing
    for intf in sw_1g_intf[0:4]:
        sw1("ovs-vsctl remove interface " + intf +
            " other_config lacp-port-priority",
            shell='bash')
        sw2("ovs-vsctl remove interface " + intf +
            " other_config lacp-port-priority",
            shell='bash')
    sw1("ovs-vsctl del-port lag1", shell='bash')
    sw2("ovs-vsctl del-port lag1", shell='bash')
    sw2("ovs-vsctl del-port lag2", shell='bash')
Exemplo n.º 4
0
def test_lacpd_lag_dynamic_port_priority(topology, step, main_setup, setup):
    """
    Case 1:
        Test the port priority functionality of LACP by setting a lower
        priority to an interface and allowing other interfaces with higher
        priority to join the corresponding LAGs.
        Two switches are connected with five interfaces using 2 LAGs in active
        mode.
        In switch 1, LAG 1 is formed with interfaces 1 and 2, LAG 2 is
        formed with interfaces 3, 4 and 5
        In switch 2, LAG 1 is formed with interfaces 1, 2 and 3, LAG 2 is
        formed with interfaces 4 and 5
    """
    step("\n============ lacpd dynamic LAG port priority test ============\n")
    sw1 = topology.get('sw1')
    sw2 = topology.get('sw2')

    assert sw1 is not None
    assert sw2 is not None

    # Enable all the interfaces under test.
    step("Enabling interfaces [1, 2, 3, 4, 5] in all switches\n")
    for intf in sw_1g_intf[0:5]:
        sw_set_intf_user_config(sw1, intf, ['admin=up'])
        sw_set_intf_user_config(sw2, intf, ['admin=up'])

    step("Creating active LAGs in switches\n")
    sw_create_bond(sw1, "lag1", sw_1g_intf[0:2], lacp_mode="active")
    sw_create_bond(sw1, "lag2", sw_1g_intf[2:5], lacp_mode="active")
    sw_create_bond(sw2, "lag1", sw_1g_intf[0:3], lacp_mode="active")
    sw_create_bond(sw2, "lag2", sw_1g_intf[3:5], lacp_mode="active")

    step("Setting LAGs lacp rate as fast in switches\n")
    set_port_parameter(sw1, "lag1", ['other_config:lacp-time=fast'])
    set_port_parameter(sw1, "lag2", ['other_config:lacp-time=fast'])
    set_port_parameter(sw2, "lag1", ['other_config:lacp-time=fast'])
    set_port_parameter(sw2, "lag2", ['other_config:lacp-time=fast'])

    step("Setting port priorities\n")
    set_intf_other_config(sw1, '1', ['lacp-port-priority=100'])
    set_intf_other_config(sw1, '2', ['lacp-port-priority=100'])
    set_intf_other_config(sw1, '3', ['lacp-port-priority=200'])
    set_intf_other_config(sw1, '4', ['lacp-port-priority=100'])
    set_intf_other_config(sw1, '5', ['lacp-port-priority=100'])

    set_intf_other_config(sw2, '1', ['lacp-port-priority=100'])
    set_intf_other_config(sw2, '2', ['lacp-port-priority=100'])
    set_intf_other_config(sw2, '3', ['lacp-port-priority=200'])
    set_intf_other_config(sw2, '4', ['lacp-port-priority=100'])
    set_intf_other_config(sw2, '5', ['lacp-port-priority=100'])

    step("Waiting for LACP to complete negotiation\n")
    """
    Interface 3 has the lower priority, this allows other interfaces to
    agreggate to the LAGs
    In switch 1:
        Interface 1 must be collecting and distributing
        Interface 2 must be collecting and distributing
        Interface 3 must not be collecting and distributing
        Interface 4 must be collecting and distributing
        Interface 5 must be collecting and distributing
    In switch 2:
        Interface 1 must be collecting and distributing
        Interface 2 must be collecting and distributing
        Interface 3 must not be collecting and distributing
        Interface 4 must be collecting and distributing
        Interface 5 must be collecting and distributing
    """
    step("Verify state machines in all switches\n")
    sw_wait_until_all_sm_ready([sw1, sw2], sw1_intf_labels_1G[0:2],
                               active_ready)
    sw_wait_until_all_sm_ready([sw1, sw2], sw1_intf_labels_1G[3:5],
                               active_ready)
    sw_wait_until_all_sm_ready([sw1, sw2], sw1_intf_labels_1G[2],
                               active_different_lag_intf)

    # finish testing
    for intf in sw_1g_intf[0:5]:
        sw1("ovs-vsctl remove interface " + intf +
            " other_config lacp-port-priority",
            shell='bash')
        sw2("ovs-vsctl remove interface " + intf +
            " other_config lacp-port-priority",
            shell='bash')
    sw1("ovs-vsctl del-port lag1", shell='bash')
    sw1("ovs-vsctl del-port lag2", shell='bash')
    sw2("ovs-vsctl del-port lag1", shell='bash')
    sw2("ovs-vsctl del-port lag2", shell='bash')
def test_lacpd_lag_defaulted_port_priority(topology, step, main_setup, setup):
    """
    Case 1:
        Test the port priority functionality of LACP when an interface is
        sent to defaulted state by disabling the partner interface connected
        to the interface with higher port priortiy. Also test when a function
        is sent to defaulted state and all interfaces have the same priority.
        Two switches are connected with 4 interfaces using 2 LAGs in active
        mode.
        In switch 1, LAG 1 is formed with interfaces 1, 2, 3 and 4
        In switch 2, LAG 1 is formed with interfaces 1, 2, 4 and 4
    """
    step("\n============ lacpd dynamic LAG port priority test ============")
    sw1 = topology.get('sw1')
    sw2 = topology.get('sw2')

    assert sw1 is not None
    assert sw2 is not None

    # Enable all the interfaces under test.
    step("Enabling interfaces [1, 2, 3, 4] in all switches")
    for intf in sw_1g_intf[0:4]:
        sw_set_intf_user_config(sw1, intf, ['admin=up'])
        sw_set_intf_user_config(sw2, intf, ['admin=up'])

    step("Creating active LAGs in switches")
    sw_create_bond(sw1, "lag1", sw_1g_intf[0:4], lacp_mode="active")
    sw_create_bond(sw2, "lag1", sw_1g_intf[0:4], lacp_mode="active")

    step("Setting LAGs lacp rate as fast in switches")
    set_port_parameter(sw1, "lag1", ['other_config:lacp-time=fast'])
    set_port_parameter(sw2, "lag1", ['other_config:lacp-time=fast'])

    step("Setting port priorities")
    set_intf_other_config(sw1, '1', ['lacp-port-priority=200'])
    set_intf_other_config(sw1, '2', ['lacp-port-priority=100'])
    set_intf_other_config(sw1, '3', ['lacp-port-priority=200'])
    set_intf_other_config(sw1, '4', ['lacp-port-priority=200'])

    set_intf_other_config(sw2, '1', ['lacp-port-priority=200'])
    set_intf_other_config(sw2, '2', ['lacp-port-priority=100'])
    set_intf_other_config(sw2, '3', ['lacp-port-priority=200'])
    set_intf_other_config(sw2, '4', ['lacp-port-priority=200'])

    step("Verify state machines in all switches")
    sw_wait_until_all_sm_ready(
        [sw1, sw2], sw1_intf_labels_1G[0:4], active_ready)

    step("Shutdown interface with higher port priority [2] in switch 2")
    disable_intf_list(sw2, sw1_intf_labels_1G[1])

    step("Verify interfaces 1, 3 and 4 are still working in both switches")
    sw_wait_until_all_sm_ready(
        [sw1, sw2], sw1_intf_labels_1G[0], active_ready)
    sw_wait_until_all_sm_ready(
        [sw1, sw2], sw1_intf_labels_1G[2:4], active_ready)

    step("Verify interface 2 is in defaulted state in switch 1")
    sw_wait_until_all_sm_ready(
        [sw1], sw1_intf_labels_1G[1], active_defaulted)

    step("No shutdown interface with higher port priority [2] in switch 2")
    enable_intf_list(sw2, sw1_intf_labels_1G[1])

    step("Verify state machines in all switches")
    sw_wait_until_all_sm_ready(
        [sw1, sw2], sw1_intf_labels_1G[0:4], active_ready)

    step("Set same port priority to all interfaces")
    set_intf_other_config(sw1, '2', ['lacp-port-priority=200'])
    set_intf_other_config(sw2, '2', ['lacp-port-priority=200'])

    step("Verify state machines in all switches")
    sw_wait_until_all_sm_ready(
        [sw1, sw2], sw1_intf_labels_1G[0:4], active_ready)

    step("Shutdown interface 2 in switch 2")
    disable_intf_list(sw2, sw1_intf_labels_1G[1])

    step("Verify interfaces 1, 3 and 4 are still working in both switches")
    sw_wait_until_all_sm_ready(
        [sw1, sw2], sw1_intf_labels_1G[0], active_ready)
    sw_wait_until_all_sm_ready(
        [sw1, sw2], sw1_intf_labels_1G[2:4], active_ready)

    step("Verify interface 2 is in defaulted state in switch 1")
    sw_wait_until_all_sm_ready(
        [sw1], sw1_intf_labels_1G[1], active_defaulted)

    step("No shutdown interface 2 in switch 2")
    enable_intf_list(sw2, sw1_intf_labels_1G[1])

    step("Verify state machines in all switches")
    sw_wait_until_all_sm_ready(
        [sw1, sw2], sw1_intf_labels_1G[0:4], active_ready)

    step("Set same port priority to all interfaces")
    # finish testing
    for intf in sw_1g_intf[0:4]:
        sw1("ovs-vsctl remove interface " + intf +
            " other_config lacp-port-priority", shell='bash')
        sw2("ovs-vsctl remove interface " + intf +
            " other_config lacp-port-priority", shell='bash')
    sw1("ovs-vsctl del-port lag1", shell='bash')
    sw2("ovs-vsctl del-port lag1", shell='bash')
def test_lacp_bond_status(topology, step):
    """
        Verify correct LACP bond_status according to the status of member
        interfaces status.
    """
    sw1 = topology.get('sw1')
    sw2 = topology.get('sw2')
    lag_name = 'lag1'

    assert sw1 is not None
    assert sw2 is not None

    p11 = sw1.ports['1']
    p12 = sw1.ports['2']
    p13 = sw1.ports['3']
    p14 = sw1.ports['4']
    p21 = sw2.ports['1']
    p22 = sw2.ports['2']
    p23 = sw2.ports['3']
    p24 = sw2.ports['4']

    ports_sw1 = [p11, p12, p13, p14]
    ports_sw2 = [p21, p22, p23, p24]

    step("Turning on all interfaces used in this test")
    enable_intf_list(sw1, ports_sw1)
    enable_intf_list(sw2, ports_sw2)

    step("Creating dynamic lag with 4 interfaces")
    sw_create_bond(sw1, lag_name, ports_sw1, lacp_mode='active')
    sw_create_bond(sw2, lag_name, ports_sw2, lacp_mode='active')

    step("Turning on all the interfaces used in this test")
    for intf in ports_sw1:
        verify_intf_status(sw1, intf, "link_state", "up")
    for intf in ports_sw2:
        verify_intf_status(sw2, intf, "link_state", "up")

    step('Setting LAGs lacp rate as fast in switches')
    set_port_parameter(sw1, lag_name, ['other_config:lacp-time=fast'])
    set_port_parameter(sw2, lag_name, ['other_config:lacp-time=fast'])

    step('Verify state machines from interfaces on Switch 1')
    sw_wait_until_all_sm_ready([sw1], ports_sw1, sm_col_and_dist)

    step('Verify state machines from interfaces on Switch 2')
    sw_wait_until_all_sm_ready([sw2], ports_sw2, sm_col_and_dist)

    ###########################################################################
    # 1.  When all member interfaces have bond_status up.
    ###########################################################################

    step("Verify that all the interfaces are added to LAG and that "
          "bond_status is up.")
    for intf in ports_sw1:
        verify_intf_in_bond(sw1, intf, "Expected interfaces "
                            "to be added to static lag")

        verify_intf_bond_status(sw1, intf, "up", "Expected interfaces "
                                "to have bond status UP")

    step("Verify LAG bond status is UP when all the member  interfaces "
         "have bond_status equal to UP")
    verify_port_bond_status(sw1, lag_name, "up", "Expected the LAG "
                            "to have bond status UP")

    ###########################################################################
    # 2.  When at least 1 member interface has bond_status up.
    ###########################################################################

    step("Turning off all interfaces of LAG but one")
    disable_intf_list(sw1, ports_sw1[1:4])

    step("Verify that turned off interfaces bond_status is down")
    for intf in ports_sw1[1:4]:
        verify_intf_bond_status(sw1, intf, "down", "Expected turned off "
                                "interfaces to have bond status DOWN")

    step("Verify that on interface bond_status is up")
    verify_intf_bond_status(sw1, ports_sw1[0], "up", "Expected turned on "
                            "interface to have bond status UP")

    step("Verify LAG bond status is UP when at least one member interface "
         "have bond_status equal to UP")
    verify_port_bond_status(sw1, lag_name, "up", "Expected the LAG "
                            "to have bond status UP")

    step("Turning back on interfaces")
    enable_intf_list(sw1, ports_sw1[1:4])

    ###########################################################################
    # 3.  Interfaces not member of LAG don't have bond_status.
    ###########################################################################

    step("Remove interface from LAG")
    remove_intf_from_bond(sw1, lag_name, ports_sw1[0])

    step("Verify interface is not part of LAG.")
    verify_intf_not_in_bond(sw1, ports_sw1[0],
                            "Expected the interfaces to be removed "
                            "from static lag")

    step("Verify that interface bond_status is empty.")
    verify_intf_bond_status_empty(sw1, ports_sw1[0], "Interface expected"
                                  " to have bond status EMPTY")

    step("Verify LAG bond status is UP")
    verify_port_bond_status(sw1, lag_name, "up", "Expected the LAG "
                            "to have bond status UP")

    step("Add interface back to LAG")
    add_intf_to_bond(sw1, lag_name, ports_sw1[0])

    step("Verify interface is part of LAG.")
    verify_intf_in_bond(sw1, ports_sw1[0], "Interfaces is not "
                        "added back to the LAG.")

    step("Verify that interface bond_status is up.")
    verify_intf_bond_status(sw1, ports_sw1[0], "up", "Expected interfaces "
                            "to have bond status UP")

    step("Verify LAG bond status is UP")
    verify_port_bond_status(sw1, lag_name, "up", "Expected the LAG "
                            "to have bond status UP")

    ###########################################################################
    # 4.  When all member interfaces have bond_status down.
    ###########################################################################

    step("Turning off all interfaces used in this test")
    disable_intf_list(sw1, ports_sw1)

    step("Verify that interfaces are not added to LAG when they are disabled"
         "and interface bond status is set to down")
    for intf in ports_sw1:
        verify_intf_not_in_bond(sw1, intf, "Interfaces should not be part "
                                "of LAG when they are disabled.")

        verify_intf_bond_status(sw1, intf, "down", "Expected interfaces "
                                "to have bond status DOWN")

    step("Verify that when all interfaces have bond_status equal to down "
         "LAG bond_status is down")
    verify_port_bond_status(sw1, lag_name, "down", "Expected the LAG "
                            "to have bond status DOWN")

    step("Turning back on all interfaces used in this test")
    enable_intf_list(sw1, ports_sw1)

    ###########################################################################
    # 5. Not eligible interface have bond_status equal to blocked.
    ###########################################################################

    step("Remove partner interfaces 2")
    remove_intf_from_bond(sw2, lag_name, p22)

    step("Verify that interface bond_status is blocked.")
    verify_intf_bond_status(sw1, p12, "blocked", "Expected "
                            "interfaces to have bond status BLOCKED")

    step("Verify LAG bond status is UP")
    verify_port_bond_status(sw1, lag_name, "up", "Expected the LAG "
                            "to have bond status UP")

    step("Add partner interface back to LAG")
    add_intf_to_bond(sw2, lag_name, p22)

    '''
        Falbback functionality is still not merge in rel/dill, so we need to
        disable cases 6 and 7.
    '''
    ###########################################################################
    # 6. When lacp_status = defaulted and fallback = false.
    ###########################################################################

    # step('Disabling Fallback on both switches')
    # set_port_parameter(sw1, lag_name, disable_fallback)
    # set_port_parameter(sw2, lag_name, disable_fallback)

    # step('Shutting down LAG1 on sw2')
    # set_port_parameter(sw2, lag_name, disable_lag)
    # step('Verify that all sw1 SMs are in "Defaulted and Expired"')
    # sw_wait_until_all_sm_ready([sw1], ports_sw1, active_no_fallback)

    # step("Verify LAG bond status is BLOCKED")
    # verify_port_bond_status(sw1, lag_name, "blocked", "Expected the LAG "
                            # "to have bond status BLOCKED")

    # step('Turning on LAG1 on sw2')
    # set_port_parameter(sw2, lag_name, active_lag)

    # step('Verify state machines from interfaces on Switch 1')
    # sw_wait_until_all_sm_ready([sw1], ports_sw1, sm_col_and_dist)

    # step('Verify state machines from interfaces on Switch 2')
    # sw_wait_until_all_sm_ready([sw2], ports_sw2, sm_col_and_dist)

    ###########################################################################
    # 7. When lacp_status = defaulted and fallback = true.
    ###########################################################################

    # step('Enabling Fallback on both switches')
    # set_port_parameter(sw1, lag_name, enable_fallback)
    # set_port_parameter(sw2, lag_name, enable_fallback)

    # step('Shutting down LAG1 on sw2')
    # set_port_parameter(sw2, lag_name, disable_lag)
    # step('Verify that all sw1 SMs are in "Defaulted and Expired"')
    # sw_wait_until_all_sm_ready([sw1], ports_sw1, active_fallback)

    # step("Verify LAG bond status is UP")
    # verify_port_bond_status(sw1, lag_name, "up", "Expected the LAG "
                            # "to have bond status UP")

    # step('Turning on LAG1 on sw2')
    # set_port_parameter(sw2, lag_name, active_lag)

    # step('Disabling Fallback on both switches')
    # set_port_parameter(sw1, lag_name, disable_fallback)
    # set_port_parameter(sw2, lag_name, disable_fallback)

    # step('Verify state machines from interfaces on Switch 1')
    # sw_wait_until_all_sm_ready([sw1], ports_sw1, sm_col_and_dist)

    # step('Verify state machines from interfaces on Switch 2')
    # sw_wait_until_all_sm_ready([sw2], ports_sw2, sm_col_and_dist)

    ###########################################################################
    # 8. When LAG has no member interfaces.
    ###########################################################################
    step("Remove all interfaces from LAG")
    remove_all_intf_from_bond(sw1, lag_name)

    step("Verify interface is not part of LAG and bond_status is empty.")
    for intf in ports_sw1:
        verify_intf_not_in_bond(sw1, intf,
                                "Expected the interfaces to be removed "
                                "from static lag")
        verify_intf_bond_status_empty(sw1, intf, "Interfaces expected"
                                      " to have bond status EMPTY")

    step("Verify LAG bond status is DOWN when LAG has no interfaces")
    verify_port_bond_status(sw1, lag_name, "down", "Expected the LAG "
                            "to have bond status DOWN")
def test_fb_toggle_lacp_flag_passive(topology, step, main_setup):
    """Toggle 'lacp' flag to 'passive'.

    To disable LAG 1 on both switches, 'lacp' flag will be toggled between
    '[]' and 'passive'.

    Note: Both switches cannot be in the same state of 'passive' or
    connectivity will be lost.
    """

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

    assert sw1 is not None
    assert sw2 is not None

    print_header('Fallback enabled, toggle "lacp" flag to passive')

    ##########################################################################
    # Add 'fallback' flag
    ##########################################################################
    print('Enabling Fallback on both switches')
    set_port_parameter(sw1, test_lag, enable_fallback)
    set_port_parameter(sw2, test_lag, enable_fallback)

    ##########################################################################
    # LAG 1 disabled on sw1
    ##########################################################################
    print('Setting sw2 LAG to "passive"')
    set_port_parameter(sw2, test_lag, passive_lag)
    print('Shutting down LAG1 on sw1')
    set_port_parameter(sw1, test_lag, disable_lag)

    print('Verify that one interface is "Collecting, Distributing and '
          'Defaulted" on sw2')
    intf_fallback_enabled = sw_wait_until_one_sm_ready([sw2], intf_labels,
                                                       passive_fallback)

    print('Found interface: %s' % intf_fallback_enabled)

    print('Verify that other interfaces are "Defaulted" on sw2')
    tmp = list(intf_labels)
    tmp.remove(intf_fallback_enabled)
    sw_wait_until_all_sm_ready([sw2], tmp, passive_other_intf)

    print('Enabling LAG1 on sw1')
    set_port_parameter(sw1, test_lag, active_lag)
    print('Verify all interface SM from sw1 are "active"')
    sw_wait_until_all_sm_ready([sw1], intf_labels, active_ready)
    print('Verify all interface SM from sw2 are "passive"')
    sw_wait_until_all_sm_ready([sw2], intf_labels, passive_ready)

    print('Setting sw2 LAG to "active"')
    set_port_parameter(sw2, test_lag, active_lag)
    print('Verify all interface SM from both switches are working')
    sw_wait_until_all_sm_ready([sw1, sw2], intf_labels, active_ready)

    ##########################################################################
    # LAG 1 disabled on sw2
    ##########################################################################
    print('Setting sw1 LAG to "passive"')
    set_port_parameter(sw1, test_lag, passive_lag)
    print('Shutting down LAG1 on sw2')
    set_port_parameter(sw2, test_lag, disable_lag)

    print('Verify that one interface is "Collecting, Distributing and '
          'Defaulted" on sw1')
    intf_fallback_enabled = sw_wait_until_one_sm_ready([sw1], intf_labels,
                                                       passive_fallback)

    print('Found interface: %s' % intf_fallback_enabled)

    print('Verify that other interfaces are "Defaulted" on sw1')
    tmp = list(intf_labels)
    tmp.remove(intf_fallback_enabled)
    sw_wait_until_all_sm_ready([sw1], tmp, passive_other_intf)

    print('Enabling LAG1 on sw2')
    set_port_parameter(sw2, test_lag, active_lag)
    print('Verify all interface SM from sw1 are "passive"')
    sw_wait_until_all_sm_ready([sw1], intf_labels, passive_ready)
    print('Verify all interface SM from sw2 are "active"')
    sw_wait_until_all_sm_ready([sw2], intf_labels, active_ready)

    print('Setting sw1 LAG to "active"')
    set_port_parameter(sw1, test_lag, active_lag)

    ##########################################################################
    # Remove added flag
    ##########################################################################
    print('Clearing "lacp-fallback-ab" flag from OVSDB')
    remove_port_parameter(sw1, test_lag, other_config_key, [fallback_key])
    remove_port_parameter(sw2, test_lag, other_config_key, [fallback_key])

    print('Verify all interface SM from both switches are working')
    sw_wait_until_all_sm_ready([sw1, sw2], intf_labels, active_ready)
def test_fb_toggle_admin_flag(topology, step, main_setup):
    """Toggle 'admin' flag.

    To disable LAG 1 on both switches, 'admin' flag will be toggled between
    'up' and 'down'.
    """

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

    assert sw1 is not None
    assert sw2 is not None

    print_header('Fallback enabled, toggle "admin" flag')

    ##########################################################################
    # Add 'fallback' flag
    ##########################################################################
    print('Enabling Fallback on both switches')
    set_port_parameter(sw1, test_lag, enable_fallback)
    set_port_parameter(sw2, test_lag, enable_fallback)

    ##########################################################################
    # LAG 1 disabled on sw1
    ##########################################################################
    print('Shutting down LAG1 on sw1')
    set_port_parameter(sw1, test_lag, disable_admin)
    print('Verify that one interface is "Collecting, Distributing and '
          'Defaulted" on sw2')
    intf_fallback_enabled = sw_wait_until_one_sm_ready([sw2], intf_labels,
                                                       active_fallback)

    print('Found interface: %s' % intf_fallback_enabled)

    print('Verify that other interfaces are "Defaulted" on sw2')
    tmp = list(intf_labels)
    tmp.remove(intf_fallback_enabled)
    sw_wait_until_all_sm_ready([sw2], tmp, active_other_intf)

    print('Enabling LAG1 on sw1')
    set_port_parameter(sw1, test_lag, enable_admin)
    print('Verify all interfaces SM from both switches are working')
    sw_wait_until_all_sm_ready([sw1, sw2], intf_labels, active_ready)

    ##########################################################################
    # LAG 1 disabled on sw2
    ##########################################################################
    print('Shutting down LAG1 on sw2')
    set_port_parameter(sw2, test_lag, disable_admin)
    print('Verify that one interface is "Collecting, Distributing and '
          'Defaulted" on sw1')
    intf_fallback_enabled = sw_wait_until_one_sm_ready([sw1], intf_labels,
                                                       active_fallback)

    print('Found interface: %s' % intf_fallback_enabled)

    print('Verify that other interfaces are "Defaulted" on sw1')
    tmp = list(intf_labels)
    tmp.remove(intf_fallback_enabled)
    sw_wait_until_all_sm_ready([sw1], tmp, active_other_intf)

    print('Enabling LAG1 on sw2')
    set_port_parameter(sw2, test_lag, enable_admin)

    ##########################################################################
    # Remove added flag
    ##########################################################################
    print('Clearing "lacp-fallback-ab" flag from OVSDB')
    remove_port_parameter(sw1, test_lag, other_config_key, [fallback_key])
    remove_port_parameter(sw2, test_lag, other_config_key, [fallback_key])

    print('Verify all interfaces SM from both switches are working')
    sw_wait_until_all_sm_ready([sw1, sw2], intf_labels, active_ready)
def test_nf_false_flag_toggle_lacp_passive(topology, step, main_setup):
    """Toggle 'lacp' flag to 'passive' with 'false' flag.

    The source code must handle also the possibility to retrieve from OVSDB the
    'lacp-fallback-ab' flag with 'false' even when by default the flag is not
    present.

    To disable LAG 1 on both switches, 'lacp' flag will be toggled between
    '[]' and 'passive'.
    """

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

    assert sw1 is not None
    assert sw2 is not None

    print_header('Fallback disabled with false flag, toggle "lacp" flag to '
                 'passive')

    ##########################################################################
    # Add 'fallback' flag as 'false'
    ##########################################################################
    print('Setting "lacp-fallback-ab" flag into OVSDB')
    set_port_parameter(sw1, test_lag, disable_fallback)
    set_port_parameter(sw2, test_lag, disable_fallback)

    ##########################################################################
    # LAG 1 disabled on sw1
    ##########################################################################
    print('Setting sw2 LAG to "passive"')
    set_port_parameter(sw2, test_lag, passive_lag)
    print('Shutting down LAG1 on sw1')
    set_port_parameter(sw1, test_lag, disable_lag)
    print('Verify that all sw2 SMs are in "Defaulted and Expired"')
    sw_wait_until_all_sm_ready([sw2], intf_labels, passive_no_fallback)

    print('Enabling LAG1 on sw1')
    set_port_parameter(sw1, test_lag, active_lag)
    print('Verify all interface SM from sw1 are "active"')
    sw_wait_until_all_sm_ready([sw1], intf_labels, active_ready)
    print('Verify all interface SM from sw2 are "passive"')
    sw_wait_until_all_sm_ready([sw2], intf_labels, passive_ready)

    print('Setting sw2 LAG to "active"')
    set_port_parameter(sw2, test_lag, active_lag)
    print('Verify all interface SM from both switches are working')
    sw_wait_until_all_sm_ready([sw1, sw2], intf_labels, active_ready)

    ##########################################################################
    # LAG 1 disabled on sw2
    ##########################################################################
    print('Setting sw1 LAG to "passive"')
    set_port_parameter(sw1, test_lag, passive_lag)
    print('Shutting down LAG1 on sw2')
    set_port_parameter(sw2, test_lag, disable_lag)
    print('Verify that all sw1 SMs are in "Defaulted and Expired"')
    sw_wait_until_all_sm_ready([sw1], intf_labels, passive_no_fallback)

    print('Enabling LAG1 on sw2')
    set_port_parameter(sw2, test_lag, active_lag)
    print('Verify all interface SM from sw1 are "passive"')
    sw_wait_until_all_sm_ready([sw1], intf_labels, passive_ready)
    print('Verify all interface SM from sw2 are "active"')
    sw_wait_until_all_sm_ready([sw2], intf_labels, active_ready)

    print('Setting sw1 LAG to "active"')
    set_port_parameter(sw1, test_lag, active_lag)

    ##########################################################################
    # Remove added flag
    ##########################################################################
    print('Clearing "lacp-fallback-ab" flag from OVSDB')
    remove_port_parameter(sw1, test_lag, other_config_key, [fallback_key])
    remove_port_parameter(sw2, test_lag, other_config_key, [fallback_key])

    print('Verify all interface SM from both switches are working')
    sw_wait_until_all_sm_ready([sw1, sw2], intf_labels, active_ready)