Skip to content

Commit 7b1b3f4

Browse files
[Storage] Use blank dv instead of Cirros in test_fail_to_vmexport_with_unprivileged_client_no_permissions (RedHatQE#2665)
##### Short description: Improving test `test_fail_to_vmexport_with_unprivileged_client_no_permissions` to use a blank data source with unprivileged lcient to create a vmexport instance. ##### More details: ##### What this PR does / why we need it: Change the test to use a blank data source instead a cirros one ##### Which issue(s) this PR fixes: ##### Special notes for reviewer: ##### jira-ticket: https://issues.redhat.com/browse/CNV-69121 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Improved VM export tests: added an admin-created data-volume fixture, renamed the unprivileged-created fixture, removed redundant readiness waits, and simplified parameterization to rely on the new fixtures. * **Utilities** * Added a reusable helper to create blank data volumes for tests, consolidating creation and readiness handling to reduce setup duplication. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 7d03d36 commit 7b1b3f4

3 files changed

Lines changed: 53 additions & 29 deletions

File tree

tests/storage/vm_export/conftest.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@
1919
from ocp_resources.virtual_machine_export import VirtualMachineExport
2020
from ocp_resources.virtual_machine_snapshot import VirtualMachineSnapshot
2121
from pyhelper_utils.shell import run_ssh_commands
22-
from pytest_testconfig import py_config
2322

2423
from tests.storage.vm_export.constants import VM_EXPORT_TEST_FILE_CONTENT, VM_EXPORT_TEST_FILE_NAME
25-
from tests.storage.vm_export.utils import get_manifest_from_vmexport, get_manifest_url
26-
from utilities.constants import OS_FLAVOR_RHEL, TIMEOUT_1MIN, U1_SMALL, UNPRIVILEGED_PASSWORD, UNPRIVILEGED_USER
24+
from tests.storage.vm_export.utils import create_blank_dv_by_specific_user, get_manifest_from_vmexport, get_manifest_url
25+
from utilities.constants import OS_FLAVOR_RHEL, U1_SMALL, UNPRIVILEGED_PASSWORD, UNPRIVILEGED_USER
2726
from utilities.infra import create_ns, login_with_user_password
28-
from utilities.storage import create_dv, data_volume_template_with_source_ref_dict
27+
from utilities.storage import data_volume_template_with_source_ref_dict
2928
from utilities.virt import VirtualMachineForTests, running_vm
3029

3130

@@ -151,18 +150,22 @@ def vm_from_vmexport(
151150

152151

153152
@pytest.fixture()
154-
def blank_dv_created_by_specific_user(namespace, unprivileged_client):
155-
with create_dv(
156-
source="blank",
157-
dv_name="blank-dv-by-unprivileged-user",
158-
namespace=namespace.name,
159-
size="1Gi",
160-
storage_class=py_config["default_storage_class"],
161-
consume_wffc=False,
162-
bind_immediate=True,
153+
def blank_dv_created_by_unprivileged_user(namespace, unprivileged_client):
154+
with create_blank_dv_by_specific_user(
163155
client=unprivileged_client,
156+
namespace_name=namespace.name,
157+
dv_name="blank-dv-by-unprivileged-user",
158+
) as dv:
159+
yield dv
160+
161+
162+
@pytest.fixture()
163+
def blank_dv_created_by_admin_user(namespace, admin_client):
164+
with create_blank_dv_by_specific_user(
165+
client=admin_client,
166+
namespace_name=namespace.name,
167+
dv_name="blank-dv-by-admin-user",
164168
) as dv:
165-
dv.wait_for_dv_success(timeout=TIMEOUT_1MIN)
166169
yield dv
167170

168171

tests/storage/vm_export/test_vm_export.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
from ocp_resources.resource import Resource
1111
from ocp_resources.virtual_machine_export import VirtualMachineExport
1212
from pyhelper_utils.shell import run_ssh_commands
13-
from pytest_testconfig import config as py_config
1413

1514
from tests.storage.vm_export.constants import VM_EXPORT_TEST_FILE_CONTENT, VM_EXPORT_TEST_FILE_NAME
16-
from utilities.constants import Images
1715
from utilities.infra import run_virtctl_command
1816
from utilities.virt import running_vm
1917

@@ -25,38 +23,33 @@
2523

2624

2725
@pytest.mark.parametrize(
28-
"namespace, data_volume_scope_function",
26+
"namespace",
2927
[
3028
pytest.param(
3129
{"use_unprivileged_client": False},
32-
{
33-
"dv_name": "cirros-dv-9338",
34-
"image": f"{Images.Cirros.DIR}/{Images.Cirros.QCOW2_IMG}",
35-
"dv_size": Images.Cirros.DEFAULT_DV_SIZE,
36-
"storage_class": py_config["default_storage_class"],
37-
},
3830
marks=pytest.mark.polarion("CNV-9338"),
3931
)
4032
],
4133
indirect=True,
4234
)
4335
@pytest.mark.s390x
4436
def test_fail_to_vmexport_with_unprivileged_client_no_permissions(
37+
namespace,
38+
blank_dv_created_by_admin_user,
4539
unprivileged_client,
46-
data_volume_scope_function,
4740
):
4841
with pytest.raises(
4942
ApiException,
5043
match=ERROR_MSG_USER_CANNOT_CREATE_VM_EXPORT,
5144
):
5245
with VirtualMachineExport(
5346
name="vmexport-unprivileged",
54-
namespace=data_volume_scope_function.namespace,
47+
namespace=blank_dv_created_by_admin_user.namespace,
5548
client=unprivileged_client,
5649
source={
5750
"apiGroup": "",
5851
"kind": PersistentVolumeClaim.kind,
59-
"name": data_volume_scope_function.name,
52+
"name": blank_dv_created_by_admin_user.name,
6053
},
6154
) as vmexport:
6255
assert not vmexport, "VMExport created by unprivileged client"
@@ -79,14 +72,14 @@ def test_vmexport_snapshot_manifests(
7972
@pytest.mark.s390x
8073
@pytest.mark.polarion("CNV-11597")
8174
def test_virtctl_vmexport_unprivileged(
82-
vmexport_download_path, blank_dv_created_by_specific_user, virtctl_unprivileged_client
75+
vmexport_download_path, blank_dv_created_by_unprivileged_user, virtctl_unprivileged_client
8376
):
8477
return_code, out, err = run_virtctl_command(
8578
command=shlex.split(
86-
f"vmexport download test-pvc-export-unprivileged --pvc={blank_dv_created_by_specific_user.name} "
79+
f"vmexport download test-pvc-export-unprivileged --pvc={blank_dv_created_by_unprivileged_user.name} "
8780
f"--output {vmexport_download_path}"
8881
),
89-
namespace=blank_dv_created_by_specific_user.namespace,
82+
namespace=blank_dv_created_by_unprivileged_user.namespace,
9083
verify_stderr=False,
9184
)
9285
assert return_code, f"Failed to run virtctl vmexport by unprivileged user, out: {out}, err: {err}."

tests/storage/vm_export/utils.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@
55
import io
66
import logging
77
import shlex
8+
from contextlib import contextmanager
9+
from typing import Generator
810

911
import yaml
12+
from kubernetes.dynamic import DynamicClient
13+
from ocp_resources.datavolume import DataVolume
1014
from ocp_resources.virtual_machine import VirtualMachine
1115
from pyhelper_utils.shell import run_command
16+
from pytest_testconfig import config as py_config
17+
18+
from utilities.constants import TIMEOUT_1MIN
19+
from utilities.storage import create_dv
1220

1321
LOGGER = logging.getLogger(__name__)
1422

@@ -34,3 +42,23 @@ def get_manifest_url(vmexport_external_links, manifest_type):
3442
).get("url")
3543
assert url, f"Manifest url '{manifest_type}' in vmexport external links {vmexport_external_links} not found"
3644
return url
45+
46+
47+
@contextmanager
48+
def create_blank_dv_by_specific_user(
49+
client: DynamicClient,
50+
namespace_name: str,
51+
dv_name: str,
52+
) -> Generator[DataVolume]:
53+
with create_dv(
54+
source="blank",
55+
dv_name=dv_name,
56+
namespace=namespace_name,
57+
size="1Gi",
58+
storage_class=py_config["default_storage_class"],
59+
consume_wffc=False,
60+
bind_immediate=True,
61+
client=client,
62+
) as dv:
63+
dv.wait_for_dv_success(timeout=TIMEOUT_1MIN)
64+
yield dv

0 commit comments

Comments
 (0)