Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Automation for encryption dashboard summary #11043

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 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 selenium.webdriver.common.by import By


class BlockAndFile(StorageSystemDetails):
Expand Down Expand Up @@ -259,3 +260,102 @@ 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,
)
from time import sleep
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There must be some other way to check it.
You can try this https://github.com/red-hat-storage/ocs-ci/blob/master/ocs_ci/ocs/ui/base_ui.py#L490 or other wait functions for elements.


sleep(3)

# Context and status mappings
context_map = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is constant we can move it to constants.

"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]

# Function to extract status from an SVG element
def extract_status(svg_path):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc for the function and if it can help other tests please move it.

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:
logger.error(f"Error extracting status: {e}")
return None

# 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_status(
"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_status(
"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_status(
"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
94 changes: 94 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,94 @@
import time

from ocs_ci.ocs.ui.helpers_ui import logger
from ocs_ci.ocs.ui.page_objects.storage_system_details import StorageSystemDetails
from selenium.webdriver.common.by import By


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,
)

time.sleep(3)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above


# 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]

# Function to extract status from an SVG element
def extract_status(svg_path):
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:
logger.error(f"Error extracting status: {e}")
return None

# 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_status(
"div.pf-v5-l-flex:nth-child(1) > div:nth-child(2) > svg"
)
elif current_context == "intransit_encryption":
encryption_summary[current_context]["status"] = extract_status(
"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
Loading