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

Commit 0a0abce

Browse files
aesteve-rhgithub-actions[bot]
authored andcommitted
novnc: Improve docstrings for coverage
Signed-off-by: Albert Esteve <aesteve@redhat.com> (cherry picked from commit 6cdcf5c)
1 parent 7fd8626 commit 0a0abce

3 files changed

Lines changed: 77 additions & 9 deletions

File tree

  • packages
    • jumpstarter-driver-network/jumpstarter_driver_network/adapters
    • jumpstarter-driver-vnc/jumpstarter_driver_vnc

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: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ 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
def stream(self, method="connect"):
@@ -33,7 +38,15 @@ async def stream_async(self, method="connect"):
3338

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

@@ -42,11 +55,28 @@ def get_default_encrypt(self) -> bool:
4255
return typing.cast(bool, self.call("get_default_encrypt"))
4356

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

4770
@driver_click_group(self)
4871
def vnc():
49-
"""Open a VNC session."""
72+
"""
73+
Open a VNC session and block until the user closes it.
74+
75+
When invoked, prints the connection URL for the noVNC session, optionally
76+
opens that URL in the user's web browser, and waits for user-initiated
77+
termination (for example, Ctrl+C). On exit, prints a message indicating
78+
the session is closing.
79+
"""
5080

5181
@vnc.command()
5282
@click.option("--browser/--no-browser", default=True, help="Open the session in a web browser.")
@@ -55,16 +85,28 @@ def vnc():
5585
"encrypt_override",
5686
flag_value=True,
5787
default=None,
58-
help="Force an encrypted connection (wss://). Overrides the driver default.",
88+
help="Force an encrypted vnc connection. Overrides the driver default.",
5989
)
6090
@click.option(
6191
"--no-encrypt",
6292
"encrypt_override",
6393
flag_value=False,
64-
help="Force an unencrypted connection (ws://). Overrides the driver default.",
94+
help="Force an unencrypted vnc connection. Overrides the driver default.",
6595
)
6696
def session(browser: bool, encrypt_override: bool | None):
67-
"""Open a VNC session."""
97+
"""
98+
Open an interactive VNC session and wait for the user to terminate it.
99+
100+
Starts a VNC session using the client's session context, prints the connection
101+
URL, optionally opens that URL in a web browser, and blocks until the user
102+
cancels (e.g., Ctrl+C), then closes the session.
103+
104+
Parameters:
105+
browser (bool): If True, open the session URL in the default web browser.
106+
encrypt_override (bool | None): If provided, overrides the driver's default
107+
encryption setting. True for encrypted,
108+
False for unencrypted, None to use driver default.
109+
"""
68110
encrypt = encrypt_override if encrypt_override is not None else self.get_default_encrypt()
69111
# The NovncAdapter is a blocking context manager that runs in a thread.
70112
# 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)