diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-01-06 00:38:13 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-01-06 00:38:13 +0000 |
| commit | 850e5d6bf989b15ca67396dc246e72f7de7524a8 (patch) | |
| tree | f8b7bb1de0b1d78c23f216e941c101e6e3bf9394 /nova/tests | |
| parent | cd0f02113110bdc25eea4f57db640e906636c814 (diff) | |
| parent | 0df60e98790c722aef59d0015c209ea0944e62c0 (diff) | |
Merge "Adding two snapshot related task states"
Diffstat (limited to 'nova/tests')
| -rw-r--r-- | nova/tests/matchers.py | 15 | ||||
| -rw-r--r-- | nova/tests/test_hypervapi.py | 34 | ||||
| -rw-r--r-- | nova/tests/test_libvirt.py | 142 | ||||
| -rw-r--r-- | nova/tests/test_virt_drivers.py | 6 | ||||
| -rw-r--r-- | nova/tests/test_vmwareapi.py | 18 | ||||
| -rw-r--r-- | nova/tests/test_xenapi.py | 20 |
6 files changed, 217 insertions, 18 deletions
diff --git a/nova/tests/matchers.py b/nova/tests/matchers.py index a421cc056..be65da823 100644 --- a/nova/tests/matchers.py +++ b/nova/tests/matchers.py @@ -198,6 +198,21 @@ class IsSubDictOf(object): return SubDictMismatch(k, sub_value, super_value) +class FunctionCallMatcher(object): + + def __init__(self, expected_func_calls): + self.expected_func_calls = expected_func_calls + self.actual_func_calls = [] + + def call(self, *args, **kwargs): + func_call = {'args': args, 'kwargs': kwargs} + self.actual_func_calls.append(func_call) + + def match(self): + dict_list_matcher = DictListMatches(self.expected_func_calls) + return dict_list_matcher.match(self.actual_func_calls) + + class XMLMismatch(object): """Superclass for XML mismatch.""" diff --git a/nova/tests/test_hypervapi.py b/nova/tests/test_hypervapi.py index eae3c0151..cab877da9 100644 --- a/nova/tests/test_hypervapi.py +++ b/nova/tests/test_hypervapi.py @@ -26,6 +26,7 @@ import sys import uuid from nova.compute import power_state +from nova.compute import task_states from nova import context from nova import db from nova.image import glance @@ -36,6 +37,7 @@ from nova.tests.hyperv import db_fakes from nova.tests.hyperv import hypervutils from nova.tests.hyperv import mockproxy import nova.tests.image.fake as fake_image +from nova.tests import matchers from nova.virt.hyperv import constants from nova.virt.hyperv import driver as driver_hyperv from nova.virt.hyperv import vmutils @@ -407,27 +409,55 @@ class HyperVAPITestCase(basetestcase.BaseTestCase): self.assertTrue(self._fetched_image is None) def test_snapshot_with_update_failure(self): + expected_calls = [ + {'args': (), + 'kwargs': + {'task_state': task_states.IMAGE_PENDING_UPLOAD}}, + {'args': (), + 'kwargs': + {'task_state': task_states.IMAGE_UPLOADING, + 'expected_state': task_states.IMAGE_PENDING_UPLOAD}}] + func_call_matcher = matchers.FunctionCallMatcher(expected_calls) + self._spawn_instance(True) self._update_image_raise_exception = True snapshot_name = 'test_snapshot_' + str(uuid.uuid4()) self.assertRaises(vmutils.HyperVException, self._conn.snapshot, - self._context, self._instance_data, snapshot_name) + self._context, self._instance_data, snapshot_name, + func_call_matcher.call) + + # assert states changed in correct order + self.assertIsNone(func_call_matcher.match()) # assert VM snapshots have been removed self.assertEquals(self._hypervutils.get_vm_snapshots_count( self._instance_data["name"]), 0) def test_snapshot(self): + expected_calls = [ + {'args': (), + 'kwargs': + {'task_state': task_states.IMAGE_PENDING_UPLOAD}}, + {'args': (), + 'kwargs': + {'task_state': task_states.IMAGE_UPLOADING, + 'expected_state': task_states.IMAGE_PENDING_UPLOAD}}] + func_call_matcher = matchers.FunctionCallMatcher(expected_calls) + self._spawn_instance(True) snapshot_name = 'test_snapshot_' + str(uuid.uuid4()) - self._conn.snapshot(self._context, self._instance_data, snapshot_name) + self._conn.snapshot(self._context, self._instance_data, snapshot_name, + func_call_matcher.call) self.assertTrue(self._image_metadata and "disk_format" in self._image_metadata and self._image_metadata["disk_format"] == "vhd") + # assert states changed in correct order + self.assertIsNone(func_call_matcher.match()) + # assert VM snapshots have been removed self.assertEquals(self._hypervutils.get_vm_snapshots_count( self._instance_data["name"]), 0) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index d8f6ddc1a..6bc18251f 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -32,6 +32,7 @@ from xml.dom import minidom from nova.api.ec2 import cloud from nova.compute import instance_types from nova.compute import power_state +from nova.compute import task_states from nova.compute import vm_mode from nova.compute import vm_states from nova import context @@ -1209,6 +1210,16 @@ class LibvirtConnTestCase(test.TestCase): self.assertEqual(devices, ['vda', 'vdb']) def test_snapshot_in_ami_format(self): + expected_calls = [ + {'args': (), + 'kwargs': + {'task_state': task_states.IMAGE_PENDING_UPLOAD}}, + {'args': (), + 'kwargs': + {'task_state': task_states.IMAGE_UPLOADING, + 'expected_state': task_states.IMAGE_PENDING_UPLOAD}}] + func_call_matcher = matchers.FunctionCallMatcher(expected_calls) + self.flags(libvirt_snapshots_directory='./') # Start test @@ -1238,15 +1249,28 @@ class LibvirtConnTestCase(test.TestCase): self.mox.ReplayAll() conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False) - conn.snapshot(self.context, instance_ref, recv_meta['id']) + conn.snapshot(self.context, instance_ref, recv_meta['id'], + func_call_matcher.call) snapshot = image_service.show(context, recv_meta['id']) + self.assertIsNone(func_call_matcher.match()) + self.assertEquals(snapshot['properties']['image_state'], 'available') self.assertEquals(snapshot['properties']['image_state'], 'available') self.assertEquals(snapshot['status'], 'active') self.assertEquals(snapshot['disk_format'], 'ami') self.assertEquals(snapshot['name'], snapshot_name) def test_lxc_snapshot_in_ami_format(self): + expected_calls = [ + {'args': (), + 'kwargs': + {'task_state': task_states.IMAGE_PENDING_UPLOAD}}, + {'args': (), + 'kwargs': + {'task_state': task_states.IMAGE_UPLOADING, + 'expected_state': task_states.IMAGE_PENDING_UPLOAD}}] + func_call_matcher = matchers.FunctionCallMatcher(expected_calls) + self.flags(libvirt_snapshots_directory='./', libvirt_type='lxc') @@ -1277,15 +1301,27 @@ class LibvirtConnTestCase(test.TestCase): self.mox.ReplayAll() conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False) - conn.snapshot(self.context, instance_ref, recv_meta['id']) + conn.snapshot(self.context, instance_ref, recv_meta['id'], + func_call_matcher.call) snapshot = image_service.show(context, recv_meta['id']) + self.assertIsNone(func_call_matcher.match()) self.assertEquals(snapshot['properties']['image_state'], 'available') self.assertEquals(snapshot['status'], 'active') self.assertEquals(snapshot['disk_format'], 'ami') self.assertEquals(snapshot['name'], snapshot_name) def test_snapshot_in_raw_format(self): + expected_calls = [ + {'args': (), + 'kwargs': + {'task_state': task_states.IMAGE_PENDING_UPLOAD}}, + {'args': (), + 'kwargs': + {'task_state': task_states.IMAGE_UPLOADING, + 'expected_state': task_states.IMAGE_PENDING_UPLOAD}}] + func_call_matcher = matchers.FunctionCallMatcher(expected_calls) + self.flags(libvirt_snapshots_directory='./') # Start test @@ -1316,15 +1352,27 @@ class LibvirtConnTestCase(test.TestCase): self.mox.ReplayAll() conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False) - conn.snapshot(self.context, instance_ref, recv_meta['id']) + conn.snapshot(self.context, instance_ref, recv_meta['id'], + func_call_matcher.call) snapshot = image_service.show(context, recv_meta['id']) + self.assertIsNone(func_call_matcher.match()) self.assertEquals(snapshot['properties']['image_state'], 'available') self.assertEquals(snapshot['status'], 'active') self.assertEquals(snapshot['disk_format'], 'raw') self.assertEquals(snapshot['name'], snapshot_name) def test_lxc_snapshot_in_raw_format(self): + expected_calls = [ + {'args': (), + 'kwargs': + {'task_state': task_states.IMAGE_PENDING_UPLOAD}}, + {'args': (), + 'kwargs': + {'task_state': task_states.IMAGE_UPLOADING, + 'expected_state': task_states.IMAGE_PENDING_UPLOAD}}] + func_call_matcher = matchers.FunctionCallMatcher(expected_calls) + self.flags(libvirt_snapshots_directory='./', libvirt_type='lxc') @@ -1356,15 +1404,27 @@ class LibvirtConnTestCase(test.TestCase): self.mox.ReplayAll() conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False) - conn.snapshot(self.context, instance_ref, recv_meta['id']) + conn.snapshot(self.context, instance_ref, recv_meta['id'], + func_call_matcher.call) snapshot = image_service.show(context, recv_meta['id']) + self.assertIsNone(func_call_matcher.match()) self.assertEquals(snapshot['properties']['image_state'], 'available') self.assertEquals(snapshot['status'], 'active') self.assertEquals(snapshot['disk_format'], 'raw') self.assertEquals(snapshot['name'], snapshot_name) def test_snapshot_in_qcow2_format(self): + expected_calls = [ + {'args': (), + 'kwargs': + {'task_state': task_states.IMAGE_PENDING_UPLOAD}}, + {'args': (), + 'kwargs': + {'task_state': task_states.IMAGE_UPLOADING, + 'expected_state': task_states.IMAGE_PENDING_UPLOAD}}] + func_call_matcher = matchers.FunctionCallMatcher(expected_calls) + self.flags(snapshot_image_format='qcow2', libvirt_snapshots_directory='./') @@ -1391,15 +1451,27 @@ class LibvirtConnTestCase(test.TestCase): self.mox.ReplayAll() conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False) - conn.snapshot(self.context, instance_ref, recv_meta['id']) + conn.snapshot(self.context, instance_ref, recv_meta['id'], + func_call_matcher.call) snapshot = image_service.show(context, recv_meta['id']) + self.assertIsNone(func_call_matcher.match()) self.assertEquals(snapshot['properties']['image_state'], 'available') self.assertEquals(snapshot['status'], 'active') self.assertEquals(snapshot['disk_format'], 'qcow2') self.assertEquals(snapshot['name'], snapshot_name) def test_lxc_snapshot_in_qcow2_format(self): + expected_calls = [ + {'args': (), + 'kwargs': + {'task_state': task_states.IMAGE_PENDING_UPLOAD}}, + {'args': (), + 'kwargs': + {'task_state': task_states.IMAGE_UPLOADING, + 'expected_state': task_states.IMAGE_PENDING_UPLOAD}}] + func_call_matcher = matchers.FunctionCallMatcher(expected_calls) + self.flags(snapshot_image_format='qcow2', libvirt_snapshots_directory='./', libvirt_type='lxc') @@ -1427,15 +1499,27 @@ class LibvirtConnTestCase(test.TestCase): self.mox.ReplayAll() conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False) - conn.snapshot(self.context, instance_ref, recv_meta['id']) + conn.snapshot(self.context, instance_ref, recv_meta['id'], + func_call_matcher.call) snapshot = image_service.show(context, recv_meta['id']) + self.assertIsNone(func_call_matcher.match()) self.assertEquals(snapshot['properties']['image_state'], 'available') self.assertEquals(snapshot['status'], 'active') self.assertEquals(snapshot['disk_format'], 'qcow2') self.assertEquals(snapshot['name'], snapshot_name) def test_snapshot_no_image_architecture(self): + expected_calls = [ + {'args': (), + 'kwargs': + {'task_state': task_states.IMAGE_PENDING_UPLOAD}}, + {'args': (), + 'kwargs': + {'task_state': task_states.IMAGE_UPLOADING, + 'expected_state': task_states.IMAGE_PENDING_UPLOAD}}] + func_call_matcher = matchers.FunctionCallMatcher(expected_calls) + self.flags(libvirt_snapshots_directory='./') # Start test @@ -1465,14 +1549,26 @@ class LibvirtConnTestCase(test.TestCase): self.mox.ReplayAll() conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False) - conn.snapshot(self.context, instance_ref, recv_meta['id']) + conn.snapshot(self.context, instance_ref, recv_meta['id'], + func_call_matcher.call) snapshot = image_service.show(context, recv_meta['id']) + self.assertIsNone(func_call_matcher.match()) self.assertEquals(snapshot['properties']['image_state'], 'available') self.assertEquals(snapshot['status'], 'active') self.assertEquals(snapshot['name'], snapshot_name) def test_lxc_snapshot_no_image_architecture(self): + expected_calls = [ + {'args': (), + 'kwargs': + {'task_state': task_states.IMAGE_PENDING_UPLOAD}}, + {'args': (), + 'kwargs': + {'task_state': task_states.IMAGE_UPLOADING, + 'expected_state': task_states.IMAGE_PENDING_UPLOAD}}] + func_call_matcher = matchers.FunctionCallMatcher(expected_calls) + self.flags(libvirt_snapshots_directory='./', libvirt_type='lxc') @@ -1503,14 +1599,26 @@ class LibvirtConnTestCase(test.TestCase): self.mox.ReplayAll() conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False) - conn.snapshot(self.context, instance_ref, recv_meta['id']) + conn.snapshot(self.context, instance_ref, recv_meta['id'], + func_call_matcher.call) snapshot = image_service.show(context, recv_meta['id']) + self.assertIsNone(func_call_matcher.match()) self.assertEquals(snapshot['properties']['image_state'], 'available') self.assertEquals(snapshot['status'], 'active') self.assertEquals(snapshot['name'], snapshot_name) def test_snapshot_no_original_image(self): + expected_calls = [ + {'args': (), + 'kwargs': + {'task_state': task_states.IMAGE_PENDING_UPLOAD}}, + {'args': (), + 'kwargs': + {'task_state': task_states.IMAGE_UPLOADING, + 'expected_state': task_states.IMAGE_PENDING_UPLOAD}}] + func_call_matcher = matchers.FunctionCallMatcher(expected_calls) + self.flags(libvirt_snapshots_directory='./') # Start test @@ -1536,14 +1644,26 @@ class LibvirtConnTestCase(test.TestCase): self.mox.ReplayAll() conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False) - conn.snapshot(self.context, instance_ref, recv_meta['id']) + conn.snapshot(self.context, instance_ref, recv_meta['id'], + func_call_matcher.call) snapshot = image_service.show(context, recv_meta['id']) + self.assertIsNone(func_call_matcher.match()) self.assertEquals(snapshot['properties']['image_state'], 'available') self.assertEquals(snapshot['status'], 'active') self.assertEquals(snapshot['name'], snapshot_name) def test_lxc_snapshot_no_original_image(self): + expected_calls = [ + {'args': (), + 'kwargs': + {'task_state': task_states.IMAGE_PENDING_UPLOAD}}, + {'args': (), + 'kwargs': + {'task_state': task_states.IMAGE_UPLOADING, + 'expected_state': task_states.IMAGE_PENDING_UPLOAD}}] + func_call_matcher = matchers.FunctionCallMatcher(expected_calls) + self.flags(libvirt_snapshots_directory='./', libvirt_type='lxc') @@ -1570,9 +1690,11 @@ class LibvirtConnTestCase(test.TestCase): self.mox.ReplayAll() conn = libvirt_driver.LibvirtDriver(False) - conn.snapshot(self.context, instance_ref, recv_meta['id']) + conn.snapshot(self.context, instance_ref, recv_meta['id'], + func_call_matcher.call) snapshot = image_service.show(context, recv_meta['id']) + self.assertIsNone(func_call_matcher.match()) self.assertEquals(snapshot['properties']['image_state'], 'available') self.assertEquals(snapshot['status'], 'active') self.assertEquals(snapshot['name'], snapshot_name) diff --git a/nova/tests/test_virt_drivers.py b/nova/tests/test_virt_drivers.py index b0e25d095..9d9ebcad9 100644 --- a/nova/tests/test_virt_drivers.py +++ b/nova/tests/test_virt_drivers.py @@ -215,13 +215,15 @@ class _VirtDriverTestCase(_FakeDriverBackendTestCase): img_ref = self.image_service.create(self.ctxt, {'name': 'snap-1'}) self.assertRaises(exception.InstanceNotRunning, self.connection.snapshot, - self.ctxt, instance_ref, img_ref['id']) + self.ctxt, instance_ref, img_ref['id'], + lambda *args, **kwargs: None) @catch_notimplementederror def test_snapshot_running(self): img_ref = self.image_service.create(self.ctxt, {'name': 'snap-1'}) instance_ref, network_info = self._get_running_instance() - self.connection.snapshot(self.ctxt, instance_ref, img_ref['id']) + self.connection.snapshot(self.ctxt, instance_ref, img_ref['id'], + lambda *args, **kwargs: None) @catch_notimplementederror def test_reboot(self): diff --git a/nova/tests/test_vmwareapi.py b/nova/tests/test_vmwareapi.py index 3a404a122..86b3a5730 100644 --- a/nova/tests/test_vmwareapi.py +++ b/nova/tests/test_vmwareapi.py @@ -20,11 +20,13 @@ Test suite for VMWareAPI. """ from nova.compute import power_state +from nova.compute import task_states from nova import context from nova import db from nova import exception from nova import test import nova.tests.image.fake +from nova.tests import matchers from nova.tests.vmwareapi import db_fakes from nova.tests.vmwareapi import stubs from nova.virt.vmwareapi import driver @@ -159,17 +161,29 @@ class VMWareAPIVMTestCase(test.TestCase): self._check_vm_info(info, power_state.RUNNING) def test_snapshot(self): + expected_calls = [ + {'args': (), + 'kwargs': + {'task_state': task_states.IMAGE_PENDING_UPLOAD}}, + {'args': (), + 'kwargs': + {'task_state': task_states.IMAGE_UPLOADING, + 'expected_state': task_states.IMAGE_PENDING_UPLOAD}}] + func_call_matcher = matchers.FunctionCallMatcher(expected_calls) self._create_vm() info = self.conn.get_info({'name': 1}) self._check_vm_info(info, power_state.RUNNING) - self.conn.snapshot(self.context, self.instance, "Test-Snapshot") + self.conn.snapshot(self.context, self.instance, "Test-Snapshot", + func_call_matcher.call) info = self.conn.get_info({'name': 1}) self._check_vm_info(info, power_state.RUNNING) + self.assertIsNone(func_call_matcher.match()) def test_snapshot_non_existent(self): self._create_instance_in_the_db() self.assertRaises(exception.InstanceNotFound, self.conn.snapshot, - self.context, self.instance, "Test-Snapshot") + self.context, self.instance, "Test-Snapshot", + lambda *args, **kwargs: None) def test_reboot(self): self._create_vm() diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 3ca69dc4c..8b57dfef4 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -397,6 +397,7 @@ class XenAPIVMTestCase(stubs.XenAPITestBase): self.assertThat(fake_diagnostics, matchers.DictMatches(expected)) def test_instance_snapshot_fails_with_no_primary_vdi(self): + def create_bad_vbd(session, vm_ref, vdi_ref, userdevice, vbd_type='disk', read_only=False, bootable=False, osvol=False): @@ -417,9 +418,20 @@ class XenAPIVMTestCase(stubs.XenAPITestBase): image_id = "my_snapshot_id" self.assertRaises(exception.NovaException, self.conn.snapshot, - self.context, instance, image_id) + self.context, instance, image_id, + lambda *args, **kwargs: None) def test_instance_snapshot(self): + expected_calls = [ + {'args': (), + 'kwargs': + {'task_state': task_states.IMAGE_PENDING_UPLOAD}}, + {'args': (), + 'kwargs': + {'task_state': task_states.IMAGE_UPLOADING, + 'expected_state': task_states.IMAGE_PENDING_UPLOAD}}] + func_call_matcher = matchers.FunctionCallMatcher(expected_calls) + stubs.stubout_instance_snapshot(self.stubs) stubs.stubout_is_snapshot(self.stubs) # Stubbing out firewall driver as previous stub sets alters @@ -428,7 +440,8 @@ class XenAPIVMTestCase(stubs.XenAPITestBase): instance = self._create_instance() image_id = "my_snapshot_id" - self.conn.snapshot(self.context, instance, image_id) + self.conn.snapshot(self.context, instance, image_id, + func_call_matcher.call) # Ensure VM was torn down vm_labels = [] @@ -447,6 +460,9 @@ class XenAPIVMTestCase(stubs.XenAPITestBase): self.assertEquals(vbd_labels, [instance['name']]) + # Ensure task states changed in correct order + self.assertIsNone(func_call_matcher.match()) + # Ensure VDIs were torn down for vdi_ref in xenapi_fake.get_all('VDI'): vdi_rec = xenapi_fake.get_record('VDI', vdi_ref) |
