function get_sd return 0 early if len(hosts) is 0
Prevent workload_stabilization strategy from failing in a network with 0 hosts. Change-Id: I9f1a9524923c14d958eb50a70dad379a6021b884 Closes-Bug: #1815059
This commit is contained in:
@@ -334,14 +334,17 @@ class WorkloadStabilization(base.WorkloadStabilizationBaseStrategy):
|
|||||||
def get_sd(self, hosts, meter_name):
|
def get_sd(self, hosts, meter_name):
|
||||||
"""Get standard deviation among hosts by specified meter"""
|
"""Get standard deviation among hosts by specified meter"""
|
||||||
mean = 0
|
mean = 0
|
||||||
variaton = 0
|
variation = 0
|
||||||
|
num_hosts = len(hosts)
|
||||||
|
if num_hosts == 0:
|
||||||
|
return 0
|
||||||
for host_id in hosts:
|
for host_id in hosts:
|
||||||
mean += hosts[host_id][meter_name]
|
mean += hosts[host_id][meter_name]
|
||||||
mean /= len(hosts)
|
mean /= num_hosts
|
||||||
for host_id in hosts:
|
for host_id in hosts:
|
||||||
variaton += (hosts[host_id][meter_name] - mean) ** 2
|
variation += (hosts[host_id][meter_name] - mean) ** 2
|
||||||
variaton /= len(hosts)
|
variation /= num_hosts
|
||||||
sd = math.sqrt(variaton)
|
sd = math.sqrt(variation)
|
||||||
return sd
|
return sd
|
||||||
|
|
||||||
def calculate_weighted_sd(self, sd_case):
|
def calculate_weighted_sd(self, sd_case):
|
||||||
|
|||||||
Reference in New Issue
Block a user