[Kimchi-devel] [PATCH 7/8] Check QEMU stream DNS capability when attaching new disk to guest
Aline Manera
alinefm at linux.vnet.ibm.com
Thu Oct 30 12:26:19 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.
To make xmlutils/ independent of model instances, that verification must
be done prior to the XML generation.
Signed-off-by: Aline Manera <alinefm at linux.vnet.ibm.com>
---
src/kimchi/model/utils.py | 19 +++++++++++++++----
src/kimchi/model/vmstorages.py | 8 +++++---
tests/test_model.py | 11 ++++++++++-
3 files changed, 30 insertions(+), 8 deletions(-)
diff --git a/src/kimchi/model/utils.py b/src/kimchi/model/utils.py
index 4d8e65a..5cc5075 100644
--- a/src/kimchi/model/utils.py
+++ b/src/kimchi/model/utils.py
@@ -17,14 +17,16 @@
# 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 re
-from kimchi.exception import OperationFailed
-from kimchi.featuretests import FeatureTests
-from kimchi.model.config import CapabilitiesModel
import libvirt
+import re
+import socket
+import urlparse
from lxml import etree
from lxml.builder import E, ElementMaker
+from kimchi.exception import OperationFailed
+from kimchi.featuretests import FeatureTests
+from kimchi.model.config import CapabilitiesModel
KIMCHI_META_URL = "https://github.com/kimchi-project/kimchi"
KIMCHI_NAMESPACE = "kimchi"
@@ -40,6 +42,15 @@ def get_vm_name(vm_name, t_name, name_list):
raise OperationFailed("KCHUTILS0003E")
+def check_remote_disk_path(path):
+ hostname = urlparse.urlparse(path).hostname
+ if hostname is not None and not CapabilitiesModel().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/vmstorages.py b/src/kimchi/model/vmstorages.py
index 70240b0..72f6bfd 100644
--- a/src/kimchi/model/vmstorages.py
+++ b/src/kimchi/model/vmstorages.py
@@ -25,7 +25,7 @@ from kimchi.exception import InvalidOperation, InvalidParameter, NotFoundError
from kimchi.exception import OperationFailed
from kimchi.model.vms import DOM_STATE_MAP, VMModel
from kimchi.model.storagevolumes import StorageVolumeModel
-from kimchi.model.utils import get_vm_config_flag
+from kimchi.model.utils import check_remote_disk_path, get_vm_config_flag
from kimchi.osinfo import lookup
from kimchi.xmlutils.disk import get_device_node, get_disk_xml
from kimchi.xmlutils.disk import get_vm_disk_info, get_vm_disks
@@ -122,6 +122,8 @@ class VMStoragesModel(object):
params['path'] = vol_info['path']
params.update(self._get_available_bus_address(params['bus'], vm_name))
+ params['path'] = check_remote_disk_path(params['path'])
+
# Add device to VM
dev, xml = get_disk_xml(params)
try:
@@ -175,10 +177,10 @@ class VMStorageModel(object):
if dev_info['type'] != 'cdrom':
raise InvalidOperation("KCHVMSTOR0006E")
- params['path'] = params.get('path', '')
+ params['path'] = check_remote_disk_path(params.get('path', ''))
dev_info.update(params)
-
dev, xml = get_disk_xml(dev_info)
+
try:
dom.updateDeviceFlags(xml, get_vm_config_flag(dom, 'all'))
except Exception as e:
diff --git a/tests/test_model.py b/tests/test_model.py
index 896540d..3e43780 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
@@ -435,7 +437,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