Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Commit f2df238

Browse files
committed
novnc: Improve docstrings for coverage
Signed-off-by: Albert Esteve <aesteve@redhat.com>
1 parent ff3a60f commit f2df238

File tree

3 files changed

+79
-7
lines changed
  • packages
    • jumpstarter-driver-network/jumpstarter_driver_network/adapters
    • jumpstarter-driver-vnc/jumpstarter_driver_vnc

3 files changed

+79
-7
lines changed

packages/jumpstarter-driver-network/jumpstarter_driver_network/adapters/novnc.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@
1111
@blocking
1212
@asynccontextmanager
1313
async def NovncAdapter(*, client: DriverClient, method: str = "connect", encrypt: bool = False):
14+
"""
15+
Provide a noVNC URL that proxies a temporary local TCP listener to a remote
16+
driver stream via a WebSocket bridge.
17+
18+
Parameters:
19+
client (DriverClient): Client used to open the remote stream that will be
20+
bridged to the local listener.
21+
method (str): Name of the async stream method to call on the client (default "connect").
22+
encrypt (bool): If True use "https" in the generated URL;
23+
if False use "http" and include `ncrypt=0` in the URL query.
24+
25+
Returns:
26+
str: A fully constructed noVNC URL pointing at the temporary listener
27+
(host and port encoded in the query).
28+
"""
29+
1430
async def handler(conn):
1531
async with conn:
1632
async with client.stream_async(method) as stream:

packages/jumpstarter-driver-vnc/jumpstarter_driver_vnc/client.py

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,56 @@ class VNClient(CompositeClient):
2121

2222
@property
2323
def tcp(self) -> TCPClient:
24-
"""Get the TCP client."""
24+
"""
25+
Access the underlying TCP client.
26+
27+
Returns:
28+
TCPClient: The TCP client instance stored in this composite client's children mapping.
29+
"""
2530
return typing.cast("TCPClient", self.children["tcp"])
2631

2732
@contextlib.contextmanager
2833
def session(self, *, encrypt: bool = False) -> typing.Iterator[str]:
29-
"""Create a new VNC session."""
34+
"""
35+
Open a noVNC session and yield the connection URL.
36+
37+
Parameters:
38+
encrypt (bool): If True, request an encrypted WebSocket (use `wss://`);
39+
otherwise use `ws://`.
40+
41+
Returns:
42+
url (str): The URL to connect to the VNC session.
43+
"""
3044
with NovncAdapter(client=self.tcp, method="connect", encrypt=encrypt) as adapter:
3145
yield adapter
3246

3347
def cli(self) -> click.Command:
34-
"""Return a click command handler for this driver."""
48+
"""
49+
Provide a Click command group for running VNC sessions.
50+
51+
The returned command exposes a `session` subcommand that opens a VNC session,
52+
prints the connection URL, optionally opens it in the user's browser,
53+
and waits until the user cancels the session.
54+
55+
Returns:
56+
click.Command: Click command group with a `session` subcommand that accepts
57+
`--browser/--no-browser` and `--encrypt/--no-encrypt` options.
58+
"""
3559

3660
@driver_click_group(self)
3761
def vnc():
38-
"""Open a VNC session."""
62+
"""
63+
Open a VNC session and block until the user closes it.
64+
65+
When invoked, prints the connection URL for the noVNC session, optionally
66+
opens that URL in the user's web browser, and waits for user-initiated
67+
termination (for example, Ctrl+C). On exit, prints a message indicating
68+
the session is closing.
69+
70+
Parameters:
71+
browser (bool): If True, open the session URL in the default web browser.
72+
encrypt (bool): If True, request an encrypted (wss://) connection.
73+
"""
3974

4075
@vnc.command()
4176
@click.option("--browser/--no-browser", default=True, help="Open the session in a web browser.")
@@ -45,7 +80,17 @@ def vnc():
4580
help="Use an encrypted connection (wss://).",
4681
)
4782
def session(browser: bool, encrypt: bool):
48-
"""Open a VNC session."""
83+
"""
84+
Open an interactive VNC session and wait for the user to terminate it.
85+
86+
Starts a VNC session using the client's session context, prints the connection
87+
URL, optionally opens that URL in a web browser, and blocks until the user
88+
cancels (e.g., Ctrl+C), then closes the session.
89+
90+
Parameters:
91+
browser (bool): If True, open the session URL in the default web browser.
92+
encrypt (bool): If True, request an encrypted (wss://) connection for the session.
93+
"""
4994
# The NovncAdapter is a blocking context manager that runs in a thread.
5095
# We can enter it, open the browser, and then just wait for the user
5196
# to press Ctrl+C to exit. The adapter handles the background work.

packages/jumpstarter-driver-vnc/jumpstarter_driver_vnc/driver.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,23 @@ class Vnc(Driver):
88
"""A driver for VNC."""
99

1010
def __post_init__(self):
11-
"""Initialize the VNC driver."""
11+
"""
12+
Validate the VNC driver's post-initialization configuration.
13+
Ensures the driver has a "tcp" child configured.
14+
15+
Raises:
16+
ConfigurationError: If a "tcp" child is not present.
17+
"""
1218
super().__post_init__()
1319
if "tcp" not in self.children:
1420
raise ConfigurationError("A tcp child is required for Vnc")
1521

1622
@classmethod
1723
def client(cls) -> str:
18-
"""Return the client class path for this driver."""
24+
"""
25+
Client class path for this driver.
26+
27+
Returns:
28+
str: Dotted import path of the client class.
29+
"""
1930
return "jumpstarter_driver_vnc.client.VNClient"

0 commit comments

Comments
 (0)