Fix workload stabilization strategy to ignore disabled hosts
Change-Id: Ib5244da196111fac03b1ac4b756a59ad15deb778 Closes-Bug: #1640102
This commit is contained in:
@@ -218,10 +218,16 @@ class WorkloadStabilization(base.WorkloadStabilizationBaseStrategy):
|
|||||||
|
|
||||||
return normalized_hosts
|
return normalized_hosts
|
||||||
|
|
||||||
|
def get_available_nodes(self):
|
||||||
|
return {node_uuid: node for node_uuid, node in
|
||||||
|
self.compute_model.get_all_compute_nodes().items()
|
||||||
|
if node.state == element.ServiceState.ONLINE.value and
|
||||||
|
node.status == element.ServiceState.ENABLED.value}
|
||||||
|
|
||||||
def get_hosts_load(self):
|
def get_hosts_load(self):
|
||||||
"""Get load of every host by gathering instances load"""
|
"""Get load of every available host by gathering instances load"""
|
||||||
hosts_load = {}
|
hosts_load = {}
|
||||||
for node_id in self.compute_model.get_all_compute_nodes():
|
for node_id in self.get_available_nodes():
|
||||||
hosts_load[node_id] = {}
|
hosts_load[node_id] = {}
|
||||||
host_vcpus = self.compute_model.get_resource_by_uuid(
|
host_vcpus = self.compute_model.get_resource_by_uuid(
|
||||||
element.ResourceType.cpu_cores).get_capacity(
|
element.ResourceType.cpu_cores).get_capacity(
|
||||||
@@ -320,7 +326,7 @@ class WorkloadStabilization(base.WorkloadStabilizationBaseStrategy):
|
|||||||
yield nodes
|
yield nodes
|
||||||
|
|
||||||
instance_host_map = []
|
instance_host_map = []
|
||||||
nodes = list(self.compute_model.get_all_compute_nodes())
|
nodes = list(self.get_available_nodes())
|
||||||
for source_hp_id in nodes:
|
for source_hp_id in nodes:
|
||||||
c_nodes = copy.copy(nodes)
|
c_nodes = copy.copy(nodes)
|
||||||
c_nodes.remove(source_hp_id)
|
c_nodes.remove(source_hp_id)
|
||||||
|
|||||||
@@ -112,6 +112,11 @@ class TestWorkloadStabilization(base.TestCase):
|
|||||||
normalized_hosts,
|
normalized_hosts,
|
||||||
self.strategy.normalize_hosts_load(fake_hosts))
|
self.strategy.normalize_hosts_load(fake_hosts))
|
||||||
|
|
||||||
|
def test_get_available_nodes(self):
|
||||||
|
self.m_model.return_value = self.fake_cluster. \
|
||||||
|
generate_scenario_9_with_3_active_plus_1_disabled_nodes()
|
||||||
|
self.assertEqual(3, len(self.strategy.get_available_nodes()))
|
||||||
|
|
||||||
def test_get_hosts_load(self):
|
def test_get_hosts_load(self):
|
||||||
self.m_model.return_value = self.fake_cluster.generate_scenario_1()
|
self.m_model.return_value = self.fake_cluster.generate_scenario_1()
|
||||||
self.assertEqual(self.strategy.get_hosts_load(),
|
self.assertEqual(self.strategy.get_hosts_load(),
|
||||||
|
|||||||
Reference in New Issue
Block a user