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

Power.on/off method returns None#268

Merged
NickCao merged 2 commits intomainfrom
power
Feb 10, 2025
Merged

Power.on/off method returns None#268
NickCao merged 2 commits intomainfrom
power

Conversation

@NickCao
Copy link
Copy Markdown
Collaborator

@NickCao NickCao commented Feb 10, 2025

Summary by CodeRabbit

  • New Features

    • Introduced enhanced exporter configuration management with YAML support and gRPC serving.
    • Added more granular error handling for file operations in TFTP.
  • Refactor

    • Simplified power and device control methods to remove unnecessary outputs.
    • Updated method signatures and type annotations for clearer behavior.
  • Tests

    • Expanded and streamlined test coverage for power control and TFTP operations, improving overall reliability.
  • Style

    • Standardized formatting and string usage across components for improved consistency.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 10, 2025

Walkthrough

The changes update various drivers and tests by removing assertions that checked the return values of the on() and off() methods. Method signatures across multiple modules (including Dutlink, Power, Raspberry Pi, and Yepkit drivers) have been adjusted to return None with added type hints. In addition, the TFTP component now defines specific exceptions and includes new tests for file operations. A new exporter configuration class has been introduced for managing exporter settings and serving via gRPC. Overall, the modifications simplify method invocations, refine type annotations, and improve code readability and test structure.

Changes

