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

Init UnixPortforwardAdapter#248

Merged
mangelajo merged 7 commits intomainfrom
unixportforward
Feb 3, 2025
Merged

Init UnixPortforwardAdapter#248
mangelajo merged 7 commits intomainfrom
unixportforward

Conversation

@NickCao
Copy link
Copy Markdown
Collaborator

@NickCao NickCao commented Feb 3, 2025

Summary by CodeRabbit

  • New Features

    • Introduced TcpPortforwardAdapter and UnixPortforwardAdapter for enhanced network connectivity options.
    • Added comprehensive documentation for the new network adapters, detailing their usage and configuration.
  • Refactor

    • Updated existing adapters to inherit from the new TCP-based adapter, improving the structure and functionality.
  • Tests

    • Expanded test coverage to verify functionality for both TCP and Unix domain socket forwarding scenarios.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 3, 2025

Walkthrough

The changes refactor the adapter interfaces within the driver network package. The modifications replace the generic PortforwardAdapter with two specific classes: TcpPortforwardAdapter and UnixPortforwardAdapter. The public interface in the __init__.py file is updated accordingly. Additionally, several adapter classes (FabricAdapter, NovncAdapter, and PexpectAdapter) now inherit from TcpPortforwardAdapter, and their import statements have been amended. New functionality is introduced in the portforward module, and the test suite has been updated to validate both TCP and Unix network port forwarding.

Changes

File(s) Change Summary
.../adapters/__init__.py Replaced PortforwardAdapter import with TcpPortforwardAdapter and UnixPortforwardAdapter; updated __all__ export list.
.../adapters/fabric.py, .../adapters/novnc.py, .../adapters/pexpect.py Updated class inheritance from PortforwardAdapter to TcpPortforwardAdapter; adjusted import in pexpect.py.
.../adapters/portforward.py Introduced new classes: TcpPortforwardAdapter and UnixPortforwardAdapter; revised method declarations to centralize common functionality.
.../driver_test.py Updated test functions to use TcpPortforwardAdapter instead of PortforwardAdapter and added a new test (test_unix_network_portforward) for Unix adapter.
.../api-reference/adapters/index.md Added new section "Adapter Packages" and included a directive for network.md.
.../api-reference/adapters/network.md Documented TcpPortforwardAdapter and UnixPortforwardAdapter classes with usage examples and configuration details.
.../api-reference/index.md Added new entry to the toctree for adapters/index.md.

Sequence Diagram(s)

sequenceDiagram
  participant T as Test Function (TCP)
  participant A as TcpPortforwardAdapter
  participant B as PortforwardAdapter (Base)
  
  T->>A: Instantiate & enter context (__aenter__)
  A->>B: Inherit and apply common behaviors
  T->>A: Execute TCP port-forwarding logic
  A-->>T: Return TCP connection details
  T->>A: Exit context (__aexit__)
Loading
sequenceDiagram
  participant T as Test Function (Unix)
  participant A as UnixPortforwardAdapter
  participant L as TemporaryUnixListener
  
  T->>A: Instantiate & enter context (__aenter__)
  A->>L: Set up temporary Unix listener
  T->>A: Send test message
  A-->>T: Confirm message reception
  T->>A: Exit context (__aexit__)
Loading

Poem

I'm a rabbit, hopping with cheer,
New adapters have now appeared.
TCP and Unix lead the way,
In each test, they come to play.
Code hops ahead—let's cheer all day! 🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2eaad83 and 7296d2b.

📒 Files selected for processing (1)
  • docs/source/api-reference/adapters/network.md (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: pytest-matrix (3.13)
  • GitHub Check: pytest-matrix (3.12)
  • GitHub Check: e2e
  • GitHub Check: pytest-matrix (3.11)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-devspace .devfile/Containerfile.client)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-dev .devfile/Containerfile)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter Dockerfile)
🔇 Additional comments (21)
docs/source/api-reference/adapters/network.md (21)

1-1: Clear and concise header.
The heading "# Network adapters" immediately informs the reader of the document's topic.


3-3: Informative introductory description.
The sentence provides a brief, accurate summary of the role and purpose of network adapters in the driver system.


5-8: Auto-documentation for TcpPortforwardAdapter.
The reStructuredText block using the autoclass directive is correctly set up to document the TcpPortforwardAdapter and its members.


10-13: Auto-documentation for UnixPortforwardAdapter.
This block correctly documents the UnixPortforwardAdapter class, ensuring consistency with your API reference.


15-18: Auto-documentation for NovncAdapter.
The directive properly generates API documentation for the NovncAdapter, maintaining a standardized format across adapter classes.


