11import logging
22
3- from _pytest ._py .path import LocalPath
43from kubernetes .dynamic import DynamicClient
54from timeout_sampler import TimeoutExpiredError , TimeoutSampler
65
76from utilities .constants import TIMEOUT_1MIN , TIMEOUT_5SEC , VIRTCTL_CLI_DOWNLOADS
8- from utilities .infra import download_and_extract_file_from_cluster , get_console_spec_links
7+ from utilities .infra import get_console_spec_links
98
109LOGGER = logging .getLogger (__name__ )
1110CUSTOMIZED_VIRT_DL = "customized-virt-dl"
@@ -27,23 +26,26 @@ def validate_custom_cli_downloads_urls_updated(
2726 admin_client (DynamicClient): Kubernetes dynamic client for API operations
2827 new_hostname (str, optional): New hostname that should be present in all URLs.
2928 If provided, validates that all URLs contain this hostname.
29+ Mutually exclusive with original_virtctl_console_cli_downloads_spec_links.
3030 original_virtctl_console_cli_downloads_spec_links (list[str], optional):
3131 Original list of CLI download URLs. If provided, validates that current
3232 URLs match these original URLs.
33-
34- Returns:
35- None: Function returns when validation succeeds
33+ Mutually exclusive with new_hostname.
3634
3735 Raises:
3836 TimeoutExpiredError: If validation fails within the timeout period (1 minute).
3937 This can occur when:
4038 - URLs don't revert to original state within timeout
4139 - URLs don't get updated with new hostname within timeout
42-
43- Note:
44- - Exactly one of new_hostname or original_virtctl_console_cli_downloads_spec_links
45- should be provided, not both
40+ ValueError: If both new_hostname and original_virtctl_console_cli_downloads_spec_links
41+ are provided, or if neither is provided.
4642 """
43+ if (new_hostname is None ) == (original_virtctl_console_cli_downloads_spec_links is None ):
44+ raise ValueError (
45+ "Exactly one of 'new_hostname' or 'original_virtctl_console_cli_downloads_spec_links' "
46+ "must be provided, not both or neither."
47+ )
48+
4749 samples = TimeoutSampler (
4850 wait_timeout = TIMEOUT_1MIN ,
4951 sleep = TIMEOUT_5SEC ,
@@ -64,17 +66,15 @@ def validate_custom_cli_downloads_urls_updated(
6466 if not urls_not_updated_with_new_hostname :
6567 return
6668 except TimeoutExpiredError :
67- LOGGER .error (
68- f"Failed to update cluster ingress downloads spec links to the original links: "
69- f"original_cli_spec_links: { original_virtctl_console_cli_downloads_spec_links } , "
70- f"current_cli_spec_links: { current_cli_spec_links } "
71- ) if original_virtctl_console_cli_downloads_spec_links else (
72- f"Failed to get console spec links: { current_cli_spec_links } , "
73- f"There are urls that are not updated with new hostname: { urls_not_updated_with_new_hostname } "
74- )
69+ if original_virtctl_console_cli_downloads_spec_links :
70+ LOGGER .error (
71+ f"Failed to update cluster ingress downloads spec links to the original links: "
72+ f"original_cli_spec_links: { original_virtctl_console_cli_downloads_spec_links } , "
73+ f"current_cli_spec_links: { current_cli_spec_links } "
74+ )
75+ else :
76+ LOGGER .error (
77+ f"Failed to get console spec links: { current_cli_spec_links } , "
78+ f"There are urls that are not updated with new hostname: { urls_not_updated_with_new_hostname } "
79+ )
7580 raise
76-
77-
78- def validate_custom_cli_urls_downloaded (urls : list [str ], dest_dir : LocalPath ) -> None :
79- not_valid_urls = [url for url in urls if not download_and_extract_file_from_cluster (tmpdir = dest_dir , url = url )]
80- assert not not_valid_urls , f"Some urls is not valid, { not_valid_urls } "
0 commit comments