File(s) Change Summary
docs/.../setup-local-exporter.md Documentation update (no functional changes)
*test.py files (e.g., mytest.py, jumpstarter_driver_composite/driver_test.py, jumpstarter_driver_power/client_test.py, jumpstarter_driver_power/driver_test.py, jumpstarter_testing/pytest_test.py, jumpstarter/jumpstarter/config/exporter_test.py, jumpstarter/jumpstarter/listener_test.py) Removed assertions checking return values of on()/off(); now the methods are simply invoked without validation
jumpstarter_driver_dutlink/driver.py, jumpstarter_driver_power/client.py, jumpstarter_driver_power/driver.py, jumpstarter_driver_raspberrypi/client.py, jumpstarter_driver_raspberrypi/driver.py, jumpstarter_driver_yepkit/driver.py Updated method signatures for on() and off() to return None; added explicit type hints and adjusted related CLI commands and formatting
jumpstarter-driver-tftp/* (e.g., driver.py, driver_test.py, server.py, server_test.py, __init__.py, examples/tftp_test.py) Introduced new TFTP exceptions (ServerNotRunning, FileNotFound); added test fixtures and enhanced TFTP file operation tests; applied formatting and minor comment adjustments
jumpstarter/jumpstarter/config/exporter.py Added new class ExporterConfigV1Alpha1 for managing exporter configurations and serving via gRPC
Miscellaneous (e.g., formatting changes in comments and multi-line expressions in various files) Applied minor formatting improvements and standardized string delimiters

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ExporterConfig
    participant DynamicImport
    participant GRPCChannel
    participant ExporterInstance

    User->>ExporterConfig: Call serve() method
    ExporterConfig->>DynamicImport: Dynamically import exporter module
    DynamicImport-->>ExporterConfig: Return exporter reference
    ExporterConfig->>GRPCChannel: Establish gRPC channel
    GRPCChannel-->>ExporterConfig: Channel established
    ExporterConfig->>ExporterInstance: Instantiate exporter
    ExporterInstance-->>ExporterConfig: Exporter ready
    ExporterConfig-->>User: Return exporter instance
Loading
sequenceDiagram
    participant Tester
    participant TFTPClient
    participant TFTPServer

    Tester->>TFTPClient: Create test file (test.bin)
    TFTPClient->>TFTPServer: Upload test.bin
    TFTPServer-->>TFTPClient: Acknowledge upload
    Tester->>TFTPClient: Request file listing
    TFTPServer-->>TFTPClient: Send list including test.bin
    Tester->>TFTPClient: Delete test.bin
    TFTPServer-->>TFTPClient: Confirm deletion or raise FileNotFound
Loading

Possibly related PRs

Suggested reviewers

  • mangelajo
  • bennyz

Poem

I'm a hoppy little bunny, full of cheer,
Watching code get simpler, crystal clear.
No more "ok" returns to check along the way,
Just smooth method calls that brighten the day.
With TFTP and Exporter shining bright,
I celebrate these changes with pure delight!
🐇🌟

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 (5)
packages/jumpstarter-testing/jumpstarter_testing/pytest_test.py (1)

15-15: Consider adding state verification after on() call.

While removing the return value assertion aligns with the PR objectives, this test now only verifies that the method can be called without error. Consider adding assertions to verify the expected state after calling on().

Example addition:

 def test_simple(self, client):
     client.on()
+    # Verify power state after on() call
+    assert list(client.read())[0].voltage > 0
packages/jumpstarter-driver-tftp/jumpstarter_driver_tftp/driver_test.py (1)

100-114: Consider adding error handling to the helper function.

The _upload_file helper function should handle potential errors during file upload.

 async def _upload_file(server, filename: str, data: bytes) -> str:
-    send_stream, receive_stream = create_memory_object_stream()
-    resource_uuid = uuid4()
-    server.resources[resource_uuid] = receive_stream
-    resource_handle = ClientStreamResource(uuid=resource_uuid).model_dump(mode="json")
+    try:
+        send_stream, receive_stream = create_memory_object_stream()
+        resource_uuid = uuid4()
+        server.resources[resource_uuid] = receive_stream
+        resource_handle = ClientStreamResource(uuid=resource_uuid).model_dump(mode="json")
 
-    async def send_data():
-        await send_stream.send(data)
-        await send_stream.aclose()
+        async def send_data():
+            try:
+                await send_stream.send(data)
+            finally:
+                await send_stream.aclose()
 
-    async with anyio.create_task_group() as tg:
-        tg.start_soon(send_data)
-        await server.put_file(filename, resource_handle, hashlib.sha256(data).hexdigest())
+        async with anyio.create_task_group() as tg:
+            tg.start_soon(send_data)
+            await server.put_file(filename, resource_handle, hashlib.sha256(data).hexdigest())
 
-    return hashlib.sha256(data).hexdigest()
+        return hashlib.sha256(data).hexdigest()
+    except Exception as e:
+        raise RuntimeError(f"Failed to upload file: {str(e)}") from e
packages/jumpstarter-driver-dutlink/jumpstarter_driver_dutlink/driver.py (2)

125-126: LGTM! Consider adding docstring to document the breaking change.

The change to return None aligns with the PR objectives. However, since this is a breaking change, consider adding a docstring to document that this method no longer returns a value.


129-130: LGTM! Consider adding docstring to document the breaking change.

The change to return None aligns with the PR objectives. However, since this is a breaking change, consider adding a docstring to document that this method no longer returns a value.

packages/jumpstarter/jumpstarter/config/exporter.py (1)

49-49: Consider storing tokens more securely.

Storing tokens directly in plain text can present a security risk, especially in multi-user environments. If this token is sensitive, explore using environment variables or a secure secrets manager.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b7ad12c and 82860f2.

📒 Files selected for processing (20)
  • docs/source/getting-started/setup-local-exporter.md (1 hunks)
  • packages/jumpstarter-driver-composite/jumpstarter_driver_composite/driver_test.py (1 hunks)
  • packages/jumpstarter-driver-dutlink/jumpstarter_driver_dutlink/driver.py (1 hunks)
  • packages/jumpstarter-driver-power/jumpstarter_driver_power/client.py (2 hunks)
  • packages/jumpstarter-driver-power/jumpstarter_driver_power/client_test.py (2 hunks)
  • packages/jumpstarter-driver-power/jumpstarter_driver_power/driver.py (2 hunks)
  • packages/jumpstarter-driver-power/jumpstarter_driver_power/driver_test.py (2 hunks)
  • packages/jumpstarter-driver-raspberrypi/jumpstarter_driver_raspberrypi/client.py (1 hunks)
  • packages/jumpstarter-driver-raspberrypi/jumpstarter_driver_raspberrypi/driver.py (1 hunks)
  • packages/jumpstarter-driver-tftp/examples/tftp_test.py (1 hunks)
  • packages/jumpstarter-driver-tftp/jumpstarter_driver_tftp/__init__.py (1 hunks)
  • packages/jumpstarter-driver-tftp/jumpstarter_driver_tftp/driver.py (3 hunks)
  • packages/jumpstarter-driver-tftp/jumpstarter_driver_tftp/driver_test.py (3 hunks)
  • packages/jumpstarter-driver-tftp/jumpstarter_driver_tftp/server.py (19 hunks)
  • packages/jumpstarter-driver-tftp/jumpstarter_driver_tftp/server_test.py (16 hunks)
  • packages/jumpstarter-driver-yepkit/jumpstarter_driver_yepkit/driver.py (6 hunks)
  • packages/jumpstarter-testing/jumpstarter_testing/pytest_test.py (1 hunks)
  • packages/jumpstarter/jumpstarter/config/exporter.py (1 hunks)
  • packages/jumpstarter/jumpstarter/config/exporter_test.py (1 hunks)
  • packages/jumpstarter/jumpstarter/listener_test.py (2 hunks)
✅ Files skipped from review due to trivial changes (4)
  • packages/jumpstarter-driver-tftp/jumpstarter_driver_tftp/init.py
  • packages/jumpstarter-driver-yepkit/jumpstarter_driver_yepkit/driver.py
  • packages/jumpstarter-driver-tftp/jumpstarter_driver_tftp/server_test.py
  • packages/jumpstarter-driver-tftp/jumpstarter_driver_tftp/server.py
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • 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 (26)
packages/jumpstarter-driver-raspberrypi/jumpstarter_driver_raspberrypi/client.py (2)

8-9: LGTM! Clear type annotation added.

The added return type annotation correctly reflects that the method performs an action without returning a value.


11-12: LGTM! Clear type annotation added.

The added return type annotation correctly reflects that the method performs an action without returning a value.

packages/jumpstarter-driver-composite/jumpstarter_driver_composite/driver_test.py (1)

20-21: LGTM! Changes align with PR objectives.

The removal of assertions for on() method return values is consistent with the change to make these methods return None.

packages/jumpstarter-driver-power/jumpstarter_driver_power/driver_test.py (1)

12-13: LGTM! Changes maintain test coverage while aligning with new return type.

The removal of assertions for on()/off() return values is appropriate, and the tests still verify core functionality through the read() method assertions.

Also applies to: 24-25

packages/jumpstarter-driver-power/jumpstarter_driver_power/client_test.py (1)

8-9: LGTM! Changes maintain test coverage while aligning with new return type.

The removal of assertions for on()/off() return values is appropriate, and the tests still verify core functionality through the read() method assertions.

Also applies to: 19-20

packages/jumpstarter-driver-power/jumpstarter_driver_power/client.py (4)

10-11: LGTM! Return type updated correctly.

The change aligns with the PR objectives by updating the return type to None and removing the unnecessary return value.


13-14: LGTM! Return type updated correctly.

The change aligns with the PR objectives by updating the return type to None and removing the unnecessary return value.


29-29: LGTM! CLI command updated correctly.

The change aligns with the PR objectives by removing the unnecessary echo of the return value.


34-34: LGTM! CLI command updated correctly.

The change aligns with the PR objectives by removing the unnecessary echo of the return value.

packages/jumpstarter-driver-tftp/examples/tftp_test.py (1)

1-39: Skipping review of TFTP test file.

This file is unrelated to the PR objectives of updating power.on/off method return types.

packages/jumpstarter-driver-power/jumpstarter_driver_power/driver.py (3)

14-14: LGTM! Interface updated correctly.

The abstract methods' return types have been updated to align with the PR objectives.

Also applies to: 17-17


25-26: LGTM! Mock implementation updated correctly.

The mock methods' return types have been updated to align with the PR objectives.

Also applies to: 29-30


40-41: LGTM! Sync mock implementation updated correctly.

The sync mock methods' return types have been updated to align with the PR objectives.

Also applies to: 44-45

packages/jumpstarter-driver-raspberrypi/jumpstarter_driver_raspberrypi/driver.py (2)

29-29: LGTM! Return type added correctly.

The method signature has been updated to include the None return type, aligning with the PR objectives.


36-36: LGTM! Return type added correctly.

The method signature has been updated to include the None return type, aligning with the PR objectives.

packages/jumpstarter-driver-tftp/jumpstarter_driver_tftp/driver_test.py (4)

32-64: LGTM! Well-structured test for file operations.

The test comprehensively covers file upload, verification, and deletion scenarios, including error cases.


66-70: LGTM! Good test for host configuration.

The test verifies that the host configuration is properly set and retrieved.


72-76: LGTM! Good test for root directory creation.

The test ensures that the root directory is created when initializing the TFTP server.


79-92: LGTM! Good test for file corruption detection.

The test verifies that the checksum validation correctly identifies corrupted files.

packages/jumpstarter/jumpstarter/listener_test.py (1)

52-52: LGTM! Removed return value assertions.

The changes align with the PR objective to remove return value checks from power.on/off methods.

Also applies to: 100-103, 106-106

packages/jumpstarter/jumpstarter/config/exporter_test.py (1)

56-56: LGTM! Removed return value assertion.

The change aligns with the PR objective to remove return value checks from power.on/off methods.

packages/jumpstarter-driver-tftp/jumpstarter_driver_tftp/driver.py (2)

24-33: LGTM! Good addition of specific exception classes.

The new exception classes improve error handling specificity.


49-49: LGTM! Standardized empty string representation.

The change standardizes the empty string representation and maintains the same logic.

Also applies to: 62-63

docs/source/getting-started/setup-local-exporter.md (2)

167-167: LGTM! Test updated to match new method signature.

The test has been correctly updated to remove the return value assertion, aligning with the new implementation where power.on() returns None.


170-170: LGTM! Test updated to match new method signature.

The test has been correctly updated to remove the return value assertion, aligning with the new implementation where power.off() returns None.

packages/jumpstarter/jumpstarter/config/exporter.py (1)

37-37: No functional changes in this line.

This line only introduces or removes whitespace. No concerns or action needed here.

@NickCao NickCao merged commit c653ff9 into main Feb 10, 2025
@NickCao NickCao deleted the power branch February 19, 2025 20:11
@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.

3 participants