Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Layer2 topology class #2145

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open

Conversation

sbahar619
Copy link
Contributor

@sbahar619 sbahar619 commented Oct 7, 2024

Short description:

Add Layer2 topology class to manage Layer2 network configurations in UserDefinedNetwork.

More details:
What this PR does / why we need it:
Which issue(s) this PR fixes:
Special notes for reviewer:
Bug:

Summary by CodeRabbit

  • New Features

    • Introduced support for Layer2 network configurations with the new Layer2UserDefinedNetwork class.
    • Added a centralized definition for topology types with the TopologyType class.
  • Improvements

    • Enhanced error handling in network configuration to ensure mandatory parameters are provided.
    • Improved the to_dict method to better structure Layer2 network configurations, incorporating additional Layer2-specific attributes.

@redhat-qe-bot2
Copy link

Report bugs in Issues

The following are automatically added:

  • Add reviewers from OWNER file (in the root of the repository) under reviewers section.
  • Set PR size label.
  • New issue is created for the PR. (Closed when PR is merged/closed)
  • Run pre-commit if .pre-commit-config.yaml exists in the repo.

Available user actions:

  • To mark PR as WIP comment /wip to the PR, To remove it from the PR comment /wip cancel to the PR.
  • To block merging of PR comment /hold, To un-block merging of PR comment /hold cancel.
  • To mark PR as verified comment /verified to the PR, to un-verify comment /verified cancel to the PR.
    verified label removed on each new commit push.
  • To cherry pick a merged PR comment /cherry-pick <target branch to cherry-pick to> in the PR.
    • Multiple target branches can be cherry-picked, separated by spaces. (/cherry-pick branch1 branch2)
    • Cherry-pick will be started when PR is merged
  • To build and push container image command /build-and-push-container in the PR (tag will be the PR number).
    • You can add extra args to the Podman build command
      • Example: /build-and-push-container --build-arg OPENSHIFT_PYTHON_WRAPPER_COMMIT=<commit_hash>
  • To add a label by comment use /<label name>, to remove, use /<label name> cancel
  • To assign reviewers based on OWNERS file use /assign-reviewers
  • To check if PR can be merged use /check-can-merge
Supported /retest check runs
  • /retest tox: Retest tox
  • /retest python-module-install: Retest python-module-install
Supported labels
  • hold
  • verified
  • wip
  • lgtm

Copy link

coderabbitai bot commented Oct 7, 2024

Walkthrough

The changes in this pull request primarily focus on the ocp_resources/user_defined_network.py file, introducing new classes and modifying existing functionalities related to user-defined networks. Key additions include the TopologyType class and the Layer2UserDefinedNetwork subclass, which enhance the configuration capabilities for Layer2 networks. Constructor parameters and method signatures have been updated to accommodate these changes, alongside improved error handling for required arguments.

Changes

File Change Summary
ocp_resources/user_defined_network.py - Added new class TopologyType with constants for topology types.
- Introduced Layer2UserDefinedNetwork subclass with additional attributes for Layer2 configurations.
- Modified constructor of Layer2UserDefinedNetwork to accept new parameters and set topology to TopologyType.LAYER2.
- Overridden to_dict method in Layer2UserDefinedNetwork to include Layer2-specific attributes.
- Updated to_dict method in UserDefinedNetwork to raise MissingRequiredArgumentError if topology is not provided.

Possibly related PRs

Suggested labels

can-be-merged, approved-myakove

Suggested reviewers

  • myakove
  • rnetser
  • dbasunag
  • omrirh
  • yossisegev

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 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.

@sbahar619
Copy link
Contributor Author

/verified

@sbahar619
Copy link
Contributor Author

/verified

Copy link

@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: 2

🧹 Outside diff range and nitpick comments (1)
ocp_resources/user_defined_network.py (1)

Line range hint 15-33: Make 'topology' a required parameter without a default value

In the UserDefinedNetwork class, the topology parameter in the __init__ method is currently optional with a default empty string. However, the to_dict method raises a MissingRequiredArgumentError if topology is not provided. To enforce this requirement and prevent runtime errors, consider making topology a required parameter without a default value.

Apply this diff to update the constructor signature:

 def __init__(
     self,
     layer2: Optional[Dict[str, Any]] = None,
     layer3: Optional[Dict[str, Any]] = None,
     local_net: Optional[Dict[str, Any]] = None,
-    topology: Optional[str] = "",
+    topology: str,
     **kwargs: Any,
 ) -> None:
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8b92aef and 6fbe01b.

📒 Files selected for processing (1)
  • ocp_resources/user_defined_network.py (2 hunks)
🧰 Additional context used
🔇 Additional comments (1)
ocp_resources/user_defined_network.py (1)

5-6: Imports are necessary for the new functionality

The added imports of DynamicClient and List are appropriate and required for the new classes and type annotations introduced.

