[Kimchi-devel] [PATCH] Do not resolve hostname to IP in using remote ISOs

Daniel Henrique Barboza dhbarboza82 at gmail.com
Mon Apr 27 19:26:15 UTC 2015


Reviewed-by: Daniel Barboza <dhbarboza82 at gmail.com>

On 04/27/2015 03:50 PM, Aline Manera wrote:
> Due a limitation in old versions of qemu-io (qemu-io was not able to resolve
> hostnames preveting the ISO streaming support), Kimchi automatically
> resolved the hostname to IP to workaround this problem.
> As all the most used Linux distributions (RHEl7.1, Ubuntu 14.10, Fedora
> 21 and openSUSE 13.2) have a working version of qemu-io, Kimchi does not
> need to care about it anymore.
>
> It also fixes the issue #436
>
> Signed-off-by: Aline Manera <alinefm at linux.vnet.ibm.com>
> Signed-off-by: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>
> ---
>   src/kimchi/model/config.py       |  2 --
>   src/kimchi/model/featuretests.py | 26 --------------------------
>   src/kimchi/model/utils.py        | 11 -----------
>   src/kimchi/model/vms.py          |  1 -
>   src/kimchi/model/vmstorages.py   | 10 +++-------
>   src/kimchi/vmtemplate.py         | 12 ++----------
>   tests/test_model.py              | 11 +----------
>   7 files changed, 6 insertions(+), 67 deletions(-)
>
> diff --git a/src/kimchi/model/config.py b/src/kimchi/model/config.py
> index a417c9b..ca0a74b 100644
> --- a/src/kimchi/model/config.py
> +++ b/src/kimchi/model/config.py
> @@ -51,7 +51,6 @@ class CapabilitiesModel(object):
>       def __init__(self, **kargs):
>           self.conn = kargs['conn']
>           self.qemu_stream = False
> -        self.qemu_stream_dns = False
>           self.libvirt_stream_protocols = []
>           self.fc_host_support = False
>           self.metadata_support = False
> @@ -88,7 +87,6 @@ class CapabilitiesModel(object):
>           kimchi_log.info("*** Running feature tests ***")
>           conn = self.conn.get()
>           self.qemu_stream = FeatureTests.qemu_supports_iso_stream()
> -        self.qemu_stream_dns = FeatureTests.qemu_iso_stream_dns()
>           self.nfs_target_probe = FeatureTests.libvirt_support_nfs_probe(conn)
>           self.fc_host_support = FeatureTests.libvirt_support_fc_host(conn)
>           self.metadata_support = FeatureTests.has_metadata_support(conn)
> diff --git a/src/kimchi/model/featuretests.py b/src/kimchi/model/featuretests.py
> index 8cbe31d..9400151 100644
> --- a/src/kimchi/model/featuretests.py
> +++ b/src/kimchi/model/featuretests.py
> @@ -21,9 +21,7 @@ import cherrypy
>   import libvirt
>   import lxml.etree as ET
>   import platform
> -import socket
>   import subprocess
> -import threading
>   
>   from lxml.builder import E
>   
> @@ -153,30 +151,6 @@ class FeatureTests(object):
>           return len(stderr) == 0
>   
>       @staticmethod
> -    @servermethod
> -    def qemu_iso_stream_dns():
> -        host = socket.getfqdn(cherrypy.server.socket_host)
> -        port = cherrypy.server.socket_port
> -        cmd = ["qemu-io", "-r", "http://%s:%d/images/icon-fedora.png" %
> -               (host, port), "-c", "'read -v 0 512'"]
> -        proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
> -                                stderr=subprocess.PIPE)
> -
> -        thread = threading.Thread(target=proc.communicate)
> -        thread.start()
> -        thread.join(5)
> -
> -        if thread.is_alive():
> -            proc.kill()
> -            thread.join()
> -            return False
> -
> -        if proc.returncode != 0:
> -            return False
> -
> -        return True
> -
> -    @staticmethod
>       def libvirt_support_fc_host(conn):
>           try:
>               FeatureTests.disable_libvirt_error_logging()
> diff --git a/src/kimchi/model/utils.py b/src/kimchi/model/utils.py
> index b2739b2..0c9d519 100644
> --- a/src/kimchi/model/utils.py
> +++ b/src/kimchi/model/utils.py
> @@ -18,8 +18,6 @@
>   # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
>   
>   import libvirt
> -import socket
> -import urlparse
>   from lxml import etree, objectify
>   from lxml.builder import E, ElementMaker
>   
> @@ -41,15 +39,6 @@ def get_vm_name(vm_name, t_name, name_list):
>       raise OperationFailed("KCHUTILS0003E")
>   
>   
> -def check_remote_disk_path(path, qemu_stream_dns):
> -    hostname = urlparse.urlparse(path).hostname
> -    if hostname is not None and not qemu_stream_dns:
> -        ip = socket.gethostbyname(hostname)
> -        return path.replace(hostname, ip)
> -
> -    return path
> -
> -
>   def get_vm_config_flag(dom, mode="persistent"):
>       # libvirt.VIR_DOMAIN_AFFECT_CURRENT is 0
>       # VIR_DOMAIN_AFFECT_LIVE is 1, VIR_DOMAIN_AFFECT_CONFIG is 2
> diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py
> index c8267c1..a6ca27b 100644
> --- a/src/kimchi/model/vms.py
> +++ b/src/kimchi/model/vms.py
> @@ -125,7 +125,6 @@ class VMsModel(object):
>           stream_protocols = self.caps.libvirt_stream_protocols
>           xml = t.to_vm_xml(name, vm_uuid,
>                             libvirt_stream_protocols=stream_protocols,
> -                          qemu_stream_dns=self.caps.qemu_stream_dns,
>                             graphics=graphics,
>                             volumes=vol_list)
>   
> diff --git a/src/kimchi/model/vmstorages.py b/src/kimchi/model/vmstorages.py
> index 37aca64..87c6b3d 100644
> --- a/src/kimchi/model/vmstorages.py
> +++ b/src/kimchi/model/vmstorages.py
> @@ -1,7 +1,7 @@
>   #
>   # Project Kimchi
>   #
> -# Copyright IBM, Corp. 2014
> +# 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
> @@ -26,7 +26,7 @@ from kimchi.exception import OperationFailed
>   from kimchi.model.config import CapabilitiesModel
>   from kimchi.model.vms import DOM_STATE_MAP, VMModel
>   from kimchi.model.storagevolumes import StorageVolumeModel
> -from kimchi.model.utils import check_remote_disk_path, get_vm_config_flag
> +from kimchi.model.utils import get_vm_config_flag
>   from kimchi.osinfo import lookup
>   from kimchi.model.diskutils import get_disk_ref_cnt, set_disk_ref_cnt
>   from kimchi.utils import kimchi_log
> @@ -131,8 +131,6 @@ class VMStoragesModel(object):
>               params['disk'] = vol_info['type']
>   
>           params.update(self._get_available_bus_address(params['bus'], vm_name))
> -        params['path'] = check_remote_disk_path(params['path'],
> -                                                self.caps.qemu_stream_dns)
>   
>           # Add device to VM
>           dev, xml = get_disk_xml(params)
> @@ -215,9 +213,7 @@ class VMStorageModel(object):
>           if dev_info['type'] != 'cdrom':
>               raise InvalidOperation("KCHVMSTOR0006E")
>   
> -        params['path'] = check_remote_disk_path(params.get('path', ''),
> -                                                self.caps.qemu_stream_dns)
> -
> +        params['path'] = params.get('path', '')
>           old_disk_path = dev_info['path']
>           new_disk_path = params['path']
>           if new_disk_path != old_disk_path:
> diff --git a/src/kimchi/vmtemplate.py b/src/kimchi/vmtemplate.py
> index ef97d83..e047228 100644
> --- a/src/kimchi/vmtemplate.py
> +++ b/src/kimchi/vmtemplate.py
> @@ -18,7 +18,6 @@
>   # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
>   
>   import os
> -import socket
>   import stat
>   import time
>   import urlparse
> @@ -128,7 +127,7 @@ class VMTemplate(object):
>           except IsoFormatError:
>               raise InvalidParameter("KCHISO0001E", {'filename': iso})
>   
> -    def _get_cdrom_xml(self, libvirt_stream_protocols, qemu_stream_dns):
> +    def _get_cdrom_xml(self, libvirt_stream_protocols):
>           if 'cdrom' not in self.info:
>               return ''
>   
> @@ -139,11 +138,6 @@ class VMTemplate(object):
>           params['index'] = self.info['cdrom_index']
>           params['path'] = self.info['cdrom']
>   
> -        hostname = urlparse.urlparse(params['path']).hostname
> -        if hostname is not None and not qemu_stream_dns:
> -            ip = socket.gethostbyname(hostname)
> -            params['path'] = params['path'].replace(hostname, ip)
> -
>           if self.info.get('iso_stream', False):
>               protocol = urlparse.urlparse(params['path']).scheme
>               if protocol not in libvirt_stream_protocols:
> @@ -304,10 +298,8 @@ class VMTemplate(object):
>           graphics.update(kwargs.get('graphics', {}))
>           params['graphics'] = get_graphics_xml(graphics)
>   
> -        qemu_stream_dns = kwargs.get('qemu_stream_dns', False)
>           libvirt_stream_protocols = kwargs.get('libvirt_stream_protocols', [])
> -        cdrom_xml = self._get_cdrom_xml(libvirt_stream_protocols,
> -                                        qemu_stream_dns)
> +        cdrom_xml = self._get_cdrom_xml(libvirt_stream_protocols)
>   
>           if not urlparse.urlparse(self.info.get('cdrom', "")).scheme in \
>                   libvirt_stream_protocols and \
> diff --git a/tests/test_model.py b/tests/test_model.py
> index 210adfd..bd195b5 100644
> --- a/tests/test_model.py
> +++ b/tests/test_model.py
> @@ -23,9 +23,7 @@ import os
>   import pwd
>   import re
>   import shutil
> -import socket
>   import time
> -import urlparse
>   import unittest
>   import uuid
>   
> @@ -564,14 +562,7 @@ class ModelTests(unittest.TestCase):
>                                     {'path': valid_remote_iso_path})
>               cdrom_info = inst.vmstorage_lookup(vm_name, cdrom_dev)
>               cur_cdrom_path = re.sub(":80/", '/', cdrom_info['path'])
> -
> -            # As Kimchi server is not running during this test case
> -            # CapabilitiesModel.qemu_stream_dns will be always False
> -            # so we need to convert the hostname to IP
> -            output = urlparse.urlparse(valid_remote_iso_path)
> -            hostname = socket.gethostbyname(output.hostname)
> -            url = valid_remote_iso_path.replace(output.hostname, hostname)
> -            self.assertEquals(url, cur_cdrom_path)
> +            self.assertEquals(valid_remote_iso_path, cur_cdrom_path)
>   
>       @unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
>       def test_vm_storage_provisioning(self):




More information about the Kimchi-devel mailing list