Skip to content

Update hyperv features test to use instance types #1126

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

RoniKishner
Copy link
Contributor

@RoniKishner RoniKishner commented Jun 3, 2025

Short description:

hyperv_vm will now use preferences instead of templates

More details:

The tests in test_hyperv_features_in_vm.py currently use templates (windows-2019 and fedora) to create VMs. This PR updates them to use common-instance types instead, as that is the recommended approach.

What this PR does / why we need it:

Change tests from using templates to common-instance types

jira-ticket:

https://issues.redhat.com/browse/CNV-62919

Summary by CodeRabbit

  • Tests
    • Refactored Hyper-V feature support tests to enhance VM creation and configuration using new resource-based fixtures.
    • Improved test parameterization for more flexible and maintainable validation of Hyper-V features.

Copy link

coderabbitai bot commented Jun 3, 2025

Walkthrough

The test suite for Hyper-V feature support in virtual machines was refactored to use new fixtures and abstractions for VM instantiation and configuration. The tests now utilize resource-based instance type and preference objects, replacing direct dictionary manipulation and template-based VM creation.

Changes

Files / Areas Changed Summary of Changes
tests/virt/node/hyperv_support/test_hyperv_features_in_vm.py Refactored to use VirtualMachineForTests, added hyperv_instance_type and hyperv_preference fixtures, updated test parameterization, and VM creation logic.

Possibly related PRs

Suggested labels

size/L, can-be-merged, lgtm-dshchedr, approved-rnetser

Suggested reviewers

  • dshchedr
  • vsibirsk
  • geetikakay
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@openshift-virtualization-qe-bot-2

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
  • to assign reviewer to PR use /assign-reviewer @<reviewer>

PR will be approved when the following conditions are met:

  • /approve from one of the approvers.
  • Minimum number of required /lgtm (2) is met.
Approvers and Reviewers
  • Approvers:

    • dshchedr
    • vsibirsk
  • Reviewers:

    • SiboWang1997
    • akri3i
    • dshchedr
    • jerry7z
    • kbidarkar
    • vsibirsk
Supported /retest check runs
  • /retest tox: Retest tox
  • /retest build-container: Retest build-container
  • /retest all: Retest all
Supported labels
  • hold
  • verified
  • wip
  • lgtm
  • approve

@RoniKishner
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: 1

🧹 Nitpick comments (1)
tests/virt/node/hyperv_support/test_hyperv_features_in_vm.py (1)

46-54: Add docstring to document the fixture purpose and parameters.

The fixture implementation is correct, but it's missing documentation. Consider adding a docstring to explain its purpose and expected parameters.

 @pytest.fixture()
 def hyperv_instance_type(request):
