Repository: RedHatQE/openshift-virtualization-tests
Pull request #786:   [Virt] Separate test_legacy_machinetype as test_legacy_machinetype.py
Author: login: SiboWang1997
Labels: name: verified
name: size/L
name: can-be-merged
name: branch-main
name: tox:verify-tc-requirement-polarion:passed
description: D/S Testing
name: lgtm-polarion-jenkins
name: tox:verify-bugs-are-open:passed
description: D/S Testing
name: commented-SiboWang1997
name: approved-dshchedr
Created: 2025-04-22T07:21:13Z | Merged: 2025-04-23T16:57:16Z


##### Short description:
When test arm64 related cases, we use `global_config_arm64.py` as global configuration file, which not include `rhel-8-10` matrix_os, so it will failed when test machine_type cases.
So the purpose of this change is to separate `test_legacy_machinetype` as python file to avoid it impacts machine_type cases within arm64 tests 

##### More details:

##### What this PR does / why we need it:

##### Which issue(s) this PR fixes:

##### Special notes for reviewer:

##### jira-ticket:
<!--  full-ticket-url needs to be provided. This would add a link to the pull request to the jira and close it when the pull request is merged
If the task is not tracked by a Jira ticket, just write "NONE".
-->



Diff:
diff --git a/tests/virt/node/general/test_legacy_machinetype.py b/tests/virt/node/general/test_legacy_machinetype.py
new file mode 100644
index 0000000000..3a64c066ed
--- /dev/null
+++ b/tests/virt/node/general/test_legacy_machinetype.py
@@ -0,0 +1,98 @@
+import logging
+
+import pytest
+from ocp_resources.kubevirt import KubeVirt
+from ocp_resources.template import Template
+from pytest_testconfig import config as py_config
+
+from tests.virt.node.general.constants import MachineTypesNames
+from tests.virt.utils import validate_machine_type
+from utilities.constants import Images
+from utilities.hco import is_hco_tainted, update_hco_annotations
+from utilities.storage import create_dv, create_or_update_data_source, get_test_artifact_server_url
+from utilities.virt import (
+    VirtualMachineForTestsFromTemplate,
+    get_rhel_os_dict,
+    running_vm,
+    wait_for_updated_kv_value,
+)
+
+pytestmark = pytest.mark.post_upgrade
+LOGGER = logging.getLogger(__name__)
+
+
+@pytest.fixture()
+def updated_hco_emulated_machine_i440fx(
+    hyperconverged_resource_scope_function,
+    admin_client,
+    hco_namespace,
+):
+    annotations_path = "architectureConfiguration"
+    amd64_machine_type_list = ["q35*", "pc-q35*", "pc-i440fx-rhel7.6.0"]
+    with update_hco_annotations(
+        resource=hyperconverged_resource_scope_function,
+        path=annotations_path,
+        value={"amd64": {"emulatedMachines": amd64_machine_type_list}},
+        resource_list=[KubeVirt],
+    ):
+        wait_for_updated_kv_value(
+            admin_client=admin_client,
+            hco_namespace=hco_namespace,
+            path=[annotations_path, "amd64", "emulatedMachines"],
+            value=amd64_machine_type_list,
+        )
+        yield
+    assert not is_hco_tainted(admin_client=admin_client, hco_namespace=hco_namespace.name)
+
+
+@pytest.fixture()
+def rhel_8_10_dv(admin_client, golden_images_namespace):
+    with create_dv(
+        dv_name="rhel-8-10-dv",
+        namespace=golden_images_namespace.name,
+        storage_class=py_config["default_storage_class"],
+        url=f"{get_test_artifact_server_url()}{Images.Rhel.DIR}/{Images.Rhel.RHEL8_10_IMG}",
+        size=Images.Rhel.DEFAULT_DV_SIZE,
+        client=admin_client,
+    ) as dv:
+        yield dv
+
+
+@pytest.fixture()
+def rhel_8_10_ds(admin_client, rhel_8_10_dv):
+    yield from create_or_update_data_source(admin_client=admin_client, dv=rhel_8_10_dv)
+
+
+@pytest.fixture()
+def rhel_8_10_vm(unprivileged_client, namespace, rhel_8_10_ds):
+    rhel_8_10 = get_rhel_os_dict(rhel_version="rhel-8-10")
+    with VirtualMachineForTestsFromTemplate(
+        name="rhel-8-10",
+        namespace=namespace.name,
+        client=unprivileged_client,
+        labels=Template.generate_template_labels(**rhel_8_10["template_labels"]),
+        data_source=rhel_8_10_ds,
+        machine_type=MachineTypesNames.pc_i440fx_rhel7_6,
+    ) as vm:
+        running_vm(vm=vm)
+        yield vm
+
+
+@pytest.mark.parametrize(
+    "expected_machine_type",
+    [
+        pytest.param(
+            MachineTypesNames.pc_i440fx_rhel7_6,
+            marks=pytest.mark.polarion("CNV-7311"),
+        )
+    ],
+)
+def test_legacy_machine_type(
+    updated_hco_emulated_machine_i440fx,
+    rhel_8_10_vm,
+    expected_machine_type,
+):
+    validate_machine_type(
+        vm=rhel_8_10_vm,
+        expected_machine_type=expected_machine_type,
+    )
diff --git a/tests/virt/node/general/test_machinetype.py b/tests/virt/node/general/test_machinetype.py
index f41ca7e682..26ab78d6ea 100644
--- a/tests/virt/node/general/test_machinetype.py
+++ b/tests/virt/node/general/test_machinetype.py
@@ -2,15 +2,13 @@
 
 import pytest
 from kubernetes.dynamic.exceptions import UnprocessibleEntityError
