From 1c9a71b8d32c633eb3495681e69dc983c1febafa Mon Sep 17 00:00:00 2001 From: Parag Kamble Date: Fri, 13 Dec 2024 14:21:25 +0530 Subject: [PATCH] Done block file encryption summary validation Signed-off-by: Parag Kamble --- ocs_ci/ocs/ui/page_objects/block_and_file.py | 30 ++++----- ...test_encryption_configuration_dashboard.py | 67 +++++++++---------- 2 files changed, 44 insertions(+), 53 deletions(-) diff --git a/ocs_ci/ocs/ui/page_objects/block_and_file.py b/ocs_ci/ocs/ui/page_objects/block_and_file.py index 6d5f6bb1204..8d88bb1d18d 100644 --- a/ocs_ci/ocs/ui/page_objects/block_and_file.py +++ b/ocs_ci/ocs/ui/page_objects/block_and_file.py @@ -270,7 +270,6 @@ def get_block_file_encryption_summary(self): "storageclass_encryption": { "status": None, "kms": "", - "block_storage": {"status": None}, }, "intransit_encryption": {"status": None}, } @@ -282,9 +281,9 @@ def get_block_file_encryption_summary(self): self.validation_loc["encryption_summary"]["file_and_block"]["enabled"], enable_screenshot=True, ) - import time + from time import sleep - time.sleep(3) + sleep(3) # Context and status mappings context_map = { @@ -293,7 +292,7 @@ def get_block_file_encryption_summary(self): "In-transit encryption": "intransit_encryption", "Block storage": "block_storage", } - status_code = {"#3e8635": True, "#c9190b": False} + # status_code = {"#3e8635": True, "#c9190b": False} # Get elements for text and root encryption_content_location = self.validation_loc["encryption_summary"][ @@ -307,18 +306,20 @@ def get_block_file_encryption_summary(self): root_element = root_elements[0] # Function to extract status from an SVG element - def extract_status(svg_path, context): + def extract_status(svg_path): try: svg_element = root_element.find_element(By.CSS_SELECTOR, svg_path) if svg_element and svg_element.tag_name == "svg": - return status_code.get(svg_element.get_attribute("color")) - raise ValueError(f"Error Getting {context} status information") + if svg_element.get_attribute("data-test") == "success-icon": + return True + else: + return False except Exception as e: - logger.error(f"Error extracting status for {context}: {e}") + logger.error(f"Error extracting status: {e}") return None + # Process encryption summary text current_context = None - for line in encryption_summary_text.split("\n"): line = line.strip() if line in context_map: @@ -331,8 +332,7 @@ def extract_status(svg_path, context): ): encryption_summary[current_context]["kms"] = line.split(":")[-1].strip() encryption_summary[current_context]["status"] = extract_status( - "div.pf-m-align-items-center:nth-child(1) > div:nth-child(2) > svg:nth-child(1)", - current_context, + "div.pf-m-align-items-center:nth-child(1) > div:nth-child(2) > svg:nth-child(1)" ) elif ( current_context == "storageclass_encryption" @@ -340,16 +340,14 @@ def extract_status(svg_path, context): ): encryption_summary[current_context]["kms"] = line.split(":")[-1].strip() encryption_summary[current_context]["status"] = extract_status( - "div.pf-v5-l-flex:nth-child(6) > div:nth-child(2) > svg:nth-child(1)", - current_context, + "div.pf-v5-l-flex:nth-child(6) > div:nth-child(2) > svg:nth-child(1)" ) elif current_context == "intransit_encryption": encryption_summary[current_context]["status"] = extract_status( - "div.pf-v5-l-flex:nth-child(6) > div:nth-child(2) > svg:nth-child(1)", - current_context, + "div.pf-v5-l-flex:nth-child(10) > div:nth-child(2) > svg" ) - logger.info(f"Encryption Summary>>>>>>>>>: {encryption_summary}") + logger.info(f"Encryption Summary: {encryption_summary}") # Close the popup logger.info("Closing the popup") diff --git a/tests/functional/encryption/test_encryption_configuration_dashboard.py b/tests/functional/encryption/test_encryption_configuration_dashboard.py index 9cb8344ac91..008eadac61d 100644 --- a/tests/functional/encryption/test_encryption_configuration_dashboard.py +++ b/tests/functional/encryption/test_encryption_configuration_dashboard.py @@ -38,54 +38,47 @@ def test_encryption_configuration_dashboard(self, setup_ui_class): # Retrieve encryption summary from the dashboard encryption_summary = block_and_file_page.get_block_file_encryption_summary() - # Helper function to assert encryption details - def assert_encryption(key, condition, error_message): - assert condition, error_message - log.info(f"Encryption status for {key} is correct.") + # Helper function to validate encryption details + def validate_encryption(context, actual_status, expected_status, error_message): + assert actual_status == expected_status, error_message + log.info(f"{context} status is as expected: {actual_status}") - # Validate encryption configurations + # Validate cluster-wide encryption cluster_wide_details = enc_details.get("clusterWide", {}) if isinstance(cluster_wide_details, dict): - if cluster_wide_details.get("status", False): - assert_encryption( - "ClusterWide Encryption", - encryption_summary["cluster_wide_encryption"]["status"], - "ClusterWide Encryption is not showing as enabled in the encryption summary dashboard.", - ) - - if cluster_wide_details.get("kms", {}).get("enable", False): - assert_encryption( - "ClusterWide KMS", - encryption_summary["cluster_wide_encryption"]["kms"], - "KMS is not mentioned in the encryption summary.", - ) + validate_encryption( + "ClusterWide Encryption", + encryption_summary["cluster_wide_encryption"]["status"], + cluster_wide_details.get("status", False), + "ClusterWide Encryption is not showing correctly in the dashboard.", + ) + validate_encryption( + "ClusterWide KMS", + encryption_summary["cluster_wide_encryption"]["kms"], + cluster_wide_details.get("kms", {}).get("enable", False), + "KMS is not mentioned in the encryption summary.", + ) else: log.warning( "ClusterWide Encryption details are not a dictionary, skipping checks." ) - # Safely validate storage class encryption + # Validate storage class encryption storage_class_details = enc_details.get("storageClass", {}) if isinstance(storage_class_details, dict): - if storage_class_details.get("status", False): - assert_encryption( - "StorageClass Encryption", - encryption_summary["storageclass_encryption"]["status"], - "StorageClass encryption is not showing as enabled.", - ) + validate_encryption( + "StorageClass Encryption", + encryption_summary["storageclass_encryption"]["status"], + storage_class_details.get("status", False), + "StorageClass encryption is not showing correctly in the dashboard.", + ) else: log.warning("StorageClass details are not a dictionary, skipping checks.") # Validate in-transit encryption - if intransit_encryption_status: - assert_encryption( - "InTransit Encryption Enabled", - encryption_summary["intransit_encryption"]["status"], - "InTransit Encryption is not enabled in the dashboard.", - ) - else: - assert_encryption( - "InTransit Encryption Disabled", - not encryption_summary["intransit_encryption"]["status"], - "InTransit Encryption is showing as enabled in the dashboard, but it should be disabled.", - ) + validate_encryption( + "InTransit Encryption", + encryption_summary["intransit_encryption"]["status"], + intransit_encryption_status, + "InTransit Encryption status is incorrect in the dashboard.", + )