Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,20 @@
from ocp_resources.resource import Resource
from ocp_resources.ssp import SSP
from ocp_resources.volume_snapshot import VolumeSnapshot
from timeout_sampler import TimeoutExpiredError, TimeoutSampler

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Test Execution Plan

  • Run smoke tests: False

    • No smoke tests depend on delete_resources_from_namespace_by_type (removed from utilities/infra.py)
    • No smoke tests import or depend on test_custom_golden_images_namespace.py
  • tests/install_upgrade_operators/hco_enablement_golden_image_updates/test_custom_golden_images_namespace.py — full file: bug fix to verify_resource_in_ns (generator materialization), refactored test_resources_in_custom_ns, and new test_resources_deleted_from_default_namespace all require verification

from tests.install_upgrade_operators.hco_enablement_golden_image_updates.utils import (
COMMON_TEMPLATE,
get_templates_by_type_from_hco_status,
)
from utilities.constants import (
TIMEOUT_2MIN,
TIMEOUT_3MIN,
TIMEOUT_10MIN,
TIMEOUT_30SEC,
)
from utilities.hco import (
ResourceEditorValidateHCOReconcile,
wait_for_hco_conditions,
)
from utilities.infra import create_ns, delete_resources_from_namespace_by_type
from utilities.infra import create_ns
from utilities.storage import get_data_sources_managed_by_data_import_cron

LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -55,7 +52,7 @@ def verify_resource_in_ns(expected_resource_names, namespace, client, resource_t
"""
Verify that resources exist in expected_namespace and in ready status.
"""
resources = resource_type.get(client=client, namespace=namespace)
resources = list(resource_type.get(client=client, namespace=namespace))
resources_names = {resource.name for resource in resources}
missing_resources_names = expected_resource_names - resources_names
assert not missing_resources_names, f"Missing {resource_type.kind} in {namespace}: {missing_resources_names}"
Expand All @@ -70,27 +67,6 @@ def verify_resource_in_ns(expected_resource_names, namespace, client, resource_t
)


def wait_for_any_resource_exists_in_namespace(client, namespace, resource_types):
for sample in TimeoutSampler(
wait_timeout=TIMEOUT_2MIN,
sleep=TIMEOUT_30SEC,
func=lambda: any(
list(resource_type.get(client=client, namespace=namespace)) for resource_type in resource_types
),
):
if sample:
return


def verify_resources_not_reconciled(resources_to_verify, namespace, client):
delete_resources_from_namespace_by_type(resources_types=resources_to_verify, namespace=namespace, wait=True)
with pytest.raises(TimeoutExpiredError):
wait_for_any_resource_exists_in_namespace(
client=client, namespace=namespace, resource_types=resources_to_verify
)
LOGGER.error(f"resources shouldn't reconcile in {namespace} namespace")


def verify_common_template_namespace_updated(common_templates, namespace_name):
non_updated_templates = []
for template in common_templates:
Expand Down Expand Up @@ -197,7 +173,6 @@ def test_resources_in_custom_ns(
self,
admin_client,
custom_golden_images_namespace,
golden_images_namespace,
default_common_templates_related_resources,
resource_type,
ready_condition,
Expand All @@ -209,20 +184,16 @@ def test_resources_in_custom_ns(
resource_type=resource_type,
ready_condition=ready_condition,
)
if resource_type != DataSource:
verify_resource_not_in_ns(
resource_type=resource_type,
namespace=golden_images_namespace.name,
client=admin_client,
)

@pytest.mark.polarion("CNV-11477")
def test_boot_sources_not_reconciled_in_default_namespace(self, admin_client, golden_images_namespace):
verify_resources_not_reconciled(
resources_to_verify=[DataVolume, VolumeSnapshot],
namespace=golden_images_namespace.name,
client=admin_client,
)
def test_resources_deleted_from_default_namespace(self, admin_client, golden_images_namespace, subtests):
for resource_type in [DataImportCron, ImageStream, DataVolume, VolumeSnapshot]:
with subtests.test(msg=resource_type.kind):
verify_resource_not_in_ns(
resource_type=resource_type,
namespace=golden_images_namespace.name,
client=admin_client,
)


@pytest.mark.polarion("CNV-11631")
Expand Down
6 changes: 0 additions & 6 deletions utilities/infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -1146,12 +1146,6 @@ def get_node_selector_dict(node_selector):
return {f"{Resource.ApiGroup.KUBERNETES_IO}/hostname": node_selector}


def delete_resources_from_namespace_by_type(resources_types, namespace, wait=False):
for resource_type in resources_types:
for resource in list(resource_type.get(namespace=namespace)):
resource.delete(wait=wait)


def get_linux_guest_agent_version(ssh_exec):
ssh_exec.sudo = True
return guest_agent_version_parser(version_string=ssh_exec.package_manager.info("qemu-guest-agent"))
Expand Down
Loading