Exemplo n.º 1
0
def test_brctl_14():
    """Verify that brctl function with mac parameter return exception when bridge name is not set.

    """
    lh = GenericLinuxHost(LH_CFG, OPTS)
    with pytest.raises(Exception) as excepinfo:
        lh.brctl("macs", ["xe1"])
    result = "Bridge name is not set."
    assert result == str(excepinfo.value)
Exemplo n.º 2
0
def test_brctl_9():
    """Verify that brctl command return exception when br name is not set.

    """
    lh = GenericLinuxHost(LH_CFG, OPTS)
    mode = "del"
    with pytest.raises(Exception) as excepinfo:
        lh.brctl(mode)
    result = "Bridge name is not set."
    assert result == str(excepinfo.value)
Exemplo n.º 3
0
def test_brctl_10():
    """Verify brctl command return exception when incorrect mode is set.

    """
    lh = GenericLinuxHost(LH_CFG, OPTS)
    mode = "upfg"
    with pytest.raises(Exception) as excepinfo:
        lh.brctl(mode)
    result = "Unknown mode for brctl method."
    assert result == str(excepinfo.value)
Exemplo n.º 4
0
def test_brctl_6():
    """Verify brctl command with delif parameter return exception when ports are not given.

    """
    lh = GenericLinuxHost(LH_CFG, OPTS)
    mode = "delif"
    with pytest.raises(Exception) as excepinfo:
        lh.brctl(mode, None, "br0")
    result = "Bridge name or port is not set."
    assert result == str(excepinfo.value)
Exemplo n.º 5
0
def test_brctl_5():
    """Verify brctl command return exception when bridge name is not given as parameter.

    """
    lh = GenericLinuxHost(LH_CFG, OPTS)
    mode = "delif"
    with pytest.raises(Exception) as excepinfo:
        lh.brctl(mode)
    result = "Bridge name or port is not set."
    assert result == str(excepinfo.value)
Exemplo n.º 6
0
def test_brctl_4(monkeypatch):
    """Verify cfg parameter in brctl return exception when bridge name is not given.

    """
    lh = GenericLinuxHost(LH_CFG, OPTS)
    mode = "cfg"
    with pytest.raises(Exception) as excepinfo:
        lh.brctl(mode)
    result = "Bridge name is not set."
    assert result == str(excepinfo.value)
Exemplo n.º 7
0
def test_brctl_1(monkeypatch):
    """Verify that brctl command return correct set of commands when add parameter with stp_cfg  is defined.

    """
    expected_commands = ["ifconfig -s -a | grep ^lhbr | awk '{print $1}'", 'sudo brctl addbr lhbr1', 'sudo brctl addif lhbr1 xe1',
                         'sudo brctl stp lhbr1 on', 'sudo brctl setbridgeprio lhbr1 1000', 'sudo ifconfig lhbr1 up']
    cmd_list = []

    def mockreturn(command):
        cmd_list.append(command)
        return CmdStatus("", "", 0)
    lh = GenericLinuxHost(LH_CFG, OPTS)
    monkeypatch.setattr(lh.ssh, 'exec_command', mockreturn)
    lh.brctl("add", ["xe1"], "br0", "on", {"bprio": 1000})
    for comm, value in enumerate(expected_commands):
        assert expected_commands[comm] == cmd_list[comm]
Exemplo n.º 8
0
def test_brctl_12(monkeypatch):
    """Verify that brctl function return dictionary when "macs" parameter is set.

    """
    result_expected = {'1': [{'ageing timer': '119.25', 'no mac addr': '00:10:4b:b6:c6:e4', 'is local?': 'no'}],
                       '4': [{'ageing timer': '0.00', 'no mac addr': '08:00:09:fc:d2:11', 'is local?': 'yes'}]}
    cmd_list = []

    def mockreturn(self, command):
        cmd_list.append(command)
        result = "port \t no mac addr \t is local? \t ageing timer \n 1 \t 00:10:4b:b6:c6:e4 \t no \t 119.25 \n 4 \t 08:00:09:fc:d2:11 \t yes \t 0.00 \n"
        return CmdStatus(result, "", 0)
    monkeypatch.setattr(GenericLinuxHost, 'exec_cmd', mockreturn)
    lh2 = GenericLinuxHost(LH_CFG, OPTS)
    result_received = lh2.brctl("macs", None, "br0")
    assert result_received == result_expected
Exemplo n.º 9
0
def test_brctl_2(monkeypatch):
    """Verify that brctl command return correct set of commands when add command is used.

    """
    expected_brname = "lhbr1"
    expected_commands = ["ifconfig -s -a | grep ^lhbr | awk '{print $1}'", 'sudo brctl addbr lhbr1', 'sudo brctl addif lhbr1 xe1', 'sudo brctl stp lhbr1 on',
                         'sudo ifconfig lhbr1 up']
    cmd_list = []

    def mockreturn(command):
        cmd_list.append(command)
        return CmdStatus("", "", 0)
    lh = GenericLinuxHost(LH_CFG, OPTS)
    monkeypatch.setattr(lh.ssh, 'exec_command', mockreturn)
    brname = lh.brctl("add", ["xe1"], "br0", "on")
    assert brname == expected_brname
    for comm, value in enumerate(expected_commands):
        assert expected_commands[comm] == cmd_list[comm]
Exemplo n.º 10
0
def test_brctl_11(monkeypatch):
    """Verify that brctl function return proper dictionary when 'stpstat' parameter is set.

    """
    result_expected = {'': {}, 'proxy1': {'designated root': '01f4.001b2189ac4c', 'state': 'forwarding', 'port id': '0000', 'path cost': '2',
                       'port number': '0'}, 'proxy0': {'port number': '2'}, 'lhbr2': {'max age': '20.00', 'designated root': '05dc.4aa38155aa0f',
                       'bridge max age': '4', 'max age 20.00': 'bridge max age', 'bridge id': '05dc.4aa38155aa0f', 'path cost': '4', 'root port': '1'}}
    cmd_list = []

    def mockreturn(self, command):
        cmd_list.append(command)
        result = "lhbr2 \nbridge id \t 05dc.4aa38155aa0f \ndesignated root \t 05dc.4aa38155aa0f \nroot port \t1 \t path cost \t4 \nmax age \t 20.00 \t \
                bridge max age \t 4 \n  max age 20.00 \t bridge max age \t 20.00 \n\nproxy0 (2) \n\n port id \t 0000 \t state \t forwarding \
                \ndesignated root \t 01f4.001b2189ac4c \t path cost \t 2 \n\nproxy1 (0) \n port id \t 0000 \t state \t forwarding \n designated root \
                \t 01f4.001b2189ac4c \t path cost \t 2 \n\n"
        return CmdStatus(result, "", 0)
    monkeypatch.setattr(GenericLinuxHost, 'exec_cmd', mockreturn)
    lh2 = GenericLinuxHost(LH_CFG, OPTS)
    result_received = lh2.brctl("stpstat", None, "br0")
    assert result_expected == result_received