20-23: Auto-documentation for PexpectAdapter.
The block correctly employs the autoclass directive to capture all members of the PexpectAdapter class.


25-28: Auto-documentation for FabricAdapter.
This segment adheres to the same documentation pattern, ensuring that the FabricAdapter is well-documented.


30-30: Examples section header is well defined.
The "## Examples" header clearly separates configuration examples from the adapter documentation, aiding navigation.


31-42: Clear YAML configuration examples.
The YAML snippet effectively demonstrates how to export TCP and Unix sockets by specifying types and configuration parameters.


44-44: Descriptive sub-header for TCP port forwarding.
This line aptly introduces the TCP port forwarding example, setting clear expectations for the subsequent test code.


46-54: Comprehensive code example for TCP port forwarding.
The test code illustrates two use cases: using default settings and specifying a custom local host and port. The inline comments further enhance clarity.


56-56: Sub-header for Unix domain socket forwarding.
This header clearly indicates the start of an example focused on Unix socket usage.


58-66: Effective example for Unix socket forwarding.
The example demonstrates both direct usage of UnixPortforwardAdapter and the flexibility of forwarding via TcpPortforwardAdapter, which can be valuable information for developers.


67-68: Sub-header introducing VNC client connection.
The header marks the transition to an example that integrates a web-based VNC client, adding clarity to the document's structure.


70-74: NovncAdapter usage example is clear.
The test code for NovncAdapter is succinct and explains how to access the VNC client through the generated URL, with a helpful inline comment.


75-75: Header for serial console interaction example.
The title "Interact with a remote TCP port as if it's a serial console" prepares the reader for a different interaction modality, which is clearly differentiated.


76-77: Reference to Pexpect documentation.
Linking to the Pexpect API documentation is a useful touch, ensuring that developers can easily find further details if needed.


78-86: PexpectAdapter test code example.
This code snippet provides a clear demonstration of how to interact with a remote console using PexpectAdapter, with sequential calls that mimic a login process.


88-89: Header for Fabric SSH client connection example.
The header clearly signals a transition to an example that deals with Fabric for SSH, ensuring logical sequencing within the document.


90-90: Helpful documentation reference for Fabric.
Including a direct link to Fabric's API documentation offers developers immediate access to more detailed information, enhancing the example's usefulness.


92-95: FabricAdapter test code example is concise and informative.
The example succinctly shows how to establish a connection and execute a command, neatly complementing the other examples in the file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/jumpstarter-driver-network/jumpstarter_driver_network/adapters/portforward.py (1)

35-41: Consider adding a configurable path parameter.

The Unix adapter implementation looks good, but consider adding a configurable path parameter to allow users to specify the Unix socket path when needed.

 @dataclass(kw_only=True)
 class UnixPortforwardAdapter(PortforwardAdapter):
+    path: str | None = None
+
     async def __aenter__(self):
-        self.listener = TemporaryUnixListener(self.handler)
+        self.listener = TemporaryUnixListener(self.handler, path=self.path)

         return await self.listener.__aenter__()
packages/jumpstarter-driver-network/jumpstarter_driver_network/driver_test.py (1)

51-60: Consider adding error condition test cases.

The test covers the basic functionality well. Consider adding test cases for error conditions such as:

  • Connection to non-existent Unix socket
  • Connection to socket with incorrect permissions
  • Connection to socket that's already in use
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1382071 and bf1ecd5.

📒 Files selected for processing (6)
  • packages/jumpstarter-driver-network/jumpstarter_driver_network/adapters/__init__.py (1 hunks)
  • packages/jumpstarter-driver-network/jumpstarter_driver_network/adapters/fabric.py (1 hunks)
  • packages/jumpstarter-driver-network/jumpstarter_driver_network/adapters/novnc.py (1 hunks)
  • packages/jumpstarter-driver-network/jumpstarter_driver_network/adapters/pexpect.py (1 hunks)
  • packages/jumpstarter-driver-network/jumpstarter_driver_network/adapters/portforward.py (2 hunks)
  • packages/jumpstarter-driver-network/jumpstarter_driver_network/driver_test.py (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: pytest-matrix (3.13)
  • GitHub Check: pytest-matrix (3.12)
  • GitHub Check: pytest-matrix (3.11)
  • GitHub Check: e2e
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-devspace .devfile/Containerfile.client)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-dev .devfile/Containerfile)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter Dockerfile)
🔇 Additional comments (8)
packages/jumpstarter-driver-network/jumpstarter_driver_network/adapters/__init__.py (1)

4-4: LGTM!

The import and export changes correctly reflect the new adapter structure with TcpPortforwardAdapter and UnixPortforwardAdapter.

Also applies to: 6-6

