refactor: ruff autofixes

This commit is contained in:
Mark Paronyan committed 2026-10-17 11:43:36 +03:00
1 parent 54139dced2
commit b7e6c02647
39 files changed
+76 -88

No files matched your search

+3 -3
View File
@@ -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
+4 -12
View File
@@ -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
+1 -1
View File
@@ -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:
+1 -1
View File
@@ -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:
+5 -5
View File
@@ -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}")
+1 -1
View File
@@ -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:
+4 -4
View File
@@ -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.
+1 -1
View File
@@ -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:
+1 -1
View File
@@ -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."
)
+1 -1
View File
@@ -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:
+1 -1
View File
@@ -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()