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

Fixing issue by adding range of +-1.0 numbers to avoid the errors #10764

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
36 changes: 14 additions & 22 deletions ocs_ci/ocs/ui/block_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ def cross_check_raw_capacity(self, pool_name):
bool: True if raw capacity of the blockpool is is same in GUI as obtained from CLI, otherwise False

"""
import numpy as np

logger.info(
"Checking if the Block Pool Raw Capacity is same in GUI as obtained from CLI"
)
Expand Down Expand Up @@ -442,9 +444,19 @@ def cross_check_raw_capacity(self, pool_name):
# created custom round method because the cli is rounding the number after .5 and
# python function rounds from .5
# ex. cli is doing 157.5 to 157 where as python round function will do 158
value_in_UI = float(used_capacity_in_UI)
lower_bound = value_in_UI - 1
upper_bound = value_in_UI + 1 # Add 1 to include the upper bound
step = 0.1

range_list = [
round(num, 1)
for num in np.arange(lower_bound, upper_bound + step, step)
]
if (
(self.custom_round(float(used_capacity_in_CLI)))
== self.custom_round(float(used_capacity_in_UI))
# adding range of +-1 point to avoid error as mentioned in issue/10750
(float(used_capacity_in_CLI))
in range_list
) and (unit == used_capacity_unit_in_UI):
logger.info("UI values did match as per CLI for the Raw Capacity")
return True
Expand All @@ -471,23 +483,3 @@ 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)
Loading