summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2011-11-10 06:51:11 +0000
committerGerrit Code Review <review@openstack.org>2011-11-10 06:51:11 +0000
commit26d2bad187ba8fab4f5e4b2f76b86f3e8762caa8 (patch)
tree1dc67d774277265c7761de4c59f8c0fee6bef248
parent8e3da64784a6a412a8806d666398236cbb83be81 (diff)
parentbee61b32420a2b8ce982406cd6c9647098bdf70b (diff)
Merge "Fixes LP878319"
-rw-r--r--nova/tests/test_xenapi.py17
-rw-r--r--nova/tests/xenapi/stubs.py8
-rw-r--r--nova/virt/xenapi/fake.py2
-rw-r--r--nova/virt/xenapi/vmops.py9
-rw-r--r--nova/virt/xenapi_conn.py11
5 files changed, 42 insertions, 5 deletions
diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py
index ee8d5ae20..b09bacc42 100644
--- a/nova/tests/test_xenapi.py
+++ b/nova/tests/test_xenapi.py
@@ -789,6 +789,23 @@ class XenAPIMigrateInstance(test.TestCase):
stubs.stubout_get_this_vm_uuid(self.stubs)
glance_stubs.stubout_glance_client(self.stubs)
+ def test_resize_xenserver_6(self):
+ instance = db.instance_create(self.context, self.instance_values)
+ called = {'resize': False}
+
+ def fake_vdi_resize(*args, **kwargs):
+ called['resize'] = True
+
+ self.stubs.Set(stubs.FakeSessionForMigrationTests,
+ "VDI_resize", fake_vdi_resize)
+ stubs.stubout_session(self.stubs,
+ stubs.FakeSessionForMigrationTests,
+ product_version=(6, 0, 0))
+ stubs.stubout_loopingcall_start(self.stubs)
+ conn = xenapi_conn.get_connection(False)
+ conn._vmops.resize_instance(instance, '')
+ self.assertEqual(called['resize'], True)
+
def test_migrate_disk_and_power_off(self):
instance = db.instance_create(self.context, self.instance_values)
stubs.stubout_session(self.stubs, stubs.FakeSessionForMigrationTests)
diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py
index c79bda682..51ca78708 100644
--- a/nova/tests/xenapi/stubs.py
+++ b/nova/tests/xenapi/stubs.py
@@ -57,8 +57,8 @@ def stubout_instance_snapshot(stubs):
stubs.Set(vm_utils, 'wait_for_vhd_coalesce', fake_wait_for_vhd_coalesce)
-def stubout_session(stubs, cls):
- """Stubs out two methods from XenAPISession"""
+def stubout_session(stubs, cls, product_version=None):
+ """Stubs out three methods from XenAPISession"""
def fake_import(self):
"""Stubs out get_imported_xenapi of XenAPISession"""
fake_module = 'nova.virt.xenapi.fake'
@@ -69,6 +69,10 @@ def stubout_session(stubs, cls):
lambda s, url: cls(url))
stubs.Set(xenapi_conn.XenAPISession, 'get_imported_xenapi',
fake_import)
+ if product_version is None:
+ product_version = (5, 6, 2)
+ stubs.Set(xenapi_conn.XenAPISession, 'get_product_version',
+ lambda s: product_version)
def stub_out_get_target(stubs):
diff --git a/nova/virt/xenapi/fake.py b/nova/virt/xenapi/fake.py
index 91dc60cee..59ea19fd0 100644
--- a/nova/virt/xenapi/fake.py
+++ b/nova/virt/xenapi/fake.py
@@ -441,6 +441,8 @@ class SessionBase(object):
def VDI_resize_online(self, *args):
return 'derp'
+ VDI_resize = VDI_resize_online
+
def VM_clean_reboot(self, *args):
return 'burp'
diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py
index 4f53c8ab9..5533b8cfd 100644
--- a/nova/virt/xenapi/vmops.py
+++ b/nova/virt/xenapi/vmops.py
@@ -85,13 +85,14 @@ class VMOps(object):
"""
Management class for VM-related tasks
"""
- def __init__(self, session):
+ def __init__(self, session, product_version):
self.XenAPI = session.get_imported_xenapi()
self.compute_api = compute.API()
self._session = session
self.poll_rescue_last_ran = None
VMHelper.XenAPI = self.XenAPI
self.vif_driver = utils.import_object(FLAGS.xenapi_vif_driver)
+ self._product_version = product_version
def list_instances(self):
"""List VM instances."""
@@ -768,7 +769,11 @@ class VMOps(object):
" GB") % locals())
vdi_ref = self._session.call_xenapi('VDI.get_by_uuid', vdi_uuid)
# for an instance with no local storage
- self._session.call_xenapi('VDI.resize_online', vdi_ref,
+ if self._product_version[0] > 5:
+ resize_func_name = 'VDI.resize'
+ else:
+ resize_func_name = 'VDI.resize_online'
+ self._session.call_xenapi(resize_func_name, vdi_ref,
str(new_disk_size))
LOG.debug(_("Resize instance %s complete") % (instance.name))
diff --git a/nova/virt/xenapi_conn.py b/nova/virt/xenapi_conn.py
index ab9c3e368..73d1b0cb7 100644
--- a/nova/virt/xenapi_conn.py
+++ b/nova/virt/xenapi_conn.py
@@ -169,9 +169,10 @@ class XenAPIConnection(driver.ComputeDriver):
def __init__(self, url, user, pw):
super(XenAPIConnection, self).__init__()
self._session = XenAPISession(url, user, pw)
- self._vmops = VMOps(self._session)
self._volumeops = VolumeOps(self._session)
self._host_state = None
+ self._product_version = self._session.get_product_version()
+ self._vmops = VMOps(self._session, self._product_version)
@property
def host_state(self):
@@ -455,6 +456,14 @@ class XenAPISession(object):
session.login_with_password(user, pw)
self._sessions.put(session)
+ def get_product_version(self):
+ """Return a tuple of (major, minor, rev) for the host version"""
+ host = self.get_xenapi_host()
+ software_version = self.call_xenapi('host.get_software_version',
+ host)
+ product_version = software_version['product_version']
+ return tuple(int(part) for part in product_version.split('.'))
+
def get_imported_xenapi(self):
"""Stubout point. This can be replaced with a mock xenapi module."""
return __import__('XenAPI')