Skip to content

Commit

Permalink
Updating function call
Browse files Browse the repository at this point in the history
Signed-off-by: Shivam Durgbuns <sdurgbun@redhat.com>
  • Loading branch information
shivamdurgbuns committed Jun 5, 2024
1 parent 7eb3d7b commit 028ab94
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
19 changes: 0 additions & 19 deletions ocs_ci/helpers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4776,22 +4776,3 @@ def is_rbd_default_storage_class(custom_sc=None):

logger.error("Storageclass {default_rbd_sc} is not a default RBD StorageClass.")
return False
def custom_round(number):
"""Rounds a number down for values ending in exactly ".5".
Args:
number: The number to round.
Returns:
The rounded number (down for values ending in ".5").
"""
# Convert the number to a string to check the decimal part
number_str = str(number)

# Check if the decimal part exists and ends in ".5"
if "." in number_str and number_str.endswith(".5"):
# Round down if it ends in ".5"
return int(number)
else:
# Use regular rounding for other cases
return round(number)
26 changes: 23 additions & 3 deletions ocs_ci/ocs/ui/block_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from ocs_ci.ocs.ui.page_objects.page_navigator import PageNavigator
from selenium.webdriver.common.by import By
from ocs_ci.helpers.helpers import create_unique_resource_name, custom_round
from ocs_ci.helpers.helpers import create_unique_resource_name
from ocs_ci.ocs.exceptions import PoolStateIsUnknow
import ocs_ci.ocs.resources.pod as pod
from ocs_ci.ocs.ui.page_objects.block_and_file import BlockAndFile
Expand Down Expand Up @@ -437,8 +437,8 @@ def cross_check_raw_capacity(self, pool_name):
# python function rounds from .5
# ex. cli is doing 157.5 to 157 where as python round function will do 158
if (
(custom_round(float(used_capacity_in_CLI)))
== custom_round(float(used_capacity_in_UI))
(self.custom_round(float(used_capacity_in_CLI)))
== self.custom_round(float(used_capacity_in_UI))
) and (unit == used_capacity_unit_in_UI):
logger.info("UI values did match as per CLI for the Raw Capacity")
return True
Expand All @@ -465,3 +465,23 @@ def select_blockpool(self, pool_name):
locator=format_locator(self.generic_locators["blockpool_name"], pool_name)
)
return True

def custom_round(self, number):
"""Rounds a number down for values ending in exactly ".5".
Args:
number: The number to round.
Returns:
The rounded number (down for values ending in ".5").
"""
# Convert the number to a string to check the decimal part
number_str = str(number)

# Check if the decimal part exists and ends in ".5"
if "." in number_str and number_str.endswith(".5"):
# Round down if it ends in ".5"
return int(number)
else:
# Use regular rounding for other cases
return round(number)
8 changes: 6 additions & 2 deletions tests/cross_functional/ui/test_create_pool_block_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,14 @@ def test_create_delete_pool(

# Checking the raw capcity is loaded on the UI or not.
blockpool_ui_object = BlockPoolUI()
assert blockpool_ui_object.pool_raw_capacity_loaded(self.pool_name)
assert blockpool_ui_object.pool_raw_capacity_loaded(
self.pool_name
), "Block pool raw capacity is not visible on UI"

# Cross checking the raw capacity of the blockpool between CLI and UI
assert blockpool_ui_object.cross_check_raw_capacity(self.pool_name)
assert blockpool_ui_object.cross_check_raw_capacity(
self.pool_name
), "Block pool raw capacity did not matched with UI"

# Checking Results for compression and replication
if compression:
Expand Down

0 comments on commit 028ab94

Please sign in to comment.