mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Fix div-by-zero when svc weight is 0 for all masters in location
The relative service weight output tries to show the relative chance that any given master in a locaiton will be picked. This didn't account for all masters having a weight of 0 which would result in a divide-by-zero error. Implement the following rules: 1. If all masters have weight == 0 then all are equally weighted. 2. If any masters have weight == 0 then they have an extremely small chance of being chosen, percentage is 0.1. 3. Otherwise it's percentage change is based on the sum of the weights of non-zero masters. https://pagure.io/freeipa/issue/8135 Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
This commit is contained in:
@@ -224,10 +224,30 @@ class location_show(LDAPRetrieve):
|
||||
if 'DNS server' in s_roles:
|
||||
dns_servers.append(s_name)
|
||||
|
||||
# 1. If all masters have weight == 0 then all are equally
|
||||
# weighted.
|
||||
# 2. If any masters have weight == 0 then they have an
|
||||
# extremely small chance of being chosen, percentage is
|
||||
# 0.1.
|
||||
# 3. Otherwise it's percentage change is based on the sum of
|
||||
# the weights of non-zero masters.
|
||||
dividend = 100.0
|
||||
if weight_sum != 0:
|
||||
for server in servers_additional_info.values():
|
||||
if int(server['ipaserviceweight'][0]) == 0:
|
||||
dividend = dividend - 0.1
|
||||
for server in servers_additional_info.values():
|
||||
if weight_sum == 0:
|
||||
val = 100 / len(servers)
|
||||
elif int(server['ipaserviceweight'][0]) == 0:
|
||||
val = 0.1
|
||||
else:
|
||||
val = (
|
||||
int(server['ipaserviceweight'][0]) *
|
||||
dividend / weight_sum
|
||||
)
|
||||
server['service_relative_weight'] = [
|
||||
u'{:.1f}%'.format(
|
||||
int(server['ipaserviceweight'][0])*100.0/weight_sum)
|
||||
u'{:.1f}%'.format(val)
|
||||
]
|
||||
if servers_name:
|
||||
result['result']['servers_server'] = servers_name
|
||||
|
||||
Reference in New Issue
Block a user