def test_vconf_1(monkeypatch): """Verify vconf function return correct command when rem parameter is set. """ commands_expected = ['vconfig rem 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.vlans = {'xe1': [3]} lh.vconfig("rem", "xe1", 3) assert cmd_list[0] == commands_expected[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