commit e2e2721c569cfe157a7b5deaf47d940a5ab8103d
Author: Ondrej Lichtner <olichtne(a)redhat.com>
Date: Wed Sep 11 15:10:25 2013 +0200
SlavePool: fix map_setup_virt method
This commit reimplements the method _map_setup_virt because it turned
out that it didn't work properly for some cases. The problem was there
was no backtracking for machine matches, and therefore lnst wouldn't
find a match even if there was one.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
Signed-off-by: Jiri Pirko <jiri(a)resnulli.us>
lnst/Controller/SlavePool.py | 51 +++++++++++++++++++++++++++--------------
1 files changed, 33 insertions(+), 18 deletions(-)
---
diff --git a/lnst/Controller/SlavePool.py b/lnst/Controller/SlavePool.py
index 686f20f..24724be 100644
--- a/lnst/Controller/SlavePool.py
+++ b/lnst/Controller/SlavePool.py
@@ -692,24 +692,39 @@ class SetupMapper:
return True
+ @staticmethod
+ def _get_machine_with_most_params(machines):
+ max_machine = None
+ max_len = 0
+ for m_id, m in machines.iteritems():
+ if len(m["params"]) >= max_len:
+ max_len = len(m["params"])
+ max_machine = m_id
+
+ return max_machine
+
def _map_setup_virt(self, template_machines, pool_machines):
- available = set()
- matches = set()
- for m_id in pool_machines.iterkeys():
- available.add(m_id)
-
- for tm_id, tm in template_machines.iteritems():
- match = None
- for am_id in available:
- if self._machine_matches(tm, pool_machines[am_id]):
- match = (tm_id, am_id)
- available.remove(am_id)
- break
+ if len(template_machines) <= 0:
+ return True
- if match:
- matches.add(match)
- else:
- return False
+ machine_id = self._get_machine_with_most_params(template_machines)
+ machine = template_machines[machine_id]
- self._machine_map = list(matches)
- return True
+ for pm_id, pm in pool_machines.iteritems():
+ if not self._machine_matches(machine, pm):
+ continue
+
+ self._machine_map.add((machine_id, pm_id))
+
+ new_pool = copy.deepcopy(pool_machines)
+ del new_pool[pm_id]
+
+ new_template = copy.deepcopy(template_machines)
+ del new_template[machine_id]
+
+ if self._map_setup_virt(new_template, new_pool):
+ return True
+
+ self._machine_map.discard((machine, possible_match))
+
+ return False
Show replies by date