-from ocp_resources.kubevirt import KubeVirt
-from pytest_testconfig import config as py_config
 
 from tests.virt.node.general.constants import MachineTypesNames
-from utilities.hco import is_hco_tainted, update_hco_annotations
+from tests.virt.utils import validate_machine_type
+from utilities.hco import update_hco_annotations
 from utilities.virt import (
     VirtualMachineForTests,
     fedora_vm_body,
-    get_rhel_os_dict,
     migrate_vm_and_verify,
     restart_vm_wait_for_running_vm,
     running_vm,
@@ -20,46 +18,6 @@
 pytestmark = pytest.mark.post_upgrade
 LOGGER = logging.getLogger(__name__)
 
-RHEL_8_10 = get_rhel_os_dict(rhel_version="rhel-8-10")
-RHEL_8_10_TEMPLATE_LABELS = RHEL_8_10["template_labels"]
-
-
-def validate_machine_type(expected_machine_type, vm):
-    vm_machine_type = vm.instance.spec.template.spec.domain.machine.type
-    vmi_machine_type = vm.vmi.instance.spec.domain.machine.type
-
-    assert vm_machine_type == vmi_machine_type == expected_machine_type, (
-        f"Created VM's machine type does not match the request. "
-        f"Expected: {expected_machine_type} VM: {vm_machine_type}, VMI: {vmi_machine_type}"
-    )
-    vmi_xml_machine_type = vm.privileged_vmi.xml_dict["domain"]["os"]["type"]["@machine"]
-    assert vmi_xml_machine_type == expected_machine_type, (
-        f"libvirt machine type {vmi_xml_machine_type} does not match expected type {expected_machine_type}"
-    )
-
-
-@pytest.fixture()
-def updated_hco_emulated_machine_i440fx(
-    hyperconverged_resource_scope_function,
-    admin_client,
-    hco_namespace,
-):
-    annotations_path = "architectureConfiguration"
-    with update_hco_annotations(
-        resource=hyperconverged_resource_scope_function,
-        path=annotations_path,
-        value={"amd64": {"emulatedMachines": ["q35*", "pc-q35*", "pc-i440fx-rhel7.6.0"]}},
-        resource_list=[KubeVirt],
-    ):
-        wait_for_updated_kv_value(
-            admin_client=admin_client,
-            hco_namespace=hco_namespace,
-            path=[annotations_path, "amd64", "emulatedMachines"],
-            value=["q35*", "pc-q35*", "pc-i440fx-rhel7.6.0"],
-        )
-        yield
-    assert not is_hco_tainted(admin_client=admin_client, hco_namespace=hco_namespace.name)
-
 
 @pytest.fixture()
 def vm(request, cluster_cpu_model_scope_function, unprivileged_client, namespace):
@@ -261,39 +219,3 @@ def test_machine_type_as_rhel_9_4(machine_type_from_kubevirt_config):
         f"Machine type value is {machine_type_from_kubevirt_config}"
         f"does not match with {MachineTypesNames.pc_q35_rhel9_4}"
     )
