Skip to content

Commit

Permalink
Done block file encryption summary validation
Browse files Browse the repository at this point in the history
Signed-off-by: Parag Kamble <[email protected]>
  • Loading branch information
paraggit committed Dec 13, 2024
1 parent 03feb80 commit 1c9a71b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 53 deletions.
30 changes: 14 additions & 16 deletions ocs_ci/ocs/ui/page_objects/block_and_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ def get_block_file_encryption_summary(self):
"storageclass_encryption": {
"status": None,
"kms": "",
"block_storage": {"status": None},
},
"intransit_encryption": {"status": None},
}
Expand All @@ -282,9 +281,9 @@ def get_block_file_encryption_summary(self):
self.validation_loc["encryption_summary"]["file_and_block"]["enabled"],
enable_screenshot=True,
)
import time
from time import sleep

time.sleep(3)
sleep(3)

# Context and status mappings
context_map = {
Expand All @@ -293,7 +292,7 @@ def get_block_file_encryption_summary(self):
"In-transit encryption": "intransit_encryption",
"Block storage": "block_storage",
}
status_code = {"#3e8635": True, "#c9190b": False}
# status_code = {"#3e8635": True, "#c9190b": False}

# Get elements for text and root
encryption_content_location = self.validation_loc["encryption_summary"][
Expand All @@ -307,18 +306,20 @@ def get_block_file_encryption_summary(self):
root_element = root_elements[0]

# Function to extract status from an SVG element
def extract_status(svg_path, context):
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":
return status_code.get(svg_element.get_attribute("color"))
raise ValueError(f"Error Getting {context} status information")
if svg_element.get_attribute("data-test") == "success-icon":
return True
else:
return False
except Exception as e:
logger.error(f"Error extracting status for {context}: {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:
Expand All @@ -331,25 +332,22 @@ def extract_status(svg_path, context):
):
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)",
current_context,
"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)",
current_context,
"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(6) > div:nth-child(2) > svg:nth-child(1)",
current_context,
"div.pf-v5-l-flex:nth-child(10) > div:nth-child(2) > svg"
)

logger.info(f"Encryption Summary>>>>>>>>>: {encryption_summary}")
logger.info(f"Encryption Summary: {encryption_summary}")

# Close the popup
logger.info("Closing the popup")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,54 +38,47 @@ def test_encryption_configuration_dashboard(self, setup_ui_class):
# Retrieve encryption summary from the dashboard
encryption_summary = block_and_file_page.get_block_file_encryption_summary()

# Helper function to assert encryption details
def assert_encryption(key, condition, error_message):
assert condition, error_message
log.info(f"Encryption status for {key} is correct.")
# Helper function to validate encryption details
def validate_encryption(context, actual_status, expected_status, error_message):
assert actual_status == expected_status, error_message
log.info(f"{context} status is as expected: {actual_status}")

# Validate encryption configurations
# Validate cluster-wide encryption
cluster_wide_details = enc_details.get("clusterWide", {})
if isinstance(cluster_wide_details, dict):
if cluster_wide_details.get("status", False):
assert_encryption(
"ClusterWide Encryption",
encryption_summary["cluster_wide_encryption"]["status"],
"ClusterWide Encryption is not showing as enabled in the encryption summary dashboard.",
)

if cluster_wide_details.get("kms", {}).get("enable", False):
assert_encryption(
"ClusterWide KMS",
encryption_summary["cluster_wide_encryption"]["kms"],
"KMS is not mentioned in the encryption summary.",
)
validate_encryption(
"ClusterWide Encryption",
encryption_summary["cluster_wide_encryption"]["status"],
cluster_wide_details.get("status", False),
"ClusterWide Encryption is not showing correctly in the dashboard.",
)
validate_encryption(
"ClusterWide KMS",
encryption_summary["cluster_wide_encryption"]["kms"],
cluster_wide_details.get("kms", {}).get("enable", False),
"KMS is not mentioned in the encryption summary.",
)
else:
log.warning(
"ClusterWide Encryption details are not a dictionary, skipping checks."
)

# Safely validate storage class encryption
# Validate storage class encryption
storage_class_details = enc_details.get("storageClass", {})
if isinstance(storage_class_details, dict):
if storage_class_details.get("status", False):
assert_encryption(
"StorageClass Encryption",
encryption_summary["storageclass_encryption"]["status"],
"StorageClass encryption is not showing as enabled.",
)
validate_encryption(
"StorageClass Encryption",
encryption_summary["storageclass_encryption"]["status"],
storage_class_details.get("status", False),
"StorageClass encryption is not showing correctly in the dashboard.",
)
else:
log.warning("StorageClass details are not a dictionary, skipping checks.")

# Validate in-transit encryption
if intransit_encryption_status:
assert_encryption(
"InTransit Encryption Enabled",
encryption_summary["intransit_encryption"]["status"],
"InTransit Encryption is not enabled in the dashboard.",
)
else:
assert_encryption(
"InTransit Encryption Disabled",
not encryption_summary["intransit_encryption"]["status"],
"InTransit Encryption is showing as enabled in the dashboard, but it should be disabled.",
)
validate_encryption(
"InTransit Encryption",
encryption_summary["intransit_encryption"]["status"],
intransit_encryption_status,
"InTransit Encryption status is incorrect in the dashboard.",
)

0 comments on commit 1c9a71b

Please sign in to comment.