[Kimchi-devel] [PATCH 03/13] refactor model: Create a separated model for config resource
Aline Manera
alinefm at linux.vnet.ibm.com
Fri Jan 17 02:24:39 UTC 2014
From: Aline Manera <alinefm at br.ibm.com>
To avoid duplicating code in model and mockmodel, the common code related to
config resource (and its sub-resources) was added to model_/config.py
and the specific code for each backend (libvirt or mock) was added to
model_/libvirtbackend.py and model_/mockbackend.py
Signed-off-by: Aline Manera <alinefm at br.ibm.com>
---
src/kimchi/model_/config.py | 52 +++++++++++++++++++++++++++++++++++
src/kimchi/model_/libvirtbackend.py | 28 +++++++++++++++++++
src/kimchi/model_/mockbackend.py | 7 +++++
3 files changed, 87 insertions(+)
create mode 100644 src/kimchi/model_/config.py
diff --git a/src/kimchi/model_/config.py b/src/kimchi/model_/config.py
new file mode 100644
index 0000000..7c0a5d6
--- /dev/null
+++ b/src/kimchi/model_/config.py
@@ -0,0 +1,52 @@
+#
+# Project Kimchi
+#
+# Copyright IBM, Corp. 2013
+#
+# Authors:
+# Adam Litke <agl at linux.vnet.ibm.com>
+# Aline Manera <alinefm at linux.vnet.ibm.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+from kimchi.distroloader import DistroLoader
+from kimchi.exception import NotFoundError
+
+ERR_DISTRO_NOT_FOUND = "Distro '%s' not found."
+
+class Config(object):
+ pass
+
+class Capabilities(object):
+ def __init__(self, backend):
+ self.backend = backend
+
+ def lookup(self, ident):
+ return self.backend.get_capabilities()
+
+class Distros(object):
+ def __init__(self):
+ self._distroloader = DistroLoader()
+ self._distros = self._distroloader.get()
+
+ def get_list(self):
+ return self._distros.keys()
+
+class Distro(Distros):
+ def lookup(self, ident):
+ if ident not in self.get_list():
+ raise NotFoundError(ERR_DISTRO_NOT_FOUND % ident)
+
+ return self._distros[ident]
diff --git a/src/kimchi/model_/libvirtbackend.py b/src/kimchi/model_/libvirtbackend.py
index ea46a13..506b8c4 100644
--- a/src/kimchi/model_/libvirtbackend.py
+++ b/src/kimchi/model_/libvirtbackend.py
@@ -21,6 +21,7 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+import cherrypy
import fnmatch
import glob
import logging
@@ -30,6 +31,7 @@ import subprocess
from kimchi import config
from kimchi.asynctask import AsyncTask
+from kimchi.featuretests import FeatureTests
from kimchi.exception import OperationFailed
from kimchi.objectstore import ObjectStore
from kimchi.utils import kimchi_log
@@ -39,12 +41,38 @@ class LibvirtBackend(object):
self.objstore = ObjectStore(objstore_loc)
self.next_taskid = 1
+ # Subscribe function to set host capabilities to be run when cherrypy
+ # server is up
+ # It is needed because some features tests depends on the server
+ cherrypy.engine.subscribe('start', self._set_capabilities)
+
# Please add new possible debug report command here
# and implement the report generating function
# based on the new report command
self.report_tools = ({'cmd': 'sosreport --help',
'fn': self._sosreport_generate},)
+ def _set_capabilities(self):
+ kimchi_log.info("*** Running feature tests ***")
+ self.qemu_stream = FeatureTests.qemu_supports_iso_stream()
+ self.qemu_stream_dns = FeatureTests.qemu_iso_stream_dns()
+
+ self.libvirt_stream_protocols = []
+ for p in ['http', 'https', 'ftp', 'ftps', 'tftp']:
+ if FeatureTests.libvirt_supports_iso_stream(p):
+ self.libvirt_stream_protocols.append(p)
+
+ kimchi_log.info("*** Feature tests completed ***")
+ _set_capabilities.priority = 90
+
+ def get_capabilities(self):
+ report_tool = self._get_system_report_tool()
+
+ return {'libvirt_stream_protocols': self.libvirt_stream_protocols,
+ 'qemu_stream': self.qemu_stream,
+ 'screenshot': VMScreenshot.get_stream_test_result(),
+ 'system_report_tool': bool(report_tool)}
+
def gen_debugreport_file(self, name):
gen_cmd = self._get_system_report_tool()
if gen_cmd is None:
diff --git a/src/kimchi/model_/mockbackend.py b/src/kimchi/model_/mockbackend.py
index fa60fc1..d6b8925 100644
--- a/src/kimchi/model_/mockbackend.py
+++ b/src/kimchi/model_/mockbackend.py
@@ -33,6 +33,13 @@ class MockBackend(object):
self.objstore = ObjectStore(objstore_loc)
self.next_taskid = 1
+ def get_capabilities(self):
+ protocols = ['http', 'https', 'ftp', 'ftps', 'tftp']
+ return {'libvirt_stream_protocols': protocols,
+ 'qemu_stream': True,
+ 'screenshot': True,
+ 'system_report_tool': True}
+
def gen_debugreport_file(self, ident):
return self.add_task('', self._create_debugreport, ident)
--
1.7.10.4
More information about the Kimchi-devel
mailing list