[Kimchi-devel] [PATCH 7/8] Check QEMU stream DNS capability while generating guest disk XML

Aline Manera alinefm at linux.vnet.ibm.com
Mon Oct 27 15:40:26 UTC 2014


When QEMU is not able to solve hostname for a remote CDROM path, we need to
convert the hostname to IP to avoid problems.
Add this logic to get_disk_xml() too.

Signed-off-by: Aline Manera <alinefm at linux.vnet.ibm.com>
---
 src/kimchi/xmlutils/disk.py |  7 ++++++-
 tests/test_model.py         | 11 ++++++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/kimchi/xmlutils/disk.py b/src/kimchi/xmlutils/disk.py
index f066dbe..adc45da 100644
--- a/src/kimchi/xmlutils/disk.py
+++ b/src/kimchi/xmlutils/disk.py
@@ -28,6 +28,7 @@ from lxml import objectify
 from lxml.builder import E
 
 from kimchi.exception import InvalidParameter, NotFoundError
+from kimchi.model.config import CapabilitiesModel
 from kimchi.utils import check_url_path
 
 BUS_TO_DEV_MAP = {'ide': 'hd', 'virtio': 'vd', 'scsi': 'sd'}
@@ -74,8 +75,12 @@ def get_disk_xml(params):
         output = urlparse.urlparse(params['path'])
         port = str(output.port or socket.getservbyname(output.scheme))
 
+        hostname = output.hostname
+        if not CapabilitiesModel().qemu_stream_dns:
+            hostname = socket.gethostbyname(hostname)
+
         source = E.source(protocol=output.scheme, name=output.path)
-        source.append(E.host(name=output.hostname, port=port))
+        source.append(E.host(name=hostname, port=port))
     else:
         """
         <source file='%(src)s' />
diff --git a/tests/test_model.py b/tests/test_model.py
index e407fe5..f094ed7 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -25,9 +25,11 @@ import psutil
 import pwd
 import re
 import shutil
+import socket
 import tempfile
 import threading
 import time
+import urlparse
 import unittest
 import uuid
 
@@ -433,7 +435,14 @@ 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'])
-            self.assertEquals(valid_remote_iso_path, cur_cdrom_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)
 
     @unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
     def test_vm_storage_provisioning(self):
-- 
1.9.3




More information about the Kimchi-devel mailing list