2016-09-13 07:47:22 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# Copyright (C) 2016 GNS3 Technologies Inc.
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
import uuid
|
|
|
|
|
|
|
|
from tests.utils import AsyncioMagicMock
|
|
|
|
|
|
|
|
from gns3server.controller.node import Node
|
2017-01-05 16:49:36 +00:00
|
|
|
from gns3server.controller.ports.ethernet_port import EthernetPort
|
2016-09-13 07:47:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def compute():
|
|
|
|
s = AsyncioMagicMock()
|
|
|
|
s.id = "http://test.com:42"
|
|
|
|
return s
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def node(compute, project):
|
|
|
|
node = Node(project, compute, "demo",
|
|
|
|
node_id=str(uuid.uuid4()),
|
2017-01-09 15:48:42 +00:00
|
|
|
node_type="qemu",
|
2016-09-13 07:47:22 +00:00
|
|
|
console_type="vnc",
|
|
|
|
properties={"startup_script": "echo test"})
|
|
|
|
return node
|
|
|
|
|
|
|
|
|
|
|
|
def test_list_ports(node):
|
|
|
|
"""
|
|
|
|
List port by default
|
|
|
|
"""
|
2020-06-16 04:29:03 +00:00
|
|
|
|
2021-04-17 14:04:28 +00:00
|
|
|
assert node.asdict()["ports"] == [
|
2016-09-13 07:47:22 +00:00
|
|
|
{
|
|
|
|
"name": "Ethernet0",
|
2018-08-13 08:45:24 +00:00
|
|
|
"short_name": "e0",
|
2016-09-13 07:47:22 +00:00
|
|
|
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
|
|
|
"port_number": 0,
|
|
|
|
"adapter_number": 0,
|
|
|
|
"link_type": "ethernet"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2017-01-09 15:48:42 +00:00
|
|
|
def test_list_ports_vpcs(node):
|
|
|
|
"""
|
|
|
|
List port by default
|
|
|
|
"""
|
2020-06-16 04:29:03 +00:00
|
|
|
|
2017-01-09 15:48:42 +00:00
|
|
|
node._node_type = "vpcs"
|
2021-04-17 14:04:28 +00:00
|
|
|
assert node.asdict()["ports"] == [
|
2017-01-09 15:48:42 +00:00
|
|
|
{
|
|
|
|
"name": "Ethernet0",
|
|
|
|
"short_name": "e0",
|
|
|
|
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
|
|
|
"port_number": 0,
|
|
|
|
"adapter_number": 0,
|
|
|
|
"link_type": "ethernet"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2017-01-11 17:38:28 +00:00
|
|
|
def test_list_ports_docker(node):
|
|
|
|
"""
|
|
|
|
List port by default
|
|
|
|
"""
|
2020-06-16 04:29:03 +00:00
|
|
|
|
2017-01-11 17:38:28 +00:00
|
|
|
node._node_type = "docker"
|
|
|
|
node._properties["adapters"] = 2
|
2021-04-17 14:04:28 +00:00
|
|
|
assert node.asdict()["ports"] == [
|
2017-01-11 17:38:28 +00:00
|
|
|
{
|
|
|
|
"name": "eth0",
|
|
|
|
"short_name": "eth0",
|
|
|
|
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
|
|
|
"port_number": 0,
|
|
|
|
"adapter_number": 0,
|
|
|
|
"link_type": "ethernet"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "eth1",
|
|
|
|
"short_name": "eth1",
|
|
|
|
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
|
|
|
"port_number": 0,
|
|
|
|
"adapter_number": 1,
|
|
|
|
"link_type": "ethernet"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2016-09-13 07:47:22 +00:00
|
|
|
def test_list_ports_port_name_format(node):
|
|
|
|
"""
|
|
|
|
Support port name format
|
|
|
|
"""
|
2020-06-16 04:29:03 +00:00
|
|
|
|
2016-09-13 07:47:22 +00:00
|
|
|
node._first_port_name = None
|
|
|
|
node._port_name_format = "eth{}"
|
2016-09-15 12:51:40 +00:00
|
|
|
node._list_ports()
|
2021-04-17 14:04:28 +00:00
|
|
|
assert node.asdict()["ports"][0]["name"] == "eth0"
|
2016-09-13 07:47:22 +00:00
|
|
|
node._port_name_format = "eth{port0}"
|
2016-09-15 12:51:40 +00:00
|
|
|
node._list_ports()
|
2021-04-17 14:04:28 +00:00
|
|
|
assert node.asdict()["ports"][0]["name"] == "eth0"
|
2016-09-13 07:47:22 +00:00
|
|
|
node._port_name_format = "eth{port1}"
|
2016-09-15 12:51:40 +00:00
|
|
|
node._list_ports()
|
2021-04-17 14:04:28 +00:00
|
|
|
assert node.asdict()["ports"][0]["name"] == "eth1"
|
2016-09-13 07:47:22 +00:00
|
|
|
|
|
|
|
node._first_port_name = ""
|
|
|
|
node._port_segment_size = 2
|
|
|
|
node._port_name_format = "eth{segment0}/{port0}"
|
|
|
|
node.properties["adapters"] = 8
|
2016-09-15 12:51:40 +00:00
|
|
|
node._list_ports()
|
2021-04-17 14:04:28 +00:00
|
|
|
assert node.asdict()["ports"][6]["name"] == "eth3/0"
|
|
|
|
assert node.asdict()["ports"][7]["name"] == "eth3/1"
|
2016-09-13 07:47:22 +00:00
|
|
|
|
|
|
|
node._first_port_name = "mgnt0"
|
2016-09-15 12:51:40 +00:00
|
|
|
node._list_ports()
|
2021-04-17 14:04:28 +00:00
|
|
|
assert node.asdict()["ports"][0]["name"] == "mgnt0"
|
|
|
|
assert node.asdict()["ports"][1]["name"] == "eth0/0"
|
2016-09-13 07:47:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_list_ports_adapters(node):
|
|
|
|
"""
|
|
|
|
List port using adapters properties
|
|
|
|
"""
|
2020-06-16 04:29:03 +00:00
|
|
|
|
2016-09-13 07:47:22 +00:00
|
|
|
node.properties["adapters"] = 2
|
2021-04-17 14:04:28 +00:00
|
|
|
assert node.asdict()["ports"] == [
|
2016-09-13 07:47:22 +00:00
|
|
|
{
|
|
|
|
"name": "Ethernet0",
|
2018-08-13 08:45:24 +00:00
|
|
|
"short_name": "e0",
|
2016-09-13 07:47:22 +00:00
|
|
|
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
|
|
|
"port_number": 0,
|
|
|
|
"adapter_number": 0,
|
|
|
|
"link_type": "ethernet"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Ethernet1",
|
2018-08-13 08:45:24 +00:00
|
|
|
"short_name": "e1",
|
2016-09-13 07:47:22 +00:00
|
|
|
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
|
|
|
"port_number": 0,
|
|
|
|
"adapter_number": 1,
|
|
|
|
"link_type": "ethernet"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2016-09-22 15:11:40 +00:00
|
|
|
def test_list_ports_adapters_cloud(project, compute):
|
|
|
|
"""
|
|
|
|
List port using adapters properties
|
|
|
|
"""
|
2020-06-16 04:29:03 +00:00
|
|
|
|
2016-09-22 15:11:40 +00:00
|
|
|
node = Node(project, compute, "demo",
|
|
|
|
node_id=str(uuid.uuid4()),
|
|
|
|
node_type="cloud")
|
|
|
|
node.properties["ports_mapping"] = [
|
|
|
|
{
|
|
|
|
"interface": "eth0",
|
|
|
|
"name": "eth0",
|
|
|
|
"port_number": 0,
|
|
|
|
"type": "ethernet"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2021-04-17 14:04:28 +00:00
|
|
|
assert node.asdict()["ports"] == [
|
2016-09-22 15:11:40 +00:00
|
|
|
{
|
|
|
|
"name": "eth0",
|
2017-01-05 16:49:36 +00:00
|
|
|
"short_name": "eth0",
|
2016-09-22 15:11:40 +00:00
|
|
|
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
|
|
|
"port_number": 0,
|
|
|
|
"adapter_number": 0,
|
|
|
|
"link_type": "ethernet"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2016-09-29 12:40:56 +00:00
|
|
|
def test_list_ports_ethernet_hub(project, compute):
|
|
|
|
"""
|
|
|
|
List port for atm switch
|
|
|
|
"""
|
2020-06-16 04:29:03 +00:00
|
|
|
|
2016-09-29 12:40:56 +00:00
|
|
|
node = Node(project, compute, "demo",
|
|
|
|
node_id=str(uuid.uuid4()),
|
|
|
|
node_type="ethernet_hub")
|
|
|
|
node.properties["ports_mapping"] = [
|
|
|
|
{
|
|
|
|
"name": "Ethernet0",
|
|
|
|
"port_number": 0
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Ethernet1",
|
|
|
|
"port_number": 1
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2021-04-17 14:04:28 +00:00
|
|
|
assert node.asdict()["ports"] == [
|
2016-09-29 12:40:56 +00:00
|
|
|
{
|
|
|
|
"name": "Ethernet0",
|
2017-01-09 15:48:42 +00:00
|
|
|
"short_name": "e0",
|
2016-09-29 12:40:56 +00:00
|
|
|
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
|
|
|
"port_number": 0,
|
|
|
|
"adapter_number": 0,
|
|
|
|
"link_type": "ethernet"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Ethernet1",
|
2017-01-09 15:48:42 +00:00
|
|
|
"short_name": "e1",
|
2016-09-29 12:40:56 +00:00
|
|
|
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
|
|
|
"port_number": 1,
|
|
|
|
"adapter_number": 0,
|
|
|
|
"link_type": "ethernet"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2016-09-13 07:47:22 +00:00
|
|
|
def test_list_ports_atm_switch(project, compute):
|
|
|
|
"""
|
|
|
|
List port for atm switch
|
|
|
|
"""
|
2020-06-16 04:29:03 +00:00
|
|
|
|
2016-09-13 07:47:22 +00:00
|
|
|
node = Node(project, compute, "demo",
|
|
|
|
node_id=str(uuid.uuid4()),
|
|
|
|
node_type="atm_switch")
|
|
|
|
node.properties["mappings"] = {
|
|
|
|
"1:0:100": "10:0:200"
|
|
|
|
}
|
|
|
|
|
2021-04-17 14:04:28 +00:00
|
|
|
assert node.asdict()["ports"] == [
|
2016-09-13 07:47:22 +00:00
|
|
|
{
|
2016-10-26 10:03:54 +00:00
|
|
|
"name": "1",
|
|
|
|
"short_name": "1",
|
2016-09-13 07:47:22 +00:00
|
|
|
"data_link_types": {"ATM": "DLT_ATM_RFC1483"},
|
2016-10-26 10:03:54 +00:00
|
|
|
"port_number": 1,
|
|
|
|
"adapter_number": 0,
|
|
|
|
"link_type": "serial"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "10",
|
|
|
|
"short_name": "10",
|
|
|
|
"data_link_types": {"ATM": "DLT_ATM_RFC1483"},
|
|
|
|
"port_number": 10,
|
2016-09-13 07:47:22 +00:00
|
|
|
"adapter_number": 0,
|
|
|
|
"link_type": "serial"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def test_list_ports_frame_relay_switch(project, compute):
|
|
|
|
"""
|
|
|
|
List port for frame relay switch
|
|
|
|
"""
|
2020-06-16 04:29:03 +00:00
|
|
|
|
2016-09-13 07:47:22 +00:00
|
|
|
node = Node(project, compute, "demo",
|
|
|
|
node_id=str(uuid.uuid4()),
|
|
|
|
node_type="frame_relay_switch")
|
|
|
|
node.properties["mappings"] = {
|
2016-10-26 09:59:16 +00:00
|
|
|
"1:101": "10:202",
|
|
|
|
"2:102": "11:203"
|
2016-09-13 07:47:22 +00:00
|
|
|
}
|
|
|
|
|
2021-04-17 14:04:28 +00:00
|
|
|
assert node.asdict()["ports"] == [
|
2016-09-13 07:47:22 +00:00
|
|
|
{
|
2016-10-26 09:59:16 +00:00
|
|
|
"name": "1",
|
|
|
|
"short_name": "1",
|
2016-09-13 07:47:22 +00:00
|
|
|
"data_link_types": {"Frame Relay": "DLT_FRELAY"},
|
2016-10-26 09:59:16 +00:00
|
|
|
"port_number": 1,
|
|
|
|
"adapter_number": 0,
|
|
|
|
"link_type": "serial"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "2",
|
|
|
|
"short_name": "2",
|
|
|
|
"data_link_types": {"Frame Relay": "DLT_FRELAY"},
|
|
|
|
"port_number": 2,
|
|
|
|
"adapter_number": 0,
|
|
|
|
"link_type": "serial"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "10",
|
|
|
|
"short_name": "10",
|
|
|
|
"data_link_types": {"Frame Relay": "DLT_FRELAY"},
|
|
|
|
"port_number": 10,
|
|
|
|
"adapter_number": 0,
|
|
|
|
"link_type": "serial"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "11",
|
|
|
|
"short_name": "11",
|
|
|
|
"data_link_types": {"Frame Relay": "DLT_FRELAY"},
|
|
|
|
"port_number": 11,
|
2016-09-13 07:47:22 +00:00
|
|
|
"adapter_number": 0,
|
|
|
|
"link_type": "serial"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def test_list_ports_iou(compute, project):
|
|
|
|
"""
|
|
|
|
IOU has a special behavior 4 port by adapters
|
|
|
|
"""
|
2020-06-16 04:29:03 +00:00
|
|
|
|
2016-09-13 07:47:22 +00:00
|
|
|
node = Node(project, compute, "demo",
|
|
|
|
node_id=str(uuid.uuid4()),
|
|
|
|
node_type="iou")
|
|
|
|
node.properties["serial_adapters"] = 2
|
|
|
|
node.properties["ethernet_adapters"] = 3
|
2021-04-17 14:04:28 +00:00
|
|
|
assert node.asdict()["ports"] == [
|
2016-09-13 07:47:22 +00:00
|
|
|
{
|
2016-10-16 22:06:34 +00:00
|
|
|
"name": "Ethernet0/0",
|
|
|
|
"short_name": "e0/0",
|
|
|
|
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
2016-09-13 07:47:22 +00:00
|
|
|
"port_number": 0,
|
|
|
|
"adapter_number": 0,
|
2016-10-16 22:06:34 +00:00
|
|
|
"link_type": "ethernet"
|
2016-09-13 07:47:22 +00:00
|
|
|
},
|
|
|
|
{
|
2016-10-16 22:06:34 +00:00
|
|
|
"name": "Ethernet0/1",
|
|
|
|
"short_name": "e0/1",
|
|
|
|
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
2016-09-13 07:47:22 +00:00
|
|
|
"port_number": 1,
|
|
|
|
"adapter_number": 0,
|
2016-10-16 22:06:34 +00:00
|
|
|
"link_type": "ethernet"
|
2016-09-13 07:47:22 +00:00
|
|
|
},
|
|
|
|
{
|
2016-10-16 22:06:34 +00:00
|
|
|
"name": "Ethernet0/2",
|
|
|
|
"short_name": "e0/2",
|
|
|
|
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
2016-09-13 07:47:22 +00:00
|
|
|
"port_number": 2,
|
|
|
|
"adapter_number": 0,
|
2016-10-16 22:06:34 +00:00
|
|
|
"link_type": "ethernet"
|
2016-09-13 07:47:22 +00:00
|
|
|
},
|
|
|
|
{
|
2016-10-16 22:06:34 +00:00
|
|
|
"name": "Ethernet0/3",
|
|
|
|
"short_name": "e0/3",
|
|
|
|
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
2016-09-13 07:47:22 +00:00
|
|
|
"port_number": 3,
|
|
|
|
"adapter_number": 0,
|
2016-10-16 22:06:34 +00:00
|
|
|
"link_type": "ethernet"
|
2016-09-13 07:47:22 +00:00
|
|
|
},
|
|
|
|
{
|
2016-10-16 22:06:34 +00:00
|
|
|
"name": "Ethernet1/0",
|
|
|
|
"short_name": "e1/0",
|
|
|
|
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
2016-09-13 07:47:22 +00:00
|
|
|
"port_number": 0,
|
|
|
|
"adapter_number": 1,
|
2016-10-16 22:06:34 +00:00
|
|
|
"link_type": "ethernet"
|
2016-09-13 07:47:22 +00:00
|
|
|
},
|
|
|
|
{
|
2016-10-16 22:06:34 +00:00
|
|
|
"name": "Ethernet1/1",
|
|
|
|
"short_name": "e1/1",
|
|
|
|
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
2016-09-13 07:47:22 +00:00
|
|
|
"port_number": 1,
|
|
|
|
"adapter_number": 1,
|
2016-10-16 22:06:34 +00:00
|
|
|
"link_type": "ethernet"
|
2016-09-13 07:47:22 +00:00
|
|
|
},
|
|
|
|
{
|
2016-10-16 22:06:34 +00:00
|
|
|
"name": "Ethernet1/2",
|
|
|
|
"short_name": "e1/2",
|
|
|
|
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
2016-09-13 07:47:22 +00:00
|
|
|
"port_number": 2,
|
|
|
|
"adapter_number": 1,
|
2016-10-16 22:06:34 +00:00
|
|
|
"link_type": "ethernet"
|
2016-09-13 07:47:22 +00:00
|
|
|
},
|
|
|
|
{
|
2016-10-16 22:06:34 +00:00
|
|
|
"name": "Ethernet1/3",
|
|
|
|
"short_name": "e1/3",
|
|
|
|
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
2016-09-13 07:47:22 +00:00
|
|
|
"port_number": 3,
|
|
|
|
"adapter_number": 1,
|
2016-10-16 22:06:34 +00:00
|
|
|
"link_type": "ethernet"
|
2016-09-13 07:47:22 +00:00
|
|
|
},
|
|
|
|
{
|
2016-10-16 22:06:34 +00:00
|
|
|
"name": "Ethernet2/0",
|
|
|
|
"short_name": "e2/0",
|
2016-09-13 07:47:22 +00:00
|
|
|
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
|
|
|
"port_number": 0,
|
2016-09-15 09:49:41 +00:00
|
|
|
"adapter_number": 2,
|
2016-09-13 07:47:22 +00:00
|
|
|
"link_type": "ethernet"
|
|
|
|
},
|
|
|
|
{
|
2016-10-16 22:06:34 +00:00
|
|
|
"name": "Ethernet2/1",
|
|
|
|
"short_name": "e2/1",
|
2016-09-13 07:47:22 +00:00
|
|
|
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
|
|
|
"port_number": 1,
|
2016-09-15 09:49:41 +00:00
|
|
|
"adapter_number": 2,
|
2016-09-13 07:47:22 +00:00
|
|
|
"link_type": "ethernet"
|
|
|
|
},
|
|
|
|
{
|
2016-10-16 22:06:34 +00:00
|
|
|
"name": "Ethernet2/2",
|
|
|
|
"short_name": "e2/2",
|
2016-09-13 07:47:22 +00:00
|
|
|
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
|
|
|
"port_number": 2,
|
2016-09-15 09:49:41 +00:00
|
|
|
"adapter_number": 2,
|
2016-09-13 07:47:22 +00:00
|
|
|
"link_type": "ethernet"
|
|
|
|
},
|
|
|
|
{
|
2016-10-16 22:06:34 +00:00
|
|
|
"name": "Ethernet2/3",
|
|
|
|
"short_name": "e2/3",
|
2016-09-13 07:47:22 +00:00
|
|
|
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
|
|
|
"port_number": 3,
|
2016-09-15 09:49:41 +00:00
|
|
|
"adapter_number": 2,
|
2016-09-13 07:47:22 +00:00
|
|
|
"link_type": "ethernet"
|
|
|
|
},
|
|
|
|
{
|
2016-10-25 13:26:36 +00:00
|
|
|
"name": "Serial3/0",
|
|
|
|
"short_name": "s3/0",
|
2016-10-16 22:06:34 +00:00
|
|
|
"data_link_types": {
|
|
|
|
"Frame Relay": "DLT_FRELAY",
|
|
|
|
"Cisco HDLC": "DLT_C_HDLC",
|
|
|
|
"Cisco PPP": "DLT_PPP_SERIAL"
|
|
|
|
},
|
2016-09-13 07:47:22 +00:00
|
|
|
"port_number": 0,
|
2016-09-15 09:49:41 +00:00
|
|
|
"adapter_number": 3,
|
2016-10-16 22:06:34 +00:00
|
|
|
"link_type": "serial"
|
2016-09-13 07:47:22 +00:00
|
|
|
},
|
|
|
|
{
|
2016-10-25 13:26:36 +00:00
|
|
|
"name": "Serial3/1",
|
|
|
|
"short_name": "s3/1",
|
2016-10-16 22:06:34 +00:00
|
|
|
"data_link_types": {
|
|
|
|
"Frame Relay": "DLT_FRELAY",
|
|
|
|
"Cisco HDLC": "DLT_C_HDLC",
|
|
|
|
"Cisco PPP": "DLT_PPP_SERIAL"
|
|
|
|
},
|
2016-09-13 07:47:22 +00:00
|
|
|
"port_number": 1,
|
2016-09-15 09:49:41 +00:00
|
|
|
"adapter_number": 3,
|
2016-10-16 22:06:34 +00:00
|
|
|
"link_type": "serial"
|
2016-09-13 07:47:22 +00:00
|
|
|
},
|
|
|
|
{
|
2016-10-25 13:26:36 +00:00
|
|
|
"name": "Serial3/2",
|
|
|
|
"short_name": "s3/2",
|
2016-10-16 22:06:34 +00:00
|
|
|
"data_link_types": {
|
|
|
|
"Frame Relay": "DLT_FRELAY",
|
|
|
|
"Cisco HDLC": "DLT_C_HDLC",
|
|
|
|
"Cisco PPP": "DLT_PPP_SERIAL"
|
|
|
|
},
|
2016-09-13 07:47:22 +00:00
|
|
|
"port_number": 2,
|
2016-09-15 09:49:41 +00:00
|
|
|
"adapter_number": 3,
|
2016-10-16 22:06:34 +00:00
|
|
|
"link_type": "serial"
|
2016-09-13 07:47:22 +00:00
|
|
|
},
|
|
|
|
{
|
2016-10-25 13:26:36 +00:00
|
|
|
"name": "Serial3/3",
|
|
|
|
"short_name": "s3/3",
|
2016-10-16 22:06:34 +00:00
|
|
|
"data_link_types": {
|
|
|
|
"Frame Relay": "DLT_FRELAY",
|
|
|
|
"Cisco HDLC": "DLT_C_HDLC",
|
|
|
|
"Cisco PPP": "DLT_PPP_SERIAL"
|
|
|
|
},
|
2016-09-13 07:47:22 +00:00
|
|
|
"port_number": 3,
|
2016-09-15 09:49:41 +00:00
|
|
|
"adapter_number": 3,
|
2016-10-16 22:06:34 +00:00
|
|
|
"link_type": "serial"
|
2016-09-13 07:47:22 +00:00
|
|
|
},
|
|
|
|
{
|
2016-10-25 13:26:36 +00:00
|
|
|
"name": "Serial4/0",
|
|
|
|
"short_name": "s4/0",
|
2016-10-16 22:06:34 +00:00
|
|
|
"data_link_types": {
|
|
|
|
"Frame Relay": "DLT_FRELAY",
|
|
|
|
"Cisco HDLC": "DLT_C_HDLC",
|
|
|
|
"Cisco PPP": "DLT_PPP_SERIAL"
|
|
|
|
},
|
2016-09-13 07:47:22 +00:00
|
|
|
"port_number": 0,
|
2016-09-15 09:49:41 +00:00
|
|
|
"adapter_number": 4,
|
2016-10-16 22:06:34 +00:00
|
|
|
"link_type": "serial"
|
2016-09-13 07:47:22 +00:00
|
|
|
},
|
|
|
|
{
|
2016-10-25 13:26:36 +00:00
|
|
|
"name": "Serial4/1",
|
|
|
|
"short_name": "s4/1",
|
2016-10-16 22:06:34 +00:00
|
|
|
"data_link_types": {
|
|
|
|
"Frame Relay": "DLT_FRELAY",
|
|
|
|
"Cisco HDLC": "DLT_C_HDLC",
|
|
|
|
"Cisco PPP": "DLT_PPP_SERIAL"
|
|
|
|
},
|
2016-09-13 07:47:22 +00:00
|
|
|
"port_number": 1,
|
2016-09-15 09:49:41 +00:00
|
|
|
"adapter_number": 4,
|
2016-10-16 22:06:34 +00:00
|
|
|
"link_type": "serial"
|
2016-09-13 07:47:22 +00:00
|
|
|
},
|
|
|
|
{
|
2016-10-25 13:26:36 +00:00
|
|
|
"name": "Serial4/2",
|
|
|
|
"short_name": "s4/2",
|
2016-10-16 22:06:34 +00:00
|
|
|
"data_link_types": {
|
|
|
|
"Frame Relay": "DLT_FRELAY",
|
|
|
|
"Cisco HDLC": "DLT_C_HDLC",
|
|
|
|
"Cisco PPP": "DLT_PPP_SERIAL"
|
|
|
|
},
|
2016-09-13 07:47:22 +00:00
|
|
|
"port_number": 2,
|
2016-09-15 09:49:41 +00:00
|
|
|
"adapter_number": 4,
|
2016-10-16 22:06:34 +00:00
|
|
|
"link_type": "serial"
|
2016-09-13 07:47:22 +00:00
|
|
|
},
|
|
|
|
{
|
2016-10-25 13:26:36 +00:00
|
|
|
"name": "Serial4/3",
|
|
|
|
"short_name": "s4/3",
|
2016-10-16 22:06:34 +00:00
|
|
|
"data_link_types": {
|
|
|
|
"Frame Relay": "DLT_FRELAY",
|
|
|
|
"Cisco HDLC": "DLT_C_HDLC",
|
|
|
|
"Cisco PPP": "DLT_PPP_SERIAL"
|
|
|
|
},
|
2016-09-13 07:47:22 +00:00
|
|
|
"port_number": 3,
|
2016-09-15 09:49:41 +00:00
|
|
|
"adapter_number": 4,
|
2016-10-16 22:06:34 +00:00
|
|
|
"link_type": "serial"
|
2016-09-13 07:47:22 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def test_list_ports_dynamips(project, compute):
|
|
|
|
"""
|
|
|
|
List port for dynamips
|
|
|
|
"""
|
2020-06-16 04:29:03 +00:00
|
|
|
|
2016-09-13 07:47:22 +00:00
|
|
|
node = Node(project, compute, "demo",
|
|
|
|
node_id=str(uuid.uuid4()),
|
|
|
|
node_type="dynamips")
|
|
|
|
node.properties["slot0"] = "C7200-IO-FE"
|
|
|
|
node.properties["slot1"] = "GT96100-FE"
|
|
|
|
node.properties["wic0"] = "WIC-2T"
|
|
|
|
node.properties["wic1"] = "WIC-2T"
|
|
|
|
|
2021-04-17 14:04:28 +00:00
|
|
|
assert node.asdict()["ports"] == [
|
2016-09-13 07:47:22 +00:00
|
|
|
{
|
|
|
|
"name": "FastEthernet0/0",
|
|
|
|
"short_name": "f0/0",
|
|
|
|
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
|
|
|
"port_number": 0,
|
|
|
|
"adapter_number": 0,
|
|
|
|
"link_type": "ethernet"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "FastEthernet1/0",
|
|
|
|
"short_name": "f1/0",
|
|
|
|
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
|
|
|
"port_number": 0,
|
|
|
|
"adapter_number": 1,
|
|
|
|
"link_type": "ethernet"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "FastEthernet1/1",
|
|
|
|
"short_name": "f1/1",
|
|
|
|
"data_link_types": {"Ethernet": "DLT_EN10MB"},
|
|
|
|
"port_number": 1,
|
|
|
|
"adapter_number": 1,
|
|
|
|
"link_type": "ethernet"
|
|
|
|
},
|
|
|
|
{
|
2017-05-12 07:48:05 +00:00
|
|
|
"name": "Serial0/0",
|
|
|
|
"short_name": "s0/0",
|
2016-09-13 07:47:22 +00:00
|
|
|
"data_link_types": {
|
|
|
|
"Cisco HDLC": "DLT_C_HDLC",
|
|
|
|
"Cisco PPP": "DLT_PPP_SERIAL",
|
|
|
|
"Frame Relay": "DLT_FRELAY"},
|
|
|
|
"port_number": 16,
|
|
|
|
"adapter_number": 0,
|
|
|
|
"link_type": "serial"
|
|
|
|
},
|
|
|
|
{
|
2017-05-12 07:48:05 +00:00
|
|
|
"name": "Serial0/1",
|
|
|
|
"short_name": "s0/1",
|
2016-09-13 07:47:22 +00:00
|
|
|
"data_link_types": {
|
|
|
|
"Cisco HDLC": "DLT_C_HDLC",
|
|
|
|
"Cisco PPP": "DLT_PPP_SERIAL",
|
|
|
|
"Frame Relay": "DLT_FRELAY"},
|
|
|
|
"port_number": 17,
|
|
|
|
"adapter_number": 0,
|
|
|
|
"link_type": "serial"
|
|
|
|
},
|
|
|
|
{
|
2017-05-12 07:48:05 +00:00
|
|
|
"name": "Serial0/2",
|
|
|
|
"short_name": "s0/2",
|
2016-09-13 07:47:22 +00:00
|
|
|
"data_link_types": {
|
|
|
|
"Cisco HDLC": "DLT_C_HDLC",
|
|
|
|
"Cisco PPP": "DLT_PPP_SERIAL",
|
|
|
|
"Frame Relay": "DLT_FRELAY"},
|
2017-05-12 12:12:24 +00:00
|
|
|
"port_number": 32,
|
2016-09-13 07:47:22 +00:00
|
|
|
"adapter_number": 0,
|
|
|
|
"link_type": "serial"
|
|
|
|
},
|
|
|
|
{
|
2017-05-12 07:48:05 +00:00
|
|
|
"name": "Serial0/3",
|
|
|
|
"short_name": "s0/3",
|
2016-09-13 07:47:22 +00:00
|
|
|
"data_link_types": {
|
|
|
|
"Cisco HDLC": "DLT_C_HDLC",
|
|
|
|
"Cisco PPP": "DLT_PPP_SERIAL",
|
|
|
|
"Frame Relay": "DLT_FRELAY"},
|
2017-05-12 12:12:24 +00:00
|
|
|
"port_number": 33,
|
2016-09-13 07:47:22 +00:00
|
|
|
"adapter_number": 0,
|
|
|
|
"link_type": "serial"
|
|
|
|
}
|
|
|
|
]
|
2017-01-05 16:49:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_short_name():
|
2020-06-16 04:29:03 +00:00
|
|
|
|
2017-01-05 16:49:36 +00:00
|
|
|
# If no customization of port name format return the default short name
|
2018-08-13 08:45:24 +00:00
|
|
|
assert EthernetPort("Ethernet0", 0, 0, 0).short_name == "e0"
|
2017-01-09 15:48:42 +00:00
|
|
|
assert EthernetPort("Ethernet0", 0, 0, 0, short_name="mgmt").short_name == "mgmt"
|
2018-08-13 08:45:24 +00:00
|
|
|
assert EthernetPort("Ethernet0/0", 0, 0, 0).short_name == "e0/0"
|
2017-01-05 16:49:36 +00:00
|
|
|
# If port name format has change we use the port name as the short name (1.X behavior)
|
|
|
|
assert EthernetPort("eth0", 0, 0, 0).short_name == "eth0"
|