1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-25 01:38:08 +00:00
gns3-server/tests/dynamips/test_ethernet_switch.py

88 lines
2.2 KiB
Python
Raw Normal View History

2013-12-22 00:42:33 +00:00
from gns3server.modules.dynamips import EthernetSwitch
from gns3server.modules.dynamips import NIO_Null
from gns3server.modules.dynamips import DynamipsError
import pytest
@pytest.fixture
def ethsw(request, hypervisor):
ethsw = EthernetSwitch(hypervisor, "Ethernet switch")
request.addfinalizer(ethsw.delete)
return ethsw
def test_ethsw_exists(ethsw):
assert ethsw.list()
def test_rename_ethsw(ethsw):
ethsw.name = "new Ethernet switch"
2013-12-22 00:42:33 +00:00
assert ethsw.name == "new Ethernet switch"
def test_add_remove_nio(ethsw):
nio = NIO_Null(ethsw.hypervisor)
ethsw.add_nio(nio, 0) # add NIO on port 0
assert ethsw.nios
ethsw.remove_nio(0) # remove NIO from port 0
nio.delete()
def test_add_nio_already_allocated_port(ethsw):
nio = NIO_Null(ethsw.hypervisor)
ethsw.add_nio(nio, 0) # add NIO on port 0
with pytest.raises(DynamipsError):
ethsw.add_nio(nio, 0)
nio.delete()
def test_remove_nio_non_allocated_port(ethsw):
with pytest.raises(DynamipsError):
ethsw.remove_nio(0) # remove NIO from port 0
def test_set_access_port(ethsw):
nio = NIO_Null(ethsw.hypervisor)
ethsw.add_nio(nio, 0) # add NIO on port 0
ethsw.set_access_port(0, 10) # set port 0 as access in VLAN 10
assert ethsw.mapping[0] == ("access", 10)
ethsw.remove_nio(0) # remove NIO from port 0
nio.delete()
def test_set_dot1q_port(ethsw):
nio = NIO_Null(ethsw.hypervisor)
ethsw.add_nio(nio, 0) # add NIO on port 0
ethsw.set_dot1q_port(0, 1) # set port 0 as 802.1Q trunk with native VLAN 1
assert ethsw.mapping[0] == ("dot1q", 1)
ethsw.remove_nio(0) # remove NIO from port 0
nio.delete()
def test_set_qinq_port(ethsw):
nio = NIO_Null(ethsw.hypervisor)
ethsw.add_nio(nio, 0) # add NIO on port 0
ethsw.set_qinq_port(0, 100) # set port 0 as QinQ trunk with outer VLAN 100
assert ethsw.mapping[0] == ("qinq", 100)
ethsw.remove_nio(0) # remove NIO from port 0
nio.delete()
def test_get_mac_addr_table(ethsw):
assert not ethsw.get_mac_addr_table() # MAC address table should be empty
def test_clear_mac_addr_table(ethsw):
ethsw.clear_mac_addr_table()