Skip to content

Commit

Permalink
Fixes LP878319
Browse files Browse the repository at this point in the history
* Adds lookup of host version in XenAPI session
* Add call to determine function name of resize

Change-Id: I797ff2ea34a3b3fde1091efba803a4572aaf1ede
  • Loading branch information
jkoelker committed Nov 10, 2011
1 parent 7a2e8a1 commit bee61b3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
17 changes: 17 additions & 0 deletions nova/tests/test_xenapi.py
Expand Up @@ -789,6 +789,23 @@ def setUp(self):
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)
Expand Down
8 changes: 6 additions & 2 deletions nova/tests/xenapi/stubs.py
Expand Up @@ -57,8 +57,8 @@ def fake_wait_for_vhd_coalesce(session, instance_id, sr_ref, vdi_ref,
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'
Expand All @@ -69,6 +69,10 @@ def fake_import(self):
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):
Expand Down
2 changes: 2 additions & 0 deletions nova/virt/xenapi/fake.py
Expand Up @@ -441,6 +441,8 @@ def host_call_plugin(self, *args):
def VDI_resize_online(self, *args):
return 'derp'

VDI_resize = VDI_resize_online

def VM_clean_reboot(self, *args):
return 'burp'

Expand Down
9 changes: 7 additions & 2 deletions nova/virt/xenapi/vmops.py
Expand Up @@ -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."""
Expand Down Expand Up @@ -768,7 +769,11 @@ def resize_instance(self, instance, vdi_uuid):
" 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))

Expand Down
11 changes: 10 additions & 1 deletion nova/virt/xenapi_conn.py
Expand Up @@ -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):
Expand Down Expand Up @@ -455,6 +456,14 @@ def __init__(self, url, user, pw):
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')
Expand Down

0 comments on commit bee61b3

Please sign in to comment.