Пример #1
0
def test_iface_type(mock_bridgemem, mock_bridge, mock_bond, mock_bondmem):
    # port is a bridge
    mock_bond.return_value = False
    mock_bridgemem.return_value = False
    mock_bridge.return_value = True
    eth1 = linux_iface.iface('eth1')
    assert_equals(isinstance(eth1, linux_bridge.Bridge), True)
    # port is bond
    mock_bridgemem.return_value = False
    mock_bridge.return_value = False
    mock_bond.return_value = True
    bond0 = linux_iface.iface('bond0')
    assert_equals(isinstance(bond0, linux_bond.Bond), True)
    # port is bridgemem
    mock_bridgemem.return_value = True
    mock_bridge.return_value = False
    mock_bond.return_value = False
    mock_bondmem.return_value = False
    bridgemem = linux_iface.iface('eth2')
    assert_equals(isinstance(bridgemem, linux_bridge.BridgeMember), True)
    # port is bondmem
    mock_bondmem.return_value = True
    mock_bridgemem.return_value = False
    mock_bridge.return_value = False
    mock_bond.return_value = False
    bridgemem = linux_iface.iface('eth2')
    assert_equals(isinstance(bridgemem, linux_bond.BondMember), True)
    # regular port
    mock_bridge.return_value = False
    mock_bond.return_value = False
    eth2 = linux_iface.iface('eth2')
    assert_equals(isinstance(eth2, linux_iface.Iface), True)
    assert_equals(isinstance(eth2, linux_bond.Bond), False)
    assert_equals(isinstance(eth2, linux_bridge.Bridge), False)
Пример #2
0
def test_iface_type(mock_bridgemem,
                    mock_bridge, mock_bond,
                    mock_bondmem):
    # port is a bridge
    mock_bond.return_value = False
    mock_bridgemem.return_value = False
    mock_bridge.return_value = True
    eth1 = linux_iface.iface('eth1')
    assert_equals(isinstance(eth1, linux_bridge.Bridge), True)
    # port is bond
    mock_bridgemem.return_value = False
    mock_bridge.return_value = False
    mock_bond.return_value = True
    bond0 = linux_iface.iface('bond0')
    assert_equals(isinstance(bond0, linux_bond.Bond), True)
    # port is bridgemem
    mock_bridgemem.return_value = True
    mock_bridge.return_value = False
    mock_bond.return_value = False
    mock_bondmem.return_value = False
    bridgemem = linux_iface.iface('eth2')
    assert_equals(isinstance(bridgemem, linux_bridge.BridgeMember), True)
    # port is bondmem
    mock_bondmem.return_value = True
    mock_bridgemem.return_value = False
    mock_bridge.return_value = False
    mock_bond.return_value = False
    bridgemem = linux_iface.iface('eth2')
    assert_equals(isinstance(bridgemem, linux_bond.BondMember), True)
    # regular port
    mock_bridge.return_value = False
    mock_bond.return_value = False
    eth2 = linux_iface.iface('eth2')
    assert_equals(isinstance(eth2, linux_iface.Iface), True)
    assert_equals(isinstance(eth2, linux_bond.Bond), False)
    assert_equals(isinstance(eth2, linux_bridge.Bridge), False)
Пример #3
0
def iface(name, cache=None):
    """
    :return: ``:class:PrintIface`` instance that matches \
        correct iface type of the named interface
    :return: None if interface does not exist
    """
    # create test iface.
    test_iface = linux_iface.iface(name, cache=cache)
    if not test_iface.exists():
        return None
    if test_iface.is_bridge():
        bridge = nn.import_module('netshow.linux.print_bridge')
        return bridge.PrintBridge(test_iface)
    elif test_iface.is_bond():
        bond = nn.import_module('netshow.linux.print_bond')
        return bond.PrintBond(test_iface)
    elif test_iface.is_bondmem():
        bondmem = nn.import_module('netshow.linux.print_bond')
        return bondmem.PrintBondMember(test_iface)
    elif test_iface.is_bridgemem():
        bridge = nn.import_module('netshow.linux.print_bridge')
        return bridge.PrintBridgeMember(test_iface)
    return PrintIface(test_iface)