use current weighted sd as min_sd when starting to simulate migrations

If it uses a specific value(usually 1 or 2) as the min_sd when starting
to simulate migrations. The first simulate_migration case will always be
less than the min_sd and come into the solution, even though the migration
will increase the weighted sd. This is unreasonable, and make migrations
among hosts back and forth

Change-Id: I7813c4c92c380c489c349444b85187c5611d9c92
Closes-Bug: #1739723
This commit is contained in:
suzhengwei 2017-12-25 15:58:37 +08:00 committed by Alexander Chadin
parent b69244f8ef
commit 96fa7f33ac
2 changed files with 15 additions and 4 deletions

View File

@ -379,6 +379,16 @@ class WorkloadStabilization(base.WorkloadStabilizationBaseStrategy):
migration_case.append(new_hosts)
return migration_case
def get_current_weighted_sd(self, hosts_load):
"""Calculate current weighted sd"""
current_sd = []
normalized_load = self.normalize_hosts_load(hosts_load)
for metric in self.metrics:
metric_sd = self.get_sd(normalized_load, metric)
current_sd.append(metric_sd)
current_sd.append(hosts_load)
return self.calculate_weighted_sd(current_sd[:-1])
def simulate_migrations(self, hosts):
"""Make sorted list of pairs instance:dst_host"""
def yield_nodes(nodes):
@ -393,14 +403,15 @@ class WorkloadStabilization(base.WorkloadStabilizationBaseStrategy):
yield nodes
instance_host_map = []
nodes = list(self.get_available_nodes())
nodes = sorted(list(self.get_available_nodes()))
current_weighted_sd = self.get_current_weighted_sd(hosts)
for src_host in nodes:
src_node = self.compute_model.get_node_by_uuid(src_host)
c_nodes = copy.copy(nodes)
c_nodes.remove(src_host)
node_list = yield_nodes(c_nodes)
for instance in self.compute_model.get_node_instances(src_node):
min_sd_case = {'value': len(self.metrics)}
min_sd_case = {'value': current_weighted_sd}
if instance.state not in [element.InstanceState.ACTIVE.value,
element.InstanceState.PAUSED.value]:
continue

View File

@ -228,9 +228,9 @@ class TestWorkloadStabilization(base.TestCase):
def test_simulate_migrations(self):
model = self.fake_cluster.generate_scenario_1()
self.m_model.return_value = model
self.strategy.host_choice = 'retry'
self.strategy.host_choice = 'fullsearch'
self.assertEqual(
8,
10,
len(self.strategy.simulate_migrations(self.hosts_load_assert)))
def test_check_threshold(self):