packages/jumpstarter-driver-network/jumpstarter_driver_network/adapters/pexpect.py (1)

6-6: LGTM!

The changes correctly update PexpectAdapter to use TcpPortforwardAdapter. The use of socket.AF_INET aligns with TCP socket operations.

Also applies to: 10-10

packages/jumpstarter-driver-network/jumpstarter_driver_network/adapters/fabric.py (1)

7-7: LGTM!

The changes correctly update FabricAdapter to use TcpPortforwardAdapter. The use of host and port in the Connection setup aligns with TCP connections.

Also applies to: 11-11

packages/jumpstarter-driver-network/jumpstarter_driver_network/adapters/novnc.py (1)

5-5: LGTM!

The changes correctly update NovncAdapter to use TcpPortforwardAdapter. The use of host and port in the URL parameters aligns with TCP connections.

Also applies to: 10-10

packages/jumpstarter-driver-network/jumpstarter_driver_network/adapters/portforward.py (2)

8-20: LGTM! Well-structured base class.

The base class is well-designed with common functionality extracted into __aexit__ and handler methods. The stream forwarding logic is correct and properly handles cleanup.


22-33: LGTM! Well-implemented TCP adapter.

The TCP adapter correctly uses TemporaryTcpListener with appropriate defaults and socket options.

packages/jumpstarter-driver-network/jumpstarter_driver_network/driver_test.py (2)

44-44: LGTM! Correct adapter usage.

The test correctly uses the new TcpPortforwardAdapter.


104-104: LGTM! Correct adapter usage.

The test correctly uses the new TcpPortforwardAdapter.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
docs/source/api-reference/adapters/network.md (1)

29-39: Example: Forwarding a Remote TCP Port.
The test code example demonstrates how to forward a remote TCP port to a local one using TcpPortforwardAdapter, including both random and specific host/port scenarios. Consider adding a short comment or note explaining the expected behavior if client.tcp_port is not immediately obvious to the reader.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bf1ecd5 and 2eaad83.

📒 Files selected for processing (3)
  • docs/source/api-reference/adapters/index.md (1 hunks)
  • docs/source/api-reference/adapters/network.md (1 hunks)
  • docs/source/api-reference/index.md (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • docs/source/api-reference/adapters/index.md
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: pytest-matrix (3.13)
  • GitHub Check: pytest-matrix (3.12)
  • GitHub Check: e2e
  • GitHub Check: pytest-matrix (3.11)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-devspace .devfile/Containerfile.client)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-dev .devfile/Containerfile)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter Dockerfile)
🔇 Additional comments (6)
docs/source/api-reference/index.md (1)

9-9: New TOC Entry Addition in API Reference Documentation.
The addition of adapters/index.md in the toctree enhances navigation by including the adapters section. Please verify that the referenced file exists and that its content is properly structured to integrate with the overall API reference.

docs/source/api-reference/adapters/network.md (5)

1-4: Introduction and Overview Section.
The header and introductory description clearly state the purpose of the Network adapters documentation. This provides a good context for users to understand the role of network adapters in transforming network connections exposed by drivers.


5-8: Autoclass Directive for TcpPortforwardAdapter.
The eval-rst block uses the autoclass directive to automatically document the TcpPortforwardAdapter class, including its members. Ensure that all relevant public members are being displayed and that any customizations (e.g., exclusion of private members, if necessary) are properly documented as per your project’s guidelines.


10-13: Autoclass Directive for UnixPortforwardAdapter.
Similarly, the documentation for UnixPortforwardAdapter is added with the autoclass directive. Double-check that this adapter’s members are appropriately documented and that the output meets your documentation standards.


15-27: YAML Configuration Example.
The YAML snippet provides clear configuration examples for both tcp_port and unix_socket. Verify that the keys (e.g., type and config) and the values correspond to the actual configuration requirements in the codebase. This example is very helpful for users to set up network adapters correctly.


41-51: Example: Forwarding a Remote Unix Domain Socket and Mixed-Protocol Forwarding.
This example clearly illustrates two scenarios: one for forwarding a Unix domain socket to a local Unix socket and another demonstrating that the remote and local socket types can differ (i.e., forwarding to a local TCP port). This nuance is well documented by the inline comments.

Copy link
Copy Markdown
Member

@mangelajo mangelajo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good work, thank you Nick!

Documentation is becoming super important for this project

@mangelajo mangelajo enabled auto-merge February 3, 2025 21:34
@mangelajo mangelajo merged commit cae60f6 into main Feb 3, 2025
@NickCao NickCao deleted the unixportforward branch February 6, 2025 14:29
@mangelajo mangelajo added this to the 0.6.0 milestone May 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants