def test_vconf_4(monkeypatch): """Verify that vconfig function return exception when mode is incorrect. """ def mockreturn_8021q(self): pass monkeypatch.setattr(GenericLinuxHost, 'enable_8021q', mockreturn_8021q) lh = GenericLinuxHost(LH_CFG, OPTS) mode = "upfg" with pytest.raises(Exception) as excepinfo: lh.vconfig(mode, "xe1", 3) result = "Incorrect mode=%s" % mode assert result == str(excepinfo.value)
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]
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