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 14, 2025
1 parent 27ec5a6 commit 55064f3
Show file tree
Hide file tree
Showing 6 changed files with 354 additions and 1 deletion.
7 changes: 7 additions & 0 deletions ocs_ci/ocs/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3117,3 +3117,10 @@
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",
"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}")
107 changes: 107 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,107 @@
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


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": 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}")

# 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 the root element for encryption details
encryption_content_location = self.validation_loc["encryption_summary"][
context_key
]["encryption_content_data"]
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
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]
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}")

# 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_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
36 changes: 36 additions & 0 deletions ocs_ci/ocs/ui/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1794,6 +1794,41 @@
),
}

validation_4_18 = {
"encryption_summary": {
"file_and_block": {
"enabled": (
"//button[@class='pf-v5-c-button pf-m-link pf-m-inline' and "
"(text()='Enabled' or text()='Not 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' or text()='Not 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 +2070,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 55064f3

Please sign in to comment.