ocp_resources/user_defined_network.py Outdated Show resolved Hide resolved
ocp_resources/user_defined_network.py Outdated Show resolved Hide resolved
ocp_resources/user_defined_network.py Outdated Show resolved Hide resolved
ocp_resources/user_defined_network.py Outdated Show resolved Hide resolved
ocp_resources/user_defined_network.py Outdated Show resolved Hide resolved
ocp_resources/user_defined_network.py Outdated Show resolved Hide resolved
ocp_resources/user_defined_network.py Outdated Show resolved Hide resolved
ocp_resources/user_defined_network.py Show resolved Hide resolved
@sbahar619
Copy link
Contributor Author

/verified

Copy link

@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

🧹 Outside diff range and nitpick comments (2)
ocp_resources/user_defined_network.py (2)

75-110: LGTM with suggestion: Layer2UserDefinedNetwork class definition

The Layer2UserDefinedNetwork class is well-structured and properly documented. The inheritance from UserDefinedNetwork and the constructor implementation are correct.

Suggestion: Consider adding validation for the role parameter in the constructor to ensure it's not an empty string:

if not role:
    raise ValueError("The 'role' parameter is required and cannot be empty.")

This would provide an early error if an invalid role is provided.


112-131: LGTM with suggestion: to_dict method implementation

The to_dict method is well-implemented, correctly overriding the parent class method and adding Layer2-specific attributes to the resource specification.

Suggestion: Consider simplifying the code by using a dictionary comprehension to add non-None values:

_layer2 = {
    "role": self.role,
    "mtu": self.mtu,
    "subnets": self.subnets,
    "joinSubnets": self.join_subnets,
    "ipamLifecycle": self.ipam_lifecycle
}
self.res["spec"][LAYER2.lower()] = {k: v for k, v in _layer2.items() if v is not None}

This approach reduces repetition and makes the code more concise.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between bee20d6 and 6ebbaeb.

📒 Files selected for processing (1)
  • ocp_resources/user_defined_network.py (2 hunks)
🧰 Additional context used
🔇 Additional comments (3)
ocp_resources/user_defined_network.py (3)

5-5: LGTM: Import statement addition

The addition of from typing import List is appropriate and necessary for the type hinting used in the Layer2UserDefinedNetwork class.


72-72: LGTM: Constant definition

The addition of the LAYER2 constant is a good practice. It improves code maintainability by centralizing the definition of the "Layer2" string used in the Layer2UserDefinedNetwork class.


Line range hint 1-131: Overall assessment: Well-implemented Layer2 network support

The changes introduce a well-structured and documented Layer2UserDefinedNetwork class, enhancing the module's capabilities for Layer2 network configurations. The code follows good practices in terms of inheritance, type hinting, and constant usage. Minor suggestions have been made for error handling and code simplification, but overall, the implementation is solid and ready for integration.

ocp_resources/user_defined_network.py Outdated Show resolved Hide resolved
Copy link

@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

🧹 Outside diff range and nitpick comments (1)
ocp_resources/user_defined_network.py (1)

Line range hint 52-54: Simplify the condition for checking topology

The current condition if not all([self.topology]) is redundant for checking a single item. It can be simplified to improve readability.

Consider simplifying the condition as follows:

- if not all([
-     self.topology,
- ]):
+ if not self.topology:

This change maintains the same functionality while making the code more concise and easier to read.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6ebbaeb and bca64fe.

📒 Files selected for processing (1)
  • ocp_resources/user_defined_network.py (2 hunks)
🧰 Additional context used
🔇 Additional comments (5)
ocp_resources/user_defined_network.py (5)

5-5: LGTM: New import for List type

The addition of from typing import List is appropriate for the type hinting used in the new Layer2UserDefinedNetwork class. This improves code readability and enables better type checking.


72-72: LGTM: New constant for Layer2 topology

The addition of the LAYER2 constant is a good practice. It improves code maintainability by centralizing the definition of the Layer2 topology string.


75-81: LGTM: Well-structured Layer2UserDefinedNetwork class

The new Layer2UserDefinedNetwork class is well-defined and documented. It appropriately extends UserDefinedNetwork and includes a clear docstring with an API reference, which enhances code readability and maintainability.


112-131: LGTM: Comprehensive to_dict method implementation

The to_dict method is well-implemented:

  1. It correctly extends the base class method.
  2. The check for kind_dict and yaml_file is consistent with the base class.
  3. Layer2-specific attributes are added only if they are not None, preventing unnecessary null values.
  4. The implementation aligns well with the constructor parameters.

83-110: LGTM: Flexible constructor for Layer2UserDefinedNetwork

The constructor is well-designed with appropriate parameters for Layer2 network configuration. All parameters are optional, which aligns with the requirement to support configuration via yaml_file or kind_dict. The use of the LAYER2 constant in the super constructor call is consistent.

To ensure the optional parameters are handled correctly, please verify that the to_dict method properly handles cases where these parameters are not provided:

@sbahar619
Copy link
Contributor Author

/verified

@sbahar619
Copy link
Contributor Author

/verified

@sbahar619
Copy link
Contributor Author

/verified

@sbahar619
Copy link
Contributor Author

/verified

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants