diff --git a/ocs_ci/ocs/resources/storage_cluster.py b/ocs_ci/ocs/resources/storage_cluster.py index dac06ef07fa..fe66ee8b216 100644 --- a/ocs_ci/ocs/resources/storage_cluster.py +++ b/ocs_ci/ocs/resources/storage_cluster.py @@ -2931,19 +2931,3 @@ def get_csi_images_for_client_ocp_version(ocp_version=None): csi_ocp_version_images = csi_images.split(first_str)[1].split(last_str)[0] csi_ocp_version_images_urls = extract_image_urls(csi_ocp_version_images) return csi_ocp_version_images_urls - - -def get_storagecluster_obj(): - """Get StorageCluster object""" - cluster_name = ( - constants.DEFAULT_CLUSTERNAME_EXTERNAL_MODE - if storagecluster_independent_check() - else constants.DEFAULT_CLUSTERNAME - ) - - ocp_obj = StorageCluster( - resource_name=cluster_name, - namespace=config.ENV_DATA["cluster_namespace"], - ) - - return ocp_obj 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 a144ae9b177..1355dbbd0de 100644 --- a/ocs_ci/ocs/ui/page_objects/block_and_file.py +++ b/ocs_ci/ocs/ui/page_objects/block_and_file.py @@ -264,6 +264,9 @@ def get_avg_consumption_from_ui(self): def get_block_file_encryption_summary(self): """ Click on Encryption Summary button and retrieve the encryption details. + + Returns: + dict: Encryption summary on block and file page. """ encryption_summary = { "cluster_wide_encryption": {"status": None, "kms": ""}, diff --git a/ocs_ci/ocs/ui/page_objects/object_details_tab.py b/ocs_ci/ocs/ui/page_objects/object_details_tab.py new file mode 100644 index 00000000000..4eeb42ee79b --- /dev/null +++ b/ocs_ci/ocs/ui/page_objects/object_details_tab.py @@ -0,0 +1,94 @@ +import time + +from ocs_ci.ocs.ui.helpers_ui import logger +from ocs_ci.ocs.ui.page_objects.storage_system_details import StorageSystemDetails +from selenium.webdriver.common.by import By + + +class ObjectDetails(StorageSystemDetails): + def __init__(self): + StorageSystemDetails.__init__(self) + + def get_encryption_summary(self): + """ + Collecting Encryption summary shown in the Object details page. + + Returns: + encryption_summary (dict): encryption summary on object details page. + """ + encryption_summary = { + "object_storage": {"status": None, "kms": ""}, + "intransit_encryption": {"status": None}, + } + + logger.info("Getting Block and File Encryption Summary Details") + + # Open the encryption summary popup + self.do_click( + self.validation_loc["encryption_summary"]["object"]["enabled"], + enable_screenshot=True, + ) + + time.sleep(3) + + # Context and status mappings + context_map = { + "Object storage": "object_storage", + "In-transit encryption": "intransit_encryption", + } + + # Get elements for text and root + encryption_content_location = self.validation_loc["encryption_summary"][ + "object" + ]["encryption_content_data"] + encryption_summary_text = self.get_element_text(encryption_content_location) + root_elements = self.get_elements(encryption_content_location) + + if not root_elements: + raise ValueError("Error getting root web element") + root_element = root_elements[0] + + # Function to extract status from an SVG element + 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": + if svg_element.get_attribute("data-test") == "success-icon": + return True + else: + return False + except Exception as 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: + current_context = context_map[line] + continue + + if ( + current_context == "object_storage" + and "External Key Management Service" in line + ): + encryption_summary[current_context]["kms"] = line.split(":")[-1].strip() + encryption_summary[current_context]["status"] = extract_status( + "div.pf-v5-l-flex:nth-child(1) > div:nth-child(2) > svg" + ) + elif current_context == "intransit_encryption": + encryption_summary[current_context]["status"] = extract_status( + "div.pf-v5-l-flex:nth-child(4) > div:nth-child(2) > svg" + ) + + logger.info(f"Encryption Summary: {encryption_summary}") + + # Close the popup + logger.info("Closing the popup") + self.do_click( + self.validation_loc["encryption_summary"]["object"]["close"], + enable_screenshot=True, + ) + + return encryption_summary diff --git a/tests/functional/encryption/test_encryption_configuration_dashboard.py b/tests/functional/encryption/test_encryption_configuration_dashboard.py index 8d47ca12121..25eb9a77a9a 100644 --- a/tests/functional/encryption/test_encryption_configuration_dashboard.py +++ b/tests/functional/encryption/test_encryption_configuration_dashboard.py @@ -3,10 +3,12 @@ log = logging.getLogger(__name__) from ocs_ci.ocs.ui.page_objects.page_navigator import PageNavigator -from ocs_ci.ocs.resources.storage_cluster import get_storagecluster_obj from ocs_ci.framework.pytest_customization.marks import green_squad, tier1 from ocs_ci.ocs.ocp import OCP from ocs_ci.framework import config +from ocs_ci.ocs import constants +from ocs_ci.ocs.resources.storage_cluster import StorageCluster +from ocs_ci.helpers.helpers import storagecluster_independent_check @green_squad @@ -14,9 +16,21 @@ class TestEncryptionConfigurationDashboard: @pytest.fixture(autouse=True) def encryption_status(self): - """_summary_""" + """ + Collect Encryption status from storagecluster and noobaa spec. + """ # Retrieve encryption details - sc_obj = get_storagecluster_obj() + cluster_name = ( + constants.DEFAULT_CLUSTERNAME_EXTERNAL_MODE + if storagecluster_independent_check() + else constants.DEFAULT_CLUSTERNAME + ) + + sc_obj = StorageCluster( + resource_name=cluster_name, + namespace=config.ENV_DATA["cluster_namespace"], + ) + self.enc_details = sc_obj.data["spec"].get("encryption", {}) self.intransit_encryption_status = ( sc_obj.data["spec"] @@ -25,7 +39,7 @@ def encryption_status(self): .get("encryption", {}) .get("enabled", False) ) - log.info(f"Encryption details: {self.enc_details}") + log.info(f"Encryption details from storagecluster Spec: {self.enc_details}") noobaa_obj = OCP( kind="noobaa", @@ -40,14 +54,23 @@ def encryption_status(self): .get("connectionDetails", {}) .get("KMS_PROVIDER", None) # Provide a default value of None if not found ) + log.info(f"Noobaa Spec has mentioned KMS: {self.noobaa_kms}") - # Helper function to validate encryption details def validate_encryption( self, context, actual_status, expected_status, error_message ): + """Helper function to validate encryption details + + Args: + context (str): Encryption Type + actual_status (str): Encryption status in the spec file + expected_status (str): Encryption status shown on the dashboard. + error_message (str): Error message to display. + """ assert actual_status == expected_status, error_message log.info(f"{context} status is as expected: {actual_status}") + @pytest.mark.polarion_id("OCS-6300") def test_file_block_encryption_configuration_dashboard(self, setup_ui_class): """Test the encryption configuration dashboard of File And Block details for correctness. @@ -109,6 +132,7 @@ def test_file_block_encryption_configuration_dashboard(self, setup_ui_class): "InTransit Encryption status is incorrect in the dashboard.", ) + @pytest.mark.polarion_id("OCS-6301") def test_object_storage_encryption_configuration_dashboard(self, setup_ui_class): """Test the encryption configuration dashboard of Object details for correctness.