[Kimchi-devel] [PATCH] [Kimchi] Reverting model/config.py deleted on last commit

Paulo Ricardo Paz Vital pvital at linux.vnet.ibm.com
Tue Dec 1 15:46:46 UTC 2015


Tested-by: Paulo Vital <pvital at linux.vnet.ibm.com>
Reviewed-by: Paulo Vital <pvital at linux.vnet.ibm.com>

On 12/01/2015 01:37 PM, Ramon Medeiros wrote:
> The file was wrongly removed on last commit. Restore it to the correct
> location.
> 
> Signed-off-by: Ramon Medeiros <ramonn at linux.vnet.ibm.com>
> ---
>  model/config.py | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 155 insertions(+)
>  create mode 100644 model/config.py
> 
> diff --git a/model/config.py b/model/config.py
> new file mode 100644
> index 0000000..e552edb
> --- /dev/null
> +++ b/model/config.py
> @@ -0,0 +1,155 @@
> +#
> +# Project Kimchi
> +#
> +# Copyright IBM, Corp. 2014-2015
> +#
> +# 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
> +
> +import cherrypy
> +from multiprocessing.pool import ThreadPool
> +
> +from wok.basemodel import Singleton
> +from wok.config import config as kconfig
> +from wok.config import get_version
> +from wok.exception import NotFoundError
> +from wok.utils import run_command, wok_log
> +
> +from wok.plugins.kimchi.config import find_qemu_binary
> +from wok.plugins.kimchi.distroloader import DistroLoader
> +from wok.plugins.kimchi.model.featuretests import FeatureTests
> +from wok.plugins.kimchi.model.featuretests import FEATURETEST_POOL_NAME
> +from wok.plugins.kimchi.model.featuretests import FEATURETEST_VM_NAME
> +from wok.plugins.kimchi.screenshot import VMScreenshot
> +from wok.plugins.kimchi.utils import check_url_path
> +
> +
> +class ConfigModel(object):
> +    def __init__(self, **kargs):
> +        pass
> +
> +    def lookup(self, name):
> +        proxy_port = kconfig.get('display', 'display_proxy_port')
> +        return {'display_proxy_port': proxy_port,
> +                'version': get_version()}
> +
> +
> +class CapabilitiesModel(object):
> +    __metaclass__ = Singleton
> +
> +    def __init__(self, **kargs):
> +        self.conn = kargs['conn']
> +        self.qemu_stream = False
> +        self.libvirt_stream_protocols = []
> +        self.fc_host_support = False
> +        self.kernel_vfio = False
> +        self.mem_hotplug_support = False
> +
> +        # 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)
> +
> +        # Subscribe function to clean any Kimchi leftovers
> +        cherrypy.engine.subscribe('stop', self._clean_leftovers)
> +
> +    def _clean_leftovers(self):
> +        conn = self.conn.get()
> +        FeatureTests.disable_libvirt_error_logging()
> +        try:
> +            dom = conn.lookupByName(FEATURETEST_VM_NAME)
> +            dom.undefine()
> +        except Exception:
> +            # Any exception can be ignored here
> +            pass
> +
> +        try:
> +            pool = conn.storagePoolLookupByName(FEATURETEST_POOL_NAME)
> +            pool.undefine()
> +        except Exception:
> +            # Any exception can be ignored here
> +            pass
> +
> +        FeatureTests.enable_libvirt_error_logging()
> +
> +    def _set_capabilities(self):
> +        wok_log.info("*** Running feature tests ***")
> +        conn = self.conn.get()
> +        self.qemu_stream = FeatureTests.qemu_supports_iso_stream()
> +        self.nfs_target_probe = FeatureTests.libvirt_support_nfs_probe(conn)
> +        self.fc_host_support = FeatureTests.libvirt_support_fc_host(conn)
> +        self.kernel_vfio = FeatureTests.kernel_support_vfio()
> +        self.mem_hotplug_support = FeatureTests.has_mem_hotplug_support(conn)
> +
> +        self.libvirt_stream_protocols = []
> +        for p in ['http', 'https', 'ftp', 'ftps', 'tftp']:
> +            if FeatureTests.libvirt_supports_iso_stream(conn, p):
> +                self.libvirt_stream_protocols.append(p)
> +
> +        wok_log.info("*** Feature tests completed ***")
> +    _set_capabilities.priority = 90
> +
> +    def _qemu_support_spice(self):
> +        qemu_path = find_qemu_binary(find_emulator=True)
> +        out, err, rc = run_command(['ldd', qemu_path])
> +        if rc != 0:
> +            wok_log.error('Failed to find qemu binary dependencies: %s',
> +                          err)
> +            return False
> +        for line in out.split('\n'):
> +            if line.lstrip().startswith('libspice-server.so'):
> +                return True
> +        return False
> +
> +    def lookup(self, *ident):
> +        return {'libvirt_stream_protocols': self.libvirt_stream_protocols,
> +                'qemu_spice': self._qemu_support_spice(),
> +                'qemu_stream': self.qemu_stream,
> +                'screenshot': VMScreenshot.get_stream_test_result(),
> +                'federation': kconfig.get("server", "federation"),
> +                'auth': kconfig.get("authentication", "method"),
> +                'kernel_vfio': self.kernel_vfio,
> +                'nm_running': FeatureTests.is_nm_running(),
> +                'mem_hotplug_support': self.mem_hotplug_support
> +                }
> +
> +
> +class DistrosModel(object):
> +    def __init__(self, **kargs):
> +        distroloader = DistroLoader()
> +        self.distros = distroloader.get()
> +
> +    def get_list(self):
> +        def validate_distro(distro):
> +            if check_url_path(distro['path']):
> +                return distro['name']
> +
> +        n_processes = len(self.distros.keys())
> +        pool = ThreadPool(processes=n_processes)
> +        map_res = pool.map_async(validate_distro, self.distros.values())
> +        pool.close()
> +        pool.join()
> +        res = list(set(map_res.get()) - set([None]))
> +        return sorted(res)
> +
> +
> +class DistroModel(object):
> +    def __init__(self, **kargs):
> +        self._distros = DistrosModel()
> +
> +    def lookup(self, name):
> +        try:
> +            return self._distros.distros[name]
> +        except KeyError:
> +            raise NotFoundError("KCHDISTRO0001E", {'name': name})
> 

-- 
---
Paulo Ricardo Paz Vital
IBM Linux Technology Center




More information about the Kimchi-devel mailing list