mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Merge branch '3.1' into fix/duplicate-device-configs-merge
Resolve conflicts against the upstream wave (PRs #2952-#2965, incl. the typed-response/schema hardening and the drop of Python 3.10): - controller/node.py: keep upstream's _transitioning/_confirm_status lifecycle guard; the kernel-anchor link wiring (node_started) runs after the transition completes. - controller/link.py: keep upstream's add_node rollback (release_ports on create failure) and delete via release_ports; release_ports now resolves ports live (same staleness reason as _bind_members) and discards the node link unconditionally. - schemas/controller/links.py: extend LinkFilterType with the eight kernel-datapath filter types and LinkFilterParameter.type with "str" so the newly typed /available_filters response validates; Link.filters stays a free-form dict — the vocabulary is capability-gated per link and validated by the controller (409), not by a strict request schema. - schemas/controller/topology.py: drop the type: ignore made redundant by the dict filters field. - tests: route-level filter validation now expects the controller's 409 (unknown types, out-of-range values); packet_loss correlation is a valid kernel parameter (positive test added); OpenAPI assertions match the free-form filters property.
This commit is contained in:
60 files changed
+2654
-271
No files matched your search
@@ -17,10 +17,21 @@
|
||||
|
||||
import pydantic
|
||||
import pytest
|
||||
from pydantic import TypeAdapter
|
||||
|
||||
from gns3server.controller.appliance import Appliance
|
||||
from gns3server.controller.appliance_to_template import ApplianceToTemplate
|
||||
from gns3server.schemas.controller.appliances import ApplianceModel
|
||||
from gns3server.schemas.controller.appliances import (
|
||||
ApplianceModel,
|
||||
ApplianceVersionCreate,
|
||||
ApplianceVersionCreateV1_6,
|
||||
ApplianceVersionCreateV8,
|
||||
DockerTemplateSetting,
|
||||
DynamipsTemplateSetting,
|
||||
IouTemplateSetting,
|
||||
QemuTemplateSetting,
|
||||
TemplateSetting,
|
||||
)
|
||||
|
||||
# v8 mirror of the XRd Control Plane appliance shape (docker, custom_adapters, no versions)
|
||||
XRD_V8 = {
|
||||
@@ -242,3 +253,44 @@ def test_v8_netmiko_device_type_empty_string_clears():
|
||||
appliance = dict(XRD_V8, netmiko_device_type="")
|
||||
model = ApplianceModel.model_validate(appliance)
|
||||
assert model.netmiko_device_type == ""
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"template_type, properties, expected",
|
||||
[
|
||||
("qemu", {"ram": 512}, QemuTemplateSetting),
|
||||
("dynamips", {"platform": "c7200", "ram": 256}, DynamipsTemplateSetting),
|
||||
("iou", {"ram": 256}, IouTemplateSetting),
|
||||
("docker", {"image": "alpine:latest"}, DockerTemplateSetting),
|
||||
],
|
||||
)
|
||||
def test_template_setting_decoded_through_discriminator(template_type, properties, expected):
|
||||
setting = TypeAdapter(TemplateSetting).validate_python(
|
||||
{"name": "a", "template_type": template_type, "template_properties": properties}
|
||||
)
|
||||
assert type(setting) is expected
|
||||
assert setting.template_type == template_type
|
||||
|
||||
|
||||
def test_template_setting_unknown_template_type_rejected():
|
||||
with pytest.raises(pydantic.ValidationError):
|
||||
TypeAdapter(TemplateSetting).validate_python({"template_type": "vpcs", "template_properties": {}})
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"data, expected",
|
||||
[
|
||||
({"name": "1", "registry_version": 1}, ApplianceVersionCreateV1_6),
|
||||
({"name": "6", "registry_version": 6}, ApplianceVersionCreateV1_6),
|
||||
({"name": "8", "registry_version": 8}, ApplianceVersionCreateV8),
|
||||
({"name": "plain", "images": {"hda_disk_image": "a.qcow2"}}, ApplianceVersionCreateV1_6),
|
||||
({"name": "v8", "category": "guest"}, ApplianceVersionCreateV8),
|
||||
],
|
||||
)
|
||||
def test_appliance_version_decoded_through_discriminator(data, expected):
|
||||
assert type(TypeAdapter(ApplianceVersionCreate).validate_python(data)) is expected
|
||||
|
||||
|
||||
def test_appliance_version_unknown_registry_version_rejected():
|
||||
with pytest.raises(pydantic.ValidationError):
|
||||
TypeAdapter(ApplianceVersionCreate).validate_python({"name": "x", "registry_version": 7})
|
||||
@@ -15,6 +15,7 @@
|
||||
# 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 asyncio
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
@@ -530,3 +531,67 @@ async def test_update_link_style(project, compute):
|
||||
}
|
||||
link._project.emit_notification.assert_called_with("link.updated", link.asdict())
|
||||
assert project.dump.called
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_node_concurrent_same_port(project, compute):
|
||||
project.dump = MagicMock()
|
||||
node1 = Node(project, compute, "node1", node_type="qemu")
|
||||
node1._ports = [EthernetPort("E0", 0, 0, 4)]
|
||||
node2 = Node(project, compute, "node2", node_type="qemu")
|
||||
node2._ports = [EthernetPort("E0", 0, 0, 4), EthernetPort("E1", 0, 0, 5)]
|
||||
node3 = Node(project, compute, "node3", node_type="qemu")
|
||||
node3._ports = [EthernetPort("E0", 0, 0, 4)]
|
||||
|
||||
async def slow_create():
|
||||
await asyncio.sleep(0)
|
||||
|
||||
async def connect(other, other_port):
|
||||
link = Link(project)
|
||||
link.create = slow_create
|
||||
try:
|
||||
await link.add_node(other, 0, other_port)
|
||||
await link.add_node(node1, 0, 4)
|
||||
except ControllerError as e:
|
||||
return e
|
||||
return link
|
||||
|
||||
results = await asyncio.gather(connect(node2, 4), connect(node3, 4))
|
||||
errors = [r for r in results if isinstance(r, ControllerError)]
|
||||
assert len(errors) == 1
|
||||
assert errors[0].code == "port_in_use"
|
||||
assert node1._ports[0].link in results
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_node_create_failure_releases_ports(project, compute):
|
||||
project.dump = MagicMock()
|
||||
node1 = Node(project, compute, "node1", node_type="qemu")
|
||||
node1._ports = [EthernetPort("E0", 0, 0, 4)]
|
||||
node2 = Node(project, compute, "node2", node_type="qemu")
|
||||
node2._ports = [EthernetPort("E0", 0, 0, 4)]
|
||||
|
||||
link = Link(project)
|
||||
link.create = AsyncioMagicMock(side_effect=ControllerError("boom"))
|
||||
await link.add_node(node1, 0, 4)
|
||||
with pytest.raises(ControllerError):
|
||||
await link.add_node(node2, 0, 4)
|
||||
|
||||
assert node1._ports[0].link is None
|
||||
assert node2._ports[0].link is None
|
||||
assert not node1.links
|
||||
assert not node2.links
|
||||
|
||||
|
||||
def test_node_get_port_by_name_and_free_port(project, compute):
|
||||
node = Node(project, compute, "node1", node_type="qemu")
|
||||
node._ports = [EthernetPort("E1", 0, 0, 1), EthernetPort("E0", 0, 0, 0), SerialPort("S0", 0, 1, 0)]
|
||||
|
||||
assert node.get_port_by_name("E0") is node._ports[1]
|
||||
assert node.get_port_by_name("nope") is None
|
||||
assert node.get_free_port() is node._ports[1]
|
||||
assert node.get_free_port("serial") is node._ports[2]
|
||||
node._ports[1].link = object()
|
||||
assert node.get_free_port("ethernet") is node._ports[0]
|
||||
node._ports[0].link = object()
|
||||
assert node.get_free_port("ethernet") is None
|
||||
Reference in new issue
Block a user