Exemplo n.º 1
0
def test_del_mgmt_bridge_1(monkeypatch):
    """Verify that del_mgmt_bridge function return correct set of commands to delete mgmt bridge.

    """
    comm_expect = ['ifconfig mbrlocalhos254 down', 'brctl delbr mbrlocalhos254']
    cmd_list = []

    def mockreturn_mgmt_br(command):
        so = True
        return so

    def mockreturn_native_cmd(command):
        cmd_list.append(command)
        rc = "0"
        return "", "", rc
    lh = IpNetworkNamespace(LH_CFG, OPTS)
    monkeypatch.setattr(IpNetworkNamespace, 'check_mgmt_bridge', mockreturn_mgmt_br)
    monkeypatch.setattr(lh.ssh, 'native_cmd', mockreturn_native_cmd)
    lh.del_mgmt_bridge()
    print(cmd_list)
    assert comm_expect[0] == cmd_list[0]
Exemplo n.º 2
0
def test_del_mgmt_bridge_2(monkeypatch):
    """Verify that del_mgmt_bridge function return exception when management bridge can not be deleted.

    """
    output_result = "Failed to delete management bridge for Network namespaces.\n" + "Stdout: , Stderr: Error"
    cmd_list = []

    def mockreturn_mgmt_br(command):
        so = True
        return so

    def mockreturn_native_cmd(command):
        cmd_list.append(command)
        rc = "5"
        se = "Error"
        return "", se, rc
    lh = IpNetworkNamespace(LH_CFG, OPTS)
    monkeypatch.setattr(IpNetworkNamespace, 'check_mgmt_bridge', mockreturn_mgmt_br)
    monkeypatch.setattr(lh.ssh, 'native_cmd', mockreturn_native_cmd)
    with pytest.raises(Exception) as excepinfo:
        lh.del_mgmt_bridge()
    print(str(excepinfo.value))
    assert str(excepinfo.value) == output_result