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 1, 2025
1 parent 8333f51 commit 230c70a
Show file tree
Hide file tree
Showing 6 changed files with 422 additions and 0 deletions.
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}")
99 changes: 99 additions & 0 deletions ocs_ci/ocs/ui/page_objects/block_and_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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


class BlockAndFile(StorageSystemDetails):
Expand Down Expand Up @@ -259,3 +260,101 @@ 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"
]
)

# Context and status mappings
context_map = {
"Cluster-wide encryption": "cluster_wide_encryption",
"Storage class encryption": "storageclass_encryption",
"In-transit encryption": "intransit_encryption",
"Block storage": "block_storage",
}

# 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 context_map:
current_context = 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
89 changes: 89 additions & 0 deletions ocs_ci/ocs/ui/page_objects/object_details_tab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
from ocs_ci.ocs.ui.helpers_ui import logger
from ocs_ci.ocs.ui.page_objects.storage_system_details import StorageSystemDetails
from ocs_ci.ocs.ui.helpers_ui import extract_encryption_status


class ObjectDetails(StorageSystemDetails):
def __init__(self):
StorageSystemDetails.__init__(self)

def get_encryption_summary(self):
"""
Collecting Encryption summary shown in the Object details page.
Returns:
encryption_summary (dict): encryption summary on object details page.
"""
encryption_summary = {
"object_storage": {"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"]["object"]["enabled"],
enable_screenshot=True,
)

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

# Context and status mappings
context_map = {
"Object storage": "object_storage",
"In-transit encryption": "intransit_encryption",
}

# Get elements for text and root
encryption_content_location = self.validation_loc["encryption_summary"][
"object"
]["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 context_map:
current_context = context_map[line]
continue

if (
current_context == "object_storage"
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(1) > div:nth-child(2) > svg",
)
elif current_context == "intransit_encryption":
encryption_summary[current_context][
"status"
] = extract_encryption_status(
root_element,
"div.pf-v5-l-flex:nth-child(4) > 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"]["object"]["close"],
enable_screenshot=True,
)

return encryption_summary
4 changes: 4 additions & 0 deletions ocs_ci/ocs/ui/page_objects/storage_system_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ 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()

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 @@ -1784,6 +1784,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": {
"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 @@ -2025,6 +2058,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 230c70a

Please sign in to comment.