[Kimchi-devel] [PATCH] Fix Kimchi model
Lucio Correia
luciojhc at linux.vnet.ibm.com
Sun Oct 18 15:15:32 UTC 2015
With the Kimchi/Wok split, the Tasks model is now outside of
Kimchi's model tree and needs to be imported separately.
This patch does that and creates function get_instances() to
avoid code duplication.
With this fix Kimchi tests have about 7 errors less.
Signed-off-by: Lucio Correia <luciojhc at linux.vnet.ibm.com>
---
src/wok/plugins/kimchi/model/model.py | 28 +++++++++++++++++++++-------
1 file changed, 21 insertions(+), 7 deletions(-)
diff --git a/src/wok/plugins/kimchi/model/model.py b/src/wok/plugins/kimchi/model/model.py
index 0c94f63..39097c4 100644
--- a/src/wok/plugins/kimchi/model/model.py
+++ b/src/wok/plugins/kimchi/model/model.py
@@ -30,23 +30,37 @@ from libvirtconnection import LibvirtConnection
class Model(BaseModel):
def __init__(self, libvirt_uri=None, objstore_loc=None):
+ def get_instances(module_name):
+ instances = []
+ module = import_module(module_name)
+ members = inspect.getmembers(module, inspect.isclass)
+ for cls_name, instance in members:
+ if inspect.getmodule(instance) == module and \
+ cls_name.endswith('Model'):
+ instances.append(instance)
+
+ return instances
+
self.objstore = ObjectStore(objstore_loc)
self.conn = LibvirtConnection(libvirt_uri)
kargs = {'objstore': self.objstore, 'conn': self.conn}
+ models = []
+ # Import task model from Wok
+ instances = get_instances('wok.model.tasks')
+ for instance in instances:
+ models.append(instance(**kargs))
+
+ # Import all Kimchi plugin models
this = os.path.basename(__file__)
this_mod = os.path.splitext(this)[0]
- models = []
for mod_name in listPathModules(os.path.dirname(__file__)):
if mod_name.startswith("_") or mod_name == this_mod:
continue
- module = import_module('plugins.kimchi.model.' + mod_name)
- members = inspect.getmembers(module, inspect.isclass)
- for cls_name, instance in members:
- if inspect.getmodule(instance) == module:
- if cls_name.endswith('Model'):
- models.append(instance(**kargs))
+ instances = get_instances('plugins.kimchi.model.' + mod_name)
+ for instance in instances:
+ models.append(instance(**kargs))
return super(Model, self).__init__(models)
--
1.9.1
More information about the Kimchi-devel
mailing list