-
Notifications
You must be signed in to change notification settings - Fork 72
[Storage] Windows Session Scoped Data Source + CDI Clone and Hotplug implementation of it #4571
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
c127604
Use DataSource sourceRef for Windows VM cloning with vTPM
acinko-rh 7c50e63
remove artifactory credential fetching from fixture
acinko-rh 102beed
apply reviewer's suggestions
acinko-rh 176ef09
code cleanup
acinko-rh a776bc8
cleanup only if the config map and secret existed
acinko-rh f383451
verify the PVC from DataStore exists before proceeding
acinko-rh 4d91562
add edge case where user provides own PVC
acinko-rh 76f3de2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] fd9a86d
use PVC instead of DV
acinko-rh 860367b
use new DataSource object instead
acinko-rh 8bd5964
update the `DataSource` object's source directly
acinko-rh e607c01
access the private value directly
acinko-rh a6da977
remove PVC logic, keep the DV fixture only since the DV will always
acinko-rh edd9325
reverting change for `test_successful_snapshot_clone` in `test_clone.py`
acinko-rh 2a2f44f
reformat
acinko-rh 0c24719
Merge branch 'main' into add_vtpm_to_cdi_clone
acinko-rh 44641c1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 9ab441e
Merge branch 'main' into add_vtpm_to_cdi_clone
acinko-rh 6b51fb1
Merge branch 'main' into add_vtpm_to_cdi_clone
acinko-rh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| import pytest | ||
| from ocp_resources.cluster_role import ClusterRole | ||
| from ocp_resources.data_source import DataSource | ||
| from ocp_resources.datavolume import DataVolume | ||
| from ocp_resources.namespace import Namespace | ||
| from ocp_resources.role_binding import RoleBinding | ||
| from ocp_resources.utils.constants import TIMEOUT_1MINUTE | ||
| from pytest_testconfig import config as py_config | ||
|
|
||
| from utilities.artifactory import ( | ||
| cleanup_artifactory_secret_and_config_map, | ||
| get_artifactory_config_map, | ||
| get_artifactory_secret, | ||
| get_test_artifact_server_url, | ||
| ) | ||
| from utilities.constants import Images | ||
| from utilities.constants.storage import BIND_IMMEDIATE_ANNOTATION, REGISTRY_STR | ||
| from utilities.constants.timeouts import TIMEOUT_10MIN, TIMEOUT_50MIN | ||
| from utilities.constants.virt import WIN_2K22 | ||
| from utilities.os_utils import get_windows_container_disk_path | ||
| from utilities.storage import construct_datavolume_source_dict, generate_data_source_dict | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def validation_os_images_namespace(admin_client): | ||
| validation_os_images_namespace = Namespace( | ||
| name="validation-os-images", | ||
| client=admin_client, | ||
| ) | ||
| if validation_os_images_namespace.exists: | ||
| yield validation_os_images_namespace | ||
| else: | ||
| with validation_os_images_namespace as ns: | ||
| yield ns | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def validation_os_images_role_binding(admin_client, validation_os_images_namespace): | ||
| """Grants view permissions in the namespace so unprivileged clients can clone from it.""" | ||
| role_binding = RoleBinding( | ||
| client=admin_client, | ||
| name="validation-os-images-view", | ||
| namespace=validation_os_images_namespace.name, | ||
| subjects_kind="Group", | ||
| subjects_name="system:authenticated", | ||
| role_ref_kind=ClusterRole.kind, | ||
| role_ref_name="view", | ||
| ) | ||
|
|
||
| if role_binding.exists: | ||
| subjects = next(iter(role_binding.instance.subjects)) | ||
| assert subjects.kind == "Group", ( | ||
| f"RoleBinding {role_binding.name} subjects kind is {subjects.kind}, expected Group" | ||
| ) | ||
| assert subjects.name == "system:authenticated", ( | ||
| f"RoleBinding {role_binding.name} subjects name is {subjects.name}, expected system:authenticated" | ||
| ) | ||
| role_ref = role_binding.instance.roleRef | ||
| assert role_ref.kind == ClusterRole.kind, ( | ||
| f"RoleBinding {role_binding.name} roleRef kind is {role_ref.kind}, expected {ClusterRole.kind}" | ||
| ) | ||
| assert role_ref.name == "view", ( | ||
| f"RoleBinding {role_binding.name} roleRef name is {role_ref.name}, expected view" | ||
| ) | ||
| yield role_binding | ||
|
acinko-rh marked this conversation as resolved.
|
||
| return | ||
|
|
||
| with role_binding as rb: | ||
| yield rb | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def windows_validation_os_images_data_volume_scope_session( | ||
| validation_os_images_role_binding, | ||
| conformance_tests, | ||
| ): | ||
| """Provides the DV backing the Windows Server 2022 image in the validation-os-images namespace. | ||
|
|
||
| Resolution order: | ||
| 1. DataVolume exists — waits for success, yields it. | ||
| 2. DataVolume does not exist — imports via Artifactory (fails on conformance runs), yields the new DataVolume. | ||
|
|
||
| Yields: | ||
| DataVolume: The DV containing the Windows 2022 image. | ||
| """ | ||
|
|
||
| win_dv = DataVolume( | ||
| name=WIN_2K22, | ||
| namespace=validation_os_images_role_binding.namespace, | ||
| client=validation_os_images_role_binding.client, | ||
| ) | ||
|
|
||
| if win_dv.exists: | ||
| win_dv.wait_for_dv_success(timeout=TIMEOUT_1MINUTE) | ||
| yield win_dv | ||
| return | ||
|
|
||
| assert not conformance_tests, ( | ||
| f"Windows image {win_dv.name} does not exist in namespace {validation_os_images_role_binding.namespace}." | ||
| " Self-validation requires the Windows image to be pre-created." | ||
| ) | ||
|
|
||
| artifactory_secret = get_artifactory_secret( | ||
| namespace=validation_os_images_role_binding.namespace, client=validation_os_images_role_binding.client | ||
| ) | ||
| artifactory_config_map = get_artifactory_config_map( | ||
| namespace=validation_os_images_role_binding.namespace, client=validation_os_images_role_binding.client | ||
| ) | ||
|
|
||
| win_dv.storage_class = py_config["default_storage_class"] | ||
| win_dv.source_dict = construct_datavolume_source_dict( | ||
| source=REGISTRY_STR, | ||
| url=f"{get_test_artifact_server_url(schema=REGISTRY_STR)}/{get_windows_container_disk_path(os_value=WIN_2K22)}", | ||
| secret_name=artifactory_secret.name, | ||
| cert_configmap_name=artifactory_config_map.name, | ||
| ) | ||
| win_dv.size = Images.Windows.CONTAINER_DISK_DV_SIZE | ||
| win_dv.api_name = "storage" | ||
| win_dv.annotations = BIND_IMMEDIATE_ANNOTATION | ||
|
acinko-rh marked this conversation as resolved.
|
||
|
|
||
| with win_dv as wdv: | ||
| wdv.wait_for_dv_success(timeout=TIMEOUT_50MIN) | ||
| yield wdv | ||
| cleanup_artifactory_secret_and_config_map( | ||
| artifactory_secret=artifactory_secret, | ||
| artifactory_config_map=artifactory_config_map, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def windows_validation_os_images_data_source_scope_session( | ||
| admin_client, windows_validation_os_images_data_volume_scope_session | ||
| ): | ||
| win_data_source = DataSource( | ||
| name=windows_validation_os_images_data_volume_scope_session.name, | ||
| namespace=windows_validation_os_images_data_volume_scope_session.namespace, | ||
| client=admin_client, | ||
| ) | ||
| if win_data_source.exists: | ||
| source_pvc = win_data_source.instance.spec.source.pvc | ||
| assert source_pvc.name == windows_validation_os_images_data_volume_scope_session.name, ( | ||
| f"DataSource {win_data_source.name} source PVC name is {source_pvc.name}, " | ||
| f"expected {windows_validation_os_images_data_volume_scope_session.name}" | ||
| ) | ||
|
acinko-rh marked this conversation as resolved.
|
||
| assert source_pvc.namespace == windows_validation_os_images_data_volume_scope_session.pvc.namespace, ( | ||
| f"DataSource {win_data_source.name} source PVC namespace is {source_pvc.namespace}, " | ||
| f"expected {windows_validation_os_images_data_volume_scope_session.namespace}" | ||
| ) | ||
| yield win_data_source | ||
| return | ||
|
|
||
| win_data_source._source = generate_data_source_dict(dv=windows_validation_os_images_data_volume_scope_session) | ||
| with win_data_source as wds: | ||
| wds.wait_for_condition( | ||
| condition=wds.Condition.READY, | ||
| status=wds.Condition.Status.TRUE, | ||
| timeout=TIMEOUT_10MIN, | ||
| ) | ||
| yield wds | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.