def test_add_mgmt_iface_2(monkeypatch): """Verify that add_mgmt_iface function return exception when mgmt iface can't be deleted. """ output_exept = "Failed to create management iface for HOST.\n" def mockreturn(command): return "", "", "" lh = IpNetworkNamespace(LH_CFG, OPTS) with pytest.raises(Exception) as excepinfo: lh.add_mgmt_iface() assert str(excepinfo.value) == output_exept
def test_add_mgmt_iface_1(monkeypatch): """Verify that mgmt interface return correct set of commands for adding mgmt interface. """ comm_expect = ['ip link add veth19 type veth peer name veth19 netns HOST', 'brctl addif mbrlocalhos254 veth19', 'ifconfig veth19 up', 'ifconfig veth19 localhost up'] cmd_list = [] def mockreturn_native_cmd(command): cmd_list.append(command) rc = "0" return "", "", rc def mockreturn_exec_cmd(command): cmd_list.append(command) return CmdStatus("", "", 0) lh = IpNetworkNamespace(LH_CFG, OPTS) monkeypatch.setattr(lh.ssh, 'native_cmd', mockreturn_native_cmd) monkeypatch.setattr(lh.ssh, 'exec_command', mockreturn_exec_cmd) lh.add_mgmt_iface() assert comm_expect == comm_expect