mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-21 05:35:15 +02:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8ef9d08c6c | ||
|
|
6baeca873e | ||
|
|
f727847112 | ||
|
|
a2c1fd3b3e | ||
|
|
b23a47a460 |
No files matched your search
+2
-2
@@ -7,7 +7,7 @@
|
||||
|
||||
# Core AI and Automation Framework
|
||||
# Note: aiosqlite is in core requirements.txt
|
||||
langchain>=1.2.10
|
||||
langchain>=1.5.0
|
||||
langchain-core>=1.7.3
|
||||
langgraph>=1.2.19
|
||||
langgraph-checkpoint>=4.0.0
|
||||
@@ -42,7 +42,7 @@ python-dotenv>=1.2.4
|
||||
|
||||
# Authentication
|
||||
PyJWT>=2.15.1
|
||||
psycopg-pool>=3.1.0
|
||||
psycopg-pool>=3.3.3
|
||||
|
||||
# Skills Repository Management
|
||||
PyYAML>=6.0.3
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
pytest==9.2.0
|
||||
pytest-timeout==2.4.0
|
||||
pytest-asyncio==1.4.1
|
||||
pytest-asyncio==1.5.0
|
||||
httpx==0.28.1
|
||||
httpx_ws==0.9.0
|
||||
pytest-random-order==1.2.0 # opt-in: --random-order --random-order-bucket=global (legacy suites are not shuffle-clean yet, see .claude/skills/gns3-api-test-writing)
|
||||
|
||||
@@ -2495,7 +2495,17 @@ class Project:
|
||||
return new_node
|
||||
|
||||
def stats(self):
|
||||
"""
|
||||
Return the project statistics.
|
||||
|
||||
A closed project keeps no scene elements in memory: the counts come
|
||||
from the topology file instead (issue #1836).
|
||||
"""
|
||||
|
||||
if self._status == "closed":
|
||||
stats = self._stats_from_topology_file()
|
||||
if stats is not None:
|
||||
return stats
|
||||
return {
|
||||
"nodes": len(self._nodes),
|
||||
"links": len(self._links),
|
||||
@@ -2504,6 +2514,32 @@ class Project:
|
||||
"markers": sum(len(link.markers) for link in self._links.values()),
|
||||
}
|
||||
|
||||
def _stats_from_topology_file(self):
|
||||
"""
|
||||
Count the scene elements from the .gns3 file. The snapshots are
|
||||
already restored from the snapshot config, and the markers are
|
||||
counted from the per-link markers persisted with each link. Return
|
||||
None when the file cannot be read (e.g. a project never dumped), so
|
||||
the caller falls back to the in-memory counts.
|
||||
"""
|
||||
|
||||
try:
|
||||
with open(self.topology_file, encoding="utf-8") as f:
|
||||
topology = json.load(f)
|
||||
except (OSError, UnicodeDecodeError, ValueError) as e:
|
||||
log.warning(f"Could not read the topology file of project '{self._name}' for the statistics: {e}")
|
||||
return None
|
||||
|
||||
scene = topology.get("topology") or {}
|
||||
links = scene.get("links") or []
|
||||
return {
|
||||
"nodes": len(scene.get("nodes") or []),
|
||||
"links": len(links),
|
||||
"drawings": len(scene.get("drawings") or []),
|
||||
"snapshots": len(self._snapshots),
|
||||
"markers": sum(len(link.get("markers") or {}) for link in links),
|
||||
}
|
||||
|
||||
def asdict(self):
|
||||
return {
|
||||
"name": self._name,
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ platformdirs>=4.14.2
|
||||
truststore>=0.10.5
|
||||
|
||||
# Shared dependencies (also used by AI Copilot)
|
||||
telnetlib3==5.0.1,<6
|
||||
telnetlib3==5.0.2
|
||||
asyncssh>=2.24.1,<3
|
||||
typing-extensions>=4.16.0
|
||||
requests>=2.34.2
|
||||
|
||||
@@ -1417,3 +1417,95 @@ async def test_restore_deferred_links(project):
|
||||
|
||||
assert link._deferred is False
|
||||
assert link.create.called is True
|
||||
|
||||
|
||||
async def _populate_scene(project):
|
||||
"""
|
||||
Add two nodes, a link between them and a drawing to a project.
|
||||
"""
|
||||
|
||||
compute = MagicMock()
|
||||
compute.id = "local"
|
||||
response = MagicMock()
|
||||
response.json = {"console": 2048}
|
||||
compute.post = AsyncioMagicMock(return_value=response)
|
||||
|
||||
node1 = await project.add_node(compute, "n1", None, node_type="vpcs", properties={})
|
||||
node2 = await project.add_node(compute, "n2", None, node_type="vpcs", properties={})
|
||||
node1._ports = [EthernetPort("E0", 0, 0, 0)]
|
||||
node2._ports = [EthernetPort("E0", 0, 1, 0)]
|
||||
|
||||
link = await project.add_link()
|
||||
await link.add_node(node1, 0, 0)
|
||||
with asyncio_patch("gns3server.controller.udp_link.UDPLink.create"):
|
||||
await link.add_node(node2, 1, 0)
|
||||
|
||||
project.emit_notification = MagicMock()
|
||||
await project.add_drawing(None, svg="<svg></svg>")
|
||||
return link
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stats_closed_project_counts_from_topology_file(controller, project):
|
||||
"""
|
||||
A closed project has no scene elements in memory: the stats must come
|
||||
from the .gns3 file (issue #1836).
|
||||
"""
|
||||
|
||||
await _populate_scene(project)
|
||||
project.dump()
|
||||
|
||||
# same net effect as close(): the in-memory collections are emptied
|
||||
project.reset()
|
||||
project._status = "closed"
|
||||
|
||||
stats = project.stats()
|
||||
assert stats["nodes"] == 2
|
||||
assert stats["links"] == 1
|
||||
assert stats["drawings"] == 1
|
||||
assert stats["snapshots"] == 0
|
||||
assert stats["markers"] == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stats_closed_project_counts_markers_from_topology_file(controller, project):
|
||||
"""
|
||||
The markers of a closed project are counted from the per-link markers
|
||||
persisted in the .gns3 file.
|
||||
"""
|
||||
|
||||
link = await _populate_scene(project)
|
||||
link.markers["http"] = {"bpf": "tcp port 80", "tag": "HTTP"}
|
||||
project.dump()
|
||||
|
||||
project.reset()
|
||||
project._status = "closed"
|
||||
|
||||
assert project.stats()["markers"] == 1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stats_closed_project_without_topology_file(controller, project):
|
||||
"""
|
||||
A project never dumped (no .gns3 file yet) falls back to the in-memory
|
||||
counts instead of raising.
|
||||
"""
|
||||
|
||||
project._status = "closed"
|
||||
|
||||
assert project.stats() == {"nodes": 0, "links": 0, "drawings": 0, "snapshots": 0, "markers": 0}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stats_opened_project_counts_from_memory(controller, project):
|
||||
"""
|
||||
An opened project reports the live in-memory counts.
|
||||
"""
|
||||
|
||||
await _populate_scene(project)
|
||||
project._status = "opened"
|
||||
|
||||
stats = project.stats()
|
||||
assert stats["nodes"] == 2
|
||||
assert stats["links"] == 1
|
||||
assert stats["drawings"] == 1
|
||||
Reference in new issue
Block a user