Exemple #1
0
def test_enable_8021q_1(monkeypatch):
    """Verify that enable_802q_1 function return exception when 802.1q is not supported by current os.

    """
    def mockreturn(command):
        return CmdStatus("", "", 0)
    # monkeypatch.setattr(CLISSHNetNS, 'exec_command', mockreturn)
    lh = GenericLinuxHost(LH_CFG, OPTS)
    monkeypatch.setattr(lh.ssh, 'exec_command', mockreturn)
    with pytest.raises(Exception) as excepinfo:
        lh.enable_8021q()
    result = "Current OS doesn't support 802.1q."
    assert result == str(excepinfo.value)
Exemple #2
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]
Exemple #3
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