Skip to content

Commit

Permalink
Test Automation for encryption dashboard summary
Browse files Browse the repository at this point in the history
Signed-off-by: Parag Kamble <[email protected]>
  • Loading branch information
paraggit committed Jan 8, 2025
1 parent 27ec5a6 commit 2261415
Show file tree
Hide file tree
Showing 6 changed files with 381 additions and 1 deletion.
8 changes: 8 additions & 0 deletions ocs_ci/ocs/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3117,3 +3117,11 @@
MACHINE_POOL_ACTIONS = [CREATE, EDIT, DELETE]
# MDR multicluster roles
MDR_ROLES = ["ActiveACM", "PassiveACM", "PrimaryODF", "SecondaryODF"]

ENCRYPTION_DASHBOARD_CONTEXT_MAP = {
"Cluster-wide encryption": "cluster_wide_encryption",
"Storage class encryption": "storageclass_encryption",
"In-transit encryption": "intransit_encryption",
"Block storage": "block_storage",
"Object storage": "object_storage",
}
25 changes: 25 additions & 0 deletions ocs_ci/ocs/ui/helpers_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ocs_ci.ocs.ui.base_ui import login_ui, close_browser
from ocs_ci.ocs.ui.add_replace_device_ui import AddReplaceDeviceUI
from ocs_ci.ocs.resources.storage_cluster import get_deviceset_count, get_osd_size
from ocs_ci.ocs.exceptions import ResourceNotFoundError

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -217,3 +218,27 @@ def is_ui_deployment():
return True

return False


def extract_encryption_status(root_element, svg_path):
"""Function to extract encryption status from an SVG element
Args:
root_element (str): Dom root element
svg_element (str): svg element path
Returns:
bool: if encryption status is enable for given element return True otherwise False.
Raises:
ResourceNotFoundError: If given resource is not found.
"""
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:
raise ResourceNotFoundError(f"Given SVG element is not Found: {e}")
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")
6 changes: 5 additions & 1 deletion 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,6 +35,8 @@ def nav_details_object(self):
else:
self.do_click(self.validation_loc["object"], enable_screenshot=True)

return self

def nav_block_and_file(self):
"""
Accessible only at StorageSystems / StorageSystem details / Overview
Expand Down
34 changes: 34 additions & 0 deletions ocs_ci/ocs/ui/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1794,6 +1794,39 @@
),
}

validation_4_18 = {
"encryption_summary": {
"file_and_block": {
"enabled": (
"//button[@class='pf-v5-c-button pf-m-link pf-m-inline' and text()='Enabled']",
By.XPATH,
),
"close": (
"//button[@class='pf-v5-c-button pf-m-plain' and @aria-label='Close']",
By.XPATH,
),
"encryption_content_data": (
"//div[@class='pf-v5-c-popover__body']",
By.XPATH,
),
},
"object_storage": {
"enabled": (
"//button[@class='pf-v5-c-button pf-m-link pf-m-inline' and text()='Enabled']",
By.XPATH,
),
"close": (
"//button[@class='pf-v5-c-button pf-m-plain' and @aria-label='Close']",
By.XPATH,
),
"encryption_content_data": (
"//div[@class='pf-v5-c-popover__content']",
By.XPATH,
),
},
}
}

topology = {
"topology_graph": ("//*[@data-kind='graph']", By.XPATH),
"node_label": ("//*[@class='pf-topology__node__label']", By.XPATH),
Expand Down Expand Up @@ -2035,6 +2068,7 @@
**validation_4_13,
**validation_4_14,
**validation_4_17,
**validation_4_18,
},
"block_pool": {**block_pool, **block_pool_4_12, **block_pool_4_13},
"storageclass": {**storageclass, **storageclass_4_9},
Expand Down
Loading

0 comments on commit 2261415

Please sign in to comment.