Skip to content

Commit

Permalink
removed css path and kept element filtering logic
Browse files Browse the repository at this point in the history
Signed-off-by: Parag Kamble <[email protected]>
  • Loading branch information
paraggit committed Jan 14, 2025
1 parent cc6031e commit f7f4211
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 67 deletions.
1 change: 0 additions & 1 deletion ocs_ci/ocs/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
98 changes: 32 additions & 66 deletions ocs_ci/ocs/ui/page_objects/encryption_module.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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}")
Expand All @@ -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}")
Expand All @@ -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.
Expand Down

0 comments on commit f7f4211

Please sign in to comment.