summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-03-09 16:19:45 +0000
committerGerrit Code Review <review@openstack.org>2012-03-09 16:19:45 +0000
commit0c3c67e085018316d2e6174d852bbc8cd2e4ccb1 (patch)
tree311c0f03a0166e85c9f5c094014ecefd6cb05ede /nova
parent76a2da5ebc46e52d0939a430dbacb94bb9f837f2 (diff)
parent86bcb49b43e052b17fc173520ce8094dcc1db965 (diff)
downloadnova-0c3c67e085018316d2e6174d852bbc8cd2e4ccb1.tar.gz
nova-0c3c67e085018316d2e6174d852bbc8cd2e4ccb1.tar.xz
nova-0c3c67e085018316d2e6174d852bbc8cd2e4ccb1.zip
Merge "Simplify unnecessary XenAPI Async calls to be synchronous"
Diffstat (limited to 'nova')
-rw-r--r--nova/tests/test_xenapi.py14
-rw-r--r--nova/virt/xenapi/vm_utils.py22
-rw-r--r--nova/virt/xenapi/vmops.py40
3 files changed, 30 insertions, 46 deletions
diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py
index 408c27982..e7357b028 100644
--- a/nova/tests/test_xenapi.py
+++ b/nova/tests/test_xenapi.py
@@ -210,10 +210,6 @@ def configure_instance(*args):
pass
-def _find_rescue_vbd_ref(*args):
- pass
-
-
class XenAPIVMTestCase(test.TestCase):
"""Unit tests for VM operations."""
def setUp(self):
@@ -235,8 +231,6 @@ class XenAPIVMTestCase(test.TestCase):
stubs.stubout_is_vdi_pv(self.stubs)
self.stubs.Set(vmops.VMOps, '_configure_instance',
configure_instance)
- self.stubs.Set(vmops.VMOps, '_find_rescue_vbd_ref',
- _find_rescue_vbd_ref)
stubs.stub_out_vm_methods(self.stubs)
glance_stubs.stubout_glance_client(self.stubs)
fake_utils.stub_out_utils_execute(self.stubs)
@@ -699,7 +693,15 @@ class XenAPIVMTestCase(test.TestCase):
str(3 * 1024))
def test_rescue(self):
+ def _find_rescue_vbd_ref(*args):
+ return vbd
+
+ self.stubs.Set(vmops.VMOps, '_find_rescue_vbd_ref',
+ _find_rescue_vbd_ref)
instance = self._create_instance()
+ session = xenapi_conn.XenAPISession('test_url', 'root', 'test_pass')
+ vm = vm_utils.VMHelper.lookup(session, instance.name)
+ vbd = xenapi_fake.create_vbd(vm, None)
conn = xenapi_conn.get_connection(False)
conn.rescue(self.context, instance, [], None)
diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py
index cde76642f..a929449b4 100644
--- a/nova/virt/xenapi/vm_utils.py
+++ b/nova/virt/xenapi/vm_utils.py
@@ -283,8 +283,7 @@ class VMHelper(xenapi.HelperBase):
def destroy_vbd(cls, session, vbd_ref):
"""Destroy VBD from host database"""
try:
- task = session.call_xenapi('Async.VBD.destroy', vbd_ref)
- session.wait_for_task(task)
+ session.call_xenapi('VBD.destroy', vbd_ref)
except cls.XenAPI.Failure, exc:
LOG.exception(exc)
raise volume_utils.StorageError(
@@ -293,8 +292,7 @@ class VMHelper(xenapi.HelperBase):
@classmethod
def destroy_vdi(cls, session, vdi_ref):
try:
- task = session.call_xenapi('Async.VDI.destroy', vdi_ref)
- session.wait_for_task(task)
+ session.call_xenapi('VDI.destroy', vdi_ref)
except cls.XenAPI.Failure, exc:
LOG.exception(exc)
raise volume_utils.StorageError(
@@ -366,8 +364,7 @@ class VMHelper(xenapi.HelperBase):
original_parent_uuid = get_vhd_parent_uuid(session, vm_vdi_ref)
- task = session.call_xenapi('Async.VM.snapshot', vm_ref, label)
- template_vm_ref = session.wait_for_task(task, instance['uuid'])
+ template_vm_ref = session.call_xenapi('VM.snapshot', vm_ref, label)
template_vdi_rec = cls.get_vdi_for_vm_safely(session,
template_vm_ref)[1]
template_vdi_uuid = template_vdi_rec["uuid"]
@@ -754,7 +751,7 @@ class VMHelper(xenapi.HelperBase):
LOG.debug(_("xapi 'download_vhd' returned VDI of "
"type '%(vdi_type)s' with UUID '%(vdi_uuid)s'") % vdi)
- cls.scan_sr(session, instance, sr_ref)
+ cls.scan_sr(session, sr_ref)
# Pull out the UUID of the first VDI (which is the os VDI)
os_vdi_uuid = vdis[0]['vdi_uuid']
@@ -1097,19 +1094,16 @@ class VMHelper(xenapi.HelperBase):
raise exception.CouldNotFetchMetrics()
@classmethod
- def scan_sr(cls, session, instance=None, sr_ref=None):
+ def scan_sr(cls, session, sr_ref=None):
"""Scans the SR specified by sr_ref"""
if sr_ref:
LOG.debug(_("Re-scanning SR %s"), sr_ref)
- task = session.call_xenapi('Async.SR.scan', sr_ref)
- instance_uuid = instance['uuid'] if instance else None
- session.wait_for_task(task, instance_uuid)
+ session.call_xenapi('SR.scan', sr_ref)
@classmethod
def scan_default_sr(cls, session):
"""Looks for the system default SR and triggers a re-scan"""
- sr_ref = cls.find_sr(session)
- session.call_xenapi('SR.scan', sr_ref)
+ cls.scan_sr(session, cls.find_sr(session))
@classmethod
def safe_find_sr(cls, session):
@@ -1409,7 +1403,7 @@ def _wait_for_vhd_coalesce(session, instance, sr_ref, vdi_ref,
max_attempts = FLAGS.xenapi_vhd_coalesce_max_attempts
for i in xrange(max_attempts):
- VMHelper.scan_sr(session, instance, sr_ref)
+ VMHelper.scan_sr(session, sr_ref)
parent_uuid = get_vhd_parent_uuid(session, vdi_ref)
if original_parent_uuid and (parent_uuid != original_parent_uuid):
LOG.debug(_("Parent %(parent_uuid)s doesn't match original parent"
diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py
index 9de6242bf..8669fbd09 100644
--- a/nova/virt/xenapi/vmops.py
+++ b/nova/virt/xenapi/vmops.py
@@ -920,11 +920,9 @@ class VMOps(object):
vm_ref = self._get_vm_opaque_ref(instance)
if reboot_type == "HARD":
- task = self._session.call_xenapi('Async.VM.hard_reboot', vm_ref)
+ self._session.call_xenapi('VM.hard_reboot', vm_ref)
else:
- task = self._session.call_xenapi('Async.VM.clean_reboot', vm_ref)
-
- self._session.wait_for_task(task, instance['uuid'])
+ self._session.call_xenapi('VM.clean_reboot', vm_ref)
def get_agent_version(self, instance):
"""Get the version of the agent running on the VM instance."""
@@ -1061,12 +1059,9 @@ class VMOps(object):
try:
task = None
if hard:
- task = self._session.call_xenapi("Async.VM.hard_shutdown",
- vm_ref)
+ self._session.call_xenapi('VM.hard_shutdown', vm_ref)
else:
- task = self._session.call_xenapi("Async.VM.clean_shutdown",
- vm_ref)
- self._session.wait_for_task(task, instance['uuid'])
+ self._session.call_xenapi('VM.clean_shutdown', vm_ref)
except self.XenAPI.Failure, exc:
LOG.exception(exc)
@@ -1105,10 +1100,9 @@ class VMOps(object):
for vdi_ref in vdi_refs:
try:
- task = self._session.call_xenapi('Async.VDI.destroy', vdi_ref)
- self._session.wait_for_task(task, instance['uuid'])
- except self.XenAPI.Failure, exc:
- LOG.exception(exc)
+ VMHelper.destroy_vdi(self._session, vdi_ref)
+ except volume_utils.StorageError as exc:
+ LOG.error(exc)
def _destroy_rescue_vdis(self, rescue_vm_ref):
"""Destroys all VDIs associated with a rescued VM."""
@@ -1174,8 +1168,7 @@ class VMOps(object):
"""Destroys a VM record."""
instance_uuid = instance['uuid']
try:
- task = self._session.call_xenapi('Async.VM.destroy', vm_ref)
- self._session.wait_for_task(task, instance_uuid)
+ self._session.call_xenapi('VM.destroy', vm_ref)
except self.XenAPI.Failure, exc:
LOG.exception(exc)
@@ -1233,27 +1226,22 @@ class VMOps(object):
def pause(self, instance):
"""Pause VM instance."""
vm_ref = self._get_vm_opaque_ref(instance)
- task = self._session.call_xenapi('Async.VM.pause', vm_ref)
- self._session.wait_for_task(task, instance['uuid'])
+ self._session.call_xenapi('VM.pause', vm_ref)
def unpause(self, instance):
"""Unpause VM instance."""
vm_ref = self._get_vm_opaque_ref(instance)
- task = self._session.call_xenapi('Async.VM.unpause', vm_ref)
- self._session.wait_for_task(task, instance['uuid'])
+ self._session.call_xenapi('VM.unpause', vm_ref)
def suspend(self, instance):
"""Suspend the specified instance."""
vm_ref = self._get_vm_opaque_ref(instance)
- task = self._session.call_xenapi('Async.VM.suspend', vm_ref)
- self._session.wait_for_task(task, instance['uuid'])
+ self._session.call_xenapi('VM.suspend', vm_ref)
def resume(self, instance):
"""Resume the specified instance."""
vm_ref = self._get_vm_opaque_ref(instance)
- task = self._session.call_xenapi('Async.VM.resume',
- vm_ref, False, True)
- self._session.wait_for_task(task, instance['uuid'])
+ self._session.call_xenapi('VM.resume', vm_ref, False, True)
def rescue(self, context, instance, network_info, image_meta):
"""Rescue the specified instance.
@@ -1277,7 +1265,7 @@ class VMOps(object):
rescue_vm_ref = VMHelper.lookup(self._session, instance.name)
rescue_vbd_ref = self._find_rescue_vbd_ref(vm_ref, rescue_vm_ref)
- self._session.call_xenapi("Async.VBD.plug", rescue_vbd_ref)
+ self._session.call_xenapi('VBD.plug', rescue_vbd_ref)
def unrescue(self, instance):
"""Unrescue the specified instance.
@@ -1329,7 +1317,7 @@ class VMOps(object):
"""
# NOTE(jk0): All existing clean_reboot tasks must be cancelled before
# we can kick off the hard_reboot tasks.
- self._cancel_stale_tasks(timeout, "Async.VM.clean_reboot")
+ self._cancel_stale_tasks(timeout, 'VM.clean_reboot')
ctxt = nova_context.get_admin_context()
instances = db.instance_get_all_hung_in_rebooting(ctxt, timeout)