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

Commit ec22e95

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

File tree

3 files changed

+80
-8
lines changed
  • packages
    • jumpstarter-driver-network/jumpstarter_driver_network/adapters
    • jumpstarter-driver-vnc/jumpstarter_driver_vnc

3 files changed

+80
-8
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 `encrypt=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: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,76 @@ class VNClient(CompositeClient):
2020

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

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

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

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

3974
@vnc.command()
4075
@click.option("--browser/--no-browser", default=True, help="Open the session in a web browser.")
4176
@click.option(
4277
"--encrypt/--no-encrypt",
4378
default=False,
44-
help="Use an encrypted connection (wss://).",
79+
help="Use HTTPS and request noVNC to use secure WebSockets.",
4580
)
4681
def session(browser: bool, encrypt: bool):
47-
"""Open a VNC session."""
82+
"""
83+
Open an interactive VNC session and wait for the user to terminate it.
84+
85+
Starts a VNC session using the client's session context, prints the connection
86+
URL, optionally opens that URL in a web browser, and blocks until the user
87+
cancels (e.g., Ctrl+C), then closes the session.
88+
89+
Parameters:
90+
browser (bool): If True, open the session URL in the default web browser.
91+
encrypt (bool): If True, use HTTPS and request noVNC to use secure WebSockets.
92+
"""
4893
# The NovncAdapter is a blocking context manager that runs in a thread.
4994
# We can enter it, open the browser, and then just wait for the user
5095
# 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)