Skip to content

Commit

Permalink
Created a EncryptionModule class and moved the encryption summary che…
Browse files Browse the repository at this point in the history
…ck functionality in same class

Signed-off-by: Parag Kamble <[email protected]>
  • Loading branch information
paraggit committed Jan 7, 2025
1 parent c36ccc0 commit 7bdacad
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 179 deletions.
92 changes: 0 additions & 92 deletions ocs_ci/ocs/ui/page_objects/block_and_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from ocs_ci.ocs.ui.page_objects.storage_system_details import StorageSystemDetails
from ocs_ci.ocs.ui.workload_ui import PvcCapacityDeploymentList, compare_mem_usage
from ocs_ci.utility.utils import TimeoutSampler
from ocs_ci.ocs.ui.helpers_ui import extract_encryption_status
from ocs_ci.ocs.constants import ENCRYPTION_DASHBOARD_CONTEXT_MAP


class BlockAndFile(StorageSystemDetails):
Expand Down Expand Up @@ -261,93 +259,3 @@ def get_avg_consumption_from_ui(self):
)
logger.info(f"'Average of storage consumption per day' from the UI : {average}")
return average

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": ""},
"storageclass_encryption": {
"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"]["file_and_block"]["enabled"],
enable_screenshot=True,
)

self.page_has_loaded(
module_loc=self.validation_loc["encryption_summary"]["file_and_block"][
"encryption_content_data"
]
)

# Get elements for text and root
encryption_content_location = self.validation_loc["encryption_summary"][
"file_and_block"
]["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]

# Process encryption summary text
current_context = None
for line in encryption_summary_text.split("\n"):
line = line.strip()
if line in ENCRYPTION_DASHBOARD_CONTEXT_MAP:
current_context = ENCRYPTION_DASHBOARD_CONTEXT_MAP[line]
continue

if (
current_context == "cluster_wide_encryption"
and "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,
"div.pf-m-align-items-center:nth-child(1) > div:nth-child(2) > svg:nth-child(1)",
)
)
elif (
current_context == "storageclass_encryption"
and "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,
"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_encryption_status(
root_element,
"div.pf-v5-l-flex:nth-child(10) > 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"]["file_and_block"]["close"],
enable_screenshot=True,
)

return encryption_summary
138 changes: 138 additions & 0 deletions ocs_ci/ocs/ui/page_objects/encryption_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
from ocs_ci.ocs.ui.helpers_ui import logger, extract_encryption_status
from ocs_ci.ocs.constants import ENCRYPTION_DASHBOARD_CONTEXT_MAP
from ocs_ci.ocs.ui.page_objects.page_navigator import PageNavigator


class EncryptionModule(PageNavigator):
def _get_encryption_summary(self, context_key):
"""
Generic method to collect encryption summary based on the context.
Args:
context_key (str): Key to determine the validation location.
Returns:
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},
}

logger.info(f"Getting Encryption Summary for context: {context_key}")

# Open the encryption summary popup
self.do_click(
self.validation_loc["encryption_summary"][context_key]["enabled"],
enable_screenshot=True,
)

self.page_has_loaded(
module_loc=self.validation_loc["encryption_summary"][context_key][
"encryption_content_data"
]
)

# Get elements for text and root
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]

# Process encryption summary text
current_context = None
for line in encryption_summary_text.split("\n"):
line = line.strip()
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
):
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),
)
)

logger.info(f"Encryption Summary for {context_key}: {encryption_summary}")

# Close the popup
logger.info("Closing the popup")
self.do_click(
self.validation_loc["encryption_summary"][context_key]["close"],
enable_screenshot=True,
)

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.
Returns:
dict: Encryption summary on object details page.
"""
return self._get_encryption_summary("object_storage")

def get_block_file_encryption_summary(self):
"""
Retrieve the encryption summary for the block and file page.
Returns:
dict: Encryption summary on block and file page.
"""
return self._get_encryption_summary("file_and_block")
81 changes: 0 additions & 81 deletions ocs_ci/ocs/ui/page_objects/object_details_tab.py

This file was deleted.

8 changes: 4 additions & 4 deletions ocs_ci/ocs/ui/page_objects/storage_system_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
from ocs_ci.ocs.ui.base_ui import logger, BaseUI
from ocs_ci.ocs.ui.page_objects.storage_system_tab import StorageSystemTab
from ocs_ci.utility import version
from ocs_ci.ocs.ui.page_objects.encryption_module import EncryptionModule


class StorageSystemDetails(StorageSystemTab):
class StorageSystemDetails(StorageSystemTab, EncryptionModule):
def __init__(self):
StorageSystemTab.__init__(self)
EncryptionModule.__init__(self)

def nav_details_overview(self):
logger.info("Click on Overview tab")
Expand All @@ -33,9 +35,7 @@ def nav_details_object(self):
else:
self.do_click(self.validation_loc["object"], enable_screenshot=True)

from ocs_ci.ocs.ui.page_objects.object_details_tab import ObjectDetails

return ObjectDetails()
return self

def nav_block_and_file(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion ocs_ci/ocs/ui/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1810,7 +1810,7 @@
By.XPATH,
),
},
"object": {
"object_storage": {
"enabled": (
"//button[@class='pf-v5-c-button pf-m-link pf-m-inline' and text()='Enabled']",
By.XPATH,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def test_object_storage_encryption_configuration_dashboard(self, setup_ui_class)
.nav_details_object()
)

encryption_summary = object_details_page.get_encryption_summary()
encryption_summary = object_details_page.get_object_encryption_summary()
log.info(f"Encryption Summary from page : {encryption_summary}")

# Validate Object Encryption Summary
Expand Down

0 comments on commit 7bdacad

Please sign in to comment.