+    """Create a VirtualMachineClusterInstancetype for Hyper-V testing.
+    
+    Args:
+        request: pytest request object containing param dict with optional 'model' key
+            for CPU model configuration.
+    
+    Yields:
+        VirtualMachineClusterInstancetype: Instance type configured for Hyper-V testing
+    """
     with VirtualMachineClusterInstancetype(
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 47-47: Missing function or method docstring

(C0116)


[warning] 52-52: Redefining name 'hyperv_instance_type' from outer scope (line 47)

(W0621)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 13bca96 and 6bcefc1.

📒 Files selected for processing (1)
  • tests/virt/node/hyperv_support/test_hyperv_features_in_vm.py (6 hunks)
🧰 Additional context used
🪛 Pylint (3.3.7)
tests/virt/node/hyperv_support/test_hyperv_features_in_vm.py

[error] 4-4: Unable to import 'ocp_resources.virtual_machine_cluster_instancetype'

(E0401)


[error] 5-5: Unable to import 'ocp_resources.virtual_machine_cluster_preference'

(E0401)


[error] 6-6: Unable to import 'pytest_testconfig'

(E0401)


[error] 8-13: Unable to import 'tests.os_params'

(E0401)


[error] 14-14: Unable to import 'utilities.constants'

(E0401)


[error] 15-15: Unable to import 'utilities.storage'

(E0401)


[error] 16-16: Unable to import 'utilities.virt'

(E0401)


[warning] 27-27: Redefining name 'hyperv_instance_type' from outer scope (line 47)

(W0621)


[warning] 28-28: Redefining name 'hyperv_preference' from outer scope (line 57)

(W0621)


[convention] 47-47: Missing function or method docstring

(C0116)


[warning] 52-52: Redefining name 'hyperv_instance_type' from outer scope (line 47)

(W0621)


[convention] 57-57: Missing function or method docstring

(C0116)


[warning] 63-63: Redefining name 'hyperv_preference' from outer scope (line 57)

(W0621)

⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: build-container
  • GitHub Check: tox
🔇 Additional comments (3)
tests/virt/node/hyperv_support/test_hyperv_features_in_vm.py (3)

4-5: LGTM!

The new imports for instance type and preference resources align with the PR objective of migrating from templates to instance types.

🧰 Tools
🪛 Pylint (3.3.7)

[error] 4-4: Unable to import 'ocp_resources.virtual_machine_cluster_instancetype'

(E0401)


[error] 5-5: Unable to import 'ocp_resources.virtual_machine_cluster_preference'

(E0401)


27-43: LGTM!

The fixture has been successfully refactored to use the new instance type and preference approach, properly utilizing VirtualMachineForTests with the appropriate parameters.

🧰 Tools
🪛 Pylint (3.3.7)

[warning] 27-27: Redefining name 'hyperv_instance_type' from outer scope (line 47)

(W0621)


[warning] 28-28: Redefining name 'hyperv_preference' from outer scope (line 57)

(W0621)


105-121: LGTM!

The test parameterization has been correctly updated to use the new fixtures. The parameters properly specify OS flavor and preferences aligned with the instance type approach.

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

♻️ Duplicate comments (1)
tests/virt/node/hyperv_support/test_hyperv_features_in_vm.py (1)

56-65: 🛠️ Refactor suggestion

Simplify preference creation and add documentation.

This fixture has the same complexity issue identified in previous reviews - it creates a preference, converts to dict, modifies it, and recreates it unnecessarily.

 @pytest.fixture()
 def hyperv_preference(request):
+    """Create a VirtualMachineClusterPreference for Hyper-V testing.
+    
+    Args:
+        request: pytest request object containing param dict with:
+            - preference_name: Base preference name to use as template
+            - hyperv_dict: Optional dict of Hyper-V features to add
+    
+    Yields:
+        VirtualMachineClusterPreference: Preference configured for Hyper-V testing
+    """
-    hyperv_preference_dict = VirtualMachineClusterPreference(
-        name=request.param.get("preference_name")
-    ).instance.to_dict()
-    hyperv_preference_dict["metadata"] = {"name": "hyperv-cluster-preference"}
-    if hyperv_dict := request.param.get("hyperv_dict"):
-        hyperv_preference_dict["spec"]["features"].update(hyperv_dict)
-    with VirtualMachineClusterPreference(kind_dict=hyperv_preference_dict) as hyperv_preference:
+    # Get the base preference as a template
+    base_preference = VirtualMachineClusterPreference(
+        name=request.param.get("preference_name")
+    ).instance.to_dict()
+    
+    # Customize the preference
+    base_preference["metadata"]["name"] = "hyperv-cluster-preference"
+    if hyperv_dict := request.param.get("hyperv_dict"):
+        base_preference["spec"]["features"].update(hyperv_dict)
+    
+    with VirtualMachineClusterPreference(kind_dict=base_preference) as hyperv_preference:
         yield hyperv_preference
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 57-57: Missing function or method docstring

(C0116)


[warning] 64-64: Redefining name 'hyperv_preference' from outer scope (line 57)

(W0621)

🧹 Nitpick comments (1)
tests/virt/node/hyperv_support/test_hyperv_features_in_vm.py (1)

46-53: Add docstring to explain the fixture purpose.

The hyperv_instance_type fixture implementation is correct, but it's missing documentation to explain its purpose and parameters.

 @pytest.fixture()
 def hyperv_instance_type(request):
+    """Create a VirtualMachineClusterInstancetype for Hyper-V testing.
+    
+    Args:
+        request: pytest request object containing param dict with:
+            - model: Optional CPU model to use (e.g., "host-passthrough")
+    
+    Yields:
+        VirtualMachineClusterInstancetype: Instance type configured for Hyper-V testing
+    """
     with VirtualMachineClusterInstancetype(
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 47-47: Missing function or method docstring

(C0116)


[warning] 52-52: Redefining name 'hyperv_instance_type' from outer scope (line 47)

(W0621)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6bcefc1 and 0c7b9e1.

📒 Files selected for processing (1)
  • tests/virt/node/hyperv_support/test_hyperv_features_in_vm.py (6 hunks)
🧰 Additional context used
🪛 Pylint (3.3.7)
tests/virt/node/hyperv_support/test_hyperv_features_in_vm.py

[error] 4-4: Unable to import 'ocp_resources.virtual_machine_cluster_instancetype'

(E0401)


[error] 5-5: Unable to import 'ocp_resources.virtual_machine_cluster_preference'

(E0401)


[error] 6-6: Unable to import 'pytest_testconfig'

(E0401)


[error] 8-13: Unable to import 'tests.os_params'

(E0401)


[error] 14-14: Unable to import 'utilities.constants'

(E0401)


[error] 15-15: Unable to import 'utilities.storage'

(E0401)


[error] 16-16: Unable to import 'utilities.virt'

(E0401)


[warning] 27-27: Redefining name 'hyperv_instance_type' from outer scope (line 47)

(W0621)


[warning] 28-28: Redefining name 'hyperv_preference' from outer scope (line 57)

(W0621)


[convention] 47-47: Missing function or method docstring

(C0116)


[warning] 52-52: Redefining name 'hyperv_instance_type' from outer scope (line 47)

(W0621)


[convention] 57-57: Missing function or method docstring

(C0116)


[warning] 64-64: Redefining name 'hyperv_preference' from outer scope (line 57)

(W0621)

⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: build-container
  • GitHub Check: tox
🔇 Additional comments (7)
tests/virt/node/hyperv_support/test_hyperv_features_in_vm.py (7)

4-5: LGTM! Appropriate imports for the refactoring.

The new imports for VirtualMachineClusterInstancetype and VirtualMachineClusterPreference correctly support the transition from template-based to instance type/preference-based VM creation.

🧰 Tools
🪛 Pylint (3.3.7)

[error] 4-4: Unable to import 'ocp_resources.virtual_machine_cluster_instancetype'

(E0401)


[error] 5-5: Unable to import 'ocp_resources.virtual_machine_cluster_preference'

(E0401)


14-16: LGTM! Updated imports align with the new VM creation approach.

The imports for OS_FLAVOR constants, data_volume_template_with_source_ref_dict, and VirtualMachineForTests properly support the refactored VM instantiation logic.

🧰 Tools
🪛 Pylint (3.3.7)

[error] 14-14: Unable to import 'utilities.constants'

(E0401)


[error] 15-15: Unable to import 'utilities.storage'

(E0401)


[error] 16-16: Unable to import 'utilities.virt'

(E0401)


22-43: LGTM! Excellent refactoring to use structured VM creation.

The hyperv_vm fixture has been successfully updated to use VirtualMachineForTests with explicit instance type and preference parameters, replacing the previous template-based approach. This provides better separation of concerns and follows the recommended patterns.

🧰 Tools
🪛 Pylint (3.3.7)

[convention] 22-22: Missing function or method docstring

(C0116)


[refactor] 22-22: Too many arguments (6/5)

(R0913)


[refactor] 22-22: Too many positional arguments (6/5)

(R0917)


[warning] 27-27: Redefining name 'hyperv_instance_type' from outer scope (line 47)

(W0621)


[warning] 28-28: Redefining name 'hyperv_preference' from outer scope (line 57)

(W0621)


105-122: LGTM! Parameterization correctly updated for new fixture approach.

The test parameterization properly uses the new hyperv_instance_type and hyperv_preference fixtures, and correctly specifies os_flavor instead of template-based configuration.


147-161: LGTM! Test parameters correctly demonstrate custom Hyper-V feature configuration.

The parameterization effectively shows how to add custom Hyper-V features through the preference fixture, with the vendorid configuration being passed via the hyperv_dict parameter.


170-181: LGTM! Clean parameterization for EVMCS testing.

The test parameter setup correctly demonstrates the simple case where only the base preference is needed without additional Hyper-V features.


201-212: LGTM! Fedora test correctly configured with EVMCS feature.

The parameterization properly demonstrates adding the evmcs Hyper-V feature for Fedora VMs through the preference fixture's hyperv_dict parameter.

@kbidarkar
Copy link
Member

@RoniKishner Infra team should work only on infra tests, they should not update other component teams tests.
This is the main reason why the tests are split as per the component teams.

I discussed this with both Dan and Dominik during the Ready-Ready meeting and it was mentioned and agreed that moving to instancetypes and preferences Epic is all about only introducing the fixtures and functions ( supporting stuff for the tests for the infra team itself. ) The Epic name was also updated due to this.

@dshchedr @rnetser cc

@rnetser
Copy link
Collaborator

rnetser commented Jun 4, 2025

@RoniKishner @kbidarkar I think that this PR should be marked as hold until the teams decide on its contents

@RoniKishner RoniKishner marked this pull request as draft June 4, 2025 08:45
@RoniKishner
Copy link
Contributor Author

Moving to draft until we discuss this

data_volume_template=data_volume_template_with_source_ref_dict(
data_source=golden_image_data_source_scope_class
),
disk_type=None,
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need disk_type?

@dshchedr
Copy link
Collaborator

dshchedr commented Jun 4, 2025

@RoniKishner Infra team should work only on infra tests, they should not update other component teams tests. This is the main reason why the tests are split as per the component teams.

I discussed this with both Dan and Dominik during the Ready-Ready meeting and it was mentioned and agreed that moving to instancetypes and preferences Epic is all about only introducing the fixtures and functions ( supporting stuff for the tests for the infra team itself. ) The Epic name was also updated due to this.

@dshchedr @rnetser cc

Until the Templates officially deprecated - we have to keep the coverage. So, we can't simply switch to using IT/Perf

If Infra team is interested in covering same scenarios but with it/perf - they can clone existing tests into their component folder and update tests according to needs.

@RoniKishner
Copy link
Contributor Author

@RoniKishner Infra team should work only on infra tests, they should not update other component teams tests. This is the main reason why the tests are split as per the component teams.
I discussed this with both Dan and Dominik during the Ready-Ready meeting and it was mentioned and agreed that moving to instancetypes and preferences Epic is all about only introducing the fixtures and functions ( supporting stuff for the tests for the infra team itself. ) The Epic name was also updated due to this.
@dshchedr @rnetser cc

Until the Templates officially deprecated - we have to keep the coverage. So, we can't simply switch to using IT/Perf

If Infra team is interested in covering same scenarios but with it/perf - they can clone existing tests into their component folder and update tests according to needs.

What aspect of coverage is this test addressing?
It appears to be focused on Hyper-V rather than templates, as it uses a specific Windows.server.2019 template. Additionally, there's already a dedicated Hyper-V test under the os_support folder.
If this test does, in fact, cover something template-related, should we consider moving it under common_templates for better organization?

@dshchedr
Copy link
Collaborator

What aspect of coverage is this test addressing? It appears to be focused on Hyper-V rather than templates, as it uses a specific Windows.server.2019 template. Additionally, there's already a dedicated Hyper-V test under the os_support folder. If this test does, in fact, cover something template-related, should we consider moving it under common_templates for better organization?

This test is about Hyper-V features, not about templates. But it was working with templates for a long time and we didn't have any issues with that. Templates are still supported, so from test point of view it still ok.

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.

8 participants