mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
fix: repair imports lost in the 3.1 rebase and meet the new lint baseline
The rebase onto upstream 3.1 (mypy + ruff I001/F401 waves) left the tree short of the newly enforced baselines in three ways: * contextlib / UbridgeError imports dropped as false duplicates during conflict resolution left NameErrors in iou_vm and qemu_vm (F821); the Dynamips router grabbed the compute-level NIOTAP instead of the hypervisor one, breaking TAP anchoring (test failure). * unused imports (KERNEL_UNSUPPORTED_FILTERS, UbridgeError, List) and unsorted blocks left behind where the stack's later commits moved the last usage elsewhere — ruff I001/F401/RUF022 now enforce these. * mypy, now baseline-free: cache dict annotations in tc_probe, the locators candidate list, the resolved-params None branch in the MCP runner, and validate_bpf_syntax keeps the upstream Dict[str, Any] return (the strict Optional[str] was wrong for the "valid" bool entry). The e2e raw-frame probe resolves its compiler via shutil.which (S607) and zips with strict= (B905); the remaining subprocess call is S603 by nature and gets a per-file ignore like other test files. ruff check/format clean, mypy at upstream parity (no new errors), full unit suite 2167 passed.
This commit is contained in:
35 files changed
+165
-136
No files matched your search
@@ -23,23 +23,18 @@ fallback and cleanup.
|
||||
|
||||
import os
|
||||
import uuid
|
||||
from unittest.mock import MagicMock, call
|
||||
from unittest.mock import MagicMock, call, patch
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from tests.utils import AsyncioMagicMock
|
||||
|
||||
from gns3server.compute.docker import Docker
|
||||
from gns3server.compute.docker.docker_vm import DockerVM
|
||||
from gns3server.compute.docker.docker_error import DockerError, DockerHttp404Error
|
||||
from gns3server.compute.compute_error import ComputeError
|
||||
from gns3server.compute.nios.nio_udp import NIOUDP
|
||||
from gns3server.compute.docker import Docker
|
||||
from gns3server.compute.docker.docker_error import DockerError, DockerHttp404Error
|
||||
from gns3server.compute.docker.docker_vm import DockerVM
|
||||
from gns3server.compute.nios.nio_bridge import NIOBridge
|
||||
from gns3server.compute.ubridge.ubridge_error import UbridgeError
|
||||
|
||||
from tests.utils import AsyncioMagicMock
|
||||
|
||||
BRIDGE = "gns3a1b2c3d4e5f"
|
||||
|
||||
@@ -1373,7 +1368,13 @@ def test_create_nio_udp_rejects_kernel_only_filters(vm):
|
||||
|
||||
with pytest.raises(ComputeError, match="kernel-datapath"):
|
||||
vm.manager.create_nio(
|
||||
{"type": "nio_udp", "lport": 4242, "rport": 4343, "rhost": "127.0.0.1", "filters": {"gemodel": [100, 0, 30]}}
|
||||
{
|
||||
"type": "nio_udp",
|
||||
"lport": 4242,
|
||||
"rport": 4343,
|
||||
"rhost": "127.0.0.1",
|
||||
"filters": {"gemodel": [100, 0, 30]},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -14,19 +14,15 @@ Image-free: everything is asserted against the uBridge command stream and
|
||||
the anchor naming contract.
|
||||
"""
|
||||
|
||||
import uuid
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from tests.utils import AsyncioMagicMock
|
||||
|
||||
from gns3server.compute.docker import Docker
|
||||
from gns3server.compute.docker.docker_error import DockerError
|
||||
from gns3server.compute.docker.iol_docker_vm import IOLDockerVM
|
||||
|
||||
from tests.utils import AsyncioMagicMock
|
||||
|
||||
NODE_ID = "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||
TAP00 = "gx00010203e0p0" # the vm fixture's node id, bay 0 unit 0
|
||||
@@ -296,7 +292,9 @@ async def test_remove_nio_binding_kernel_releases_the_port_leg_first(vm):
|
||||
commands = _commands(vm)
|
||||
assert f"bridge stop {PORT_BRIDGE}" in commands
|
||||
assert f'bridge delete_nio_tap {PORT_BRIDGE} "{TAP00}"' in commands
|
||||
assert commands.index(f"bridge stop {PORT_BRIDGE}") < commands.index(f'bridge delete_nio_tap {PORT_BRIDGE} "{TAP00}"')
|
||||
assert commands.index(f"bridge stop {PORT_BRIDGE}") < commands.index(
|
||||
f'bridge delete_nio_tap {PORT_BRIDGE} "{TAP00}"'
|
||||
)
|
||||
assert f'tc reset "{TAP00}"' in commands
|
||||
assert f'brctl delif "{BRIDGE}" "{TAP00}"' in commands
|
||||
assert f'brctl delete "{BRIDGE}"' in commands
|
||||
|
||||
@@ -908,6 +908,7 @@ async def test_create_reparse_refreshes_env_knobs(compute_project, manager):
|
||||
# Kernel-datapath (NIOBridge) rejection
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_unix_socket_nio_rejects_kernel_datapath_link(compute_project, manager):
|
||||
|
||||
|
||||
@@ -25,27 +25,24 @@ hypervisor's fds released before the TAPs are unpersisted — QEMU's order,
|
||||
since here it is Dynamips that holds them).
|
||||
"""
|
||||
|
||||
import contextlib
|
||||
import os
|
||||
import shutil
|
||||
import contextlib
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from tests.utils import AsyncioMagicMock
|
||||
|
||||
from gns3server.compute.dynamips import Dynamips
|
||||
from gns3server.compute.dynamips.nodes.router import Router
|
||||
from gns3server.compute.dynamips.dynamips_error import DynamipsError
|
||||
from gns3server.compute.dynamips.adapters.gt96100_fe import GT96100_FE
|
||||
from gns3server.compute.dynamips.adapters.pa_4t import PA_4T
|
||||
from gns3server.compute.dynamips.adapters.pa_fe_tx import PA_FE_TX
|
||||
from gns3server.compute.dynamips.adapters.wic_1enet import WIC_1ENET
|
||||
from gns3server.compute.ubridge.ubridge_error import UbridgeError
|
||||
from gns3server.compute.dynamips.dynamips_error import DynamipsError
|
||||
from gns3server.compute.dynamips.nodes.router import Router
|
||||
from gns3server.compute.nios.nio_bridge import NIOBridge
|
||||
|
||||
from gns3server.compute.ubridge.ubridge_error import UbridgeError
|
||||
from tests.utils import AsyncioMagicMock
|
||||
|
||||
NODE_ID = "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||
BRIDGE = "gns3a1b2c3d4e5f"
|
||||
@@ -237,7 +234,7 @@ async def test_prepare_tap_datapath_wires_nios_bound_while_stopped(router):
|
||||
|
||||
hypervisor = _hypervisor_commands(router)
|
||||
assert any(c.startswith("nio create_tap tap-") and c.endswith(f"{TAP00}") for c in hypervisor)
|
||||
assert any(c.startswith(f"vm slot_add_nio_binding \"R1\" 0 0 tap-") for c in hypervisor)
|
||||
assert any(c.startswith('vm slot_add_nio_binding "R1" 0 0 tap-') for c in hypervisor)
|
||||
router._ubridge_send.assert_any_call(f'brctl addif "{BRIDGE}" "{TAP00}"')
|
||||
assert (0, 0) in router._tap_nios
|
||||
|
||||
@@ -489,9 +486,7 @@ async def test_stop_ubridge_releases_hypervisor_fds_before_deleting_taps(router)
|
||||
router._ubridge_send.reset_mock()
|
||||
router._hypervisor.commands.clear()
|
||||
|
||||
with patch(
|
||||
"gns3server.compute.base_node.BaseNode._stop_ubridge", new=AsyncioMagicMock()
|
||||
) as stop:
|
||||
with patch("gns3server.compute.base_node.BaseNode._stop_ubridge", new=AsyncioMagicMock()) as stop:
|
||||
await router._stop_ubridge()
|
||||
|
||||
hypervisor = _hypervisor_commands(router)
|
||||
|
||||
@@ -22,19 +22,16 @@ it, kernel-link enslavement, the relay fallback for a uBridge without the
|
||||
command, and the reverse-of-QEMU stop order (uBridge holds the anchor fds).
|
||||
"""
|
||||
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from tests.utils import AsyncioMagicMock
|
||||
|
||||
from gns3server.compute.iou import IOU
|
||||
from gns3server.compute.iou.iou_vm import IOUVM
|
||||
from gns3server.compute.iou.iou_error import IOUError
|
||||
from gns3server.compute.nios.nio_bridge import NIOBridge
|
||||
from gns3server.compute.iou.iou_vm import IOUVM
|
||||
from gns3server.compute.ubridge.ubridge_error import UbridgeError
|
||||
|
||||
from tests.utils import AsyncioMagicMock
|
||||
|
||||
NODE_ID = "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||
BRIDGE = "gns3a1b2c3d4e5f"
|
||||
|
||||
@@ -24,21 +24,16 @@ legacy socket-netdev fallback for a uBridge without the tap module.
|
||||
import asyncio
|
||||
import os
|
||||
import stat
|
||||
import sys
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from tests.utils import asyncio_patch, AsyncioMagicMock
|
||||
|
||||
from gns3server.compute.qemu import Qemu
|
||||
from gns3server.compute.qemu.qemu_vm import QemuVM
|
||||
from gns3server.compute.qemu.qemu_error import QemuError
|
||||
from gns3server.compute.nios.nio_bridge import NIOBridge
|
||||
from gns3server.compute.qemu.qemu_vm import QemuVM
|
||||
from gns3server.compute.ubridge.ubridge_error import UbridgeError
|
||||
|
||||
from tests.utils import AsyncioMagicMock, asyncio_patch
|
||||
|
||||
BRIDGE = "gns3a1b2c3d4e5f"
|
||||
TAP0 = "gq00010203e0p0" # the vm fixture's node id, adapter 0
|
||||
@@ -272,7 +267,7 @@ async def test_update_nio_binding_reapplies_filters_on_the_anchor(vm):
|
||||
|
||||
vm._ubridge_send.assert_any_call(f'tc reset "{TAP0}"')
|
||||
vm._ubridge_send.assert_any_call(f'tc netem set "{TAP0}" delay 10')
|
||||
assert not any(f"brctl addif" in str(c) for c in vm._ubridge_send.call_args_list)
|
||||
assert not any("brctl addif" in str(c) for c in vm._ubridge_send.call_args_list)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
@@ -25,8 +25,8 @@ from gns3server.compute.ubridge import tc_probe
|
||||
from gns3server.compute.ubridge.tc_probe import (
|
||||
probe_bridge_tap_support,
|
||||
probe_iol_tap_support,
|
||||
probe_tc_capabilities,
|
||||
probe_tap_support,
|
||||
probe_tc_capabilities,
|
||||
)
|
||||
from gns3server.compute.ubridge.ubridge_error import UbridgeError
|
||||
|
||||
@@ -65,7 +65,7 @@ class FakeHypervisor:
|
||||
if self.error:
|
||||
raise UbridgeError(self.error)
|
||||
if self.error_prefix and command.startswith(self.error_prefix):
|
||||
raise UbridgeError(f"202-Unknown command")
|
||||
raise UbridgeError("202-Unknown command")
|
||||
if command.startswith("bridge delete_nio_tap "):
|
||||
if FakeHypervisor.bridge_tap_error:
|
||||
raise UbridgeError(FakeHypervisor.bridge_tap_error)
|
||||
|
||||
Reference in new issue
Block a user