-
-
-@pytest.mark.parametrize(
-    "golden_image_data_volume_scope_function, vm_from_template_scope_function, expected_machine_type",
-    [
-        pytest.param(
-            {
-                "dv_name": RHEL_8_10_TEMPLATE_LABELS["os"],
-                "image": RHEL_8_10["image_path"],
-                "dv_size": RHEL_8_10["dv_size"],
-                "storage_class": py_config["default_storage_class"],
-            },
-            {
-                "vm_name": "legacy-vm",
-                "template_labels": RHEL_8_10_TEMPLATE_LABELS,
-                "machine_type": MachineTypesNames.pc_i440fx_rhel7_6,
-            },
-            MachineTypesNames.pc_i440fx_rhel7_6,
-            marks=pytest.mark.polarion("CNV-7311"),
-        )
-    ],
-    indirect=[
-        "golden_image_data_volume_scope_function",
-        "vm_from_template_scope_function",
-    ],
-)
-def test_legacy_machine_type(
-    updated_hco_emulated_machine_i440fx,
-    golden_image_data_volume_scope_function,
-    vm_from_template_scope_function,
-    expected_machine_type,
-):
-    validate_machine_type(
-        vm=vm_from_template_scope_function,
-        expected_machine_type=expected_machine_type,
-    )
diff --git a/tests/virt/utils.py b/tests/virt/utils.py
index cc6c4c89fd..a1a61c4249 100644
--- a/tests/virt/utils.py
+++ b/tests/virt/utils.py
@@ -341,3 +341,17 @@ def wait_for_virt_launcher_pod(vmi):
     except TimeoutExpiredError:
         LOGGER.error(f"Virt-laucher pod for VMI {vmi.name} was not found!")
         raise
+
+
+def validate_machine_type(vm, expected_machine_type):
+    vm_machine_type = vm.instance.spec.template.spec.domain.machine.type
+    vmi_machine_type = vm.vmi.instance.spec.domain.machine.type
+
+    assert vm_machine_type == vmi_machine_type == expected_machine_type, (
+        "Created VM's machine type does not match the request. "
+        f"Expected: {expected_machine_type} VM: {vm_machine_type}, VMI: {vmi_machine_type}"
+    )
+    vmi_xml_machine_type = vm.privileged_vmi.xml_dict["domain"]["os"]["type"]["@machine"]
+    assert vmi_xml_machine_type == expected_machine_type, (
+        f"libvirt machine type {vmi_xml_machine_type} does not match expected type {expected_machine_type}"
+    )


