-
Notifications
You must be signed in to change notification settings - Fork 170
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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): | ||
|
@@ -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 | ||
|
||
sleep(3) | ||
|
||
# Context and status mappings | ||
context_map = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
There was a problem hiding this comment.
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.