mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-10-20 01:42:21 +03:00
refactor: ruff autofixes
This commit is contained in:
parent
54139dced2
commit
b7e6c02647
@ -685,7 +685,7 @@ class AgentService:
|
||||
"Checkpointer connection closed for: %s",
|
||||
self.project_path,
|
||||
)
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
log.warning(
|
||||
"Checkpointer connection close timeout for: %s (forcing cleanup)",
|
||||
self.project_path,
|
||||
|
||||
@ -215,7 +215,7 @@ async def wait_for_mcp_ready() -> bool:
|
||||
await asyncio.wait_for(_mcp_ready_event.wait(), timeout=5.0)
|
||||
log.debug("MCP server is now ready, proceeding with connection")
|
||||
return True
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
log.warning("MCP server ready check timed out after 5 seconds - GNS3 server initialization may have issues")
|
||||
return False
|
||||
|
||||
|
||||
@ -21,7 +21,6 @@ Web Wireshark - Docker HTTP API client
|
||||
This module handles Docker API operations via aiohttp Unix socket.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
from asyncio import timeout as async_timeout
|
||||
from typing import Any
|
||||
@ -142,7 +141,7 @@ class DockerHTTPClient:
|
||||
if response.status == 204: # No Content
|
||||
return None
|
||||
return await response.json()
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
raise RuntimeError(f"Docker API timeout after {self.REQUEST_TIMEOUT}s for {endpoint}")
|
||||
except aiohttp.ClientError as e:
|
||||
raise RuntimeError(f"Docker connection error: {e}") from e
|
||||
@ -256,7 +255,7 @@ class DockerHTTPClient:
|
||||
error_text = await response.text()
|
||||
raise RuntimeError(f"Docker API error {response.status}: {error_text}")
|
||||
result = await response.json()
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
raise RuntimeError(f"Docker API timeout after {self.REQUEST_TIMEOUT}s for containers/{container_name}/top")
|
||||
except aiohttp.ClientError as e:
|
||||
raise RuntimeError(f"Docker connection error: {e}") from e
|
||||
|
||||
@ -75,7 +75,7 @@ class WebWiresharkManager:
|
||||
)
|
||||
stdout, _ = await asyncio.wait_for(proc.communicate(), timeout=self.CONTAINER_EXEC_TIMEOUT)
|
||||
return proc.returncode == 0 and b"ping" in stdout
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
logger.warning(f"Container {container_id[:12]} health check timeout")
|
||||
return False
|
||||
except FileNotFoundError:
|
||||
@ -113,12 +113,12 @@ class WebWiresharkManager:
|
||||
try:
|
||||
stdout, stderr = await asyncio.wait_for(proc.communicate(), timeout=timeout)
|
||||
return (proc.returncode, stdout.decode().strip(), stderr.decode().strip())
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
logger.error(f"Command timeout after {timeout}s: {command}")
|
||||
proc.terminate()
|
||||
try:
|
||||
await asyncio.wait_for(proc.wait(), timeout=2)
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
proc.kill()
|
||||
return (-1, "", f"timeout after {timeout}s")
|
||||
except Exception as e:
|
||||
|
||||
@ -435,7 +435,7 @@ async def _run_lifecycle(
|
||||
return node.asdict()
|
||||
try:
|
||||
await asyncio.wait_for(_run(), timeout)
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
raise ControllerTimeoutError(f"Timeout when waiting for {node.name} to be {target}")
|
||||
return node.asdict()
|
||||
|
||||
@ -711,7 +711,7 @@ async def get_file(file_path: str, node: Node = Depends(dep_node)) -> Response:
|
||||
try:
|
||||
async for chunk in compute_resp.content.iter_chunked(65536):
|
||||
yield chunk
|
||||
except (OSError, asyncio.TimeoutError) as e:
|
||||
except (TimeoutError, OSError) as e:
|
||||
log.error(f"Error streaming file '{path}' from compute: {e}")
|
||||
raise
|
||||
finally:
|
||||
|
||||
@ -323,7 +323,7 @@ class Docker(BaseManager):
|
||||
)
|
||||
except aiohttp.ClientError as e:
|
||||
raise DockerError(f"Docker has returned an error: {e}")
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
raise DockerError("Docker timeout " + method + " " + path)
|
||||
if response.status >= 300:
|
||||
body = await response.read()
|
||||
@ -391,7 +391,7 @@ class Docker(BaseManager):
|
||||
raise DockerError(
|
||||
f"Disconnected while pulling Docker image '{image}' from Docker repository"
|
||||
) from e
|
||||
except asyncio.TimeoutError as e:
|
||||
except TimeoutError as e:
|
||||
raise DockerError(f"Timeout while pulling Docker image '{image}' from Docker repository") from e
|
||||
if not chunk:
|
||||
break
|
||||
@ -448,7 +448,7 @@ class Docker(BaseManager):
|
||||
chunk = await response.content.read(CHUNK_SIZE)
|
||||
except aiohttp.ServerDisconnectedError as e:
|
||||
raise DockerError("Disconnected while loading Docker image") from e
|
||||
except asyncio.TimeoutError as e:
|
||||
except TimeoutError as e:
|
||||
raise DockerError("Timeout while loading Docker image") from e
|
||||
if not chunk:
|
||||
break
|
||||
|
||||
@ -948,7 +948,7 @@ class DockerVM(DockerKernelDatapathMixin, BaseNode):
|
||||
await self._start_vnc_process(restart=True)
|
||||
try:
|
||||
await wait_for_file_creation(x11_socket)
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
raise DockerError(f'x11 socket file "{x11_socket}" does not exist')
|
||||
monitor_process(self._vnc_process, self._vnc_callback)
|
||||
|
||||
@ -1190,7 +1190,7 @@ class DockerVM(DockerKernelDatapathMixin, BaseNode):
|
||||
return False
|
||||
try:
|
||||
_, stderr = await asyncio.wait_for(process.communicate(), timeout=60)
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
process.kill()
|
||||
await process.communicate()
|
||||
log.warning(f"Docker container '{self._name}': reclaiming '{directory}' timed out")
|
||||
@ -1254,7 +1254,7 @@ class DockerVM(DockerKernelDatapathMixin, BaseNode):
|
||||
x11_socket = os.path.join("/tmp/.X11-unix/", f"X{self._display}")
|
||||
try:
|
||||
await wait_for_file_creation(x11_socket)
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
raise DockerError(f'x11 socket file "{x11_socket}" does not exist')
|
||||
|
||||
if not hasattr(sys, "_called_from_test") or not sys._called_from_test:
|
||||
@ -1711,15 +1711,7 @@ class DockerVM(DockerKernelDatapathMixin, BaseNode):
|
||||
status_line = headers.split(b"\r\n", 1)[0]
|
||||
if b" 101 " not in status_line and b" 200 " not in status_line:
|
||||
raise DockerError(f"Docker interface monitor was rejected: {status_line.decode(errors='ignore')}")
|
||||
except (
|
||||
DockerError,
|
||||
OSError,
|
||||
KeyError,
|
||||
TypeError,
|
||||
RuntimeError,
|
||||
asyncio.IncompleteReadError,
|
||||
asyncio.TimeoutError,
|
||||
) as e:
|
||||
except (TimeoutError, DockerError, OSError, KeyError, TypeError, RuntimeError, asyncio.IncompleteReadError) as e:
|
||||
if "writer" in locals():
|
||||
await self._close_interface_monitor_writer(writer)
|
||||
log.warning("Could not monitor interfaces for Docker container '%s': %s", self.name, e)
|
||||
|
||||
@ -459,7 +459,7 @@ class VendorDockerVM(DockerVM):
|
||||
# setup; wait instead of silently blackholing the adapter.
|
||||
try:
|
||||
await wait_for_file_creation(remote_sock, timeout=30)
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
raise DockerError(
|
||||
f"Socket '{remote_sock}' for adapter {adapter_number} of container "
|
||||
f"'{self._name}' did not appear within 30 seconds. Check that the "
|
||||
@ -806,7 +806,7 @@ class _LazyExecTelnetServer(AsyncioTelnetServer):
|
||||
await writer.drain()
|
||||
try:
|
||||
headers = await asyncio.wait_for(reader.readuntil(b"\r\n\r\n"), timeout=5)
|
||||
except (asyncio.IncompleteReadError, asyncio.TimeoutError) as e:
|
||||
except (TimeoutError, asyncio.IncompleteReadError) as e:
|
||||
writer.close()
|
||||
raise DockerError(f"Docker exec start failed: {e}")
|
||||
status_line = headers.split(b"\r\n", 1)[0]
|
||||
|
||||
@ -80,7 +80,7 @@ class DynamipsHypervisor:
|
||||
self._reader, self._writer = await asyncio.wait_for(
|
||||
asyncio.open_connection(host, self._port), timeout=1
|
||||
)
|
||||
except (asyncio.TimeoutError, OSError) as e:
|
||||
except (TimeoutError, OSError) as e:
|
||||
last_exception = e
|
||||
continue
|
||||
connection_success = True
|
||||
|
||||
@ -144,7 +144,7 @@ class Hypervisor(DynamipsHypervisor):
|
||||
await asyncio.sleep(0.01)
|
||||
try:
|
||||
await wait_for_process_termination(self._process, timeout=3)
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
if self._process.returncode is None:
|
||||
log.warning(f"Dynamips process {self._process.pid} is still running... killing it")
|
||||
try:
|
||||
|
||||
@ -1034,7 +1034,7 @@ class IOUVM(KernelDatapathMixin, BaseNode):
|
||||
if self._iou_process.returncode is None:
|
||||
try:
|
||||
await gns3server.utils.asyncio.wait_for_process_termination(self._iou_process, timeout=3)
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
if self._iou_process.returncode is None:
|
||||
log.warning(f"IOU process {self._iou_process.pid} is still running... killing it")
|
||||
try:
|
||||
|
||||
@ -1272,7 +1272,7 @@ class QemuVM(KernelDatapathMixin, BaseNode):
|
||||
await gns3server.utils.asyncio.wait_for_process_termination(self._process, timeout=3)
|
||||
except ProcessLookupError:
|
||||
pass
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
if self._process:
|
||||
try:
|
||||
self._process.kill()
|
||||
@ -1324,7 +1324,7 @@ class QemuVM(KernelDatapathMixin, BaseNode):
|
||||
try:
|
||||
log.debug(f"Connecting to Qemu monitor on {self._monitor_host}:{self._monitor}")
|
||||
reader, writer = await asyncio.open_connection(self._monitor_host, self._monitor)
|
||||
except (asyncio.TimeoutError, OSError) as e:
|
||||
except (TimeoutError, OSError) as e:
|
||||
last_exception = e
|
||||
continue
|
||||
connection_success = True
|
||||
@ -1363,7 +1363,7 @@ class QemuVM(KernelDatapathMixin, BaseNode):
|
||||
line = await asyncio.wait_for(reader.readline(), timeout=3) # echo of the command
|
||||
if not line or cmd_byte in line:
|
||||
break
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
log.warning(f"Missing echo of command '{command}'")
|
||||
except OSError as e:
|
||||
log.warning(f"Could not write to QEMU monitor: {e}")
|
||||
@ -1379,7 +1379,7 @@ class QemuVM(KernelDatapathMixin, BaseNode):
|
||||
if expect in line:
|
||||
result = line.decode("utf-8").strip()
|
||||
break
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
log.warning(f"Timeout while waiting for result of command '{command}'")
|
||||
except (ConnectionError, EOFError) as e:
|
||||
log.warning(f"Could not read from QEMU monitor: {e}")
|
||||
@ -1407,7 +1407,7 @@ class QemuVM(KernelDatapathMixin, BaseNode):
|
||||
line = await asyncio.wait_for(reader.readline(), timeout=3) # echo of the command
|
||||
if not line or cmd_byte in line:
|
||||
break
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
log.warning(f"Missing echo of command '{command}'")
|
||||
except OSError as e:
|
||||
log.warning(f"Could not write to QEMU monitor: {e}")
|
||||
|
||||
@ -230,7 +230,7 @@ class Hypervisor(UBridgeHypervisor):
|
||||
await UBridgeHypervisor.stop(self)
|
||||
try:
|
||||
await wait_for_process_termination(self._process, timeout=3)
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
if self._process and self._process.returncode is None:
|
||||
log.warning(f"uBridge process {self._process.pid} is still running... killing it")
|
||||
try:
|
||||
|
||||
@ -112,7 +112,7 @@ async def _probe(path, config, timeout):
|
||||
|
||||
try:
|
||||
caps = await asyncio.wait_for(ask(), timeout=timeout)
|
||||
except (UbridgeError, OSError, asyncio.TimeoutError, ValueError) as e:
|
||||
except (TimeoutError, UbridgeError, OSError, ValueError) as e:
|
||||
# Old uBridge builds answer "Unknown command"/"Unknown module";
|
||||
# anything else here is a broken install — either way: unknown.
|
||||
log.debug("uBridge tc capabilities probe failed: %s", e)
|
||||
@ -183,7 +183,7 @@ async def _probe_tap(path, config, timeout):
|
||||
|
||||
try:
|
||||
return await asyncio.wait_for(ask(), timeout=timeout)
|
||||
except (UbridgeError, OSError, asyncio.TimeoutError, ValueError) as e:
|
||||
except (TimeoutError, UbridgeError, OSError, ValueError) as e:
|
||||
# Missing module, old build, or no CAP_NET_ADMIN: unknown.
|
||||
log.debug("uBridge tap-module probe failed: %s", e)
|
||||
return None
|
||||
@ -269,7 +269,7 @@ async def _probe_iol_tap(path, config, timeout):
|
||||
|
||||
try:
|
||||
return await asyncio.wait_for(ask(), timeout=timeout)
|
||||
except (UbridgeError, OSError, asyncio.TimeoutError, ValueError) as e:
|
||||
except (TimeoutError, UbridgeError, OSError, ValueError) as e:
|
||||
# Old build ("Unknown command"), missing module, or no
|
||||
# CAP_NET_ADMIN: unknown.
|
||||
log.debug("uBridge iol-tap probe failed: %s", e)
|
||||
@ -348,7 +348,7 @@ async def _probe_bridge_tap(path, config, timeout):
|
||||
|
||||
try:
|
||||
return await asyncio.wait_for(ask(), timeout=timeout)
|
||||
except (UbridgeError, OSError, asyncio.TimeoutError, ValueError) as e:
|
||||
except (TimeoutError, UbridgeError, OSError, ValueError) as e:
|
||||
# UbridgeError also covers hypervisor.start()/connect() failing
|
||||
# (unlike the siblings, ask() re-raises those): an unusable
|
||||
# binary means unknown, never a failed /capabilities response.
|
||||
|
||||
@ -112,7 +112,7 @@ class VirtualBox(BaseManager):
|
||||
|
||||
try:
|
||||
stdout_data, stderr_data = await asyncio.wait_for(process.communicate(), timeout=timeout)
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
raise VirtualBoxError(f"VBoxManage has timed out after {timeout} seconds!")
|
||||
|
||||
if process.returncode:
|
||||
|
||||
@ -382,7 +382,7 @@ class VMware(BaseManager):
|
||||
|
||||
try:
|
||||
stdout_data, _ = await asyncio.wait_for(process.communicate(), timeout=timeout)
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
raise VMwareError(
|
||||
f"vmrun has timed out after {timeout} seconds!\nTry to run {command_string} in a terminal to see more details.\n\nMake sure GNS3 and VMware run under the same user and whitelist vmrun.exe in your antivirus."
|
||||
)
|
||||
|
||||
@ -83,7 +83,7 @@ async def probe_vpcs_tap(timeout: float = 5.0) -> bool | None:
|
||||
return _cache[key]
|
||||
try:
|
||||
output = await asyncio.wait_for(subprocess_check_output(vpcs_path, "-h"), timeout=timeout)
|
||||
except (OSError, asyncio.TimeoutError, ValueError) as e:
|
||||
except (TimeoutError, OSError, ValueError) as e:
|
||||
log.debug("VPCS tap-mode probe failed: %s", e)
|
||||
supported = None
|
||||
else:
|
||||
|
||||
@ -333,7 +333,7 @@ class VPCSVM(KernelDatapathMixin, BaseNode):
|
||||
if self._process.returncode is None:
|
||||
try:
|
||||
await wait_for_process_termination(self._process, timeout=3)
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
if self._process.returncode is None:
|
||||
try:
|
||||
self._process.kill()
|
||||
|
||||
@ -15,7 +15,6 @@
|
||||
# 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
|
||||
import copy
|
||||
import json
|
||||
import logging
|
||||
@ -221,7 +220,7 @@ class ApplianceManager:
|
||||
raise ControllerError(f"Could not save {image_type} image '{image_path}': {e}")
|
||||
except ClientError as e:
|
||||
raise ControllerError(f"Could not connect to download '{image_name}': {e}")
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
raise ControllerError(f"Timeout while downloading '{image_name}' from '{image_url}'")
|
||||
|
||||
async def _find_appliance_version_images(
|
||||
@ -551,7 +550,7 @@ class ApplianceManager:
|
||||
log.info(f"Saving {symbol} symbol to {destination_path}")
|
||||
with open(destination_path, "wb") as f:
|
||||
f.write(symbol_data)
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
log.warning(f"Timeout while downloading '{symbol_url}'")
|
||||
except OSError as e:
|
||||
log.warning(f"Could not write appliance symbol '{destination_path}': {e}")
|
||||
@ -601,7 +600,7 @@ class ApplianceManager:
|
||||
continue
|
||||
try:
|
||||
appliance_data = await response.read()
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
log.warning("Timeout while downloading '{}'".format(appliance["download_url"]))
|
||||
continue
|
||||
path = os.path.join(appliances_dir, appliance_name)
|
||||
|
||||
@ -635,7 +635,7 @@ class Compute:
|
||||
chunked=chunked,
|
||||
timeout=timeout,
|
||||
)
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
raise ComputeError(f"Timeout error for {method} call to {url} after {timeout}s")
|
||||
except (
|
||||
aiohttp.ClientError,
|
||||
|
||||
@ -15,7 +15,6 @@
|
||||
# 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
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
@ -134,7 +133,7 @@ async def export_project(
|
||||
while True:
|
||||
try:
|
||||
data = await response.content.read(CHUNK_SIZE)
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
raise ControllerTimeoutError(
|
||||
"Timeout when downloading file '{}' from remote compute {}:{}".format(
|
||||
compute_file["path"], compute.host, compute.port
|
||||
@ -326,7 +325,7 @@ async def _export_remote_images(project, compute_id, image_type, image, project_
|
||||
while True:
|
||||
try:
|
||||
data = await response.content.read(CHUNK_SIZE)
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
raise ControllerTimeoutError(
|
||||
f"Timeout when downloading image '{image}' from remote compute {compute.host}:{compute.port}"
|
||||
)
|
||||
|
||||
@ -434,7 +434,7 @@ class VirtualBoxGNS3VM(BaseGNS3VM):
|
||||
return interface["ip_address"]
|
||||
except ValueError:
|
||||
pass
|
||||
except (OSError, aiohttp.ClientError, TimeoutError, asyncio.TimeoutError):
|
||||
except (OSError, aiohttp.ClientError, TimeoutError):
|
||||
pass
|
||||
remaining_try -= 1
|
||||
await asyncio.sleep(1)
|
||||
|
||||
@ -349,7 +349,7 @@ class _SharkdSession:
|
||||
self.proc.stdin.write((json.dumps(request) + "\n").encode())
|
||||
await self.proc.stdin.drain()
|
||||
raw = await asyncio.wait_for(self.proc.stdout.readline(), RPC_TIMEOUT_SECONDS)
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
await self._abort(f"sharkd timed out after {RPC_TIMEOUT_SECONDS:.0f}s on {method!r}")
|
||||
except (OSError, ValueError) as e:
|
||||
# ValueError: a reply line over the StreamReader limit — the
|
||||
@ -387,7 +387,7 @@ class _SharkdSession:
|
||||
# the caller — leak the process with a log instead.
|
||||
try:
|
||||
await asyncio.wait_for(self.proc.wait(), timeout=2.0)
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
log.warning("sharkd session for %s did not exit after kill", self.pcap)
|
||||
except ProcessLookupError:
|
||||
pass
|
||||
|
||||
@ -965,7 +965,7 @@ class Node:
|
||||
)
|
||||
else:
|
||||
await self.post("/start", data=data, timeout=240)
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
raise ControllerTimeoutError(f"Timeout when starting {self._name}")
|
||||
self._confirm_status("started")
|
||||
# A started node may have brought kernel anchors into existence that
|
||||
@ -990,7 +990,7 @@ class Node:
|
||||
# We don't care if a node is down at this step
|
||||
if strict:
|
||||
raise
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
raise ControllerTimeoutError(f"Timeout when stopping {self._name}")
|
||||
if stopped:
|
||||
self._confirm_status("stopped")
|
||||
@ -1015,7 +1015,7 @@ class Node:
|
||||
"""
|
||||
try:
|
||||
await self.post("/suspend", timeout=240)
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
raise ControllerTimeoutError(f"Timeout when suspending {self._name}")
|
||||
self._confirm_status("suspended")
|
||||
|
||||
@ -1025,7 +1025,7 @@ class Node:
|
||||
"""
|
||||
try:
|
||||
await self.post("/reload", timeout=240)
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
raise ControllerTimeoutError(f"Timeout when reloading {self._name}")
|
||||
self._confirm_status("started")
|
||||
|
||||
@ -1037,7 +1037,7 @@ class Node:
|
||||
if self._console and self._console_type in ("telnet", "ssh"):
|
||||
try:
|
||||
await self.post("/console/reset", timeout=240)
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
raise ControllerTimeoutError(f"Timeout when reset console {self._name}")
|
||||
|
||||
async def get(self, path="", **kwargs):
|
||||
|
||||
@ -23,7 +23,7 @@ import tempfile
|
||||
import time
|
||||
import uuid
|
||||
import zipfile
|
||||
from datetime import datetime, timezone
|
||||
from datetime import UTC, datetime
|
||||
|
||||
import aiofiles
|
||||
|
||||
@ -63,19 +63,19 @@ class Snapshot:
|
||||
if created_at:
|
||||
self._created_at = created_at
|
||||
else:
|
||||
self._created_at = int(datetime.now(timezone.utc).timestamp())
|
||||
self._created_at = int(datetime.now(UTC).timestamp())
|
||||
if not filename:
|
||||
filename = self._name + ".gns3snapshot"
|
||||
else:
|
||||
self._name = filename.rsplit("_", 2)[0]
|
||||
datestring = filename.replace(self._name + "_", "").split(".")[0]
|
||||
self._created_at = int(
|
||||
datetime.strptime(datestring, FILENAME_DATETIME_FORMAT).replace(tzinfo=timezone.utc).timestamp()
|
||||
datetime.strptime(datestring, FILENAME_DATETIME_FORMAT).replace(tzinfo=UTC).timestamp()
|
||||
)
|
||||
|
||||
if not description:
|
||||
date = (
|
||||
datetime.fromtimestamp(self._created_at, tz=timezone.utc)
|
||||
datetime.fromtimestamp(self._created_at, tz=UTC)
|
||||
.replace(tzinfo=None)
|
||||
.strftime(DESCRIPTION_DATETIME_FORMAT)
|
||||
)
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
from datetime import datetime, timezone
|
||||
from datetime import UTC, datetime
|
||||
from typing import Callable, List, Optional, cast
|
||||
|
||||
from sqlalchemy import delete, select, update
|
||||
@ -166,8 +166,8 @@ class ImagesRepository(BaseRepository):
|
||||
values.update(
|
||||
availability="available",
|
||||
last_error=None,
|
||||
last_seen_at=datetime.now(timezone.utc).replace(tzinfo=None),
|
||||
last_verified_at=datetime.now(timezone.utc).replace(tzinfo=None),
|
||||
last_seen_at=datetime.now(UTC).replace(tzinfo=None),
|
||||
last_verified_at=datetime.now(UTC).replace(tzinfo=None),
|
||||
)
|
||||
for attempt in range(2):
|
||||
try:
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
from datetime import datetime, timezone
|
||||
from datetime import UTC, datetime
|
||||
from typing import Optional
|
||||
from uuid import UUID
|
||||
|
||||
@ -54,5 +54,5 @@ class Snapshot(SnapshotBase):
|
||||
@classmethod
|
||||
def _derive_created(cls, data):
|
||||
if isinstance(data, dict) and "created" not in data and data.get("created_at") is not None:
|
||||
data = {**data, "created": datetime.fromtimestamp(data["created_at"], tz=timezone.utc)}
|
||||
data = {**data, "created": datetime.fromtimestamp(data["created_at"], tz=UTC)}
|
||||
return data
|
||||
|
||||
@ -18,7 +18,7 @@ import base64
|
||||
import json
|
||||
import logging
|
||||
import time
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from datetime import UTC, datetime, timedelta
|
||||
from typing import Optional
|
||||
|
||||
import bcrypt
|
||||
@ -64,7 +64,7 @@ class AuthService:
|
||||
def _create_token(self, username, token_version, token_type, expires_in, secret_key=None) -> str:
|
||||
"""Shared helper to create any kind of signed JWT token."""
|
||||
|
||||
issued_at = datetime.now(timezone.utc)
|
||||
issued_at = datetime.now(UTC)
|
||||
expire = issued_at + timedelta(minutes=expires_in)
|
||||
to_encode = {"sub": username, "iat": issued_at, "exp": expire, "ver": token_version, "type": token_type}
|
||||
if secret_key is None:
|
||||
|
||||
@ -6,7 +6,7 @@ import os
|
||||
import stat
|
||||
import threading
|
||||
import uuid
|
||||
from datetime import datetime, timezone
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from sqlalchemy import delete, select, update
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
@ -44,7 +44,7 @@ RAW_EXTENSIONS = {".raw", ".img", ".iso", ".fd", ".vhd", ".vdi", ".bin"}
|
||||
|
||||
|
||||
def utcnow():
|
||||
return datetime.now(timezone.utc).replace(tzinfo=None)
|
||||
return datetime.now(UTC).replace(tzinfo=None)
|
||||
|
||||
|
||||
def ignored(name):
|
||||
@ -476,7 +476,7 @@ class ImageReconciliationService:
|
||||
try:
|
||||
await asyncio.wait_for(self.dirty.wait(), Config.instance().settings.Server.image_sync_interval)
|
||||
await asyncio.sleep(1) # debounce bursts of file/directory events
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
pass
|
||||
except asyncio.CancelledError:
|
||||
break
|
||||
|
||||
@ -125,7 +125,7 @@ async def wait_for_file_creation(path, timeout=60):
|
||||
return
|
||||
await asyncio.sleep(0.5)
|
||||
timeout -= 0.5
|
||||
raise asyncio.TimeoutError()
|
||||
raise TimeoutError()
|
||||
|
||||
|
||||
def locking(f):
|
||||
|
||||
@ -66,7 +66,7 @@ async def _asyncio_open_serial_unix(path):
|
||||
try:
|
||||
# wait for VM to create the pipe file.
|
||||
await wait_for_file_creation(path)
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
raise NodeError(f'Pipe file "{path}" is missing')
|
||||
|
||||
output = SerialReaderWriterProtocol()
|
||||
|
||||
@ -147,7 +147,7 @@ class AsyncioSSHServer:
|
||||
try:
|
||||
process.stdout.write(data)
|
||||
await asyncio.wait_for(process.stdout.drain(), timeout=BROADCAST_DRAIN_TIMEOUT)
|
||||
except (OSError, ConnectionError, asyncio.TimeoutError, asyncssh.Error):
|
||||
except (TimeoutError, OSError, ConnectionError, asyncssh.Error):
|
||||
await self._disconnect_client(process)
|
||||
except asyncio.CancelledError:
|
||||
raise
|
||||
|
||||
@ -324,7 +324,7 @@ class AsyncioTelnetServer:
|
||||
try:
|
||||
connection.writer.write(data)
|
||||
await asyncio.wait_for(connection.writer.drain(), timeout=BROADCAST_DRAIN_TIMEOUT)
|
||||
except (OSError, ConnectionError, asyncio.TimeoutError) as e:
|
||||
except (TimeoutError, OSError, ConnectionError) as e:
|
||||
client_info = self._get_peername(network_writer)
|
||||
log.debug(
|
||||
"Error sending data to client %s: %s, closing and removing from connection table.",
|
||||
@ -352,7 +352,7 @@ class AsyncioTelnetServer:
|
||||
log.debug("Sending keepalive to client %s", client_info)
|
||||
connection.writer.send_iac(IAC + NOP)
|
||||
await asyncio.wait_for(connection.writer.drain(), timeout=BROADCAST_DRAIN_TIMEOUT)
|
||||
except (OSError, ConnectionError, asyncio.TimeoutError) as e:
|
||||
except (TimeoutError, OSError, ConnectionError) as e:
|
||||
log.debug(
|
||||
"Keepalive failed for client %s: %s, closing connection.",
|
||||
client_info,
|
||||
|
||||
@ -59,7 +59,7 @@ class NotificationQueue(asyncio.Queue):
|
||||
try:
|
||||
(action, msg, kwargs) = await asyncio.wait_for(super().get(), timeout - (now - self._last_ping))
|
||||
return (action, msg, kwargs)
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
continue # the ping deadline has been reached
|
||||
|
||||
def _ping(self):
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
|
||||
import os
|
||||
import uuid
|
||||
from datetime import datetime, timezone
|
||||
from datetime import UTC, datetime
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
@ -57,7 +57,7 @@ class TestSnapshotRoutes:
|
||||
assert len(response.json()) == 1
|
||||
data = response.json()[0]
|
||||
assert isinstance(data["created_at"], int)
|
||||
assert datetime.fromisoformat(data["created"]) == datetime.fromtimestamp(data["created_at"], tz=timezone.utc)
|
||||
assert datetime.fromisoformat(data["created"]) == datetime.fromtimestamp(data["created_at"], tz=UTC)
|
||||
|
||||
async def test_delete_snapshot(
|
||||
self, app: FastAPI, client: AsyncClient, project: Project, snapshot: Snapshot
|
||||
@ -86,7 +86,7 @@ class TestSnapshotRoutes:
|
||||
assert len(os.listdir(os.path.join(project.path, "snapshots"))) == 2
|
||||
data = response.json()
|
||||
assert isinstance(data["created_at"], int)
|
||||
assert datetime.fromisoformat(data["created"]) == datetime.fromtimestamp(data["created_at"], tz=timezone.utc)
|
||||
assert datetime.fromisoformat(data["created"]) == datetime.fromtimestamp(data["created_at"], tz=UTC)
|
||||
|
||||
async def test_snapshot_schema_timestamps(self, app: FastAPI) -> None:
|
||||
|
||||
|
||||
@ -239,7 +239,7 @@ async def test_pull_image_propagates_timeout():
|
||||
|
||||
class Content:
|
||||
async def read(self, size):
|
||||
raise asyncio.TimeoutError
|
||||
raise TimeoutError
|
||||
|
||||
response = MagicMock()
|
||||
response.content = Content()
|
||||
|
||||
@ -22,7 +22,6 @@ Image-free: everything is asserted against generated files, parsed knobs and
|
||||
the uBridge command stream.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import glob
|
||||
import json
|
||||
import os
|
||||
@ -454,7 +453,7 @@ async def test_add_ubridge_connection_timeout_is_actionable(compute_project, man
|
||||
vm._stop_ubridge = AsyncioMagicMock()
|
||||
|
||||
async def raise_timeout(path, timeout=60):
|
||||
raise asyncio.TimeoutError()
|
||||
raise TimeoutError()
|
||||
|
||||
with patch("gns3server.compute.docker.vendor_docker_vm.wait_for_file_creation", side_effect=raise_timeout):
|
||||
with pytest.raises(DockerError) as excinfo:
|
||||
|
||||
@ -586,7 +586,7 @@ async def test_periodic_scan_recovers_without_watcher_events(inventory, config):
|
||||
# Consume/close the unused Event.wait coroutine, then simulate a timeout.
|
||||
args[0].close()
|
||||
await real_sleep(0.01)
|
||||
raise asyncio.TimeoutError
|
||||
raise TimeoutError
|
||||
|
||||
with (
|
||||
patch.object(inventory, "_watch", new=AsyncMock()),
|
||||
|
||||
@ -72,7 +72,7 @@ class TelnetClient:
|
||||
response = data.decode("utf-8", errors="ignore")
|
||||
log.debug(f"Client {self.client_id}: Received: {response[:50]}...")
|
||||
return response
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
log.debug(f"Client {self.client_id}: No response (timeout)")
|
||||
except Exception as e:
|
||||
log.debug(f"Client {self.client_id}: Receive error: {e}")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user