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

Commit 021de5d

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

File tree

3 files changed

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

3 files changed

+79
-9
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@
1111
@blocking
1212
@asynccontextmanager
1313
async def NovncAdapter(*, client: DriverClient, method: str = "connect", encrypt: bool = True):
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 request an encrypted (TLS) vnc connection;
23+
if False request an unencrypted vnc connection.
24+
25+
Returns:
26+
str: The URL to connect to the VNC session.
27+
"""
28+
1429
async def handler(conn):
1530
async with conn:
1631
async with client.stream_async(method) as stream:

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

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ 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
def stream(self, method="connect"):
@@ -34,7 +39,15 @@ async def stream_async(self, method="connect"):
3439

3540
@contextlib.contextmanager
3641
def session(self, *, encrypt: bool = True) -> typing.Iterator[str]:
37-
"""Create a new VNC session."""
42+
"""
43+
Open a noVNC session and yield the connection URL.
44+
45+
Parameters:
46+
encrypt (bool): If True, request an encrypted vnc connection.
47+
48+
Returns:
49+
url (str): The URL to connect to the VNC session.
50+
"""
3851
with NovncAdapter(client=self.tcp, method="connect", encrypt=encrypt) as adapter:
3952
yield adapter
4053

@@ -43,11 +56,32 @@ def get_default_encrypt(self) -> bool:
4356
return self.portal.call(DriverClient.call_async, self, "get_default_encrypt")
4457

4558
def cli(self) -> click.Command:
46-
"""Return a click command handler for this driver."""
59+
"""
60+
Provide a Click command group for running VNC sessions.
61+
62+
The returned command exposes a `session` subcommand that opens a VNC session,
63+
prints the connection URL, optionally opens it in the user's browser,
64+
and waits until the user cancels the session.
65+
66+
Returns:
67+
click.Command: Click command group with a `session` subcommand that accepts
68+
`--browser/--no-browser` and `--encrypt/--no-encrypt` options.
69+
"""
4770

4871
@driver_click_group(self)
4972
def vnc():
50-
"""Open a VNC session."""
73+
"""
74+
Open a VNC session and block until the user closes it.
75+
76+
When invoked, prints the connection URL for the noVNC session, optionally
77+
opens that URL in the user's web browser, and waits for user-initiated
78+
termination (for example, Ctrl+C). On exit, prints a message indicating
79+
the session is closing.
80+
81+
Parameters:
82+
browser (bool): If True, open the session URL in the default web browser.
83+
encrypt_override (bool): If True, request an encrypted vnc connection.
84+
"""
5185

5286
@vnc.command()
5387
@click.option("--browser/--no-browser", default=True, help="Open the session in a web browser.")
@@ -56,16 +90,26 @@ def vnc():
5690
"encrypt_override",
5791
flag_value=True,
5892
default=None,
59-
help="Force an encrypted connection (wss://). Overrides the driver default.",
93+
help="Force an encrypted vnc connection. Overrides the driver default.",
6094
)
6195
@click.option(
6296
"--no-encrypt",
6397
"encrypt_override",
6498
flag_value=False,
65-
help="Force an unencrypted connection (ws://). Overrides the driver default.",
99+
help="Force an unencrypted vnc connection. Overrides the driver default.",
66100
)
67101
def session(browser: bool, encrypt_override: bool | None):
68-
"""Open a VNC session."""
102+
"""
103+
Open an interactive VNC session and wait for the user to terminate it.
104+
105+
Starts a VNC session using the client's session context, prints the connection
106+
URL, optionally opens that URL in a web browser, and blocks until the user
107+
cancels (e.g., Ctrl+C), then closes the session.
108+
109+
Parameters:
110+
browser (bool): If True, open the session URL in the default web browser.
111+
encrypt (bool): If True, request noVNC to use an encrypted vnc connection.
112+
"""
69113
encrypt = encrypt_override if encrypt_override is not None else self.get_default_encrypt()
70114
# The NovncAdapter is a blocking context manager that runs in a thread.
71115
# We can enter it, open the browser, and then just wait for the user

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ class Vnc(Composite):
1919
default_encrypt: bool = False
2020

2121
def __post_init__(self):
22-
"""Initialize the VNC driver."""
22+
"""
23+
Validate the VNC driver's post-initialization configuration.
24+
Ensures the driver has a "tcp" child configured.
25+
26+
Raises:
27+
ConfigurationError: If a "tcp" child is not present.
28+
"""
2329
super().__post_init__()
2430
if "tcp" not in self.children:
2531
raise ConfigurationError("A tcp child is required for Vnc")
@@ -31,5 +37,10 @@ async def get_default_encrypt(self) -> bool:
3137

3238
@classmethod
3339
def client(cls) -> str:
34-
"""Return the client class path for this driver."""
40+
"""
41+
Client class path for this driver.
42+
43+
Returns:
44+
str: Dotted import path of the client class.
45+
"""
3546
return "jumpstarter_driver_vnc.client.VNClient"

0 commit comments

Comments
 (0)