From f7f4211db57237a567fbe346d92b93a5866f59cd Mon Sep 17 00:00:00 2001 From: Parag Kamble Date: Tue, 14 Jan 2025 09:38:17 +0530 Subject: [PATCH] removed css path and kept element filtering logic Signed-off-by: Parag Kamble --- ocs_ci/ocs/constants.py | 1 - .../ocs/ui/page_objects/encryption_module.py | 98 ++++++------------- 2 files changed, 32 insertions(+), 67 deletions(-) diff --git a/ocs_ci/ocs/constants.py b/ocs_ci/ocs/constants.py index 348c33507ad..ffc0eedca42 100644 --- a/ocs_ci/ocs/constants.py +++ b/ocs_ci/ocs/constants.py @@ -3122,6 +3122,5 @@ "Cluster-wide encryption": "cluster_wide_encryption", "Storage class encryption": "storageclass_encryption", "In-transit encryption": "intransit_encryption", - "Block storage": "block_storage", "Object storage": "object_storage", } diff --git a/ocs_ci/ocs/ui/page_objects/encryption_module.py b/ocs_ci/ocs/ui/page_objects/encryption_module.py index 22e524eb4c5..b82e5bc114c 100644 --- a/ocs_ci/ocs/ui/page_objects/encryption_module.py +++ b/ocs_ci/ocs/ui/page_objects/encryption_module.py @@ -1,4 +1,4 @@ -from ocs_ci.ocs.ui.helpers_ui import logger, extract_encryption_status +from ocs_ci.ocs.ui.helpers_ui import logger from ocs_ci.ocs.constants import ENCRYPTION_DASHBOARD_CONTEXT_MAP from ocs_ci.ocs.ui.page_objects.page_navigator import PageNavigator @@ -15,10 +15,10 @@ def _get_encryption_summary(self, context_key): dict: Encryption summary for the given context. """ encryption_summary = { - "object_storage": {"status": None, "kms": ""}, - "cluster_wide_encryption": {"status": None, "kms": ""}, - "storageclass_encryption": {"status": None, "kms": ""}, - "intransit_encryption": {"status": None}, + "object_storage": {"status": False, "kms": False}, + "cluster_wide_encryption": {"status": False, "kms": False}, + "storageclass_encryption": {"status": False, "kms": False}, + "intransit_encryption": {"status": False}, } logger.info(f"Getting Encryption Summary for context: {context_key}") @@ -35,50 +35,46 @@ def _get_encryption_summary(self, context_key): ] ) - # Get elements for text and root + # Get the root element for encryption details encryption_content_location = self.validation_loc["encryption_summary"][ context_key ]["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] + # Extract headers and statuses + enc_headers = [ + head + for head in root_element.find_elements_by_tag_name("h6") + if head.text in ENCRYPTION_DASHBOARD_CONTEXT_MAP + ] + enc_status = [ + svg + for svg in root_element.find_elements_by_tag_name("svg") + if svg.get_attribute("color") + ] + + for header, svg in zip(enc_headers, enc_status): + context = ENCRYPTION_DASHBOARD_CONTEXT_MAP[header.text] + encryption_summary[context]["status"] = ( + svg.get_attribute("color") == "#3e8635" + ) + # Process encryption summary text current_context = None - for line in encryption_summary_text.split("\n"): - line = line.strip() + encryption_summary_text = self.get_element_text(encryption_content_location) + + for line in map(str.strip, encryption_summary_text.split("\n")): if line in ENCRYPTION_DASHBOARD_CONTEXT_MAP: current_context = ENCRYPTION_DASHBOARD_CONTEXT_MAP[line] - continue - - if ( - current_context - in [ - "object_storage", - "cluster_wide_encryption", - "storageclass_encryption", - ] - # and "External Key Management Service" in line - ): - if "External Key Management Service" in line: - encryption_summary[current_context]["kms"] = line.split(":")[ - -1 - ].strip() - encryption_summary[current_context]["status"] = ( - extract_encryption_status( - root_element, - self._get_svg_selector(context_key, current_context), - ) - ) - elif current_context == "intransit_encryption": - encryption_summary[current_context]["status"] = ( - extract_encryption_status( - root_element, - self._get_svg_selector(context_key, current_context), - ) + elif current_context and current_context in encryption_summary: + encryption_summary[current_context]["kms"] = ( + line.split(":")[-1].strip() + if "External Key Management Service" in line + else False ) logger.info(f"Encryption Summary for {context_key}: {encryption_summary}") @@ -92,36 +88,6 @@ def _get_encryption_summary(self, context_key): return encryption_summary - def _get_svg_selector(self, context_key, current_context): - """ - Get the appropriate SVG selector for extracting encryption status. - - Args: - context_key (str): The context key. - current_context (str): The current encryption context. - - Returns: - str: SVG selector path. - """ - selectors = { - "object_storage": { - "object_storage": "div.pf-v5-l-flex:nth-child(1) > div:nth-child(2) > svg", - "intransit_encryption": "div.pf-v5-l-flex:nth-child(4) > div:nth-child(2) > svg", - }, - "file_and_block": { - "cluster_wide_encryption": ( - "div.pf-m-align-items-center:nth-child(1) > " - "div:nth-child(2) > svg:nth-child(1)" - ), - "storageclass_encryption": ( - "div.pf-v5-l-flex:nth-child(6) > " - "div:nth-child(2) > svg:nth-child(1)" - ), - "intransit_encryption": "div.pf-v5-l-flex:nth-child(10) > div:nth-child(2) > svg", - }, - } - return selectors.get(context_key, {}).get(current_context, "") - def get_object_encryption_summary(self): """ Retrieve the encryption summary for the object details page.