Exemplo n.º 1
0
def test_enable_8021q_2(monkeypatch):
    """Verify that enable_802q_1 function return correct set of commands when 8021q is already loaded.

    """
    comm_expected = ['modprobe -l | grep 8021q', 'lsmod | grep ^8021q']
    cmd_list = []

    def mockreturn(command):
        cmd_list.append(command)
        so = "8021q"
        return CmdStatus(so, "", 0)
    lh = GenericLinuxHost(LH_CFG, OPTS)
    monkeypatch.setattr(lh.ssh, 'exec_command', mockreturn)
    lh.enable_8021q()
    for comm, value in enumerate(comm_expected):
        assert cmd_list[comm] == comm_expected[comm]
Exemplo n.º 2
0
def test_getmac_1(monkeypatch):
    """Verify that getmac function return interface mac address.

    """
    result_expected = "94:de:80:b0:25:f8"
    cmd_list = []

    def mockreturn(self, command):
        cmd_list.append(command)
        result = "2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 \n \
                  link/ether 94:de:80:b0:25:f8 brd ff:ff:ff:ff:ff:ff"
        return CmdStatus(result, "", 0)
    monkeypatch.setattr(GenericLinuxHost, 'exec_cmd', mockreturn)
    lh2 = GenericLinuxHost(LH_CFG, OPTS)
    result_received = lh2.getmac("xe1")
    assert result_expected == result_received
Exemplo n.º 3
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.º 4
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.º 5
0
def test_enable_8021q_3(monkeypatch):
    """Verify that enable_802q_1 function return exception if 8021q can not be loaded.

    """
    cmd_list = []

    def mockreturn(command):
        cmd_list.append(command)
        so = "8021q"
        if command == "lsmod | grep ^8021q":
            so = ""
        return CmdStatus(so, "", 0)
    lh = GenericLinuxHost(LH_CFG, OPTS)
    monkeypatch.setattr(lh.ssh, 'exec_command', mockreturn)
    with pytest.raises(Exception) as excepinfo:
        lh.enable_8021q()
    result = "Fail to load 8021q:\n8021q"
    assert str(excepinfo.value) == result
Exemplo n.º 6
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.º 7
0
def test_vconf_2(monkeypatch):
    """Verify vconf function return correct command when add parameter is set.

    """
    commands_expected = ['vconfig add xe1 3']

    def mockreturn_8021q(self):
        pass
    monkeypatch.setattr(GenericLinuxHost, 'enable_8021q', mockreturn_8021q)

    cmd_list = []

    def mockreturn_exec_cmd(self, command):
        cmd_list.append(command)
        return "", ""
    monkeypatch.setattr(GenericLinuxHost, 'exec_cmd', mockreturn_exec_cmd)
    lh = GenericLinuxHost(LH_CFG, OPTS)
    lh.vconfig("add", "xe1", 3)
    assert cmd_list[0] == commands_expected[0]
Exemplo n.º 8
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
Exemplo n.º 9
0
def test_vconf_3(monkeypatch):
    """Verify vconf function return exception after creating vlan which is already exist.

    """
    expected_result = "Port xe1 already in 3 vlan"

    def mockreturn_8021q(self):
        pass
    monkeypatch.setattr(GenericLinuxHost, 'enable_8021q', mockreturn_8021q)

    cmd_list = []

    def mockreturn_exec_cmd(self, command):
        cmd_list.append(command)
        return "", ""
    monkeypatch.setattr(GenericLinuxHost, 'exec_cmd', mockreturn_exec_cmd)
    lh = GenericLinuxHost(LH_CFG, OPTS)
    with pytest.raises(Exception) as excepinfo:
        lh.vlans = {'xe1': [3]}
        lh.vconfig("add", "xe1", 3)
    assert str(excepinfo.value) == expected_result