Reviews:
user: login: polarion-jenkins
state: DISMISSED
author_association: COLLABORATOR
submitted_at: 2025-04-22T07:24:00Z
user: login: dshchedr
body: couple of nits
state: CHANGES_REQUESTED
author_association: COLLABORATOR
submitted_at: 2025-04-22T20:16:50Z
user: login: polarion-jenkins
state: DISMISSED
author_association: COLLABORATOR
submitted_at: 2025-04-23T05:47:51Z
user: login: polarion-jenkins
state: APPROVED
author_association: COLLABORATOR
submitted_at: 2025-04-23T07:50:27Z
user: login: SiboWang1997
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-23T08:30:12Z
user: login: SiboWang1997
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-23T08:30:43Z
user: login: dshchedr
state: APPROVED
author_association: COLLABORATOR
submitted_at: 2025-04-23T16:56:38Z

Review comments:
diff_hunk: @@ -341,3 +341,17 @@ def wait_for_virt_launcher_pod(vmi):
     except TimeoutExpiredError:
         LOGGER.error(f"Virt-laucher pod for VMI {vmi.name} was not found!")
         raise
+
+
+def validate_machine_type(vm, expected_machine_type):
+    vm_machine_type = vm.instance.spec.template.spec.domain.machine.type
+    vmi_machine_type = vm.vmi.instance.spec.domain.machine.type
+
+    assert vm_machine_type == vmi_machine_type == expected_machine_type, (
+        f"Created VM's machine type does not match the request. "
path: tests/virt/utils.py
user: login: dshchedr
body: ```suggestion
        "Created VM's machine type does not match the request. "
```
created_at: 2025-04-22T20:12:23Z
author_association: COLLABORATOR
diff_hunk: @@ -0,0 +1,79 @@
+import logging
+
+import pytest
+from ocp_resources.kubevirt import KubeVirt
+from pytest_testconfig import config as py_config
+
+from tests.virt.node.general.constants import MachineTypesNames
+from tests.virt.utils import validate_machine_type
+from utilities.hco import is_hco_tainted, update_hco_annotations
+from utilities.virt import (
+    get_rhel_os_dict,
+    wait_for_updated_kv_value,
+)
+
+pytestmark = pytest.mark.post_upgrade
+LOGGER = logging.getLogger(__name__)
+
+
+RHEL_8_10 = get_rhel_os_dict(rhel_version="rhel-8-10")
+RHEL_8_10_TEMPLATE_LABELS = RHEL_8_10["template_labels"]
+
+
+@pytest.fixture()
+def updated_hco_emulated_machine_i440fx(
+    hyperconverged_resource_scope_function,
+    admin_client,
+    hco_namespace,
+):
+    annotations_path = "architectureConfiguration"
+    with update_hco_annotations(
+        resource=hyperconverged_resource_scope_function,
+        path=annotations_path,
+        value={"amd64": {"emulatedMachines": ["q35*", "pc-q35*", "pc-i440fx-rhel7.6.0"]}},
path: tests/virt/node/general/test_legacy_machinetype.py
user: login: dshchedr
body: save and reuse this list
created_at: 2025-04-22T20:15:46Z
author_association: COLLABORATOR
diff_hunk: @@ -341,3 +341,17 @@ def wait_for_virt_launcher_pod(vmi):
     except TimeoutExpiredError:
         LOGGER.error(f"Virt-laucher pod for VMI {vmi.name} was not found!")
         raise
+
+
+def validate_machine_type(vm, expected_machine_type):
+    vm_machine_type = vm.instance.spec.template.spec.domain.machine.type
+    vmi_machine_type = vm.vmi.instance.spec.domain.machine.type
+
+    assert vm_machine_type == vmi_machine_type == expected_machine_type, (
+        f"Created VM's machine type does not match the request. "
path: tests/virt/utils.py
user: login: SiboWang1997
body: thanks point out, done
created_at: 2025-04-23T08:30:12Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,79 @@
+import logging
+
+import pytest
+from ocp_resources.kubevirt import KubeVirt
+from pytest_testconfig import config as py_config
+
+from tests.virt.node.general.constants import MachineTypesNames
+from tests.virt.utils import validate_machine_type
+from utilities.hco import is_hco_tainted, update_hco_annotations
+from utilities.virt import (
+    get_rhel_os_dict,
+    wait_for_updated_kv_value,
+)
+
+pytestmark = pytest.mark.post_upgrade
+LOGGER = logging.getLogger(__name__)
+
+
+RHEL_8_10 = get_rhel_os_dict(rhel_version="rhel-8-10")
+RHEL_8_10_TEMPLATE_LABELS = RHEL_8_10["template_labels"]
+
+
+@pytest.fixture()
+def updated_hco_emulated_machine_i440fx(
+    hyperconverged_resource_scope_function,
+    admin_client,
+    hco_namespace,
+):
+    annotations_path = "architectureConfiguration"
+    with update_hco_annotations(
+        resource=hyperconverged_resource_scope_function,
+        path=annotations_path,
+        value={"amd64": {"emulatedMachines": ["q35*", "pc-q35*", "pc-i440fx-rhel7.6.0"]}},
path: tests/virt/node/general/test_legacy_machinetype.py
user: login: SiboWang1997
body: done
created_at: 2025-04-23T08:30:43Z
author_association: CONTRIBUTOR

PR comments:
user: login: dbasunag1
created_at: 2025-04-22T07:21:30Z
body: 
Report bugs in [Issues](https://github.com/myakove/github-webhook-server/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](https://pre-commit.ci/) 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>`

<details>
<summary>Supported /retest check runs</summary>

 * `/retest tox`: Retest tox
 * `/retest build-container`: Retest build-container
 * `/retest all`: Retest all

</details>

<details>
<summary>Supported labels</summary>

 * hold
 * verified
 * wip
 * lgtm

</details>
    
author_association: NONE
user: login: SiboWang1997
created_at: 2025-04-22T07:22:30Z
body: /build-and-push-container
author_association: CONTRIBUTOR
user: login: dbasunag1
created_at: 2025-04-22T07:23:16Z
body: New container for quay.io/openshift-cnv/openshift-virtualization-tests:pr-786 published
author_association: NONE
user: login: SiboWang1997
created_at: 2025-04-22T07:23:48Z
body: /wip
author_association: CONTRIBUTOR
user: login: SiboWang1997
created_at: 2025-04-22T08:01:14Z
body: /wip cancel
author_association: CONTRIBUTOR
user: login: SiboWang1997
created_at: 2025-04-22T08:01:25Z
body: /verified
author_association: CONTRIBUTOR
user: login: SiboWang1997
created_at: 2025-04-23T01:17:08Z
body: /wip

author_association: CONTRIBUTOR
user: login: SiboWang1997
created_at: 2025-04-23T05:46:42Z
body: /build-and-push-container
author_association: CONTRIBUTOR
user: login: dbasunag1
created_at: 2025-04-23T05:47:21Z
body: New container for quay.io/openshift-cnv/openshift-virtualization-tests:pr-786 published
author_association: NONE
user: login: SiboWang1997
created_at: 2025-04-23T07:49:07Z
body: /build-and-push-container
author_association: CONTRIBUTOR
user: login: dbasunag1
created_at: 2025-04-23T07:49:45Z
body: New container for quay.io/openshift-cnv/openshift-virtualization-tests:pr-786 published
author_association: NONE
user: login: SiboWang1997
created_at: 2025-04-23T08:30:57Z
body: /wip cancel

author_association: CONTRIBUTOR
user: login: SiboWang1997
created_at: 2025-04-23T08:31:12Z
body: /verified
author_association: CONTRIBUTOR
user: login: dbasunag1
created_at: 2025-04-23T16:57:50Z
body: Successfully removed PR tag: quay.io/openshift-cnv/openshift-virtualization-tests:pr-786.
author_association: NONE
user: login: dbasunag1
created_at: 2025-04-23T17:00:14Z
body: New container for quay.io/openshift-cnv/openshift-virtualization-tests:latest published
author_association: NONE